// JavaScript Document

// Top banners - playlists for loader.
var bannerPlayList = new Array();
bannerPlayList["he"] = "independanceDay_4b.swf";
bannerPlayList["he_rentabroad"] ="independanceDay_4b.swf;";
bannerPlayList["he_sale"] = "independanceDay_4b.swf";
bannerPlayList["he_common"] = "independanceDay_4b.swf";
bannerPlayList["he_common_jobs"] = "independanceDay_4b.swf";
bannerPlayList["en_common"] = "468x60_01_7_10.swf;bannerEldan468x60-02v3.swf;verlain_en_468x60.swf";
bannerPlayList["he_business"] = "independanceDay_4b.swf";
bannerPlayList["he_leasing"] = "independanceDay_4b.swf";



var Panels = new Array();
var Checkboxes = new Array();
var Radiobuttons = new Array();

var panelHide;

var cbStates = new Array();
cbStates[0] = new Image();
cbStates[0].src = "img/checkbox.gif";
cbStates[1] = new Image();
cbStates[1].src = "img/checkbox_on.gif";

var rbStates = new Array();
rbStates[0] = new Image();
rbStates[0].src = "img/radio_off.gif";
rbStates[1] = new Image();
rbStates[1].src = "img/radio_on.gif";

function RegPanel(name) {
	var temp = document.getElementById(name);
	if (temp == null || typeof temp == "undefined") {
	} else {
		Panels.push(temp);
	}
	var menu = document.getElementById(name+"_menu");
	if (menu == null || typeof menu == "undefined") {
	} else {
		menu.onmouseover = ShowPanel;
		// Check child
		if (menu.childNodes.length>0) {
			for (var j=0;j<menu.childNodes.length;j++) {
				var childnode = menu.childNodes[j];
				try {
					childnode.onmouseover = ShowPanel;
				} catch(eee) {
				}
			}
		}
	}
	document.body.onmousemove = initHidePanels;
}

function OpenDetails(params) {
	if (dwin != null) {
		dwin.close();
	}
	dwin = window.open(("/en/pop_details.aspx"+params),"details","width=559,height=280,status=yes,location=no,toolbar=no,scrollbars=yes,resizeable=yes");
}

function regCheckBox(name) {
	var isReload = false;
	var seekValue = "";
	try {
		var reloadHidden = document.getElementById("hdnPageReload").value.toString();
		if (reloadHidden == "1") {
			isReload = true;
			seekValue = document.getElementById(name+"_hidden").value.toString().toUpperCase();
		}
	} catch(errr) {
	}
	var cb = document.getElementById(name);
	Checkboxes.push(cb);
	cb.onclick = checkBoxClick;
	cb.ondblclick = Dummy;
	if (isReload) {
		var myvalue = document.getElementById(document.getElementById(name).getAttribute("myhidden")).value.toString();
		if (myvalue == "1") {
			cb.src = cbStates[1].src;
			cb.setAttribute("checked","1");
		}
	}
}

function regRadiobutton(name) {
	var isReload = false;
	var seekValue = "";
	try {
		var reloadHidden = document.getElementById("hdnPageReload").value.toString();
		if (reloadHidden == "1") {
			isReload = true;
			seekValue = document.getElementById(name+"_hidden").value.toString().toUpperCase();
		}
	} catch(errr) {
	}
	var rb = document.getElementById(name);
	Radiobuttons.push(rb);
	rb.onclick = radioClick;
	rb.ondblclick = Dummy;
	if (isReload) {
		var myvalue = document.getElementById(document.getElementById(name).getAttribute("myhidden")).value.toString();
		if (myvalue == rb.getAttribute("myvalue").toString()) {
			rb.src = rbStates[1].src;
			rb.setAttribute("active","1");
		} else {
			rb.src = rbStates[0].src;
			rb.setAttribute("active","0");
		}
	}
}

function ShowPanel(e) {
	if (typeof e == "undefined") {
		var source = event.srcElement;
	} else {
		var source = e.target;
	}
	clearTimeout(panelHide);
	panelHide = null;
	if (source.tagName.toUpperCase() != "TD") {
		source = source.parentNode;
	}
	HidePanels();
	var myx = YKM.getRealX(source);
	var myy = YKM.getRealY(source);
	var mypanel = document.getElementById(source.getAttribute("mypanel"));
	if (mypanel != null && typeof mypanel != "undefined") {
		mypanel.style.display = "inline";
		mypanel.style.top = (myy+29)+"px";
		mypanel.style.left = (myx-19)+"px";
		if (mypanel.offsetWidth < 100) {
			document.getElementById(source.getAttribute("mypanel")+"_in").style.width = "75px";
		}
	}
}

function isPartOfNavigation(who) {
	for (var i=0;i<Panels.length;i++) {
		if (YKM.isChildOf(who,Panels[i]) || YKM.isChildOf(who,document.getElementById(Panels[i].id+"_menu"))) {
			return true;
		}
	}
	return false;
}

function initHidePanels(e) {
	if (typeof e == "undefined") {
		var source = event.srcElement;
	} else {
		var source = e.target;
	}
	if (panelHide != null) {
		if (isPartOfNavigation(source)) {
		} else {
			HidePanels();
		}
	} else {
		if (!isPartOfNavigation(source)) {
			HidePanels();
		}
	}
}

function HidePanels() {
	for (var i=0;i<Panels.length;i++) {
		Panels[i].style.display = "none";
	}
	panelHide = null;
}

var dwin=null;
var ewin=null;

function OpenEnDetails(params) {
	if (dwin != null) {
		dwin.close();
	}
	dwin = window.open(("/en/pop_details.aspx"+params),"details","width=559,height=280,status=yes,location=no,toolbar=no,scrollbars=yes,resizeable=yes");
}

function OpenNewsletterEN(params) {
	if (ewin != null) {
		ewin.close();
	}
	ewin = window.open(("/en/pop_newsletter.aspx"+params),"newsletter","width=420,height=400,status=no,location=no,toolbars=no");
}

function OpenExtras2(params) {
	if (ewin != null) {
		ewin.close();
	}
	ewin = window.open(("/en/pop_extras.aspx"+params),"extras","width=350,height=240,status=yes,location=no,toolbar=no,scrollbars=yes,resizeable=yes");
}

function OpenPrice(params) {
	if (ewin != null) {
		ewin.close();
	}
	ewin = window.open(("/en/pop_price_details.aspx"+params),"extras","width=500,height=600,status=yes,location=no,toolbar=no,scrollbars=yes,resizeable=yes");
}


function OpenSpecial(params) {
	if (ewin != null) {
		ewin.close();
	}
	ewin = window.open(("/en/pop_special.aspx"+params),"extras","width=330,height=230,status=no,location=no,toolbars=no");
}

function checkBoxClick(e) {
	if (typeof e == "undefined") {
		var source = event.srcElement;
	} else {
		var source = e.target;
	}
	if (source.getAttribute("checked")=="1") {
		source.src = cbStates[0].src;
		source.setAttribute("checked","0");
		document.getElementById(source.getAttribute("myhidden")).value = "0";
	} else {
		source.src = cbStates[1].src;
		source.setAttribute("checked","1");
		document.getElementById(source.getAttribute("myhidden")).value = "1";
		if (source.getAttribute("onCheckOn")!=null) {
			window.setTimeout(source.getAttribute("onCheckOn").toString(),1);
		}
	}
	if (source.getAttribute("checkboxSpecial") != null) {
		eval(source.getAttribute("checkboxSpecial").toString() + "(this);"); 
	}
}

function radioClick(e) {
	if (typeof e == "undefined") {
		var source = event.srcElement;
	} else {
		var source = e.target;
	}
	// Find all radiobuttons of the same group
	var temparr = new Array();
	for (var i=0;i<Radiobuttons.length;i++) {
		if (Radiobuttons[i].getAttribute("group") == source.getAttribute("group")) {
			temparr.push(Radiobuttons[i]);
		}
	}
	for (i=0;i<temparr.length;i++) {
		if (temparr[i] == source) {
			temparr[i].src = rbStates[1].src;
			temparr[i].setAttribute("active","1");
			document.getElementById(temparr[i].getAttribute("myhidden")).value = temparr[i].getAttribute("myvalue");
			if (source.getAttribute("onCheckOn")!=null) {
				window.setTimeout(source.getAttribute("onCheckOn").toString(),1);
			}
		} else {
			temparr[i].src = rbStates[0].src;
			temparr[i].setAttribute("active","0");
		}
	}
	if (source.getAttribute("special")!=null) {
		window.setTimeout(source.getAttribute("special").toString(),1);
	}
	// Try to run special handler
	if (typeof RadioButtonSpecial == "function") {
		try {
			RadioButtonSpecial(source);
		} catch(e) {}
	}

}


/***** YKM HELPER OBJECT ******/

var YKM = {
	browserType: function() {
		// This funciton determines the type of browser engine 
		var isDOM = (document.getElementById)?true:false;
		var isOpera = (window.opera)?true:false;
		var isOpera5 = (isOpera && isDOM);
		var isOpera6 = (isOpera5 && window.print)?true:false;
		var isMSIE = isIE = (document.all && document.all.item && !isOpera);
		var isNC = (navigator.appName=="Netscape");
		var isNC4 = (isNC && !isDOM);
		var isNC6 = isMozilla = (isNC && isDOM);
		if (isDOM && isMSIE && isIE) {
			return "IE";
		} else if (isDOM && (isOpera || isOpera5 || isOpera6)) {
			return "OP";
		} else if (isDOM && (isNC || isNC4 || isNC6)) {
			return "MZ";
		} else {
			return false;
		}
	},
	getRealX: function(ofWho) {
		// Returns the "real" X-coordinate of the top left corner of the object's bounding box
		// The function tries to take into consideration the margins of containers, which normally are not taken into
		// the account when using the conventional properties.
		who = ((typeof ofWho == "string")?(document.getElementById(ofWho)):(ofWho));
		if (typeof who == "undefined" || who == null) {
			return 0;
		} else {
			if (who.tagName.toUpperCase() == "BODY" || who.tagName.toUpperCase() == "HTML") {
				return 0;
			} else {
				var reg = /px/g;
				var marL = who.style.marginLeft;
				if (marL!="") {
					marL = parseInt(marL.replace(reg,""));
				} else {
					marL = 0;
				}
				if (this.browserType()=="IE") {
					return who.offsetLeft + this.getRealX(who.offsetParent);
				} else if (this.browserType()=="OP" && marL!=0) {
					return who.offsetLeft + this.getRealX(who.offsetParent) - marL;
				} else {
					return who.offsetLeft + this.getRealX(who.offsetParent);
				}
			}
		}
	},
	getRealY: function(ofWho) {
		// Returns the "real" Y-coordinate of the top left corner of the object's bounding box
		// The function tries to take into consideration the margins of containers, which normally are not taken into
		// the account when using the conventional properties.
		who = ((typeof ofWho == "string")?document.getElementById(ofWho):ofWho);
		if (typeof who == "undefined" || who == null) {
			return 0;
		} else {
			if (who.tagName.toUpperCase() == "BODY" || who.tagName.toUpperCase() == "HTML") {
				return 0;
			} else {
				var reg = /px/g;
				var marT = who.style.marginTop;
				if (marT!="") {
					marT = parseInt(marT.replace(reg,""));
				} else {
					marT = 0;
				}
				if (this.browserType()=="IE") {
					return who.offsetTop + this.getRealY(who.offsetParent) + marT;
				} else if (this.browserType()=="OP" && marT!=0) {
					return who.offsetTop + this.getRealY(who.offsetParent) - marT;
				} else {
					return who.offsetTop + this.getRealY(who.offsetParent);
				}
			}
		}
	},
	isChildOf: function(whois,ofwho) {
		// This function returns "true" if the "whois" object is a child of "ofwho" object on any level of hierarchy.
		// Both parameters can be either string IDs of the objects or references to the objects
		who = ((typeof whois == "string")?document.getElementById(whois):whois);
		par = ((typeof ofwho == "string")?document.getElementById(ofwho):ofwho);
		if (typeof who == "undefined" || who == null || typeof par == "undefined" || par == null || who.tagName == null || par.tagName == null) {
			return false;
		} else {
			if (par == who) {
				return true;
			} else 
			if ((par.tagName.toUpperCase() == "HTML" || par.tagName.toUpperCase() == "BODY") && (who.tagName.toUpperCase() != "HTML" && who.tagName.toUpperCase() != "BODY")) {
				return true;
			} else 
			if ((par.tagName.toUpperCase() != "HTML" && par.tagName.toUpperCase() != "BODY") && (who.tagName.toUpperCase() == "HTML" || who.tagName.toUpperCase() == "BODY")) {
				return false;
			} else 
			if (who.parentNode == par) {
				return true;
			} else {
				return this.isChildOf(who.parentNode,par);
			}
		}
	},
	mX: 0,		// This variable contains the X-position of the mouse pointer when tracking is active
	mY: 0,		// This variable contains the Y-position of the mouse pointer when tracking is active
	mouseTarget: null,
	trackMouse: function(ev) {
		// This funciton is used to track the mouse movements and report the location of the cursor to the YKM object
		if (YKM.browserType() == "IE") {
			YKM.mouseX = event.x;
			YKM.mouseY = event.y;
			YKM.mouseTarget = event.srcElement;
		} else {
			YKM.mouseX = ev.pageX;
			YKM.mouseY = ev.pageY;
			YKM.mouseTarget = ev.target;
		}
	},
	startTracking: function() {
		// Initiates tracking of the mouse position
		document.onmousemove = this.trackMouse;
	},
	_HOUR: -1,
	_DAY: -2,
	_WEEK: -3,
	_MONTH: -4,
	_YEAR: -5,
	SetCookie: function(cname, cvalue, expiration, path, dom, secure) {
		// The "expires" parameter can receive:
		// - string value of the desired expiration date, in which case it is written to the cookie as is.
		// - null value meaning no expiration date
		// - preset constants (see above the function) add to the current datetime
		// - greater than 0 numeric value of milliseconds to add to the current datetime
		var cookiestr = cname+"="+cvalue;
		if (expiration != null) {
			if (typeof expiration == "string") {
				// Custom expiration date received
				cookiestr += (";expires="+expiration);
			} else if (expiration <0) {
				switch (cookiestr) {
					case -1: var addon = (1000 * 60 * 60); break;
					case -2: var addon = (1000 * 60 * 60 * 24); break;
					case -3: var addon = (1000 * 60 * 60 * 24 * 7); break;
					case -4: var addon = (1000 * 60 * 60 * 24 * 30); break;
					case -5: var addon = (1000 * 60 * 60 * 24 * 365); break;
					default: var addon = 0;
				}
				var d = new Date();
				var expdate = d.getTime() + addon;
				cookiestr += (";expires="+expdate);
			} else {
				var d = new Date();
				var expdate = d.getTime() + expiration;
				cookiestr += (";expires="+expdate);
			}
		}
		if (path && path != null) {
			cookiestr += (";path="+path);
		}
		if (dom && dom != null) {
			cookiestr += (";domain="+dom);
		}
		if (secure && secure == true) {
			cookiestr += (";secure");
			cookiestr += (";HttpOnly");
		}
		document.cookie = cookiestr;
	},
	GetCookie: function(cname) {
		// Returns the string value of the desired cookie or boolean "false" if the cookie not found
		var temparr = document.cookie.split("; ");
		for (var i=0;i<temparr.length;i++) {
			var tempitem = temparr[i].split("=");
			if (tempitem[0] == cname) {
				return tempitem[1];
			}
		}
		return false;
	},
	CookiesSupported: function() {
		// Returns true if cookie set/get cycle was succesful
		this.SetCookie("cookietest","1");
		var test = this.GetCookie("cookietest");
		if (test == "1") {
			this.SetCookie("cookietest","");
			return true;
		} else {
			return false;
		}
	},
	getDocHeight: function() {
		// Returns the true height of the document (including the scroll)
		if (this.browserType() == "IE") {
			var s1 = document.body.scrollHeight;
			var s2 = document.body.parentNode.scrollHeight;
			if (s1<s2) return s2; else return s1;
		} else {
			return document.body.scrollHeight;
		}
	},
	getViewportTop: function() {
		// Returns the top coordinate of the currently viewport
		return document.body.scrollTop;
	},
	getViewportHeight: function() {
		// Returns the height of the client visible area of the browser
		if (this.browserType() == "IE") {
			return document.body.clientHeight;
		} else {
			return document.body.clientHeight;
		}
	},
	Init: function(track) {
		if (track) {
			this.startTracking();
		}
	},
	compDates: function(date1,date2,percision) {
		// Returns 0 for date1 = date2, 1 for date1 > date2 and -1 for date1 < date2
		// percision is 0 by default, marking best percision (down to millisecs)
		// 1 - disregard milliseconds
		// 2 - disregard seconds
		// 3 - disregard minutes
		// 4 - disregard hours
		// 5 - disregard days
		// 6 - disregard months
		if (typeof date1 == "undefined" || typeof date2 == "undefined") {
			return false;
		} else {
			if (typeof percision == "undefined" || percision == null) {
				var per = 0;
			} else {
				var per = percision;
			}
			switch (per) {
				case 0:
					var d1 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate(),date1.getHours(),date1.getMinutes(),date1.getSeconds(),date1.getMilliseconds());
					var d2 = new Date(date2.getFullYear(),date2.getMonth(),date2.getDate(),date2.getHours(),date2.getMinutes(),date2.getSeconds(),date2.getMilliseconds());
					break;
				case 1:
					var d1 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate(),date1.getHours(),date1.getMinutes(),date1.getSeconds(),0);
					var d2 = new Date(date2.getFullYear(),date2.getMonth(),date2.getDate(),date2.getHours(),date2.getMinutes(),date2.getSeconds(),0);
					break;
				case 2:
					var d1 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate(),date1.getHours(),date1.getMinutes(),0,0);
					var d2 = new Date(date2.getFullYear(),date2.getMonth(),date2.getDate(),date2.getHours(),date2.getMinutes(),0,0);
					break;
				case 3:
					var d1 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate(),date1.getHours(),0,0,0);
					var d2 = new Date(date2.getFullYear(),date2.getMonth(),date2.getDate(),date2.getHours(),0,0,0);
					break;
				case 4:
					var d1 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate(),0,0,0,0);
					var d2 = new Date(date2.getFullYear(),date2.getMonth(),date2.getDate(),0,0,0,0);
					break;
				case 5:
					var d1 = new Date(date1.getFullYear(),date1.getMonth(),1,0,0,0,0);
					var d2 = new Date(date2.getFullYear(),date2.getMonth(),1,0,0,0,0);
					break;
				case 6:
					var d1 = new Date(date1.getFullYear(),0,1,0,0,0,0);
					var d2 = new Date(date2.getFullYear(),0,1,0,0,0,0);
					break;
			}
			if (d1.valueOf() == d2.valueOf()) {
				return 0;
			} else {
				if (d1.valueOf()>d2.valueOf()) {
					return 1;
				} else {
					return -1;
				}
			}
		}
	},
	distDates: function(date1,date2,distComponents) {
		// Returns the distance between two dates. The order of the dates is of no importance.
		// distComponents can be one of the following:
		// 0 - Days (default)
		// 1 - Months
		// 2 - Years
		// 3 - Hours
		// 4 - Minutes
		// 5 - Seconds
		// 6 - Total milliseconds
		if (typeof date1 == "undefined" || typeof date2 == "undefined") {
			return false;
		}
		var msDist = (date1.valueOf()>date2.valueOf())?(date1.valueOf() - date2.valueOf()):(date2.valueOf() - date1.valueOf());
		if (typeof distComponents == "undefined" || distComponents == null) {
			var dc = 0;
		} else {
			var dc = distComponents;
		}
		var msDate = new Date(msDist);
		switch (dc) {
			case 0:
				return (msDate.getDate()-1);
				break;
			case 1:
				return (msDate.getMonth());
				break;
			case 2:
				return (msDate.getFullYear() - 1970);
				break;
			case 3:
				return (msDate.getHours()-2);
				break;
			case 4:
				return (msDate.getMinutes());
				break;
			case 5:
				return (msDate.getSeconds());
				break;
			default:
				return msDate.valueOf();
		}
	}
}



function Dummy() {
	return false;
}

function getPrint(print_area)
{	
	//Creating new page
	var pp = window.open();
	//Adding HTML opening tag with <HEAD>  </HEAD> portion 
	pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
	pp.document.writeln('<link rel="stylesheet" type="text/css" href="/en/css/links.css"><link rel="stylesheet" type="text/css" href="/en/css/home.css"></HEAD>')
	//Adding Body Tag
	pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="5" topMargin="0" rightMargin="0">');
	//Adding form Tag
	pp.document.writeln('<form  method="post">');
	//Creating two buttons Print and Close within a table
	pp.document.writeln('<DIV align="center">Reservation details</DIV><br/><br/>');
	//Writing print area of the calling page
	pp.document.writeln('<DIV align="center">');
	pp.document.writeln(document.getElementById(print_area).innerHTML);
	pp.document.writeln('</DIV><br/><br/>');
	pp.document.writeln('<table cellspacing="0" cellpadding="0" border="0" class="ButtonGetRate" align="center">');
	pp.document.writeln('<tr><td class="ButtonGetRate"><asp:LinkButton ID="lnkPrint" runat="server" CssClass="link_BWhite12_N" onclick="javascript:location.reload(true);window.print();"><div>Print</div></asp:LinkButton></td>');
	pp.document.writeln('&nbsp;&nbsp;<td class="ButtonGetRate"><asp:LinkButton ID="lnkClose" runat="server" CssClass="link_BWhite12_N" onclick="window.close();"><div>Close</div></asp:LinkButton></td></tr></table>');
	//Ending Tag of </form>, </body> and </HTML>
	pp.document.writeln('</form></body></HTML>');			
}	


/* Test timefunctions */

function CompileStep1Date(datestr, timestr) {
	var dtext = datestr;
	dtext += " ";
	dtext += timestr.substr(0,2) + ":" + timestr.substr(2,2) + ":00";
	alert(dtext);
	var d = new Date(dtext);
	d.setMilliseconds(0);
	return d.valueOf();
}

