
//for live
var url;
    url="http://www.mastholiday.com";

//for local
    //url="http://192.168.5.10/mastholiday.com";

 function topdestinations() {
	var e, i = 0;
	while (e = document.getElementById('gallery').getElementsByTagName ('DIV') [i++]) 
	{
		if (e.className == 'on' || e.className == 'off') 
		{
			e.onclick = function () 
			{
				var getEls = document.getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) 
				{
					getEls[z].className=getEls[z].className.replace('show', 'hide');
					getEls[z].className=getEls[z].className.replace('on', 'off');
				}
				this.className = 'on';
				var max = this.getAttribute('title');
				document.getElementById(max).className = "show";
			}
		}
	}
}

function displayTopDestinations(category,id)
{
	if (category=="")
	{
		category="india";
	}
	
	var url_=url+"/topdestination.php?category="+category;
	//alert(url_);
	callByAjax(url_,id);

	
}
function removeJunk(evt)
{
	var myKeyCode=0;
	if(window.event)
	{
		myKeyCode=evt.keyCode;
	}
	else
		myKeyCode=evt.which;
	//alert(myKeyCode);
	if(myKeyCode==34 || myKeyCode==39)
	{
		return false;
	}
    return true
}
function getCategoryByAjax(url,id)
{
	//alert(url);
	var xmlHttp_html=GetXmlHttpObject();
	var systemTime= "&ms="+new Date().getTime();
	url=url+systemTime;
	showLoader(id);
	xmlHttp_html.open("GET",url,true);
	//xmlHttp_html.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//xmlHttp_html.setRequestHeader("Content-length", parameters.length);
   // xmlHttp_html.setRequestHeader("Connection", "close");
  	xmlHttp_html.onreadystatechange=sendReq;

	function sendReq()
	{
		if(xmlHttp_html.readyState==4)
		{
			
			if(xmlHttp_html.status==200)
			{	
				getdata=xmlHttp_html.responseText;
				var arrData=new Array();
				arrData=getdata.split('`');
				//alert(arrData[1]);
				document.getElementById(id).innerHTML=arrData[1];
				if(document.getElementById('totalPrice'))
				{
					//alert(arrData[0]);
					document.getElementById('totalPrice').innerHTML='Rs. 0.00';
				}

			}
			else
				document.getElementById(id).innerHTML="";
			//hideBslLoader(id);	
		}
		
	
	}
	xmlHttp_html.send(null); 
		
}
function callByAjax(url,id)
{
	var xmlHttp_html=GetXmlHttpObject();
	var systemTime= "&ms="+new Date().getTime();
	url=url+systemTime;
	showLoader(id);
	//alert(url);
	xmlHttp_html.open("GET",url,true);
	//xmlHttp_html.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//xmlHttp_html.setRequestHeader("Content-length", parameters.length);
   // xmlHttp_html.setRequestHeader("Connection", "close");
  	xmlHttp_html.onreadystatechange=sendReq;

	function sendReq()
	{
		//alert(xmlHttp_html.readyState);
		if(xmlHttp_html.readyState==4)
		{
		//alert(xmlHttp_html.status);	
			if(xmlHttp_html.status==200)
			{	
				getdata=xmlHttp_html.responseText;
				//alert(getdata);
				document.getElementById(id).innerHTML=getdata;

			}
			else
				document.getElementById(id).innerHTML="";
			//hideBslLoader(id);	
		}
		
	
	}
	xmlHttp_html.send(null); 
		
}

function T_BSL_showDiv(id)
{
    document.getElementById(id).style.visibility="visible";
	document.getElementById(id).style.display='block';
}

function T_BSL_hideDiv(id)
{
    document.getElementById(id).style.visibility="hidden";
	document.getElementById(id).style.display='none';
}

function loginByAjax(url,id)
{
	
	var xmlHttp_html=GetXmlHttpObject();
	var systemTime= "&ms="+new Date().getTime();
	url=url+systemTime;
	
	showLoader(id);
	xmlHttp_html.open("GET",url,true);
	//xmlHttp_html.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//xmlHttp_html.setRequestHeader("Content-length", parameters.length);
   // xmlHttp_html.setRequestHeader("Connection", "close");
  	xmlHttp_html.onreadystatechange=sendReq;

	function sendReq()
	{
		if(xmlHttp_html.readyState==4)
		{
			
			if(xmlHttp_html.status==200)
			{	
				var arr=new Array();
				var i=0;
				var url='';
				getdata=xmlHttp_html.responseText;
				//alert(getdata);
				arr=getdata.split("~");
				url=arr[1];
				if(arr[0].toUpperCase()=="SUCCESS")
				{
					/*var arr1=new Array();
					var divInnerData='';
					var div=document.createElement("div");
					for(i=1;i<arr.length;++i)
					{
						arr1=arr[i].split("#");
						divInnerData=divInnerData+'<input type="hidden" name="'+arr1[0]+'" value="'+arr1[1]+'">';
						

					}
					div.innerHTML=divInnerData;
					document.getElementById('inputFieldDiv').appendChild(div);
					*/
					document.myForm.submit();
				}
				else
				{
					document.getElementById(id).innerHTML=getdata;
					
				}

			}
			else
				document.getElementById(id).innerHTML="";
			//hideBslLoader(id);	
		}
		
	
	}
	xmlHttp_html.send(null); 

}


function validateRegistration()
{
     if(document.getElementById('title').value=='')
	{
		alert('Please select a title!');
		document.getElementById('title').focus();
		return false
	}
    if(document.getElementById('firstName').value=='')
	{
		alert('Please enter your first name!');
		document.getElementById('firstName').focus();
		return false
	}
	if(document.getElementById('lastName').value=='')
	{
		alert('Please enter last name!');
		document.getElementById('lastName').focus();
		return false
	}
	if(!isValidEmail(document.getElementById('email1').value))
	{
		alert("Please Enter a valid Email address");
        
		document.getElementById('email1').focus();
		return false;
	}
	if(document.getElementById('altEmail').value!='')
	{
		if(!isValidEmail(document.getElementById('altEmail').value))
		{
			alert("Please Enter a valid alternate email!");
			document.getElementById('altEmail').focus();
			return false;
		}
		if(document.getElementById('altEmail').value==document.getElementById('email').value)
		{
			alert('Alternate email should be different from your primary email!');
			document.getElementById('altEmail').focus();
			return false;
		}
	}
	if(document.getElementById('password1').value=='')
	{
		alert('Please type a password!');
		document.getElementById('password1').focus();
		return false;
	}
	if(document.getElementById('password2').value=='')
	{
		alert('Please retype password!');
		document.getElementById('password2').focus();
		return false;
	}
	if(document.getElementById('password1').value!=document.getElementById('password2').value)
	{
		alert('Please re-type the password correctly!');
		document.getElementById('password1').focus();
		return false;
	}
	if(document.getElementById('yourCountry').value=='')
	{
		alert('Please enter your country!');
		document.getElementById('yourCountry').focus();
		return false;
	}
	if(document.getElementById('phoneNo').value=='')
	{
		alert('Please enter your contact no!');
		document.getElementById('phoneNo').focus();
		return false;
	}
	if(document.getElementById('address').value=='')
	{
		alert('Please give your address!');
		document.getElementById('address').focus();
		return false;
	}
    return true;
}

function registerByAjax(url,id)
{
	var xmlHttp_html=GetXmlHttpObject();
    var title=document.getElementById('title').value;
    var firstName=document.getElementById('firstName').value;
    var middleName=document.getElementById('middleName').value;
    var lastName=document.getElementById('lastName').value;
    var email=document.getElementById('email1').value;
    var altEmail=document.getElementById('altEmail').value;
    var password1=document.getElementById('password1').value;
    var password2=document.getElementById('password2').value;
    var country=document.getElementById('yourCountry').value;
	var phoneNo=document.getElementById('phoneNo').value;
    var address=document.getElementById('address').value;
	if(validateRegistration()==false)
        {
            return false;
        }
	showBslLoader(id);
	xmlHttp_html.open("POST",url,true);
	xmlHttp_html.onreadystatechange=register;
	xmlHttp_html.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_html.send("title="+ title +"&firstName=" + firstName + "&middleName="+ middleName +"&lastName=" + lastName + "&email=" + email + "&altEmail=" +  altEmail + "&password1=" + password1 + "&password2=" + password2 +
		"&country=" + country + "&phoneNo=" + phoneNo + "&address=" + address);
	//xmlHttp_html.setRequestHeader("Content-length", parameters.length);
   //xmlHttp_html.setRequestHeader("Connection", "close");

    function register()
    {
        if(xmlHttp_html.readyState==4)
        {

            if(xmlHttp_html.status==200)
            {
                getdata=xmlHttp_html.responseText;
                var arrData=new Array();
                arrData=getdata.split('`');
                if(arrData[0]=="SUCCESS")
                    {
                        document.myForm.submit();
                    }
                    else
                        {
                            document.getElementById(id).innerHTML=arrData[1];
                        }
                //alert(getdata);
                
                 hideBslLoader(id);
                //alert(getdata);

            }
            //else
                //document.getElementById(id).innerHTML="";
            //hideBslLoader(id);
        }
    }
}

function showLoader(divId)
{
	
	if(document.getElementById(divId))
		document.getElementById(divId).innerHTML="<div id='loaderDiv'><b>Loading</b>...</div>";
	 
	// document.parentWindow.document.getElementById(divId).appendChild(newDiv);
}

function selectOption(divId,enableFlag)
{

	if(enableFlag=="theme")
		document.getElementById(divId).innerHTML='<strong> Select Theme :</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<select name="themeid" class="frm2" id="themeid" \><option value="">---- Select Theme ---</option></select>';
	else if(enableFlag=="city")
		document.getElementById(divId).innerHTML='<strong> Select City/Region :</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<select name="city" class="frm2" id="city" ><option value="">---- Select City ----</option> </select>';
	else
		document.getElementById(divId).innerHTML='<strong> Enter Keyword :</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="keyword" id="keyword" class="frm2" onkeypress="return removeJunk(event)" size="25" onblur="this.style.background=\'#FFFFFF\'" onfocus="this.style.background=\'#B3EE3A\'" />';

	return true;
}

function fillThemeCity(url,opt)
{
	
	if(url=="")
		return ;
	var id;

	if(document.getElementById(opt))
		id=opt;
	else if(document.getElementById('city'))
		id='city';
	if(document.getElementById(id))
	{
		opt=document.getElementById(id);
		
		sendReqByAjax(url+"&flag="+id,opt);
	}
	

}
function fillTheme(url,opt)
{
	
	if(url!="")
	{
		sendReqByAjax(url+"&flag=themeid",document.getElementById(opt));
	}
	

}

function sendReqByAjax(url,opt)
{
	
		opt.options[0].text="----- Please Wait -----";
		var xmlHttp_html=GetXmlHttpObject();
		var systemTime= "&ms="+new Date().getTime();
		url=url+systemTime;
		
		xmlHttp_html.open("GET",url,true);
		xmlHttp_html.onreadystatechange=sendReq;

		function sendReq()
		{
			if(xmlHttp_html.readyState==4)
			{
				
				if(xmlHttp_html.status==200)
				{	
					getdata=xmlHttp_html.responseText;
					
					splitData(opt,getdata);

				}
				else
					opt.options[0].text="---- Error On Load ------";
				
			}
			
		
		}
		xmlHttp_html.send(null); 
	
}

function splitData(opt,string)
{
		var array="";
		
		opt.options.length=1;
		array=string.split("~");
	
		var i=0;
		for(i=0;i<array.length;i++)
		{
			var str=array[i];
			var arr=str.split("#");
			var obj = new Option(arr[1],arr[0]);
			opt.options[opt.options.length]=obj;
		}
		if(opt)
			opt.options[0].text="---- Please Select -----";
		
	return true;
}

function displayMap(tourId,id)
{
	if(document.getElementById(id))
	document.getElementById(id).innerHTML='<iframe src="'+url+'/map/bslmap.php?id='+tourId+'&mapWidth=718&mapHeight=669" align="center" name="airline" width="740" height="695" scrolling="No" frameborder="0"></iframe>';
}

function validate(frm)
{
	frm=document.getElementById(frm);
	if(frm.countryid.selectedIndex==0)
	{
		alert("Please select Country!");
		frm.countryid.focus();
		return false;
	}
	if(document.getElementById('themeid'))
	if(document.getElementById('themeid').selectedIndex==0)
	{
		alert("Please select Activity/Theme!");
		document.getElementById('themeid').focus();
		return false;
	}
	if(document.getElementById('city'))
	if(document.getElementById('city').selectedIndex==0)
	{
		alert("Please select City/Region!");
		document.getElementById('city').focus();
		return false;
	}
	if(document.getElementById('keyword'))
	if(document.getElementById('keyword').value=="")
	{
		alert("Please enter keyword!");
		document.getElementById('city').focus();
		return false;
	}
	return true;
}



// Removes leading whitespaces
   function LTrim( value )
   {
       var re = /\s*((\S+\s*)*)/;
    	return value.replace(re, "$1");

   }




   // Removes ending whitespaces
   function RTrim( value ) {
  	var re = /((\s*\S+)*)\s*/;
   	return value.replace(re, "$1");

    }

    // Removes leading and ending whitespaces
    function trim( value ) {

    	return LTrim(RTrim(value));

    }


function showBslLoader(divId)
{
	
	var oldDiv=document.getElementById(divId);
	 newDiv = document.createElement("div");
	 newDiv.className="loading";
	 newDiv.setAttribute('id','loaderDiv');

	 newDiv.innerHTML = "<b>Loading</b>...";
	 oldDiv.appendChild(newDiv);
	// document.parentWindow.document.getElementById(divId).appendChild(newDiv);
}


function hideBslLoader(divId)
{
	var oldDiv=document.getElementById(divId);
	var newdiv = document.getElementById('loaderDiv');
		oldDiv.removeChild(newdiv);
}


function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
		xmlHttp=new XMLHttpRequest();
  }
  catch (trymicrosoft)
    {
    try
      {
		//xmlHttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (othermicrosoft)
      {
		try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch(failed)
		{
			xmlHttp=null;
		}
      }
    }
	if(xmlHttp==null)
		alert("Error create request object!");
  return xmlHttp;
}

