// JavaScript Document
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var xmlhttp = createRequestObject();
function getImage(url){
	xmlhttp.open('get', url, true);
	xmlhttp.onreadystatechange = function() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
			document.getElementById("image").innerHTML = xmlhttp.responseText;	
	}
	xmlhttp.send(null);

}
function getBigImage(url){
	xmlhttp.open('get', url, true);
	xmlhttp.onreadystatechange = function() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
			document.getElementById("image").innerHTML = xmlhttp.responseText;	
	}
	xmlhttp.send(null);
}
function nextStream(url){
	xmlhttp.open('get', url, true);
	xmlhttp.onreadystatechange = function() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
			document.getElementById("stream").innerHTML = xmlhttp.responseText;	
	}
	xmlhttp.send(null);

}
function bigStream(url){
	xmlhttp.open('get', url, true);
	xmlhttp.onreadystatechange = function() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
			document.getElementById("content_area").innerHTML = xmlhttp.responseText;	
	}
	xmlhttp.send(null);

}
var ajax = new sack();
function whenLoading(){
	var e = document.getElementById('alert'); 
	e.innerHTML = "<p>Sending Data...</p>";
}

function whenLoaded(){
	var e = document.getElementById('alert'); 
	e.innerHTML = "<p>Data Sent...</p>";
}

function whenInteractive(){
	var e = document.getElementById('alert'); 
	e.innerHTML = "<p>Getting data...</p>";
}

function whenCompleted(){
	
	
	sentStatus="<p>Data sent status :"+ajax.responseStatus[1]+"</p>";
	
	var e = document.getElementById('alert'); 
	if (ajax.responseStatus){
		var string = sentStatus;
	} else{
		var string = sentStatus;	
	}
	//e.innerHTML = string;	
	
	
}
function getNights(obj,site_url){
	var from_date =document.reservation.from_period.value ;
	var to_date = document.reservation.to_period.value;
	xmlhttp.open('get', 'http://'+site_url+'/getNights.php?from_date='+ from_date +'&to_date='+to_date, true);
	xmlhttp.onreadystatechange = function() {
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
				 document.getElementById("nights").innerHTML = xmlhttp.responseText;			
		}
		xmlhttp.send(null);
	
}
function send(site_url,apps_url,lang){
	var form = document.getElementById('form');
	ajax.setVar("name", form.name.value); 
	ajax.setVar("email", form.email.value);
	ajax.setVar("phone", form.phone.value);
	ajax.setVar("message", form.message.value);
	ajax.setVar("validator", form.validator.value);
	ajax.setVar("lang", lang);
	
	ajax.requestFile = "http://"+apps_url+"/process.php";
	ajax.method = form.method;
	ajax.element = 'alert';
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();	
}
function sendReservation(site_url,apps_url,lang){
	
	var form = document.getElementById('form');
	ajax.setVar("acco_name", form.acco_name.value);
	ajax.setVar("adults", form.adults.value);
	ajax.setVar("children", form.children.value);
	ajax.setVar("infants", form.infants.value);
	ajax.setVar("bedroom", form.bedroom.value);
	ajax.setVar("from_period", form.from_period.value);
	ajax.setVar("to_period", form.to_period.value);
	ajax.setVar("night", form.night.value);
	ajax.setVar("adults", form.adults.value);
	ajax.setVar("name", form.name.value); 
	ajax.setVar("email", form.email.value);
	ajax.setVar("phone", form.phone.value);
	ajax.setVar("fax", form.fax.value);
	ajax.setVar("address1", form.address1.value);
	ajax.setVar("address2", form.address2.value);
	ajax.setVar("city", form.city.value);
	ajax.setVar("state", form.state.value);
	ajax.setVar("postal_code", form.postal_code.value);
	ajax.setVar("country", form.country.value);
	ajax.setVar("validator", form.validator.value);
	ajax.setVar("lang", lang);
	
	ajax.requestFile = "http://"+apps_url+"/process.php";
	ajax.method = form.method;
	ajax.element = 'alert';
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();	
}
function sendComments(site_url,apps_url,lang,page_id,menu_id,sef,prc){
	
	var form = document.getElementById('commentform');
	
	ajax.setVar("lname", form.lname.value);
	ajax.setVar("lemail", form.lemail.value);
	ajax.setVar("lwebsite", form.lwebsite.value);
	ajax.setVar("lpage_id", page_id);
	ajax.setVar("lmenu_id", menu_id);
	ajax.setVar("sef", sef);
	ajax.setVar("prc", prc);
	ajax.setVar("site_url", site_url);
	ajax.setVar("lcomment", form.lcomment.value);
	ajax.setVar("validator", form.validator.value);
	ajax.setVar("lang", lang);	
	ajax.requestFile = "http://"+apps_url+"/process.php";
	ajax.method = form.method;
	ajax.element = 'alert';
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	form.lcomment.value="";
	ajax.runAJAX();	
	form.submit();

}
function resend(site_url,apps_url){
	
	var form = document.getElementById('resendform');
	ajax.setVar("email", form.email.value);
	ajax.setVar("oldemail", form.oldemail.value);
	ajax.requestFile = "http://"+apps_url+"/resend.php";
	ajax.method = form.method;
	ajax.element = 'alert';
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	
	ajax.runAJAX();	
	

}
function uploadAvatar(div){
	var form = document.getElementById('commentform');
	if(!form.lname.value){
		alert("Please fill your name");	
		form.name.focus();
	}else if(!form.lemail.value){
		alert("Please fill your email");
		form.email.focus();
	}else{
		obj = document.getElementById(div);
		avatar_frm = document.getElementById('avatar_form');
		avatar_frm.email_avatar.value=form.lemail.value;
		avatar_frm.name_avatar.value=form.lname.value;
		avatar_frm.website.value=form.lwebsite.value;
		if (obj.style.display == "none") {
			obj.style.display = "block";
		} else {
			obj.style.display = "none";
		}
	}
}
function verifyAvatar(frm){
	if(!frm.avatar.value){
		alert("Please choose your image");
		return false;
	}else{
		return true;	
	}
}
function clearText(obj){
	
	obj.value="";
}
function checkClear(obj){
	if(obj.name=="keywords" && obj.value==""){
		obj.value="keywords";	
	}else if(obj.name=="name" && obj.value==""){
		obj.value="name";	
	}
}


