// JavaScript Document
function onKeyPressBlockNumbers(e)
{//alert(e.keyCode);
 var key = window.event ? e.keyCode : e.which;
 if(key==8 || key==45 || key==11 || e.keyCode==36 || e.keyCode==35 || e.keyCode==46 || e.keyCode==9 || e.keyCode==116 || e.keyCode==37 || e.keyCode==39) return true;
/* if(key==45) return true;
 if(key==11) return true;
 if(e.keyCode==9) return true;
 if(e.keyCode==116) return true;
 if(e.keyCode==37) return true;
 if(e.keyCode==39) return true;*/
 
var keychar = String.fromCharCode(key);
 reg = /\d/;
 return reg.test(keychar);
}

function Global_validate(obj)
  {
    var len=obj.length;
	for(i=0;i<len;i++)
	  {
	    if(obj.elements[i].title!='' && obj.elements[i].value=='' && obj.elements[i].disabled==false)
		  {
		    alert(obj.elements[i].title);
			obj.elements[i].focus();
			return false;
		  }
	  }
	return true;
  }
  
  function trimspaces(str)
		{
			while((str.indexOf(' ',0) == 0) && (str.length > 1))
			{
				str = str.substring(1, str.length);
			}
			while((str.lastIndexOf(' ') == (str.length - 1) && (str.length > 1)))
			{
				str = str.substring(0,(str.length - 1));
			}
			if((str.indexOf(' ',0) == 0) && (str.length == 1)) str = '';
			return str;
		}
		  
	function validate_form(Obj)
		{
				for ( i = 0; i < Obj.elements.length; i++) {
						formElem = Obj.elements[i];
						switch (formElem.type) {
								case 'text':
								case 'password':
								case 'select-one':
								case 'textarea':
								case 'select-multiple':
								case 'radio':
								case 'file':
										split_title=formElem.title.split("::");
										//alert(split_title[0]+"="+formElem.value);
										if(split_title[0]=='Fill' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill11' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill11')
										{
											

var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

var monthNames = new Array("January","February","March","April","May","June","July",
                           "August","September","October","November","December");

										var dt = new Date();
										var y  = dt.getYear();
										var d = dt.getDate();
										var m = dt.getMonth();
										// Y2K compliant
										if (y < 1000) y +=1900;
										
										var current_date= new Date(y,m+1,d)

										var mySplitResult1 = Obj.elements[0].value.split("/");
	
										var first_day = mySplitResult1[1];
										var first_month = mySplitResult1[0];
										var first_year = mySplitResult1[2];
										
										var first_new = new Date ( first_year, first_month, first_day )

										var mySplitResult2 = formElem.value.split("/");
	
										var second_day = mySplitResult2[1];
										var second_month = mySplitResult2[0];
										var second_year = mySplitResult2[2];
										
										var second_new = new Date ( second_year, second_month, second_day )
										
										if(current_date.getTime() > first_new.getTime())
										{
											alert('Check in date cannot be less than Current date');
											Obj.elements[0].focus();
											//formElem.focus();
											return false;
										}	
										
										
										if(first_new.getTime() > second_new.getTime())
										{
											alert('Check out date cannot be less than Check in date');
											formElem.focus();
											return false;
										}	
										}
										
										if(split_title[0]=='Fill2' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill2'  && isNaN(formElem.value)){
										alert('Please enter numeric value');
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill2'  && parseInt(formElem.value)<=0){
										alert('Please enter positive value grater than zero');
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill3' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill3' ){
											if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formElem.value)){
												}else{
													alert('Invalid E-mail Address! Please re-enter.');
													formElem.focus();
													return false;
											}
										}
										if(split_title[0]=='Fill31' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill31' ){
											if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formElem.value)){
												}else{
													alert('Invalid E-mail Address! Please re-enter.');
													formElem.focus();
													return false;
											}
										}
										if(split_title[0]=='Fill31' ){
											if(Obj.elements[i].value!=Obj.elements[i-1].value)
												{
													alert("Email Address Mismateched");
													formElem.focus();
													return false;
												}
										}
										if(split_title[0]=='Fill4' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill4' ){
											if(formElem.value !='')
												{
													var strLength = formElem.value.length;
													var spaceindex = formElem.value.lastIndexOf(' ');
													if(strLength < 6)
													{
														alert("Please enter "+formElem.name+" atleast 6 characters.");
														formElem.focus();
														return false;
													}
													if(spaceindex!='-1')
													{
														alert("Please remove space from "+formElem.name+".");
														formElem.focus();
														return false;
													}
												}
										}
										if(split_title[0]=='Fill8' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill8' ){
											if(formElem.value !='')
												{
													var strLength = formElem.value.length;
													var spaceindex = formElem.value.lastIndexOf(' ');
													if(strLength < 6)
													{
														alert("Please enter "+formElem.name+" atleast 6 characters.");
														formElem.focus();
														return false;
													}
													if(spaceindex!='-1')
													{
														alert("Please remove space from "+formElem.name+".");
														formElem.focus();
														return false;
													}
												}
										}
										if(split_title[0]=='Fill8' ){
											if(Obj.elements[i].value!=Obj.elements[i-1].value)
												{
													alert("Password Mismateched");
													formElem.focus();
													return false;
												}
										}
										
										//START-- CHECK IMAGE [M] FOR MANDATORY FIELD --//
										if(split_title[0]=='FillimgM')
										{
											if(formElem.value=='')
											{
												alert("Please Select a Image.");
												formElem.focus();
												return false;
											}
											
											var valid_extensions = /(.jpg|.jpeg|.png|.gif)$/;
											if(!valid_extensions.test(formElem.value.toLowerCase()))
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										//END-- CHECK IMAGE [M] FOR MANDATORY FIELD --//
										
										//START-- CHECK IMAGE [NM] FOR NOT MANDATORY FIELD --//
										if(split_title[0]=='FillimgNM')
										{
											if(formElem.value!='')
											{
												var valid_extensions = /(.jpg|.jpeg|.png|.gif)$/;
												if(!valid_extensions.test(formElem.value.toLowerCase()))
												{
													alert(split_title[1]);
													formElem.focus();
													return false;
												}
											}
										}
										//END-- CHECK IMAGE [NM] FOR NOT MANDATORY FIELD --//
														
										
										
										
										if(split_title[0]=='Fill5' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill5' && !isNaN(formElem.value)){
										alert("Please enter only letter");
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill6' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill6'  && isNaN(formElem.value)){
										alert('Please enter numeric value');
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill6'  && parseInt(formElem.value)<0){
										alert('Please enter positive value');
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill7'  && isNaN(formElem.value)){
										alert('Please enter numeric value');
										formElem.focus();
										return false;
										}
										if(split_title[0]=='Fill9' ){
											if(Obj.elements[i].value>0  && Obj.elements[i-2].checked==false)
												{
													alert(split_title[1]);
													formElem.focus();
													return false;
												}
										}
										
										if(split_title[0]=='Fill10' ){
											if(Obj.elements[i].checked==true && Obj.elements[i+2].value <=0 )
												{
													alert(split_title[1]);
													Obj.elements[i+2].focus();
													return false;
												}
										}	
									if(split_title[0]=='Fill17' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
									if(split_title[0]=='Fill17'){
										var strLength = formElem.value.length;
										if(strLength >115)
										{
											alert("Please enter maximum 115 characters "+formElem.name+".");
											formElem.focus();
											return false;
										}
									}	
								break;
								}
						}//end of for loop
						return true;
		}  

function CheckAll(obj)
{
	//alert(obj);
	var count = obj.elements.length;
	for (i=0; i < count; i++) 
	{
		if(obj.elements[i].type == 'checkbox')
			obj.elements[i].checked = obj.chkall.checked;
	}
}

function doAction(action,obj)
{
	//alert(action+" =="+obj);
	var count = obj.elements.length;
	
	var flag=false;
	var msg = "";
	for (i=0; i < count; i++) 
	{
		if(obj.elements[i].type == 'checkbox')
		{
			if(obj.elements[i].checked == 1)
			flag=true;
		}
	}
	if(flag==true)
	{
		if(action == "delete")
		{
			msg = "";			
		}
		if(window.confirm("Are you sure to delete this record?\n"+msg))
		{
			obj.action.value=action;
			obj.submit();
		}
		else
		{
			var count = obj.elements.length;
			for (i=0; i < count; i++) 
			{
							obj.elements[i].checked =0;
							flag=false;
			}
		}
	}
	else
		alert("Please select at least one Record to perform the action.");
}

function delete_record(id)
{
	var count = document.adminForm.elements.length;
	var flag=false;
	var msg = "";
	for (i=0; i < count; i++) 
	{
		if(document.adminForm.elements[i].type == 'checkbox')
		{
			if(document.adminForm.elements[i].value==id){
			document.adminForm.elements[i].checked =1;
			flag=true;
			}
		}
	}
	if(flag==true)
	{
		if(window.confirm("Are you sure to delete this record?\n"+msg))
		{
			document.adminForm.action.value='delete';
			document.adminForm.submit();
		}
	else
		{
			var count = document.adminForm.elements.length;
			for (i=0; i < count; i++) 
			{
					if(document.adminForm.elements[i].value==id)
						{
							document.adminForm.elements[i].checked =0;
							flag=false;
						}
			}
		}
	}
	
}


function next_link(ref,pulse)
{

		window.location.href='./?pulse='+pulse;
}


function validate_password()
		{
			if(document.changePassword.old_password.value=="")
				{
					alert("Please Enter The Old Password");
					document.changePassword.old_password.focus();
					return false;
				}
			if(document.changePassword.new_password.value=="")
				{
					alert("Please Enter The New Password");
					document.changePassword.new_password.focus();
					return false;
				}
			if((document.changePassword.confirm_password.value==""))
				{
					alert("Please Enter The Confirm Password");
					document.changePassword.confirm_password.focus();
					return false;
				}
			if(document.changePassword.new_password.value!=document.changePassword.confirm_password.value)
				{
					alert("Password Mismateched");
					document.changePassword.confirm_password.focus();
					return false;
				}
			return true;
		}
		
function activity_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("activities.php?activity_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}
function interest_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("interests.php?interest_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function destination_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("admin-home.php?destination_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function link_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("links.php?link_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function hotel_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("hotels.php?hotel_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function room_status_fun(action,what,hotel_id)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("view-room.php?id="+hotel_id+"&room_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}
function testimonial_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("testimonial.php?testimonial_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function user_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("list-users.php?user_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function state_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("locations.php?state_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function city_status_fun(action,what,state_id)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("cities.php?id="+state_id+"&city_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function category_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("package-category.php?category_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function travel_cat_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("travel-category.php?travel_cat_id="+what+"&status="+action+"&limitstart="+lstart);
	}		
function travel_status_fun(action,what,travel_cat_id)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("view-tour-travel.php?id="+travel_cat_id+"&travel_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}		
function package_status_fun(action,what,category_id)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("view-tour-package.php?id="+category_id+"&package_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function package_hotel_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("view-package-hotels.php?package_hotel_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}	
function enquiry_status_fun(action,what)
	{
		var lstart=document.adminForm.limitstart.value;
		location.href=("enquiry-form.php?enquiry_status_id="+what+"&status="+action+"&limitstart="+lstart);
	}		
function search_destination(id,total)
	{
		var id=id;
		if(id=='interest')
			{
				if(total>6)
					{
						document.getElementById('interests1').style.display='';
					}
				document.getElementById('interests').style.display='';
				document.getElementById('activities').style.display='none';
				if(document.getElementById('activities1'))
					document.getElementById('activities1').style.display='none';
			}
		if(id=='activity')
			{
				if(total>6)
					{
						document.getElementById('activities1').style.display='';
					}
				document.getElementById('activities').style.display='';
				document.getElementById('interests').style.display='none';
				if(document.getElementById('interests1'))
					document.getElementById('interests1').style.display='none';	
			}
	}	

function search_destination_inner(id,total)
	{
		var id=id;
		if(id=='interest_inner')
			{
				if(total>6)
					{
						document.getElementById('interests1_inner').style.display='';
					}
				if(document.getElementById('interests_inner'))
				document.getElementById('interests_inner').style.display='';
				if(document.getElementById('activities_inner'))
				document.getElementById('activities_inner').style.display='none';
				if(document.getElementById('activities1_inner'))
					document.getElementById('activities1_inner').style.display='none';
			}
		if(id=='activity_inner')
			{
				if(total>6)
					{
						document.getElementById('activities1_inner').style.display='';
					}
				document.getElementById('activities_inner').style.display='';
				document.getElementById('interests_inner').style.display='none';
				if(document.getElementById('interests1_inner'))
					document.getElementById('interests1_inner').style.display='none';	
			}
	}
	
function display_main_image(id,total)
	{
		window.parent.bigimg=id;
		var i=1;
		if(id==0)
			{
				document.getElementById('main').style.display='';
				for(i=1;i<=total;i++)
				{
					if(document.getElementById(i))
						document.getElementById(i).style.display='none';
				}
			}
		else
		{
			for(i=1;i<=total;i++)
			{
				document.getElementById('main').style.display='none';
				if(i==id)
					document.getElementById(i).style.display='';
				else
					if(document.getElementById(i))
						document.getElementById(i).style.display='none';
			}
		}
	}
	
 function CreateBookmarkLink() 
 {
 	title = document.title;
    url = window.location.href;
    if (window.sidebar) // Mozilla Firefox Bookmark
	{ 
	    window.sidebar.addPanel(title, url,"");
    } 
	else if( window.external )	// IE Favorite 
	{ 
    	window.external.AddFavorite( url, title); 
	}
    else if(window.opera && window.print) // Opera Hotlist 
	{
    	return true; 
	}
}	

function getCity(strURL)
    {      
     var aRequest;
	// Mozilla/Safari
	if (window.XMLHttpRequest)	{
		aRequest= new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject)	{
		aRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	 aRequest.open("GET", strURL, true);
					aRequest.onreadystatechange = function()
           {
                             if (aRequest.readyState == 4) { //means the data is retrieved from server
							 
                                     if (aRequest.status == 200) { // which reprents ok status                    
                      					 document.getElementById('citydiv').innerHTML=aRequest.responseText;
                                     } else {
                                             alert("There was a problem while using XMLHTTP:\n" + aRequest.statusText);
                                                 }
                                 }            
                     }        
           //open the url using get request method
           aRequest.send(null);
       }
	   
	   
function getRoom(strURL)
    {      
     var aRequest;
	// Mozilla/Safari
	if (window.XMLHttpRequest)	{
		aRequest= new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject)	{
		aRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	 aRequest.open("GET", strURL, true);
					aRequest.onreadystatechange = function()
           {
                             if (aRequest.readyState == 4) { //means the data is retrieved from server
							 
                                     if (aRequest.status == 200) { // which reprents ok status                    
                      					 document.getElementById('roomdiv').innerHTML=aRequest.responseText;
                                     } else {
                                             alert("There was a problem while using XMLHTTP:\n" + aRequest.statusText);
                                                 }
                                 }            
                     }        
           //open the url using get request method
           aRequest.send(null);
       }	

function getTotalPackageCost(strURL)
    {      
     var aRequest;
	// Mozilla/Safari
	if (window.XMLHttpRequest)	{
		aRequest= new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject)	{
		aRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	 aRequest.open("GET", strURL, true);
					aRequest.onreadystatechange = function()
           {
                             if (aRequest.readyState == 4) { //means the data is retrieved from server
							 
                                     if (aRequest.status == 200) { // which reprents ok status   
										 document.getElementById('package_total_cost_id').innerHTML=aRequest.responseText;
                                     } else {
                                             alert("There was a problem while using XMLHTTP:\n" + aRequest.statusText);
                                                 }
                                 }            
                     }        
           //open the url using get request method
           aRequest.send(null);
       }	  
function total_length(text)
{
	var maxlimit=100;
	var total_length=0;
	var t1=text.value;
	
	if(t1.length > maxlimit) 
	{
	t1 = t1.substring(0, maxlimit);
	} 
	else 
	{
	document.getElementById('countfield').value = maxlimit - t1.length;
	}
	//total_length=text.value.length;
	if(document.getElementById('countfield').value<=0)
	{
		alert('You can not enter more than 100 characters');
		text.value=t1;
		return false;
	}
}   