var currentaccommodation;
var currentowner;
var currentname;
var currentOcupation;
var currentTenant;
var currentMail;
	
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_Scroll_Area(){
	var scroll_panel = document.getElementById('Panel_Scroll');
	if (scroll_panel != null){
		scroll_panel.style.height = document.body.clientHeight - getTop(scroll_panel) - 2;
		scroll_panel.style.overflow = "auto"
		scroll_panel.style.width = "100%"
	}
}//Setup_Scroll_Area

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
	
//========== booking.i-rent =========
function StartBooking(ArgVillaCode, ArgAgentCode, ArgWebsiteCode, ArgUserCode, ArgDateFrom, ArgDateUntil, ArgLang, ArgUA) {
    pageTracker._link(document.location.href);
    window.open('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('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('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('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

//***************************************
function Open_Contract(ArgId, ArgLang){
	window.open('/form/rent_contract.aspx?lang=' + ArgLang + '&idocupacion=' + ArgId,'Contract','left=20, top=20, status = yes, resizable = yes');
	return false;
}//Open_Contract

function Send_email(ArgeMail){
	window.open('mailto:' + ArgeMail ,'email');
	return false;
}//Send_email

function Open_Map(ArgId){
	var PopUp;
	PopUp = window.open('/gestion/mapping/maps_select_points.aspx?id=' + ArgId,'Preview','left = 20, top = 20, height = 450, width = 350, status = yes');
	PopUp.focus();
	return false;
}//Open_Map

function Open_Preview(ArgId){
	var PopUp;
	PopUp = window.open('/detail/detail_GHS.aspx?id=' + ArgId,'Preview');
	PopUp.focus();
	return false;
}//Open_Preview

function mostrarMenu(){
	var bordeDerecho  = document.body.clientWidth  - event.clientX;  //lo que queda hasta el borde derecho
	var bordeInferior = document.body.clientHeight - event.clientY;  //lo que queda hasta el borde inferior
	if (bordeDerecho<menuDiv.offsetWidth) {
		menuDiv.style.left=document.body.scrollLeft+event.clientX-menuDiv.offsetWidth
	} else {
		menuDiv.style.left=document.body.scrollLeft+event.clientX
	}
	if (bordeInferior<menuDiv.offsetHeight) {
		menuDiv.style.top=document.body.scrollTop+event.clientY-menuDiv.offsetHeight
	} else {
		menuDiv.style.top=document.body.scrollTop+event.clientY
	}
	menuDiv.style.visibility="visible";
	menuDiv.style.display="block";
	return true
}//mostrar menu

function ocultarMenu(){
	menuDiv.style.visibility="hidden";
	menuDiv.style.display="none";
}//ocultarMenu

function encender(){
	if (event.srcElement.className=="menuitems"){
		event.srcElement.style.backgroundColor="highlight";
		event.srcElement.style.color="white";
		}
}//encender

function apagar(){
	if (event.srcElement.className=="menuitems"){
		event.srcElement.style.backgroundColor="";
		event.srcElement.style.color="black";
	}
}//apagar

function getLeft(MyObject){
	if (MyObject.offsetParent)
		return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
	else 
		return (MyObject.offsetLeft);
}//getLeft

function getTop(MyObject){
	if (MyObject.offsetParent)
		return (MyObject.offsetTop + getTop(MyObject.offsetParent));
	else
		return (MyObject.offsetTop);
}//getTop

function OpenGoogleMap(ArgList){
	window.open('/requests/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;
}

function Open_DMEditor(ArgPath){
 window.open('/xml_editor/xml_edit_dmt.aspx?path_to_file='+ArgPath,'MetaTagEditor','status = yes, height = 580, 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();
}