var $jg = jQuery.noConflict();

function loadProgressaPrice(element){
$jg(element).html("<select class='textareaprice'><option value=''>Loading...</option></select>");
}

function checklandlord(){
	var fname = $jg('#fname').val();
	var lname = $jg('#lname').val();
	var email = $jg('#email').val();
	var scode = $jg('#scode').val();
	 	
	if(fname == "")
	{
		alert("Enter Your First Name ");
		$jg('#fname').focus();
		return false;
	}
	if(lname == "")
	{
		alert("Enter Your Last Name ");
		$jg('#lname').focus();
		return false;
	}
	if(email == "")
	{
		alert("Enter Your email ");
		$jg('#email').focus();
		return false;
	}
	if(email !="")
	{
		var str =  email;
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!reg1.test(str) && reg2.test(str))
		{ 	// if syntax is valid
	   		//return true;
		}
		else
		{
			alert ("Please Fill Proper Email Address");
			$jg('#email').focus();
			return false;
		}
	}
	if(scode == "")
	{
		alert("Enter Security Code ");
		$jg('#scode').focus();
		return false;
	}
	return true;

}

function sort_function(val){
	if(val!=""){
	  document.myform.submit();

	}
}

function getToPrice(fromPriceIds, toPriceId){ 
loadProgressaPrice("#PriceTableAjax");
  $jg("#PriceTableAjax").show(); 
  $jg.post("http://www.rentahousenewry.com/ajax/fromprice.php", {fromPriceIds : fromPriceIds, toPriceId : toPriceId}, function(data){
     $jg("#PriceTableAjax").html(data);
  }) 
} 

$jg(function() {
	$jg( "#available_from,#available_to,#departure_date,#arrival_date,#avail_date" ).datepicker({
			changeMonth: true,
			changeYear: true,
			showButtonPanel: true
	});
	$jg("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
});

/* right side validation start */  
$jg(document).ready(function() {
	$jg("#contactform").validate();		
});     
/* right side validation stop */

$jg(document).ready(function() {
	$jg("#tenantcontactform").validate();		
});

$jg(document).ready(function() {

	$jg("#various1").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});

	
	$jg("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
});

function vali(){
	var c = document.getPrice;
	
	if(c.adults.value == "" || c.adults.value == "0")
	{
		alert("Please enter No.of Adults....");
		c.adults.focus();
		return false;
	}
	if(c.firstName.value == "")
	{
		alert("Please enter first name....");
		c.firstName.focus();
		return false;
	}
	if(c.lastName.value == "")
	{
		alert("Please enter last name....");
		c.lastName.focus();
		return false;
	}

	if(c.address1.value == "")
	{
		alert("Please enter your address....");
		c.address1.focus();
		return false;
	}
	if(c.country.value == "")
	{
		alert("Please select your country....");
		c.country.focus();
		return false;
	}
	if(c.state.value == "")
	{
		alert("Please enter your state/county....");
		c.state.focus();
		return false;
	}
	if(c.city.value == "")
	{
		alert("Please enter your city/town....");
		c.city.focus();
		return false;
	}
	if(c.zip.value == "")
	{
		alert("Please enter your postcode....");
		c.zip.focus();
		return false;
	}
return true;
}

function valid(){
	var c = document.getPrice;
	if(c.arrival_date.value == "")
	{
		alert("Please Select From Date....");
		c.arrival_date.focus();
		return false;
	}
	if(c.departure_date.value == "")
	{
		alert("Please Select To Date....");
		c.departure_date.focus();
		return false;
	}
	
	return true;
}

function popup(url,wi,hi){	
	newWindow = window.open(url,'daughter','menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=no,width='+wi+',height='+hi+',screenX=100,screenY=100,top=250,left=50');
	if (newWindow.opener == null) newWindow.opener = self;
	newWindow.focus();
}

$jg(document).ready(function() {
	/*
	for (var i = 1; i<=10; i++) {
		var showtenantdetails='showtenantdetails'+i;
		$jg("#showtenantdetails").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
		});

	}
	*/
	$jg("#variousindex").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	 
	$jg("#variousright").fancybox({
				'width'				: '65%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various1").fancybox({
				'width'				: '65%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});
	
	$jg("#various2").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various3").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various4").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various5").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});


	$jg("#various6").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various7").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various8").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});



	$jg("#various9").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#various10").fancybox({
				'width'				: '75%',
				'height'			: '20%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});

	$jg("#showtenantdetails1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	$jg("#showtenantdetails2").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	$jg("#showtenantdetails3").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

	$jg("#showtenantdetails4").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

	$jg("#showtenantdetails5").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

	$jg("#showtenantdetails6").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantdetails7").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantdetails8").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantdetails9").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantdetails10").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

});

$jg(document).ready(function() {
	/*
	for (var i = 1; i<=10; i++) {
		var showtenantdetails='showtenantdetails'+i;
		$jg("#showtenantdetails").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
		});

	}
	*/

	$jg("#showtenantenq1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	$jg("#showtenantenq2").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	$jg("#showtenantenq3").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

	$jg("#showtenantenq4").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

	$jg("#showtenantenq5").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

	$jg("#showtenantenq6").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantenq7").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantenq8").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantenq9").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	$jg("#showtenantenq10").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});

});

function agent_valid(){

	frm = document.enquiry;	
	var errorMessage = "";
	if(frm.agentname.value=='')
	{
		errorMessage += " <li> You must enter your first name </li> ";
	}
	if(frm.agentemail.value=="")
	{
		errorMessage += " <li> You must enter your email address</li> ";
	}
	if(frm.agentemail.value!="")
	{
		var str = frm.agentemail.value;
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!reg1.test(str) && reg2.test(str))
		{ 	// if syntax is valid
	   		//return true;
		}
		else
		{
			errorMessage += " <li> Please fill proper email address </li> ";
		}
	}
	if(frm.agentphone.value=='')
	{
		errorMessage += " <li> You must enter your phone number </li> ";
	}
	if(frm.agentcountry.value=='')
	{
		errorMessage += " <li> Select your Country </li> ";
	}
	if(frm.agentenquiry.value=='')
	{
		errorMessage += " <li> You must enter enquiry message </li> ";
	}
	if(frm.agentsecretcode.value=='')
	{
		errorMessage += " <li> You must enter Security code </li> ";
	}	

	if(errorMessage == "" )
	{
		return true;
	} else { 		
		document.getElementById("errorDisplay").innerHTML= "<ul>"+ errorMessage + "</ul>";
		return false;
	}

	if(errorMessage == "" ){
		return true;
	}else{ 		
		document.getElementById("errorDisplay").innerHTML= "<ul>"+ errorMessage + "</ul>";
		return false;
	}
}


function rightcheck()
{
	rightfrm = document.rightcontactform;
	if(rightfrm.fname.value=='')
	{
		alert("Please Enter Your Name");
		rightfrm.fname.focus();
		return false;
	}
	if(rightfrm.email.value=='')
	{
		alert("Please Enter Your Name");
		rightfrm.email.focus();
		return false;
	}
	if(rightfrm.enquiry.value=='')
	{
		alert("Please Enter Enquiry");
		rightfrm.enquiry.focus();
		return false;
	}
	if(rightfrm.secretcode.value=='')
	{
		alert("Please Enter Secretcode");
		rightfrm.secretcode.focus();
		return false;
	}
}

function mapProgress(){
	document.getElementById("map_canvas").innerHTML = "<div align=center><img src='{{http_path}}images/loading_m.gif' border='0' ></div>";	
}

var map = null;
var geocoder = null;

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
geocoder = new GClientGeocoder();
}
}

function showDetailMap(myObj){ 	
  $jg.post("http://www.rentahousenewry.com/mapInfo1.php", {pId : myObj}, function(data){
	  initialize();
		var spliRes = data.split("###");
		var len = spliRes.length;
		//alert(data);
		for(i=0; i<(len-1); i++){
			var args = spliRes[0].split("@@@");
			showAddressDetail(args[0], args[1], args[2], args[3], args[4], 11);

		}
     
  }) 
}
