function fixResolution()
{
	if(screen.width > 1024)
		document.getElementById('divBodyContainer').style.width = '90%';
	else
		document.getElementById('divBodyContainer').style.width = '100%';
}
function mouseOver(targetId)
	{
	targetId.className='panelStripOver';
	}
function mouseOut(targetId,styleClass)
	{
	targetId.className=styleClass;
	}
function ScrollLeft(points)
	{
	Timer = setInterval("document.getElementById('countries_container').scrollLeft -= " + points, 15);
	}
function ScrollRight(points) 
	{
	Timer = setInterval("document.getElementById('countries_container').scrollLeft += " + points, 15);
	}

function createStartBudgetBox(sBoxName,selectValue)
{
		var startBudget = -50000;
		var offset = 50000;
		
		var strHtml ='<select name="'+sBoxName+'" id="'+sBoxName+'"  onChange="createEndBudgetBox(this.value,\'endPrice\')">';
		strHtml+='<option value="">Any </option>  ';
		
		if(isNaN(startBudget)==false)
		{
			var intValue = startBudget;
			var strText = startBudget;
			for(var i=1;i<=51;i++)
			{
				var intValue = intValue + offset;
				var strText  = strText + offset;
				
				strHtml +='<option value="'+intValue+'" '+(intValue == selectValue ? "selected" : "")+'>$ '+currencyFormatted(strText)+'</option>';
			}
		}
		strHtml +='</select>';
		
		document.write(strHtml);
}
function createEndBudgetBox(startValue,sBoxName,selectValue)
{
		var startBudget = parseInt(startValue);
		var offset = 50000;
		
		var strHtml ='<select name="'+sBoxName+'" id="'+sBoxName+'" class="searchField">';
		strHtml+='<option value="">Any </option>  ';
		
		if(isNaN(startBudget)==false)
		{
			var intValue = startBudget;
			var strText = startBudget;
			for(var i=1;i<=51;i++)
			{
				var intValue = intValue + offset;
				var strText  = strText + offset;
				strHtml +='<option value="'+intValue+'" '+(intValue == selectValue ? "selected" : "")+'>$ '+currencyFormatted(strText)+'</option>';
			}
		}
		strHtml +='</select>';
		
		document.getElementById('endBudget').innerHTML = strHtml;
}

function searchStartBudgetBox(sBoxName,selectValue,sCurrency)
{
		var startBudget = -50000;
		var offset = 50000;
		
		var funCall = "searchEndBudgetBox(this.value,'endP','-1','"+getCurrency()+"')";
		var strHtml ='<select name="'+sBoxName+'" id="'+sBoxName+'" class="searchField"  onChange="'+funCall+'">';
		strHtml+='<option value="-1">Any </option>  ';
		
		if(isNaN(startBudget)==false)
		{
			var intValue = startBudget;
			var strText = startBudget;
			for(var i=1;i<=51;i++)
			{
				var intValue = intValue + offset;
				var strText  = strText + offset;
				strCaption = sCurrency+' '+currencyFormatted(strText)
				strHtml +='<option value="'+intValue+'" '+(intValue == selectValue ? "selected" : "")+'>'+strCaption+'</option>';
			}
		}
		strHtml +='</select>';
		
		document.getElementById('startBudget').innerHTML = strHtml;
}
function getCurrency()
{
	var counter=0;
	var curr='';
	for(var i=0;i<3;i++)
	{
		if(document.getElementById('cur'+i).checked)
		{
			counter++;
			curr = document.getElementById('cur'+i).value;
		}
	}
	if(counter==0)	 curr='';
	return curr;
}
function searchEndBudgetBox(startValue,sBoxName,selectValue,sCurrency)
{
		var startBudget = parseInt(startValue);
		var offset = 50000;
		var strHtml ='<select name="'+sBoxName+'" id="'+sBoxName+'" class="searchField">';
		strHtml+='<option value="">Any </option>  ';
		
		if(startBudget != -1)
		{
			if(isNaN(startBudget)==false)
			{
				var intValue = startBudget;
				var strText = startBudget;
				for(var i=1;i<=50;i++)
				{
					var intValue = intValue + offset;
					var strText  = strText + offset;
					strHtml +='<option value="'+intValue+'" '+(intValue == selectValue ? "selected" : "")+'>'+sCurrency+' '+currencyFormatted(strText)+'</option>';
				}
			}
		}
		strHtml +='</select>';
		
		document.getElementById('endBudget').innerHTML = strHtml;
}

function currencyFormatted(sAmount)
{
		var i = parseFloat(sAmount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		
		sAmount = s;
		
		var delimiter = ","; // replace comma if desired
		var a = sAmount.split('.',2)
		var d = a[1];
		var i = parseInt(a[0]);
		if(isNaN(i)) { return ''; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while(n.length > 3)
		{
			var nn = n.substr(n.length-3);
			a.unshift(nn);
			n = n.substr(0,n.length-3);
		}
		if(n.length > 0) { a.unshift(n); }
		n = a.join(delimiter);
		if(d.length < 1) { sAmount = n; }
		else { sAmount = n ; }
		sAmount = minus + sAmount;
		return sAmount;
}
//******************************* Email Alerts (Start) ***********************************************
function editEmailAlert(alertId)
{
	var sLocation = site_url +'myipbre/emailAlerts/edit/'+alertId+'/';
	window.location = sLocation;
	
}
function deleteEmailAlert(alertId)
{
	if(confirm('Do you want to delete Email Alert ?'))
	{
		var sLocation = site_url +'myipbre/emailAlerts/delete/'+alertId+'/';
		window.location = sLocation;
	}
	
}

//******************************* For Cookies   ***********************************************
function setCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();

	if (nDays == null || nDays == 0) nDays=1;

	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function getCookie(cookieName)
{
	var theCookie = ""+document.cookie;
	var ind = theCookie.indexOf(cookieName);

	if (ind == -1 || cookieName=="") return "";

	var ind1 = theCookie.indexOf(';',ind);

	if (ind1 == -1) ind1=theCookie.length;

	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
//******************************* For User Properties   ***********************************************
function saveMyProperty(propertyId)
{
	if(user_id == '')
		window.location = site_url+'register/login/';
	else
	{
		get('savedProperty.php','callAjax=addToIpbre&propertyId='+propertyId,'propertyLink_'+propertyId,'','');
	}
}
function deleteUserProperty(propertyName)
{
	if(confirm('Do you want to delete this property - '+propertyName+' ?'))
	{
		propertyName = propertyName.split(" ");
		propertyName = propertyName.join("-");
		propertyName = propertyName.split("/");
		propertyName = propertyName.join("_");
	
		var sLocation = site_url +'savedProperty/delete/'+propertyName+"/";
		window.location = sLocation;
	}
}
function removeAllUserProperties()
{
	if(confirm('Do you want to delete all properties ?'))
	{
		var sLocation = site_url +'savedProperty/delete/';
		window.location = sLocation;
	}

}
function editRegDetails()
{
	var sLocation = site_url +'myipbre/editRegDetails/';
	window.location = sLocation;
	
}
function updateRegDetails(userId)
{
	fname = document.getElementById('fname').value;
	lname = document.getElementById('lname').value;
	age = document.getElementById('age').value;
	mobile = document.getElementById('mob').value;
	email = document.getElementById('email').value;
	pwd = document.getElementById('pwd').value;
	var sLocation = base_url +'?filename=myipbre&action=updateRegDetails&userId='+userId+'&fname='+fname+'&lname='+lname+'&age='+age+'&mobile='+mobile+'&email='+email+'&pwd='+pwd;
	window.location = sLocation;	
}
function goToDetailsPage()
{
	var sLocation = site_url +'myipbre/registeredDetails/';
	window.location = sLocation;
}
function searchPreferences(userId,action)
{
	recordsNumbers 	= document.getElementById('recordsNumbers').value;
	priceOrder 		= document.getElementById('priceOrder').value;
	addedOrder 	= document.getElementById('addedOrder').value;	
	if(action == 'Save')
	{
		var sLocation = base_url +'?filename=myipbre&action=saveSearchPreferences&userId='+userId+'&recordsNumbers='+recordsNumbers+'&priceOrder='+priceOrder+'&addedOrder='+addedOrder;
	}
	else if(action == 'Update')
	{
		var sLocation = base_url +'?filename=myipbre&action=updateSearchPreferences&userId='+userId+'&recordsNumbers='+recordsNumbers+'&priceOrder='+priceOrder+'&addedOrder='+addedOrder;
	}
	window.location = sLocation;
}
function goToSearchPreference(action)
{
	var sLocation = site_url +'myipbre/searchPreference/';
	window.location = sLocation;
}
function loadHotProperty(propertyName,category,propertyId,countryName,countryId)
{
	//alert(propertyName+'     '+country);
	document.getElementById('propertyHeading').innerHTML=propertyName;
	
	propertyName = propertyName.split(" ");
	propertyName = propertyName.join("-");
	propertyName = propertyName.split("/");
	propertyName = propertyName.join("_");
	
	countryName = countryName.split(" ");
	countryName = countryName.join("-");
	
	if(category == "Rent")		strPrefix = "for ";
	else						strPrefix = "to ";
	
	document.getElementById('category').innerHTML=strPrefix + category;
	document.getElementById('enquire').href	= site_url + "contactUs/enquiry/"+propertyName+"/";
	document.getElementById('details').href	= site_url + "propertyDetail/"+countryName+"/"+propertyId+"-"+propertyName+"/";
	document.getElementById('friends').href	= site_url + "contactUs/friend/"+propertyName+"/";
	document.getElementById('price').href	= site_url + "contactUs/price/"+propertyName+"/";
}
function loadFeatureProperty(propertyName,category,propertyId,countryName,countryId,sponsorThumb)
{
//	alert(sponsorThumb);
	document.getElementById('propertyHeading').innerHTML=propertyName;
	
	propertyName = propertyName.split(" ");
	propertyName = propertyName.join("-");
	propertyName = propertyName.split("/");
	propertyName = propertyName.join("_");
	
	countryName = countryName.split(" ");
	countryName = countryName.join("-");
	if(sponsorThumb !="")
	{
		document.getElementById('thumbExist').style.display="inline";
		document.getElementById('sponsorThumb').src=sponsorThumb;
	}
	else
	{
		document.getElementById('thumbExist').style.display="none";
	}
	
	if(category == "Rent")		strPrefix = "for ";
	else						strPrefix = "to ";
	
	document.getElementById('category').innerHTML=strPrefix + category;
	document.getElementById('enquire').href	= site_url + "contactUs/enquiry/"+propertyName+"/";
	document.getElementById('details').href	= site_url + "propertyDetail/"+countryName+"/"+propertyId+"-"+propertyName+"/";
	//document.getElementById('friends').href	= site_url + "contactUs/friend/"+propertyName+"/";
	//document.getElementById('price').href	= site_url + "contactUs/price/"+propertyName+"/";
}
function openProperty(countryName,propertyName,propertyId)
{
	propertyName = propertyName.split(" ");
	propertyName = propertyName.join("-");
	propertyName = propertyName.split("/");
	propertyName = propertyName.join("_");
	
	countryName = countryName.split(" ");
	countryName = countryName.join("-");
	location.href =site_url+ "propertyDetail/"+countryName+"/"+propertyId+"-"+propertyName+"/";
}
function submitCustomViewForm()
{
	document.getElementById('frmCustomView').submit();
}

var searchMap = false;
//*******************************************************************************************************
function searchPropertyMap()
{
	var categoryId 	= document.getElementById('categoryId').value;
	var countryId 	= document.getElementById('countryId').value;
	var cityId 	= document.getElementById('city').value;
	var townId 	= document.getElementById('town').value;
	
	//alert(categoryId+','+countryId+','+cityId+','+townId);
	
	if(countryId == '')
	{	
		alert('Please Select Country.'); 
		document.getElementById('countryId').focus(); return false;
	}
	
	searchMap = true;
	document.getElementById("divMapsLoader").style.display = 'inline';
	get('propertyMapsAjax.php','callAjax=Yes&countryId='+countryId+'&categoryId='+categoryId+'&cityId='+cityId+'&townId='+townId,'propertyList','','');
	return false;
	
}
function afterAjax()
{
	if(searchMap)
	{
		searchMap = false;
		document.getElementById("divMapsLoader").style.display = 'none';
		document.getElementById('ifrm_PropertyMap').src="../propertyGoogleMaps.php";
	}
}
//*******************************************************************************************************
function setSearchPreferences()
{
	var recordsNumbers 	= document.getElementById('recordsNumbers').value;
	var priceOrder 		= document.getElementById('priceOrder').value;
	var addedOrder 		= document.getElementById('addedOrder').value;
	
	var searchForm = document.getElementById('searchForm');
	
	searchForm.recordsNumbers.value = document.getElementById('recordsNumbers').value;
	searchForm.priceOrder.value 	= document.getElementById('priceOrder').value;
	searchForm.addedOrder.value 	= document.getElementById('addedOrder').value;
	
}
function submitSearchForm()
{
	document.getElementById('p').value = 1;
	document.getElementById('startPrice').value = document.getElementById('startP').value;
	document.getElementById('endPrice').value = document.getElementById('endP').value;
	
//	setSearchPreferences();
}
//****************************handling pop up register form****************************************
var _showRegisterBox = true;
function showRegisterBox()
{
	if(_showRegisterBox == true)
	{
		_showRegisterBox = false;
		
		var bodyWidth 	= $('body').attr('scrollWidth') - 200; 
		var bodyHeight 	= $('body').attr('scrollHeight') - 200; 
		
		$('embed, object').css({ 'visibility' : 'hidden' });
		
		
		$('body').append('<div id="div_registerForm"></div>');	
		$('#div_registerForm').css({
			backgroundColor	: '#EEE',
			position		: 'absolute',
			padding			: '100px',
			opacity			: 0.5,
			left			: '0px',
			top				: '0px',
			width			: bodyWidth,
			height			: bodyHeight
		}).fadeIn();

		//making form centered
		var formLeft = parseInt( (screen.width * 15)/100 ) ;
		var formTop  = parseInt( (screen.height * 20)/100 );
		
		$('#div_registerContents').css({
			backgroundColor	: '#FFF',
			position		: 'absolute',
			border			: '2px solid',
			left			: formLeft +'px',
			top				: formTop +'px',
			width			: '70%',
			zIndex			: '1000'
		}).attr('align','center').slideDown();
	}
}
function closeRegisterBox()
{
	var registerPropertyList = getCookie(_registerCookieName);
	if(registerPropertyList == "")
		setCookie(_registerCookieName,_registerPropertyId,2);
	else
	{
		isPresent = false;
		var arrPropertyList = registerPropertyList.split('*');
		for(var x=0; x< arrPropertyList.length; x++)
		{
			if(curPropertyId == arrPropertyList[x])
			{
				isPresent = true;
			}
		}
		
		if(isPresent == false)
		{
			setCookie(_registerCookieName,'*'+_registerPropertyId,2);
		}
	}
	
	$('#div_registerContents').css({ 'display' : 'none' });
	$('#div_registerForm').fadeOut(function() { $('#div_registerForm').remove(); });
	$('embed, object').css({ 'visibility' : 'visible' });
}
