// JavaScript Document
/*
Auto center window script
*/
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
myString = new String(mypage)
myRE = new RegExp("tellfriends.php", "i")
results = myString.match(myRE)
//win = window.open(mypage+'?refer='+this.location,myname,settings)
	if(results=="tellfriends.php"){ 
		return false;
	}else{
		win = window.open(mypage,myname,settings)
	}
}


function submitListGroup(){
	var hotelnamelist=document.getElementById("hotelname");
	if(hotelnamelist.value!=""){
		document.location = hotelnamelist.options[hotelnamelist.selectedIndex].value;
	}
}

function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}


function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}

function doTrim(obj){
	if(obj.length<3){ alert("Your fill-in must more than three characters");obj.focus();}
	if(chkDoubleStr(obj.value)==true){ alert("Duplicate characters, please revise it.");obj.focus();}
	return obj.value=Trim(obj.value);
}

function chkDoubleStr(STRING){
var explode=STRING.split("");
var count=new Array();
	for(i=0;i<explode.length-2;i++){
	if((explode[i]==explode[i+1]) && (explode[i]==explode[i+2])){
			 return true;break;
		}
}
}

 function maxlength(element, maxvalue)
     {
     var q = eval("document.pooh."+element+".value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. Please abbreviate "+
       "your text by at least "+r+" characters";
     if (q > maxvalue) alert(msg);
}

function checkdigit(val)
{
 if(isNaN(document.getElementById(val).value))
 {
	 if(val=='tel')
 		alert("Telephone number must be numeric");
	if(val=='mobile')
 		alert("Mobile number must be numeric");
	if(val=='tccode')
 		alert("Telephone country code must be numeric");
		if(val=='ccode')
 		alert("Mobile country code must be numeric");
	document.getElementById(val).value="";
	document.getElementById(val).focus(); 
	return;
 }
}

// use for resize page as same as footer on the page in hotel list, hotel details and other file what to use.
function reloadspace_hotel(type,visa){
	if(type==1){
		var leftHeight=document.getElementById("menuLeftbody").offsetHeight;
		var contentBodyHeight=(document.getElementById("contentBody").offsetHeight);
		var spaceHeight=0;
		var morespace=0;
		if(leftHeight>=contentBodyHeight){
			spaceHeight=leftHeight-contentBodyHeight;
			morespace=759;
		}
		
	alert('content : '+contentBodyHeight);
	alert('left : '+leftHeight);
	var newspaceHeight=morespace+spaceHeight+"px";
	if(visa>0){
		newspaceHeight=contentBodyHeight-visa+"px";
	}
	if(visa<0){
		newspaceHeight=visa+visa+contentBodyHeight+"px";
	}

//		var spaceHeight=leftHeight-contentBodyHeight;
//		var newspaceHeight=spaceHeight+"px";

	alert(newspaceHeight);
	//alert(spaceHeight);
	document.getElementById("space").style.height=newspaceHeight;
//	if (spaceHeight>0){ document.getElementById("space").style.height=newspaceHeight;}
	}
	if(type==0){
		document.getElementById("space").style.height="0px";
	}
}

function reloadspace(type){
	if(type==1){
		var leftHeight=document.getElementById("menuLeftbody").offsetHeight;
		var contentBodyHeight=(document.getElementById("contentBody").offsetHeight);
		var spaceHeight=0;
		var morespace=0;
		if(leftHeight>=contentBodyHeight){
			spaceHeight=leftHeight-contentBodyHeight;
			morespace=759;
		}
		
	//alert('content : '+contentBodyHeight);
	//alert('left : '+leftHeight);
	var newspaceHeight=visa+morespace+spaceHeight+"px";

//		var spaceHeight=leftHeight-contentBodyHeight;
//		var newspaceHeight=spaceHeight+"px";

	//alert(newspaceHeight);
	//alert(spaceHeight);
	if (spaceHeight>0){ document.getElementById("space").style.height=newspaceHeight;}
	}
	if(type==0){
		document.getElementById("space").style.height="0px";
	}
}

function reloadspacehotelist(type){
	if(type==1){
		var leftHeight=document.getElementById("menuLeftbody").offsetHeight;
		var contentBodyHeight=(document.getElementById("contentBody").offsetHeight);
		var spaceHeight;
		var morespace=0;
		if(leftHeight>=contentBodyHeight){
			spaceHeight=leftHeight-contentBodyHeight;
			morespace=150;
		}
			else spaceHeight=contentBodyHeight-leftHeight;

		var newspaceHeight=morespace+spaceHeight+"px";
//		alert(leftHeight);
//		alert(contentBodyHeight);
//		alert(newspaceHeight);
		//if (spaceHeight>0){ document.getElementById("space").style.height=newspaceHeight;}
		if(leftHeight>=contentBodyHeight)document.getElementById("space").style.height=newspaceHeight;
	}
	if(type==0){
		document.getElementById("space").style.height="0px";
	}
}
/**********************************************************************************************************************************************/

// LOAD FOOTER

var xmlHttp;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

function loadFooter(langid){
	createXMLHttpRequest();
	var url;
	if(langid=='russian'){
		url = "http://www.hoteluae.com/languages/russian/footer.php";
	}else{
		url = "http://www.hoteluae.com/languages/english/footer.html";
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				document.getElementById("showfooter").innerHTML = xmlHttp.responseText;
			}
		}
	};
	xmlHttp.send(null);

}

function saveValue(field,value) {
	createXMLHttpRequest();
	xmlHttp.open("GET", "http://www.hoteluae.com/hotel/onsavedfieldvalue.php?"+field+"="+encodeURI(value), true);
/*	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				//alert("session saved:"+xmlHttp.responseText);
				//document.getElementById("contactForm").value="";
				//document.getElementById("showimportstatus").innerHTML=xmlHttp.responseText;
			}
		}else{
			//document.getElementById("showimportstatus").innerHTML="Import emails is processing..., please wait.";
		}
	};
*/	
	xmlHttp.send(null);
}
