//
// Scripts
//



//   POPUP OPENING FUNCTIONS
function getFrameWidth(){
	var frameWidth = 0;
	if (self.innerWidth){
		frameWidth = self.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth){
		frameWidth = document.documentElement.clientWidth;
	}else if (document.body){
		frameWidth = document.body.clientWidth;
	}
	return frameWidth;
}
function getFrameHeight(){
	var frameHeight = 0;
	if (self.innerWidth){
		frameHeight = self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientWidth){
		frameHeight = document.documentElement.clientHeight;
	}else if (document.body){
		frameHeight = document.body.clientHeight;
	}
	return frameHeight;
}

function centerPopup(width,height){
	var frameWidth = getFrameWidth();
	var frameHeight = getFrameHeight();
	var leftF = Math.round( (frameWidth - width) / 2 ) ; 
	var topF  = Math.round( (frameHeight - height) / 2 ) ;
	var coordinates = new Array(leftF,topF);

	return coordinates;
}

function openPopup(url,width,height){
	var xy = new Array();
	xy = centerPopup(width,height);
	var leftD = xy[0];
	var topD = xy[1];
	//popUpWin = open(url, 'popUpWin','toolbar=0,location=0,scrollbars=1,resizable=0,width='+width+',height='+height +',screenX='+ (leftD+screenX)+',screenY='+ (topD+screenY));
	popUpWin = open(url, 'popUpWin','toolbar=0,location=0,scrollbars=1,resizable=0,width='+width+',height='+height +',left='+ leftD +',top='+ topD );
	popUpWin.focus();
}
// end popup opening functions



function asyncImage(amodsw){
	
	// Part 1: Get an object, regardless  of browser...
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
    } catch (e)  {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
    }
	
	// Part 2: Do the async stuff
	var i = document.getElementById('imageOut');
	var w = document.getElementById('imageOutWait');
	var d = document.getElementById('f_rooms');
	//alert('ena');
	xmlHttp.onreadystatechange=function() 
	{
		if(xmlHttp.readyState==4) 
		{
			
			i.style.display = 'block';
			w.style.display = 'none';
			i.innerHTML = xmlHttp.responseText ;
		}else{
			w.style.display = "block";
			i.style.display = "none";
			//vidDiv.innerHTML = "<html><body><div align=\"center\"><br><img src=\"../images/040.gif\" ></div></body></html>";
			//vidDiv.innerHTML = '<br><br><br><br><br><br><br><img src="images/040.gif">';
		}	
	}
	

	
 	var newURI = amodsw + 'contact/doAsyncImage.php?room=' + d.value;
	//alert(newURI);
	//return;
	xmlHttp.open("GET",newURI,true);
	xmlHttp.send(null);

} 


// For rollover effects -- on & off
function switchOn(imgName){
   if (document.images){
      imgOn=eval(imgName + "_on.src");
      document[imgName].src= imgOn;
    }
}

function switchOff(imgName){
   if (document.images){
      imgOff=eval(imgName + "_off.src");
      document[imgName].src= imgOff;
    }
}




function replaceAll( str, from, to ) {
	var idx = str.indexOf( from );
	while ( idx > -1 ) {
		str = str.replace( from, to );
		idx = str.indexOf( from );
	}
	return str;
}


function showHide(sub){
	//alert('showhiding: ' + sub);
	d = document.getElementById(sub);
	if(d.style.display == 'none'){
		d.style.display = 'block';
	}else{
		d.style.display = 'none';
	}         
}


function setHomepage(url){
	this.style.behavior='url(#default#homepage)';
	this.setHomePage(url);
}


function addBookmark(url,title){

	if( window.sidebar && window.sidebar.addPanel ) {
	    //Gecko (Netscape 6 etc.) - add to Sidebar
	    window.sidebar.addPanel( title,url,'target="_content"' );
	} else if( window.external && ( navigator.platform == 'Win32' ||
	      ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
	    //IE Win32 or iCab - checking for AddFavorite produces errors in
	    //IE for no good reason, so I use a platform and browser detect.
	    //adds the current page as a favourite; if this is unwanted,
	    //simply write the desired page in here instead of 'location.href'
	    window.external.AddFavorite( url,title);
	} else if( window.opera && window.print ) {
	    //Opera 6+ - add as sidebar panel to Hotlist
	    //return true;
	} else if( document.layers ) {
	    //NS4 & Escape - tell them how to add a bookmark quickly (adds current page, not target page)
	    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
	} else {
	    //other browsers - tell them to add a bookmark (adds current page, not target page)
	    window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
	}
	//return false;
}



  
// What's this? :-S
function jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// This is for the inform a friend page (usually a popup with a form). It's used to 'automatically' refresh the contents
// of the message the visitor sends to his/her friend.
function updatePreview(){
	et = document.getElementById('eText');
	sn = document.getElementById('sName');
	rn = document.getElementById('rName');
	rm = document.getElementById('rMail');
	bt = document.getElementById('bText');
	rp = document.getElementById('recPreview');
	pl = document.getElementById('page');

	// Bother only if at least one field has something
	if ( (et.value.length > 0) || (sn.value.length > 0) || (rn.value.length > 0)  ) {
		tmp = bt.value.replace(/{RNAME}/,rn.value);
		tmp1 = tmp.replace(/{SNAME}/,sn.value);
		tmp1 = tmp1.replace(/{RMAIL}/,rm.value);		
		tmp1 = tmp1.replace(/{PROD}/,pl.value);	
		tmp1 = replaceAll(tmp1,'\n','<br>');
		tmp2 = replaceAll(et.value,'\n','<br>');
		rp.innerHTML = tmp1 + "<br><br>" + tmp2;
	}
}

// This is for the inform a friend page (usually a popup with a form). It's used to 'automatically' refresh the contents
// of the message the visitor sends to his/her friend.
function copyText(){
	bt = document.getElementById('bText');
	rp = document.getElementById('recPreview');
	bt.value = rp.innerHTML;

}


// -------------------

function showAdminSectionOptions(newURI){
	// Part 1: Get an object, regardless  of browser...
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
    } catch (e)  {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
    }
	
	// Part 2: Do the async stuff
	xmlHttp.onreadystatechange=function() 
	{
		var optionsDiv = document.getElementById('optionsDiv');
		
		if(xmlHttp.readyState==4) 
		{
			optionsDiv.style.opacity= "1";
			//wait.style.display = "none";
			//hideFieldsDiv.innerHTML = "1"+xmlHttp.responseText + "2<br>";
			optionsDiv.innerHTML = xmlHttp.responseText ;
		}else{
			//wait.style.display = "block";
			optionsDiv.style.opacity= ".60";
			optionsDiv.innerHTML = "<html><body><div align=\"center\"><br><img src=\"../images/040.gif\" ></div></body></html>";
		}	
	}
 
	xmlHttp.open("GET",newURI,true);
	xmlHttp.send(null);

} 


/*
//    OLD POPUP FUNCTIONS

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {  // This is not used anymore, it's commented out - keep for a while just in case

	//alert('You dont exist, I will open you now');
	//popUpWin = open(URLStr, 'popUpWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin = open(URLStr, 'popUpWin','toolbar=0,location=0,scrollbars=1,resizable=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.moveTo(100,100);

}


function hop(url, win, width, height, options){
	var leftPos = (screen.availWidth - width) / 2;
	var topPos = (screen.availHeight - height) / 2;
	options += 'toolbar=0,location=0,scrollbars=1,resizable=0,width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
	//return window.open(url, win, options);
	
	return window.open(url, win, options);
}
*/


