function getHTTPObject() {
  var xmlhttp;
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    
}
  return xmlhttp;

  
}
var http = getHTTPObject(); // We create the HTTP Object

/*
	Funtion Name=requestInfo 
	Param = url >> Url to call : id = Passing div id for multiple use ~ as a seprator for eg. div1~div2 :
	redirectPage >> if you like to redirect to other page once the event success then 
	the response text = 1 and the redirectPage not left empty
*/

    function requestInfo(url,id,redirectPage) {
		
		url="/phps/"+url.replace("$_",".php");
		//alert(url);      
		var temp=new Array();
			http.open("GET", url, true);
			http.onreadystatechange = function() {
				
				if (http.readyState == 4) {
					//alert(http.status);
				  if(http.status==200) {
			  		var results=http.responseText;
					//alert(results);
					if(redirectPage=="" || results!="1") {
						
						var temp=id.split("~"); // To display on multiple div 
						//alert(temp.length);
						var r=results.split("~"); // To display multiple data into the div 
						//alert(temp.length);
						if(temp.length>1) {
							for(i=0;i<temp.length;i++) {	
								//alert(temp[i]);
								document.getElementById(temp[i]).innerHTML=r[i];
							}
						} else {
							document.getElementById(id).innerHTML = results;
						}	
					} else {
						//alert('redirecting');
						//alert(results);
						window.location.href=redirectPage;			
					}
				  } 
  				}
			};
			http.send(null);
       }

	//Parameters for the function is as follows:
	// 1. url: URL to HIT fpr results
	// 2. id: The ID of the div to display the fetched results
	// 3. redirectPage: The page to redirect
	// 4. doRedirect: Shld be set to Y for redirect.
	// 5. divID: The ID of the DIV to show display the progress Message
	// 6. displayString: The String message to display for the progress bar.

	function requestDynInfo(url,id,redirectPage,doRedirect,divID,displayString) {
		if(divID != "") {
			document.getElementById(divID).style.visibility="visible";
			document.getElementById(divID).innerHTML="<img src='/images/loadingo.gif'> <font face='Tahoma' size='2' color='#000'>"+displayString+"</font><img src='/images/loadingo.gif'> ";
		}

		url="/phps/"+url.replace("$_",".php");
		//alert(url);      
		var results="";
		var temp=new Array();
			http.open("GET", url, true);
			http.onreadystatechange = function() {
				if (http.readyState == 4) {
					//alert(http.status);
				  if(http.status==200) {
			  		results = http.responseText;
					//alert(results);
					document.getElementById(id).innerHTML = results;
					if(divID != "") {
						document.getElementById(divID).innerHTML="";
						document.getElementById(divID).style.visibility="hidden";
					}

					if(redirectPage != "" && doRedirect=="Y" && results == 1) {
						document.location.href=redirectPage;
					}//end of redirectCheck
				  } 
  				}
			};
			http.send(null);
		return results;
       }

/*
	Function Name= emptyValidation
	Desc = This function is used to validation for the empty field 
	Param fieldList = This arguments set as a string varialble. you just need to supply the textbox name
	if the textbox is multiple then supply with ~ separator for eg. username~password
*/
function emptyValidation(fieldList) {
		//alert(fieldList);
		var field=new Array();
		field=fieldList.split("~");
		var counter=0;
		for(i=0;i<field.length;i++) {
			//alert(field[i]);
			if((field[i]) != "vchHotelPhoto") {
				if(document.getElementById(field[i]).value=="") {
					document.getElementById(field[i]).style.backgroundColor="#FF0000";
					counter++;
				} /*else {
					document.getElementById(field[i]).style.backgroundColor="#FFFFFF";	
				}*/
			}
		}
		if(counter>0) {
				alert("The Field mark as red could not left empty");
				return false;
				
		}  else {
			return true;
		}
		
}


function init_table() {
		requestInfo('listContentPages$_?tokenMode=list','showTable','');
	}
	

	
function confirmLink(theLink)
{
   
    var is_confirmed = confirm('Are you sure to delete this record?\n\nThis will permanently delete the Record!');
    if (is_confirmed) {
        theLink.href += '';
    }

    return is_confirmed;
}

function eMailCheck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 return true;				
}


function purchaseTour()
{
	document.getElementById('orderDiv').style.visibility='visible';
}
function cancelTour()
{
	document.getElementById('orderDiv').style.visibility='hidden';
}
function validateOrderForm()
{
	if(document.getElementById('contact').value=='')
	{
		alert('Phone Number cant be blank');
		return false;
	}
	if(document.getElementById('email').value=='')
	{
		alert('Email cant be blank');
		return false;
	}
	if(document.getElementById('fname').value=='')
	{
		alert('First Name cant be blank');
		return false;
	}
	if(document.getElementById('lname').value=='')
	{
		alert('Last Name cant be blank');
		return false;
	}
	
	if(isNaN(document.getElementById('contact').value))
	{
		alert('Phone number should be numeric');
		return false;
	}


}
