/*
Ascentia Scripts
Sean Hecking
Brulant
sean.hecking@brulant.com
Created 10.10.07
Modified 12.6.07
*/

//getElementsByClassName()
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};


var _currentId = -1;
 function togglePopup(id){
	var myPopup = document.getElementById(id);
	var myWindow = document.getElementById('popUpWindow');
		
	if(!(_currentId == id)){
		myWindow.innerHTML = myPopup.innerHTML;
		var myImg = myPopup.getElementsByTagName('img');
		var myPopUpImg = myWindow.getElementsByTagName('img');
		var myClasses = document.getElementsByClassName('popUpWindow');
		
		//Checks if classname is set to popupOn
		window.setInterval("centerIt('popUpWindow')", 10);
		myWindow.style.display = 'block';
		myWindow.className='popUpActivated';
		if(window.XMLHttpRequest) myPopUpImg[0].src=myImg[0].getAttribute('name')+'_lg.jpg';
		else myPopUpImg[0].src=myImg[0].attributes('name').value+'_lg.jpg';
		_currentId = id;
	} else {
		myWindow.className='popUpDeactived';
		myWindow.style.display = 'none';
		_currentId = -1;
	}
	
 }
 
// room style toggle popup
function togglePopup2(id){
	var myPopup = document.getElementById(id);
	var myWindow = document.getElementById('popUpWindow2');
		
	if(!(_currentId == id)){
		myWindow.innerHTML = myPopup.innerHTML;
		var myImg = myPopup.getElementsByTagName('img');
		var myPopUpImg = myWindow.getElementsByTagName('img');
		var myClasses = document.getElementsByClassName('popUpWindow2');
		
		//Checks if classname is set to popupOn
		window.setInterval("centerIt('popUpWindow2')", 10);
		myWindow.style.display = 'block';
		myWindow.className='popUpActivated';
		if(window.XMLHttpRequest) myPopUpImg[0].src=myImg[0].getAttribute('name')+'_lg.jpg';
		else myPopUpImg[0].src=myImg[0].attributes('name').value+'_lg.jpg';
		_currentId = id;
	} else {
		myWindow.className='popUpDeactived';
		myWindow.style.display = 'none';
		_currentId = -1;
	}
}


 	function centerIt(Idname){
		
		var my_width  = 0;
		var my_height = 0;
		
		if ( typeof( window.innerWidth ) == 'number' ){
			my_width  = window.innerWidth;
			my_height = window.innerHeight;
		}else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
			my_width  = document.documentElement.clientWidth;
			my_height = document.documentElement.clientHeight;
		}
		else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
			my_width  = document.body.clientWidth;
			my_height = document.body.clientHeight;
		}
	
		var scrollY = 0;
	
		if ( document.documentElement && document.documentElement.scrollTop ){
			scrollY = document.documentElement.scrollTop;
		}else if ( document.body && document.body.scrollTop ){
			scrollY = document.body.scrollTop;
		}else if ( window.pageYOffset ){
			scrollY = window.pageYOffset;
		}else if ( window.scrollY ){
			scrollY = window.scrollY;
		}
	
		var setX = ( my_width  - document.getElementById(Idname).style.width  ) / 2;
		var setY = ( my_height - document.getElementById(Idname).style.height ) / 2 + scrollY;
	
		setX = ( setX < 0 ) ? 0 : setX;
		setY = ( setY < 0 ) ? 0 : setY;
	
		//checks popupWindow2, popupWindow
		if(Idname=='popUpWindow2'){
			document.getElementById(Idname).style.left = setX - 392 + "px";
			document.getElementById(Idname).style.top  = setY - 300 + "px";
		}else{
			document.getElementById(Idname).style.left = setX - 282 + "px";
			document.getElementById(Idname).style.top  = setY - 200 + "px";
		}
	}
 
 
	function closePopUp(id){
		document.getElementById(id).style.display = 'none';
		document.getElementById(id).className='popUpDeactived';
	
  	}
	

function openstyleexplorer()
{
	myRef = window.open('/styleexplorer/flash/ise.html','mywin','left=20,top=20,width=810,height=620,toolbar=0,resizable=0');
}

/*=== footer popup window ===*/
function openFooter(footerName){
	//set the page name
	var myUrl = '/pages/'+footerName+'.html';
	//check to see if the right pages are called
	if(myUrl == 'terms' || 'privacy'){
		window.open(myUrl, 'footerWin', 'left=20,top=20,width=525,height=400,scrollbars=1,toolbar=0,resizable=0,status=0');
	}else{
		return false
	}
}
