// JavaScript Document

function funSearch(frmname,frmaction)
	{
	frmnames=eval("document."+frmname);
	frmnames.action=frmaction;
	frmnames.submit();
	}
//end Function to be used in Login page	
	//Function used for ajax
function propLinkList(url,pg,index)
{	
	var frmelements=document.accDestSearch.elements.length;
	var selids="";
	for(g=0;g<frmelements;g++)
	{
		 if(document.accDestSearch.elements[g].type=="checkbox")
			 if(document.accDestSearch.elements[g].checked==true)
					{
				 if(selids!="")
					selids=selids+","+document.accDestSearch.elements[g].name;
				 else
					selids=document.accDestSearch.elements[g].name;
				}
	}
	selids=selids.replace(/chkkey/g,"");
	
	if(url=="ajax_accommodation_listing.php" || url=="ajax_buyproperty_listing.php")
	{
		if(parseInt(document.accDestSearch.display9.value) > parseInt(document.accDestSearch.display10.value))
		{ 
			alert("Maximum price is less than minimum price.");
			document.accDestSearch.display9.focus();
			return false;
		}
	}
	var url  = url+"?"+"pg="+pg+"&index="+index+"&town_id="+document.accDestSearch.cmbTown.value+"&keys="+selids+"&price1="+document.accDestSearch.display9.value+"&price2="+document.accDestSearch.display10.value;
	passvalue(url,"lpie_admin/images","div_results");
}

//detailed_search - search_category.php
function detSearLinkList(url,pg,index,town_id,catg_id,param1,param2,param3,param4,param5,param6)
{	
	var url  = url+"?"+"pg="+pg+"&index="+index+"&tid="+town_id+"&catId="+catg_id+"&art_culture_params="+param1+"&health_wellness_params="+param2+"&outdoor_activity_params="+param3+"&food_wine_params="+param4+"&shopping_params="+param5+"&tours_courses_params="+param6;
	passvalue(url,"lpie_admin/images","div_results");
}

//Function used for booking
function validateBooking()
{
	if(trim(document.frmBooking.txtFirstName.value)=="")
	{
		alert("Please enter name.");
		document.frmBooking.txtFirstName.focus();
		return false;
	}
	if(trim(document.frmBooking.txtEmailAddress.value)=="")
	{
		alert("Please enter email address.");
		document.frmBooking.txtEmailAddress.focus();
		return false;
	}
	if(trim(document.frmBooking.txtEmailAddress.value)!="")
	{
		if(!email.test(trim(document.frmBooking.txtEmailAddress.value)))
		{
		alert("Please enter email address in the correct format.");
		document.frmBooking.txtEmailAddress.focus();
		return false;
		}
	}
	
	if(trim(document.frmBooking.security_code.value)=="")
	{
		alert("Please enter security code.");
		document.frmBooking.security_code.focus();
		return false;
	}
	document.frmBooking.action="accom_booking1.php";
	document.frmBooking.submit();
	
}
//Function used for validating reviews

function ValidateReviews()
{
	
	var d = new Date();
	var curr_date = d.getDate();
	var curr_year = d.getFullYear();
	var curr_month = d.getMonth()+1;
    
	var flag=0;
	for(t=1;t<=5;t++)
	{
		var chkName1=eval("document.frmRating.chk"+t);	
		if(chkName1.checked!=true)
		{
			flag=1;	
		}
		else
		{
			flag=0;
			break;
		}
	}
	if(flag==1)
	{
		alert("Please select your rating.");
		return false;
	}
	if(trim(document.frmRating.title.value)=="")
	{
		alert("Please enter review title.");
		document.frmRating.title.focus();
		return false;
	}
	if(trim(document.frmRating.comments.value)=="")
	{
		alert("Please enter review comments.");
		document.frmRating.comments.focus();
		return false;
	}
	if(trim(document.frmRating.month.value)=="")
	{
		alert("Please select month.");
		document.frmRating.month.focus();
		return false;
	}
	if(trim(document.frmRating.year.value)=="")
	{
		alert("Please select year.");
		document.frmRating.year.focus();
		return false;
	}
	if(trim(document.frmRating.year.value)!="" && trim(document.frmRating.month.value))
	{
		if(trim(document.frmRating.year.value)==curr_year)
		{
			if(trim(document.frmRating.month.value)>curr_month)
			{
				alert("Please select current/previous month in this year.");
				document.frmRating.month.focus();
				return false;
			}
		}
	}
	if(trim(document.frmRating.name.value)=="")
	{
		alert("Please enter reviewer name.");
		document.frmRating.name.focus();
		return false;
	}
	if(trim(document.frmRating.email.value)=="")
	{
		alert("Please enter email.");
		document.frmRating.email.focus();
		return false;
	}

	if(!email.test(trim(document.frmRating.email.value)))
	{
		alert("Please enter email address in the correct format.");
		document.frmRating.email.focus();
		return false;
	}
	if(trim(document.frmRating.nationality.value)=="")
	{
		alert("Please select nationality.");
		document.frmRating.nationality.focus();
		return false;
	}
	if(document.frmRating.chkagree.checked!=true)
	{
		alert("Please tick the declaration checkbox.");
		document.frmRating.chkagree.focus();
		return false;
	}
		   
	document.frmRating.action="accom_review1.php";
	document.frmRating.submit();
	
}

function checkBoxValidate(cb){
	var chkName=eval("document.frmRating.chk"+cb);
	if(chkName.checked==true){
		for(t=1;t<=5;t++){
			var chkName1=eval("document.frmRating.chk"+t);	
			if(chkName1.checked==true && (t!=cb))
			document.getElementById("span"+t).className="f_checkbox unchecked";								  
		}
	}
}

function funNewsletter(){
	if(trim(document.frmNewsletter.name.value)=="" || (trim(document.frmNewsletter.name.value)==trim(document.frmNewsletter.hidname.value))){
		alert("Please enter name.");
		document.frmNewsletter.name.value='';
		document.frmNewsletter.name.focus();
		return false;
	}
	if(trim(document.frmNewsletter.txtEmailAddress.value)=="" || (trim(document.frmNewsletter.txtEmailAddress.value)==trim(document.frmNewsletter.hidemail.value))){
		alert("Please enter email address.");
		document.frmNewsletter.txtEmailAddress.value='';
		document.frmNewsletter.txtEmailAddress.focus();
		return false;
	}
	if(trim(document.frmNewsletter.txtEmailAddress.value)!=""){
		if(!email.test(trim(document.frmNewsletter.txtEmailAddress.value))){
		alert("Please enter email address in correct format.");
		document.frmNewsletter.txtEmailAddress.value='';
		document.frmNewsletter.txtEmailAddress.focus();
		return false;
		}
	}
	passvalues("news_letter1.php?nam="+trim(document.frmNewsletter.name.value)+"&email="+trim(document.frmNewsletter.txtEmailAddress.value),"images",'div_newsletter');
	return false;
}

function formValueD(ctrl,hidctrl){
	ctrlname=eval("document.frmNewsletter."+ctrl);
	ctrlname1=eval("document.frmNewsletter."+hidctrl);
       if(ctrlname.value==ctrlname1.value)
       ctrlname.value="";
}
function formValueA(ctrl,hidctrl){
	ctrlname=eval("document.frmNewsletter."+ctrl);
	ctrlname1=eval("document.frmNewsletter."+hidctrl);
	    if(ctrlname.value=='')
		ctrlname.value=ctrlname1.value;
}

function funMapSearch(){
	document.frmNewsletter.action="interactive_map.php?town_id="+document.frmNewsletter.cmbTown.value+"&catId="+document.frmNewsletter.cmbCategory.value;
	document.frmNewsletter.submit();
}

function funSearchMap(){
	document.frmNewsletter.action="interactive_map.php";
	document.frmNewsletter.submit();
}
/**Google map*/
function initialize() {
	GDownloadUrl("listing.xml?dummy="+Math.random(), function(doc) {
		var xmlDoc = GXml.parse(doc);
		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
		
		var catId=''
		// obtain the attributes of each marker
		var lat = parseFloat(markers[0].getAttribute("lat"));
		var lng = parseFloat(markers[0].getAttribute("lon"));
		var point = new GLatLng(lat,lng);
		var business_name = markers[0].getAttribute("business_name");
		var short_desc = markers[0].getAttribute("short_description");
		var listingId=markers[0].getAttribute("listing_id");
		var img_src = markers[0].getAttribute("img_src");
		catId = markers[0].getAttribute("category_id");

		if(catId==1){
			url="<br><a href=accom_booking.php?list_id="+listingId+" target=_blank>Details & Booking.</a>";
		}else{
			url="";
		}
		name ='<table width=260 border=0><tr>'+
		'<td align=center width=70><img src="'+img_src+'" border=0 width=70 height=70></td><td width=5>&nbsp;</td>'+
		'<td align=center width=185 class=map_text>'+business_name+'<br/>'+short_desc+'<br/>'+url+'</td>'+
		'</tr><table>';

		var map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(lat, lng), 10);

		var marker = createMarker(point,name);
		map.addOverlay(marker);
	});

      // A function to create the marker and set up the event window
      function createMarker(point,name) {
		var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(name,{maxWidth:250});
        });
        return marker;
      }
  }
  /*** Google map*****/
  
  //Window open
  function winOpen(url,w,h)
  {
	 //window.open (url,"mywindow","location=1,status=1,scrollbars=1,width=200,height=200,left=500 top=400"); 
	 	var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		var targetWin = window.open (url, "mywindow", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
  }
  //Window open
  
  function validateAdvertise()
  {
	  if(trim(document.frmAdverise.name2.value)=="")
	{
		alert("Please enter name.");
		document.frmAdverise.name2.focus();
		return false;
	}
	if(trim(document.frmAdverise.email2.value)=="")
	{
		alert("Please enter email address.");
		document.frmAdverise.email2.focus();
		return false;
	}
	if(trim(document.frmAdverise.email2.value)!="")
	{
		if(!email.test(trim(document.frmAdverise.email2.value)))
		{
		alert("Please enter email address in the correct format.");
		document.frmAdverise.email2.focus();
		return false;
		}
	}
	
	if(trim(document.frmAdverise.tel.value)=="")
	{
		alert("Please enter telephone number.");
		document.frmAdverise.tel.focus();
		return false;
	}
	else if( isNaN(document.frmAdverise.tel.value) )
	{
		alert("Please enter a valid telephone number.");
		document.frmAdverise.tel.value='';
		document.frmAdverise.tel.focus();
		return false;
	}
	if(trim(document.frmAdverise.businessname.value)=="")
	{
		alert("Please enter business name.");
		document.frmAdverise.businessname.focus();
		return false;
	}
	if(trim(document.frmAdverise.typeofbusiness.value)=="")
	{
		alert("Please enter type of business.");
		document.frmAdverise.typeofbusiness.focus();
		return false;
	}
	if(trim(document.frmAdverise.security_code.value)=="")
	{
		alert("Please enter security code.");
		document.frmAdverise.security_code.focus();
		return false;
	}
	if(document.frmAdverise.chkAgree.checked!=true)
	{
		alert("Please accept the terms and conditions.");
		return false;
	}
	document.frmAdverise.action="advertise_action.php";
	document.frmAdverise.submit();
  }
