function trim(strText)
{
/// TRIM STRING FUNCTION
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);
    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}

function reloadCaptcha(cScheme)
{
	var captcha = document.getElementById("captcha_image");
	captcha.innerHTML = "<img src=\"CaptchaSecurityImages.php?cScheme="+cScheme+"&width=70&height=25&characters=5\" align=\"absmiddle\">";
}

function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function sideMenu_roll(rollType, menuID)
{
	changeClass=(rollType=="over")?"sideMenu_over":"sideMenu_out";
	document.getElementById("sideMenu_"+menuID).className=changeClass;
	if (menuID<1)
		document.getElementById("sideMenu_topFill").className=changeClass;
}

function checkContact(curForm)
{
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (curForm[fieldName].value=="")
		{
			cMessage = eval("contAlert_"+fieldName);
			alert(cMessage);
			curForm[fieldName].focus();
			return false;
		 }
		 if (fieldName == "email" && !checkEmail(curForm.email.value))
		{
			alert(_tpl_emailNotValid);
			curForm.email.focus();
			return false;
		 }
	}

	if (trim(curForm.security_code.value) == "")
	{
		alert(contAlert_security);
		curForm.security_code.focus();
		return false;
	}

	var url = "ajax_functions.php?action=get_session&session_name=security_code";
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (xml.getElementsByTagName('session_var')[0] && xml.getElementsByTagName('session_var')[0].firstChild && xml.getElementsByTagName('session_var')[0].firstChild.data)
		{
			security_code = xml.getElementsByTagName('session_var')[0].firstChild.data;
		}
		else
		{
			security_code = "";
		}
	}
	if (trim(curForm.security_code.value) != security_code)
	{
		alert(contAlert_security);
		curForm.security_code.focus();
		return false;
	}

	return confirm(_confirm_continue);
}

function checkReservation(curForm)
{
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (curForm[fieldName].value=="")
		{
			cMessage = eval("contAlert_"+fieldName);
			alert(cMessage);
			curForm[fieldName].focus();
			return false;
		 }
		 if (fieldName == "email" && !checkEmail(curForm.email.value))
		{
			alert(_tpl_emailNotValid);
			curForm.email.focus();
			return false;
		 }
	}
	if (curForm.phone.value=="" && curForm.mobile.value=="")
	{
		alert(_tpl_phoneOrMobile);
		curForm.phone.focus();
		return false;
	 }
	 
	 if (trim(curForm.security_code.value) == "")
	{
		alert(contAlert_security);
		curForm.security_code.focus();
		return false;
	}

	var url = "ajax_functions.php?action=get_session&session_name=security_code";
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (xml.getElementsByTagName('session_var')[0] && xml.getElementsByTagName('session_var')[0].firstChild && xml.getElementsByTagName('session_var')[0].firstChild.data)
		{
			security_code = xml.getElementsByTagName('session_var')[0].firstChild.data;
		}
		else
		{
			security_code = "";
		}
	}
	if (trim(curForm.security_code.value) != security_code)
	{
		alert(contAlert_security);
		curForm.security_code.focus();
		return false;
	}
	return confirm(_confirm_continue);
}

function showPhoto(curPic, curWidth, curHeight){
	topVar=((screen.height / 2)-300);
	leftVar=((screen.width / 2)-300);
	calAttributes="width=650, height=550, top="+topVar+", left="+leftVar+", scrollbars=no, status=no, location=no, resizable=no, menubar=no, titlebar=no, toolbar=no";
	window.open("showPic.php?curPic="+curPic+"&curWidth="+curWidth+"&curHeight="+curHeight, "showPic", calAttributes);
}