function center_window() {
	self.moveTo((self.screen.availWidth - self.document.body.offsetWidth) / 2, (self.screen.availHeight - self.document.body.offsetHeight - 40) / 2);
	self.focus();
}//center_window

function Setup_Adjust_Area(){
	var panel_left = document.getElementById('left_menu');
	var panel_center = document.getElementById('main_content');
	if (panel_left.offsetHeight > panel_center.offsetHeight)
	  {panel_center.style.height= panel_left.offsetHeight;}
	  else
	  {panel_left.style.height= panel_center.offsetHeight;}
}//Setup_Adjust_Area
	
function OpenGoogleMap(ArgList){
	window.open('/gmaps/villa_map.aspx?list=' + ArgList,'gMap','left=20, top=20, height = 450, width = 620, status = yes');
}//OpenGoogleMap

function Open_MTEditor(ArgURL){
 window.open(ArgURL,'MetaTagEditor','left=100, top=100,status = yes, height = 300, width = 600');
 //return false;
}

//========== data.i-rent =========
function StartBooking(ArgVillaCode, ArgAgentCode, ArgWebsiteCode, ArgUserCode, ArgDateFrom, ArgDateUntil, ArgLang, ArgUA){
	//pageTracker._link(document.location.href);
	window.open(pageTracker._getLinkerUrl('http://booking.i-rent.net/booking_system/start.aspx?code=' + encodeURIComponent(ArgVillaCode) + '&agentkey=' + encodeURIComponent(ArgAgentCode) + '&websitekey=' + encodeURIComponent(ArgWebsiteCode) + '&From=' + ArgDateFrom + '&To=' + ArgDateUntil + '&user=' + encodeURIComponent(ArgUserCode) + '&lan=' + encodeURIComponent(ArgLang) + '&ua=' + encodeURIComponent(ArgUA)), 'booking_process','status = yes, top = 20, left = 20, height = 660, width = 910, scrollbars = yes');
}//StartBooking

function StartForm(ArgVillaCode, ArgAgentCode, ArgWebsiteCode, ArgUserCode, ArgDateFrom, ArgDateUntil, ArgLang, ArgUA){
	//pageTracker._link(document.location.href);
	window.open(pageTracker._getLinkerUrl('http://booking.i-rent.net/booking_system/inquiries/form_01.aspx?code=' + encodeURIComponent(ArgVillaCode) + '&agentkey=' + encodeURIComponent(ArgAgentCode) + '&websitekey=' + encodeURIComponent(ArgWebsiteCode) + '&From=' + ArgDateFrom + '&To=' + ArgDateUntil + '&user=' + encodeURIComponent(ArgUserCode) + '&lan=' + encodeURIComponent(ArgLang) + '&ua=' + encodeURIComponent(ArgUA)), 'booking_process','status = yes, top = 20, left = 20, height = 660, width = 910, scrollbars = yes');
}//StartForm

function StartConfirmOption(ArgAgentCode, ArgWebsiteCode, ArgUserCode, ArgLang, ArgUA){
	//pageTracker._link(document.location.href);
	window.open(pageTracker._getLinkerUrl('http://booking.i-rent.net/booking_system/options/confirm_01.aspx?agentkey=' + encodeURIComponent(ArgAgentCode) + '&websitekey=' + encodeURIComponent(ArgWebsiteCode) + '&user=' + encodeURIComponent(ArgUserCode) + '&lan=' + encodeURIComponent(ArgLang) + '&ua=' + encodeURIComponent(ArgUA)), 'booking_process','status = yes, top = 20, left = 20, height = 660, width = 910, scrollbars = yes');
}//StartConfirmOption

function StartCallMe(ArgVillaCode, ArgAgentCode, ArgWebsiteCode, ArgUserCode, ArgLang, ArgUA){
	//pageTracker._link(document.location.href);
	window.open(pageTracker._getLinkerUrl('http://booking.i-rent.net/booking_system/callme/callme_01.aspx?code=' + encodeURIComponent(ArgVillaCode) + '&agentkey=' + encodeURIComponent(ArgAgentCode) + '&websitekey=' + encodeURIComponent(ArgWebsiteCode) + '&user=' + encodeURIComponent(ArgUserCode) + '&lan=' + encodeURIComponent(ArgLang) + '&ua=' + encodeURIComponent(ArgUA)), 'booking_process','status = yes, top = 20, left = 20, height = 660, width = 910, scrollbars = yes');
}//StartCallMe


//========== Init Functions =========
function Setup_SearchPanel(){
var left_menu = document.getElementById('left_menu');
var main_content = document.getElementById('main_content');
if (left_menu.offsetHeight > main_content.offsetHeight)
  {main_content.style.height = left_menu.offsetHeight;}
  else
  {left_menu.style.height = main_content.offsetHeight;}
}//Setup_Scroll_Area

function Open_DMEditor(ArgPath, ArgLang){
 window.open('/xml_editor/xml_edit_dmt.aspx?path_to_file='+ArgPath+'&lang='+ArgLang,'MetaTagEditor','status = yes, height = 520, width = 545');
 //return false;
}

function SelectComboValue(ArgCombo, ArgElemento) {//elegir valor en combo				
	if (ArgElemento != null && ArgElemento != ' ') {			
		var cantidad = ArgCombo.length;
		for (i = 0; i < cantidad; i++) {
			if (ArgCombo[i].value == ArgElemento) {				
				ArgCombo[i].selected = true;
				}   
			}
		}	
}

/**
	* DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
	*/
	// Declaring valid date character, minimum year and maximum year
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}

	function stripCharsInBag(s, bag){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++){   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	} 
	return this
	}

function Convert2DateObject(CalendarDate){
			var str1  = CalendarDate;
			var dt1   = parseInt(str1.substring(0,2),10); 
			var mon1  = parseInt(str1.substring(3,5),10);
			var yr1   = parseInt(str1.substring(6,10),10); 
			return new Date(yr1, mon1 - 1, dt1); 
	}
	
function isDate(dtStr){
		dtStr = dtStr.replace(/^\s*|\s*$/g,"");		
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			//alert("The date format should be : dd/mm/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			//alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			//alert("Please enter a valid day")
			return false
		}						
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}		
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){			
			//alert("Please enter a valid date")
			return false
		}
	return true
	}
	
	function ToggleTranslation(){	
	var tmp_Cookie = getCookie('TranslationState');								
	if (checkCookie('TranslationState')) {} else {tmp_Cookie='state=true'}	
	var tmp_TState = getCookieValue(tmp_Cookie, 'state');	
	if 	(tmp_TState === 'true') {	
		delSearchCookie('TranslationState');
		setCookie('TranslationState', 'state=false');  
		}
		else {		
			delSearchCookie('TranslationState');
			setCookie('TranslationState', 'state=true');  		
		}		
	document.location.reload();
	}

/*Copy Dates*/
function addDays(myDate,days) {
	MINUTE = 60 * 1000; 
	HOUR = MINUTE * 60; 
	DAY = HOUR * 24; 
	WEEK = DAY * 7;
	return new Date(myDate.getTime() + days * DAY);
}//addDays

function fmt00(ArgNumber){
	if (parseInt(ArgNumber) < 0) var neg = true;
	if (Math.abs(parseInt(ArgNumber)) < 10){
		ArgNumber = "0"+ Math.abs(ArgNumber);
	}
	if (neg) ArgNumber = "-" + ArgNumber;
	return ArgNumber;
}

function CopyDate(Sel_From,Sel_To){
	var Array_Fecha = document.getElementById(Sel_From.id).value.split("/");  
	var Fecha_From = new Date(Array_Fecha[2],Array_Fecha[1]-1,Array_Fecha[0]);  
	var Fecha_To = addDays(Fecha_From,7);	
	if (isDate(document.getElementById(Sel_From.id).value)) {	
		document.getElementById(Sel_To.id).value = fmt00(Fecha_To.getDate()) + "/" + fmt00(Fecha_To.getMonth() + 1) + "/" + Fecha_To.getFullYear();
	}else {
		document.getElementById(Sel_To.id).value = "";
	}
	return true;
}   

// Replaces all instances of the given substring. 
String.prototype.replaceAll = function( 
	strTarget, // The substring you want to replace 
	strSubString // The string you want to replace in. 
	){ 
	var strText = this; 
	var intIndexOfMatch = strText.indexOf( strTarget ); 
 
	// Keep looping while an instance of the target string 
	// still exists in the string. 
	while (intIndexOfMatch != -1){ 
	// Relace out the current instance. 
	strText = strText.replace( strTarget, strSubString ) 
 
	// Get the index of any next matching substring. 
	intIndexOfMatch = strText.indexOf( strTarget ); 
	} 
 
	// Return the updated string with ALL the target strings 
	// replaced out with the new substring. 
	return( strText ); 
}
function getUnit() {
	if (navigator.appName.toUpperCase() == "MICROSOFT INTERNET EXPLORER") { return "";}else { return "px"}
}