﻿// JavaScript Document

var Panels = new Array();
var Checkboxes = new Array();
var Radiobuttons = new Array();

var panelHide;

// Top banners - playlists for loader.



var bannerPlayList = new Array();
bannerPlayList["he"] = "468x60_heb_hanuka.swf;468x60_20.swf;468x60_heb_30102011_fatal.swf;trucks_468x60.swf";
bannerPlayList["he_rentabroad"] ="468x60_swiss.swf";
bannerPlayList["he_sale"] = "468x60_sale_dabelcheck.swf;468x60_11082011.swf;468X60_3_26052011.swf";
bannerPlayList["he_common"] = "468x60_sale_dabelcheck.swf;468x60_11082011.swf;468X60_3_26052011.swf;468x60_20.swf;trucks_468x60.swf";
bannerPlayList["he_common_jobs"] = "rh2010b_468x60_heb.swf;468x60_new_june.swf;468x60_May2010.swf;new_tadmit_468x60.swf";
bannerPlayList["en_common"] = "468x60_en_hanukah.swf;468x60_en_20per.swf;468x60_20_en_02052011.swf";
bannerPlayList["he_business"] = "trucks_468x60.swf;468x60_2252011.swf";
bannerPlayList["he_leasing"] = "468x60_2252011.swf;trucks_468x60.swf";
bannerPlayList["fr"] = "468x60_fr_hanuka.swf;468x60_en_fr_31302011.swf;fr_2_468x60.swf";
bannerPlayList["ger"] = "468x60_en_20per.swf;468X60_5_08082011.swf;468x60_ipad_16052011.swf;468x60_20_en_02052011.swf";
bannerPlayList["ru"] = "468x60_rus.swf";

var cbStates = new Array();
cbStates[0] = new Image();
cbStates[0].src = "/common/img/checkbox.gif";
cbStates[1] = new Image();
cbStates[1].src = "/common/img/checkbox_on.gif";

var rbStates = new Array();
rbStates[0] = new Image();
rbStates[0].src = "/common/img/radio_off.gif";
rbStates[1] = new Image();
rbStates[1].src = "/common/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 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 regAllCheckboxes(namestring,markall) {
	var _allCheckboxes = new Array();
	_allCheckboxes = namestring.toString().split(",");
	for (var i=0;i<_allCheckboxes.length-1;i++) {
		regCheckBox(_allCheckboxes[i]);
		var source = document.getElementById(_allCheckboxes[i]);
		if (markall) {
			source.src = cbStates[1].src;
			source.setAttribute("checked","1");
			document.getElementById(source.getAttribute("myhidden")).value = "1";
		}
	}
	if (markall) {
		var hidden = document.getElementById(source.getAttribute("myhidden"));
		var newval = "";
		for (var i in Checkboxes) {
			if (Checkboxes[i].getAttribute("synnergy")!=null && Checkboxes[i].getAttribute("checked")=="1") {
				if (newval == "") 
					newval = Checkboxes[i].getAttribute("val").toString(); 
				else
					newval += (","+Checkboxes[i].getAttribute("val").toString()); 
			}
		}
		hidden.value = newval;
	}
}

function reMarkCheckboxes() {
	var selectedValues = document.getElementById("cbCar1_Value").value.split(",");
	for (var s = 0; s < selectedValues.length; s++) {
		if (selectedValues[s] == "") continue;
		for (var i in Checkboxes) {
			if (Checkboxes[i].getAttribute("val") == selectedValues[s]) {
				Checkboxes[i].setAttribute("checked","1");
				if (Checkboxes[i].getAttribute("big")!=null) {
					Checkboxes[i].src = cbStatesBig[1].src;
				} else {
					Checkboxes[i].src = cbStates[1].src;
				}
				break;
			}
		}
	}
}

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 && !isPartOfNavigation(source)) {
		panelHide = window.setTimeout(HidePanels,250);
	}
}

function HidePanels() {
	for (var i=0;i<Panels.length;i++) {
		Panels[i].style.display = "none";
	}
	panelHide = null;
}

var ewin = null;
var dwin = null;
function OpenSaleDetails(params) {
	if (dwin != null) {
		dwin.close();
	}
	dwin = window.open(("/he_sale/pop_details.aspx"+params),"details","width=559,height=280,status=yes,location=no,toolbar=no,scrollbars=yes,resizeable=yes");
}

function OpenDetails(params) {
	if (dwin != null) {
		dwin.close();
	}
	dwin = window.open(("/he/pop_details.aspx"+params),"details","width=559,height=280,status=yes,location=no,toolbar=no,scrollbars=yes,resizeable=yes");
}

function OpenNewsletter(params) {
	if (ewin != null) {
		ewin.close();
	}
	ewin = window.open(("/common/pop_newsletter.aspx"+params),"newsletter","width=400,height=400,status=no,location=no,toolbars=no");
}

function OpenExtras(params) {
	if (ewin != null) {
		ewin.close();
	}
	ewin = window.open(("/he/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(("/he/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(("/he/pop_special.aspx"+params),"extras","width=330,height=230,status=no,location=no,toolbars=no");
}

function OpenBranchDetails(params) {
	window.open(("pop_BranchDetails.aspx"+params),"details","width=559,height=254,status=no,scrollbars=no,location=no,toolbars=no");
}


function OpenCountryDetails(params) {
	window.open(("pop_CountryDetails.aspx"+params),"details","width=559,height=254,status=no,scrollbars=no,location=no,toolbars=no");
}

function checkBoxClick(e) {
	if (typeof e == "undefined") {
		var source = event.srcElement;
	} else {
		var source = e.target;
	}
	// Check synnergy total limiter
	if (source.getAttribute("checked")=="1") {
		if (source.getAttribute("big")!=null) {
			source.src = cbStatesBig[0].src;
		} else {
			source.src = cbStates[0].src;
		}
		source.setAttribute("checked","0");
		if (source.getAttribute("synnergy")!=null) {
		} else {
			document.getElementById(source.getAttribute("myhidden")).value = "0";
		}
	} else {
		if (source.getAttribute("synnergy")!=null) {
			var hidden = document.getElementById(source.getAttribute("myhidden"));
			if (YKM.countChars(hidden.value.toString(),",")==2) {
				return false;
			}
		}
		if (source.getAttribute("big")!=null) {
			source.src = cbStatesBig[1].src;
		} else {
			source.src = cbStates[1].src;
		}
		source.setAttribute("checked","1");
		document.getElementById(source.getAttribute("myhidden")).value = "1";
	}
	// Check special functions
	if (source.getAttribute("synnergy")!=null) {
		var hidden = document.getElementById(source.getAttribute("myhidden"));
		var newval = "";
		for (var i in Checkboxes) {
			if (Checkboxes[i].getAttribute("synnergy")!=null && Checkboxes[i].getAttribute("checked")=="1") {
				if (newval == "") 
					newval = Checkboxes[i].getAttribute("val").toString(); 
				else
					newval += (","+Checkboxes[i].getAttribute("val").toString()); 
			}
		}
		hidden.value = newval;
	}
}

function CheckSynicated(hname) {
	var myval = document.getElementById(hname).value.toString();
	if (myval=="") {
		alert("לקבלת הצעה יש לבחור בין רכב אחד לשלושה רכבים");
		return false; }
	else
	{
		document.getElementById("hdnSelectedCars").value = "";
		return true
	 };
}

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");
		} else {
			temparr[i].src = rbStates[0].src;
			temparr[i].setAttribute("active","0");
		}
	}
	// 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) {
		who = ((typeof ofWho == "string")?(document.getElementById(ofWho)):(ofWho));
		if (typeof who == "undefined" || who == null) {
			return 0;
		} else {			
			var nLeftPos = who.offsetLeft;          // initialize var to store calculations
			var eParElement = who.offsetParent;     // identify first offset parent element  
			while (eParElement != null)
			{                                            // move up through element hierarchy
				nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
				eParElement = eParElement.offsetParent;  // until no more offset parents exist
			}
			return nLeftPos;                             // return the number calculated
		}
	},
	getRealY: function(ofWho) {
		who = ((typeof ofWho == "string")?document.getElementById(ofWho):ofWho);
		if (typeof who == "undefined" || who == null) {
			return 0;
		} else {			
			var nTopPos = who.offsetTop;
			var eParElement = who.offsetParent;
			while (eParElement != null)
			{
				nTopPos += eParElement.offsetTop;
				eParElement = eParElement.offsetParent;
			}
			return nTopPos;			
		}
	},
	isChildOf: function(whois,ofwho) {
		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 || typeof par.tagName == "undefined" || typeof who.tagName == "undefined") {
			return false;
		} 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 || who == 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 -4: 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;
		}
	},
	countChars: function(sourcestr, whichchar) {
		var count = 0;
		for (var i=0;i<sourcestr.length;i++) {
			count += (sourcestr.charAt(i) == whichchar)?1:0;
		}
		return count;
	},
	Init: function(track) {
		if (track) {
			this.startTracking();
		}
	}
}

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="css/links.css"><link rel="stylesheet" type="text/css" href="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>');			
}

var thisbanner = 2;

function SwitchBanner() {
	if (thisbanner == 1) {
		so2.write("banners");
		thisbanner = 2;
	} else {
		so1.write("banners");
		thisbanner = 1;
	}
}

function Href(url) {
	window.location.href = url;
}

/*** Panel exception ***/

var pantimeout;

function showPanel() {
	var strip = document.getElementById("topnavigation");
	var pan = document.getElementById("panel_deal");
	pan.style.display = "block";
	pan.style.top = (YKM.getRealY(strip) + 29) + "px";
	pan.style.left = (YKM.getRealX(strip) + 0) + "px";
	strip.onmousemove = checkMouseOut;
	pan.onmousemove = checkMouseOut;
	document.body.onmouseover = checkMouseOut;
}



function checkMouseOut() {
	if (typeof this != "undefined") {
		if (YKM.isChildOf(this,document.getElementById("panel_deal")) || this == document.getElementById("panel_deal")
			 || YKM.isChildOf(this,document.getElementById("topnavigation")) || this == document.getElementById("topnavigation")) {
			// Is child of panel
			window.clearTimeout(pantimeout);
		} else {
			pantimeout = window.setTimeout("hidePanel();",500);
		}
	} else {
		clearTimeout(pantimeout);
	}
}

function hidePanel() {
	document.getElementById("panel_deal").style.display = "none";
	document.getElementById("topnavigation").onmousemove = doNothing;
	document.getElementById("panel_deal").onmousemove = doNothing;
	document.body.onmouseover = doNothing;
}

function doNothing() {
}

function getElementByAttr(attr,tobj,inside) {
	var cres = new Array();
	if ((typeof tobj == "undefined" || tobj == null) && (!inside)) {
		var t = document.body;
	} else if ((typeof tobj == "undefined" || tobj == null) && (inside)) {
		return null;
	} else {
		if (typeof tobj == "string") {
			var t = document.getElementById(t);
		} else {
			var t = tobj;
		}
	}
	for (var inum = 0; inum<t.childNodes.length; inum++) {
		var myitem = t.childNodes[inum];
		if (typeof myitem != "undefined" &&  typeof myitem.getAttribute != "undefined" && myitem.getAttribute(attr) != null) {
			cres.push(myitem);
		}
		var tempres = getElementByAttr(attr,myitem,true);
		if (tempres != null) {
			for (var j = 0; j<tempres.length; j++) cres.push(tempres[j]);
		}
	}
	return cres;
}

function callMeCheck()
{
	if(document.getElementById('callMe_callMe'))
	{
		document.getElementById('callMe_callMe').style.display = "block";
		document.getElementById('mainHeader').className += " t_short";
		document.getElementById('underNav').style.width = "500px";
		document.getElementById('wrap').style.display = "block";
	}
	else document.getElementById('wrap').style.display = "block";
}

function closeFlash() {
	document.getElementById("ad_wrap").style.display = "none";
	document.getElementById("dropdowns").style.position = "relative";
	document.getElementById("dropdowns").style.top = "0px";
	document.getElementById("dropdowns").style.left = "0px";
}

/** HE-SALE special **/
var innerFrame = null;
function getCatalogue() {
	if (innerFrame == null) {
		document.location.href = "/he_sale/step2.aspx";
	} else {
		innerFrame.doNext();
	}
}

