﻿var menuDivFrameCurrent = null;
var menuItemCurrent = null;
var menuItemHide = false;
var gCurrDirectorDiv = null;
var globalEvent;
var xmlhttp = null;
var tableDirection = "rtl";
var gGameId = 0;
var indexSelect;
var indexGroup=new Array(0,0,0,0,0);
////////////////Tapuz////////////////////////////////////

function switchCase(i)
{
    var j;
    for(j=1;j<=5;j++)
    {
        if(j==i)
            document.getElementById("group" + j).style.display="block";
         else
            document.getElementById("group" + j).style.display="none";
    }
}

function newNumber(j)
{
    var bFlag=true;
//    var phoneRE = /^[0]([0|2|3|4|5|6|7|8|9]{1,2})\d{7}$/;
    var phoneRE = /^[0](([7]([7]|[3]|[2]))|([5]([2]|[4]|[0]|[7]))|([2]|[3]|[4]|[5]|[6]|[7]|[8]|[9]))\d{7}$/;
    var x=document.getElementById("txtfirstName" + j);
    var y=document.getElementById("txtlastName" + j);
    var z=document.getElementById("txtphoneNum" + j);
   
    if(x.value.length > 20)
     {
        bFlag=false;
        alert("שם עד 20 תוים");
        return;
     }
    if(y.value.length > 20)
     {
         bFlag=false;
         alert("שם עד 20 תוים");
         return;
     }
    if(z.value.length==0)
     {
        bFlag=false;
        alert("מספר טלפון/פלאפון חובה");    
        return;
     }
     if (!(z.value.match(phoneRE)))
     {
        bFlag=false;
        alert("מספר טלפון/פלאפון אינו תקין");    
        return;
     }
     if(!bFlag)
        return;
  
     var i;
     var div,select,label,br;
     
     for(i=1;i<=5;i++)
     {
         div=document.getElementById("groupTelephon" + i);
         select=document.createElement("<input id='Checkbox_" + i +"_"+indexSelect + "' type='checkbox'/>");
         label=document.createElement("<label id='label_" + i +"_" + indexSelect + "'></label>");
         br=document.createElement("<br/>");
         label.innerText=z.value + " " + y.value + " " + x.value;
         div.appendChild(select);
         div.appendChild(label);
         div.appendChild(br);
     }
     indexSelect++;
     x.value="";
     y.value="";
     z.value="";
 }
 
 function newDest(j)
 {
     var index=1;
     var i;
     var br=document.createElement("<br>");
     var b=document.createElement("<b>");
     var div=document.getElementById("groupDest"+j);
  
     var newDiv;
     var input;
     var label;
     var val;

     for(i=1;i<=indexGroup[j-1];i++)
     {
        div.removeChild(document.getElementById("divDest_" + j + "_" + i));
        
     }
     indexGroup[j-1]=0;
 
     for(i=1;i<indexSelect;i++)
     {  
        if(document.getElementById("Checkbox_" + j + "_" + i).checked)
        {
            newDiv=document.createElement("<div id='divDest_" + j + "_" + index + "' style='padding-bottom:4px;padding-top:4px;'></div>");
            input=document.createElement("<input id='txt_" + j + "_" + index + "' name='txt_" + j + "_" + index + "' type='text' style='border:1px solid #CDCDCD; width:200px; height:20px;' readonly='readonly' />");   
            label=document.createElement("<label id='lbl_" + j + "_" + index + "' name='lbl_" + j + "_" + index + "' style='width:84px; padding-bottom:4px;padding-top:4px; font-size:98%;font-family:Arial;font-weight:bold;'></label>");
            label.innerText=index+".";
            val=document.getElementById("label_" + j + "_" + i);
            input.value=val.innerText;
            label.appendChild(b);
            newDiv.appendChild(label);
            newDiv.appendChild(input);
            div.appendChild(newDiv);   
            indexGroup[j-1]++;
            index++;
         }
     }
 }
 
 function clearScreen(j)
 {
     document.getElementById("txtfirstName" + j).value="";
     document.getElementById("txtlastName" + j).value="";
     document.getElementById("txtPelNum" + j).value="";
 }
 
 function CancelGroups(j)
 {
    
 }
 
 function SaveGroupJs(j)
 {
    document.getElementById("index").value=indexGroup[j-1];
    alert(document.getElementById("index").value);
 }
 
 /*function saveGroup(j)
 {
    alert("aaaa");
 }*/

function CheckTimeout (id, name)
{
	var banner = document.getElementById(name + "$ad$" + id);
	
	if(banner == null || banner.childNodes == null || banner.childNodes.length == 0)
	{
		if(banner != null)
			banner.style.display = "none";
		
		var def = document.getElementById(name + "$def$" + id);
		def.style.display = ""
		
	}
}

function GetContent (serviceUrl, clientIdentificator, userSegment, bannerName)
{
	if(userSegment == "")
		userSegment = "1A2B3C4D5E";
	
	var random = new String(Math.random()).substring(2,11);
		
	//alert(serviceUrl + clientIdentificator + "/" + userSegment + "/" + random + "@" + bannerName)
	//document.write("<script language=\"Javascript1.1\" src=\"" + serviceUrl + clientIdentificator + "/" + userSegment + "/" + random + "@" + bannerName + "\"></script>");
	//document.write("<script language='Javascript1.1' src='http://rm.tapuz.co.il/RealMedia/ads/adstream_sx.ads/www.orange.co.il/1A2B3C4D5E/145102721@x01'></script>");
	
	document.write('<SCRIPT LANGUAGE="JavaScript1.1" SRC="http://rm.tapuz.co.il/RealMedia/ads/adstream_sx.ads/www.orange.co.il/1A2B3C4D5E/145102721@x01">');
	document.write('</SCRIPT>');
}
/////////////////////////////////////////////////////////

function GenerateHTTPRequest()
{
    if(arrUrls == null)
        return;
        
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject)
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
      
    if (xmlhttp != null)
    {
        xmlhttp.onreadystatechange = StateChanged;
        for(var i = 0; i < arrUrls.length; i++)
        {      
            var num = "";
            try
            {
                num = Math.floor(Math.random()*100);                   
            }
            catch (err)
            {
                
            }
            
            try
            {  
                xmlhttp.open("GET", arrUrls[i] + "?num=" + num ,false);
                xmlhttp.send();
            }
            catch (err)
            {
              
            }
        }
    }
}

function StateChanged()
{
    /// ready for debugging on server. add alert if needed
    try
    {        
        
    }
    catch(err)
    {
    }
}

function ClickGameLink ()
{
	var  link = document.getElementById(gParam);
	if(link != null)
	{
		try
		{
			link.click();
		}
		catch(ex)
		{
			
		}
	}
}

function ValidateLogin()
{
	
	
    var user = document.getElementById("txtUserName");
    var pass = document.getElementById("txtPassword");
    
    if((user != null && user.value.length == 0) || (pass != null && pass.value.length == 0))
    {
    	return false;
    }
    return true;
}

function divPopup(id, frameId)
{
	divPopup(id, frameId, 0);
}


function divPopup(id, frameId, gameId)
{

	try
	{
		if(gameId != 0)
		
			document.getElementById("hidGameId").value = gameId;
		
	}
	catch (err)
	{
		//alert(err.message);
	}
	
   var div = document.getElementById(id);
   var iframe = document.getElementById(frameId);
     
   try
   {
   if(div == null)
   	   div = document.getElementById(divID);
    if(iframe == null)
   	   iframe = document.getElementById(iframeID);
   }
   catch (ex)
   {
   	   
   }
   
   var body;
      
   try
   {
        body = document.body;
   }
   catch(err)
   {
       body = document.getElementsByTagName("TABLE")[0];
   }
      
   if(div != null && body != null)
   {
        try
        {
        	if(document.getElementById("popupBgDiv") == null)
        	{
            	var newDiv = document.createElement("DIV");
            	newDiv.id = "popupBgDiv";
            	newDiv.className = "PopupDivBG";
            	newDiv.style.height = document.body.childNodes[0] != null
            		 ?
            		 	Math.max(document.body.childNodes[0].offsetHeight, screen.height)
            		 :  document.body.offsetHeight;
            	document.body.appendChild(newDiv);
            	//document.body.scroll = "no";
            }
            var agt = navigator.userAgent.toLowerCase();
            if(agt.indexOf("msie 6.0") != -1)
            	hideElements("SELECT");
        }
         /*try
        {
        	if(document.getElementById("popupBgDiv") == null)
        	{
            	var newDiv = document.createElement("DIV");
            	newDiv.id = "popupBgDiv";
            	newDiv.className = "PopupDivBG";
            	
            	newDiv.style.height = document.body.children[0] != null
            		 ?
            		 	Math.max(document.body.children[0].offsetHeight, screen.height)
            		 :  document.body.offsetHeight;
            	document.body.appendChild(newDiv);
            	//document.body.scroll = "no";
            }
            var agt = navigator.userAgent.toLowerCase();
            if(agt.indexOf("msie 6.0") != -1)
            	hideElements("SELECT");
        }*/
        catch(err)
        {
            alert(err.message);
            
            div.style.left = 0 + "px";
            div.style.top = 100 + "px";
            div.style.visibility = "visible";
        }
       
   }
   
   if(iframe != null && div != null)
   {
   	    try
        {
           	div.style.left = body.style.left + (body.offsetWidth - div.style.width.substr(0, div.style.width.length -2))/2 + "px";
           	var scrollOffset = document.all? document.body.scrollTop : 0;
           	div.style.top = scrollOffset + 100 + "px";
            div.style.visibility = "visible";
        	div.style.display = "block";
         }
        catch(err)
        {
        	
            div.display = "block";
            iframe.width = div.offsetWidth;
            iframe.height = div.offsetHeight;
            iframe.top = div.top;
            iframe.left = div.left;
            iframe.zIndex = div.zIndex - 1;
            iframe.display = "block";
        }
   }
}

var hiddenElements = new Array();
function hideElements(elementName)
{
	var elements;
			
    try
    {
        elements = document.getElementsByTag(elementName);
    }
    catch(err)
    {
        elements = document.getElementsByTagName(elementName);
    }
    
	for(var i = 0; i < elements.length; i++)
		if(elements[i].currentStyle.display != "")
		{
			elements[i].style.display = "none";
			hiddenElements[hiddenElements.length] = elements[i];
		}		
}

function showElements()
{
	if(hiddenElements == null)
		return;
	
	for(var i = 0; i < hiddenElements.length; i++)
	{
			hiddenElements[i ].style.display = "";
			hiddenElements.splice(i, 1);
	}
}

function divClose(id, frameId)
{
	var div = document.getElementById(id);
    var iframe = document.getElementById(frameId);
    
    if(div != null)
    	div.style.display = "none";
    if(iframe != null)
    	iframe.style.display = "none";
    
    var newDiv = document.getElementById("popupBgDiv");
     if(newDiv != null)
     {
        document.body.removeChild(newDiv);
        
        var agt = navigator.userAgent.toLowerCase();
        if(agt.substr("msie 6.0") != -1)
            	showElements();  		
        
           //document.body.scroll = "auto";    	      
     }
}

var divID;
var iframeID;
function AttachEvent(eventName, eventHandler, id1, id2)
{
	divID = id1;
	iframeID = id2;
	
    try
    {
    	window.attachEvent(eventName, eventHandler);
    }
    catch (err)
    {
    	window.addEventListener(eventName, eventHandler);
    }
}

var gParam = "";
function AttachEventForDownload(eventName, eventHandler, param)
{
	if(param == 0) return;
	gParam = param;
	try
    {
    	window.attachEvent(eventName, eventHandler);
    }
    catch (err)
    {
        window.addEventListener(eventName, eventHandler, false);
    }
}

function CheckClickBool(ev)
{
    var objEvent = (ev == null ? window.event : ev);

    var agt = navigator.userAgent.toLowerCase();
    
    var isIE = (agt.indexOf('msie') != -1);
    var isFF = (agt.indexOf('firefox') != -1);
   
    var code = 0;
    
    if(isIE)
        code = objEvent.keyCode;    
    else if(isFF)
        code = objEvent.which;
            
    if(code == 13)
    {
        return true;
    }
    
    return false;
}

function checkClick(ev, flag, linkId)
{
    var objEvent = (ev == null ? window.event : ev);

    var agt = navigator.userAgent.toLowerCase();
    
    var isIE = (agt.indexOf('msie') != -1);
    var isFF = (agt.indexOf('firefox') != -1);
   
    var code = 0;
    
    if(isIE)
        code = objEvent.keyCode;    
    else if(isFF)
        code = objEvent.which;
            
    if(code == 13)
    {
    	var a = (linkId == null ? document.getElementById("searchLink" + flag) : document.getElementById(linkId));
        if(a != null)
        {
        	a.onclick();
        }
        else
        {
          alert("No link");
          return false;
        }
    }
}

function writeHTML(html)
{
	document.write(html);
}

function showSubMenu(parent, id)
{
	menuItemHide = false;
	
	if (menuItemCurrent && menuItemCurrent.id == "menuitem" + id)
	{
		return;
	}	
	if (menuItemCurrent)
	{
		menuItemCurrent.style.visibility = "hidden";
		menuDivFrameCurrent.style.display = "none";
	}
		
	var item = document.getElementById("menuitem" + id);
	if (!item) return;
		
	var isRtl = item.getAttribute("isRtl") == "True";
	item.style.top = _offsetTop(parent) + parent.offsetHeight;
	
	if(isRtl)
	{
		item.style.left = _offsetLeft(parent) + (parent.offsetWidth - item.offsetWidth)+ 2 + "px";
	}	
	else
		item.style.left = _offsetLeft(parent)-1;
	
		
	var itemIFrame = document.getElementById("divShim" + id);
			
	item.style.display = "block";
    itemIFrame.style.width = item.offsetWidth;
    itemIFrame.style.height = item.offsetHeight;
    itemIFrame.style.top = item.style.top;
    itemIFrame.style.left = item.style.left;
    itemIFrame.style.zIndex = item.style.zIndex - 1;
    itemIFrame.style.display = "block";
    
	item.style.visibility = "visible";
	
	menuItemCurrent = item;
	menuDivFrameCurrent = itemIFrame;
	
}
function hideSubMenu()
{
	if (!menuItemHide || !menuItemCurrent)
		return;
				
	menuItemCurrent.style.visibility = "hidden";
	menuDivFrameCurrent.style.display = "none";
	
	menuItemCurrent = null;
	menuItemHide = false;
}

function _offsetTop(obj)
{
	var top = 0;
	for (; obj; obj=obj.offsetParent)
		top += obj.offsetTop;
	return top;
}

function _offsetLeft(obj)
{
	var left = 0;
	for (; obj && obj != document.body; obj=obj.offsetParent)
		left += obj.offsetLeft;
	return left;
}

// returns true if node a contains event.toElement/relatedTarget.
function containsToElement(a)
{
    var b = globalEvent.toElement ? globalEvent.toElement : globalEvent.relatedTarget;
	if (b == null) return;
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

/*
	Validate a form's elements according to varius attributes
*/
function validateForm(form, title, submit)
{
	var i, j, u, sum;
	var input;
	var valid;
	var sErrorMsg = "";

	for (i=0; i<form.elements.length; i++)
	{
		input = form.elements[i];
		// skip input when it's not rendered (ie. parent display:none)
		if (input.offsetHeight == 0) continue;
		valid = true;

		// Validate value according to element type and validation type
		switch (input.type.toLowerCase())
		{
		case "text":
		case "password":
		case "textarea":
		case "file":
			if (!input.getAttribute("validation"))
				input.setAttribute("validation", "string");
			if (input.getAttribute("mandatory"))
			{
				if (input.getAttribute("mandatory").toLowerCase() != "true" && input.value.length == 0)
					continue;
			}
			else
				if (input.value.length == 0)
					continue;
			switch (input.getAttribute("validation").toLowerCase())
			{
			case "string":
			case "password":
				if (input.value.length == 0)
					valid = false;
				break;
			case "integer":
				if (!/\d+/.test(input.value))
					valid = false;
				break;
			case "email":
				if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(input.value))
					valid = false;
				break;
			case "phone":
				if (!/^\+?\d+(-\d+)*$/.test(input.value))
					valid = false;
				break;
			case "id":
				j = input.value.toString();
				input.value = j.replace(/\D/g, "");
				if (/\d+/.test(input.value))
				{
					sum = 0;
					for (j=0; j<input.value.length; j++)
					{
						u = (j % 2 ? 2 : 1) * parseInt(input.value.charAt(input.value.length - j - 1));
						sum += u > 9 ? Math.floor(u / 10) + u % 10 : u;
					}
					if (sum % 10) valid = false;
				}
				else
					valid = false;
				break;
			case "compare":
				// Check the compareInput attribute
				if (input.getAttribute("compareInput"))
					if (input.value != form.elements[input.getAttribute("compareInput")].value)
						valid = false;
				break;
			default:
				var regExp = new RegExp(input.getAttribute("validation"), "im");
				valid = regExp.test(input.value);
			}

			// Validate max and min according to validation type
			if (valid == true)
			{
				switch (input.getAttribute("validation").toLowerCase())
				{
				case "integer":
					if (input.getAttribute("validmax"))
					{
						if (parseInt(input.value) > parseInt(input.getAttribute("validmax")))
							valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (parseInt(input.value) < parseInt(input.getAttribute("validmin")))
							valid = false;
					}
					break;
				default:
					if (input.getAttribute("validmax"))
					{
						if (input.value.length > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (input.value.length < input.getAttribute("validmin")) valid = false;
					}
					break;
				}
			}
			break;
		case "select-one":
			if (input.getAttribute("mandatory"))
				if (input.selectedIndex == 0)
					valid = false;
			break;
		case "select-multiple":
			if (input.getAttribute("mandatory"))
			{
				sum = 0;
				for (j=0; j<input.options.length; j++)
				{
					if (input.options[j].selected) sum++;
				}
				if ((!input.getAttribute("validmax")) && (!input.getAttribute("validmin")))
				{
					if (sum == 0) valid = false;
				}
				else
				{
					if (input.getAttribute("validmax"))
					{
						if (sum > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (sum < input.getAttribute("validmin")) valid = false;
					}
				}
			}
			break;
		case "checkbox":
			if (input.getAttribute("mandatory"))
				valid = input.checked;
			break;
		}

		if (!valid)
		{
			if (input.getAttribute("validationError"))
				sErrorMsg += input.getAttribute("validationError") + "\n";
			else
				sErrorMsg += "Error in field " + input.name + "\n";
		}
	}
	if (sErrorMsg.length)
	{
		alert((title ? title + "\n" : "") + sErrorMsg);
		return false;
	}
	else
	{
		if (submit)
			form.submit();
		return true;
	}
}
function init()
{
	Plans_Menu.style.visibility = "hidden";
	Plans_Menu.style.display = "none";
}

function topMenu(menuId)
{
	var obj = document.getElementById(menuId)
	obj.style.visibility = (obj.style.visibility == "visible"?"hidden":"visible");
	obj.style.display = (obj.style.display == "block"?"none":"block");
}


function Chng_ON(pic_location)
{
document[pic_location].src = 'res/css/DhtmlArrow1.gif'
}

function Chng_OFF(pic_location)
{
document[pic_location].src = 'res/css/DhtmlArrow0.gif'
}


function Chng_ON_RightBar(id)
{
    var ltr = document.getElementById("tbMenu").className == "ltr";

    if(ltr)
        document.getElementById("RightBarLevel2Arrow" + id).src = 'res/css/EnglishImages/RightBarArrowGray2.gif';
    else
        document.getElementById("RightBarLevel2Arrow" + id).src = 'res/css/RightBarArrowGray2.gif';
}

function Chng_OFF_RightBar(id)
{
    var ltr = document.getElementById("tbMenu").className == "ltr";

    if(ltr)
        document.getElementById("RightBarLevel2Arrow" + id).src = 'res/css/EnglishImages/RightBarArrowOrange2.gif';
    else
        document.getElementById("RightBarLevel2Arrow" + id).src = 'res/css/RightBarArrowOrange2.gif';
}

function Chng_ON_RightBar3rd(pic_location)
{
document[pic_location].src = 'res/css/RightBarArrowGray3rd.gif'
}

function Chng_OFF_RightBar3rd(pic_location)
{
document[pic_location].src = 'res/css/RightBarArrowOrange3rd.gif'
}

var last_div = null

/*
function FAQ_Display(MessageID)
	{
	if (eval("document.all.AllText" + MessageID))
		{
		if (eval("AllText" + MessageID + ".style.display=='none'"))
			{
			eval("AllText" + MessageID + ".style.display='block'")
			document[MessageID].src = 'images/FAQ_Minus.gif'
			}
		else
			{
			eval("AllText" + MessageID + ".style.display='none'")
			document[MessageID].src = 'images/FAQ_Plus.gif'
			}
		}
	}
*/	
function printContent()
{
    alert(document.getElementById("tdContent"));
    if (typeof(document.getElementById("tdContent"))=='object')
	{
	
		var str;
		str = '<html><head><link rel="stylesheet" href="include/default.css" type="text/css"></head><body  onload="ChangeHtml();window.print();window.close();" style=text-align:justify;>';
		//str = str + '<img src="' + document.getElementById("imgTitle").src + '"';
										
		str = str + document.getElementById("tdContent").innerHTML;
				
		str  = str + '<script type="text/javascript">' + 
						'function ChangeHtml()' +
						'{' +
							'var tbPrints = document.getElementsByName("tbPrint");' +
							'var tdParents = document.getElementsByName("tdParent");' +
							'var tables = new Array();' +
							'var temp = new Array();' +
														
							'for(var m = 0; m < tdParents.length; m++) ' +
							'{ ' +
								'temp[m] = tdParents[m].childNodes[0];' +
							'}' +
														
							'for(var n =0; n < tbPrints.length; n++)' +
							'{' +
								'tables[tables.length] = tbPrints[n];'  +
							'}' +
																	
							'for(var n =0; n < temp.length; n++)' +
							'{' +
								'tables[tables.length] = temp[n];'  +
							'}' +										
																																			
							'for(var k =0; k < tables.length; k++) ' +
							'{ ' +
								'var tb = tables[k]; ' +
								
								'tb.cellSpacing = "0px"; ' +
								
								'var tr; ' +
								'for(var i=0; i < tb.rows.length;i++) ' +
								'{ '+
									'tr = tb.rows[i]; ' +
									'for(var j=0; j < tr.cells.length; j++) '+
										'{ '+
											'if(document.all) { ' +
												'if(tr.cells[j].innerText == "") ' +
													'tr.cells[j].innerText = " ";} ' +
											'else { ' + 
												'if(tr.cells[j].textContent == "") { ' +
													' var nbsp = document.createTextNode( "\u00A0" ); tr.cells[j].appendChild(nbsp); }} ' +
													
											'tr.cells[j].style.border = "1px solid #000000"; '+
										'} ' +	
								'} ' +	
								'tb.style.border = "1px solid #000000"; ' + 
							'} ' +	
						'} ' +
					 '</script>';
		
		str += '</body></html>';
		w=window.open('','newwin','top=5000','left=5000');
		w.document.write(str);
		w.document.close();
	}
}


function ValidateRecomendPlan()
{
    if( document.getElementById("select_PlansAndRates_Segment1").value  == "-1" && 
        document.getElementById("select_PlansAndRates_Segment2").value == "-1" && 
        document.getElementById("select_PlansAndRates_Segment3").value == "-1" && 
        document.getElementById("select_PlansAndRates_Segment4").value == "-1")
        {
            alert("יש לבחור לפחות שדה אחד");
            return false;
        }
        
    return true;
}

function ValidateSearch()
{
    if(document.getElementById("txtSearch").value.length < 2)
        return false;
        
    return true;
}

function LoadModels()
{
    var manufID = document.getElementById("selManuf").value;
    var select = document.getElementById("selModel");
    select.options.length  = 1; 
       
    if(arrModels != null && arrModels[manufID] != null)
    {
        var models = arrModels[manufID].split("$");
    
        for(var i=0; i < models.length; i++)
        {
            var option = document.createElement("OPTION");
            option.value = models[i].split("#")[0];
            option.text = models[i].split("#")[1];
            select.options[select.options.length] = option;           
        }
    }
    else
       return;
        
}

function ChangeBackGround(currId, anotherId, color)
{
    if(anotherId == null)
    {
        var currDiv = document.getElementById(currId);
        currDiv.style.background = '#ffffff';
        return;
    }

    var currDiv = document.getElementById(currId);
    
    if(currDiv.style.background == '#d9d9d9' && color == '#e9e9e9')
        return;
    
    var anotherDiv = document.getElementById(anotherId);
    
    //alert(currDiv.style.bgColor);
    
    currDiv.style.background = color;
    anotherDiv.style.background = '#ffffff';
}

function ValidateModel()
{
    if(document.getElementById("selModel").value == "-1")
    {
        alert("יש לבחור דגם");
        return false;
    }
    
    return true;
}

function ValidateModelOrManuf()
{
    if(document.getElementById("selModel").value == "-1" && document.getElementById("selManuf").value == "-1")
    {
        alert("יש לבחור יצרן או דגם");
        return false;
    }
   
    return true;
}

function ValidateJobs()
{
    if(document.getElementById("selDepartment").value == "-1" && document.getElementById("txtFreeText").value == "")
    {
        alert("יש לבחור חטיבה או להזין טקסט");
        return false;
    }
    
    return true;
}

var gCurrId = "";
function FAQ_Display(MessageID)
{
    var id = MessageID.substr(6,MessageID.length-6);
    
    var div = document.getElementById("AllTextAnswer" + id);
    
    var img = document.getElementById("Answer" + id);
            
    div.style.display = "block";
    img.src = "res/css/FAQ_Minus.gif";
    img.alt = "-";
    img.title = "-";
	    
	if(gCurrId != "")
	{
	    var currDiv = document.getElementById("AllTextAnswer" + gCurrId);
	    var currImg = document.getElementById("Answer" + gCurrId);
	    
	    currDiv.style.display = "none";
	    currImg.src = "res/css/FAQ_Plus.gif"
	    currImg.alt = "+";
	    currImg.title = "+";
	}	
	
	if(gCurrId == id)
	    gCurrId = "";
	else
	    gCurrId = id;
}

var gFirstTimePositionFlooder = true;
function setCurrId(MessageID,first)
{ 
   if (gFirstTimePositionFlooder)
   {
       gCurrId = MessageID ; 
       gFirstTimePositionFlooder = false ;
   }
}

function ShowAllPositions()
{
    var hid = document.getElementById("hidSearchType");
    if(hid != null)
    { 
        hid.value = "2";
        return true;
        
        document.getElementById("selDepartment").value = -1;
    }
    
    return false;
}

function ValidateFile(positionId)
{
    var hid = document.getElementById("hidPosition");
    var hid1 = document.getElementById("hidSearchType");
    
    if(hid == null) return false;
       
    var file = document.getElementById("txtFile" + positionId);
    if(file == null) return false;
       
    if(file.value.length == 0)
    {
        alert("יש לבחור קובץ");
        return false;
    }
    
    hid.value = positionId;
    hid1.value = "3";
    
    return true;
}

function ValidatePR()
{
   var select = document.getElementById("selYear");
    var text = document.getElementById("txtFreeText");
    
    if(select.value == "-1" && text.value == "")
    {
        alert("יש לבחור שנה");
        return false;
    }
    
    return true;
}

var gCurrSuffix = "TS";
var gFirstTime = true;
//var strSQ = "http://www.corporate-ir.net/ireye/ir_site.zhtml?ticker=PTNR&script=200";
//var strSC = "http://www.corporate-ir.net/ireye/ir_site.zhtml?ticker=PTNR&script=300";
//var strTS1 = "";
function ShowStock(suffix, isLtr, str1, str2, str3)
{
   
    if(gFirstTime && isLtr && gCurrSuffix == "TS")
    {
        
        gCurrSuffix = "SC";
        gFirstTime = false;
        
    }

    var iframe = document.getElementById("ifInfo");
    var iframe1 = document.getElementById("ifInfo1");
    var iframe2 = document.getElementById("ifInfo2");    
    
    var isSame = gCurrSuffix == suffix;
    
    var td = document.getElementById("td" + suffix);
    td.className = isSame ? td.className : "TabOff";
    var a = document.getElementById("a" + suffix);
    a.className = isSame ? a.className : "TabText";
            
    var currTd = document.getElementById("td" + gCurrSuffix);
    currTd.className = isSame ? currTd.className : "TabOn";
    var currA = document.getElementById("a" + gCurrSuffix);
    currA.className = isSame ? currA.className : "TabOnText";
    
    switch(suffix)
    {
        case 'SQ':
            iframe.className = "iframeBig";
            iframe.src = str1;
            
            iframe1.className = "iframeHide";
            iframe2.className = "iframeHide";
            
            break;
        case 'SC':
            iframe.className = "iframeBig";
            iframe.src = str1;
            
            iframe1.className = "iframeHide";
            iframe2.className = "iframeHide";
            
            break;
        case 'TS':
            iframe.className = "iframe";
            iframe1.className = "iframe1";
            iframe2.className = "iframe1";
            
        
            iframe.src = str1;
            iframe1.src = str2;
            iframe2.src = str3;
            
            break;
    }
    
    gCurrSuffix = suffix;
}

function ValidateFR()
{
    var selYear = document.getElementById("selYear");
    var selType = document.getElementById("selType");
    
    if(selYear.value == "-1" && selType.value == "-1")
    {
        alert("Please choose year");
        return false;
    }
    
    return true;
}

function Hilite(who, state)
{
	who.src = who.getAttribute("myname") + state + ".gif";
}


var gSortType = "";
var gColToSort = "";
var gSortTypePR = "";
var gSortTypeST = "";
var gSortTypePD = "";
function sortTable(tableId,colToSort)
{
    var table = document.getElementById(tableId);
    if(table == null)
        return;
    
    var img = document.getElementById("img" + colToSort);
    if(img == null) return;    
           	
    var tBody = table.tBodies[0];
	if(!tBody)
		return;
	
	gColToSort = colToSort;
	
	switch (colToSort)
	{	
		case "PR":
			gSortType = gSortTypePR = (gSortTypePR == "" ? "asc" : gSortTypePR == "desc" ? "asc" : "desc");
			break;
		case "ST":
			gSortType = gSortTypeST = (gSortTypeST == "" ? "asc" : gSortTypeST == "desc" ? "asc" : "desc");
			break;
		case "PD":
			gSortType = gSortTypePD = (gSortTypePD == "" ? "asc" : gSortTypePD == "desc" ? "asc" : "desc");
			break;		
	}
				
	var rows = tBody.rows;
	var rowsArr = new Array();
	
	for(var i =0;i < rows.length; i++)
	{
		rowsArr[rowsArr.length] = rows[i];	
	}
					
	rowsArr = rowsArr.sort(CompareFunction);     

	for(var i=0; i < rowsArr.length; i++)
	    tBody.appendChild(rowsArr[i]);
	
	img.src = (gSortType == "asc" || gSortType == "" ? "res/css/arrow_down.gif" : "res/css/arrow_up.gif");
	img.alt = (gSortType == "asc" || gSortType == "" ? "down": "up");
	img.title = (gSortType == "asc" || gSortType == "" ? "down" : "up");
	//alert(img.src);			
}

function CompareFunction(row1, row2)
{
	var sortValue1;
	var sortValue2;
	var sortType;
			
	switch (gColToSort)
	{
	    case "ST":
	        sortValue1 = row1.getAttribute("sortValueST");
	        sortValue2 = row2.getAttribute("sortValueST");
	    
	        switch (gSortType)
	        {
	            case "desc":
	                if(sortValue1 > sortValue2)
	                    return -1;
	                else if (sortValue1 < sortValue2)
	                    return 1;
	                else return 0;
	                break;
	            default:
	               if(sortValue1 < sortValue2)
	                    return -1;
	                else if (sortValue1 > sortValue2)
	                    return 1;
	                else return 0;
	                break;         
	        }   
	        break;
	    case "PR":
	        sortValue1 = row1.getAttribute("sortValuePR");
	        sortValue2 = row2.getAttribute("sortValuePR");
	    
	        switch (gSortType)
	        {
	            case "desc":
	                if(sortValue1 > sortValue2)
	                    return -1;
	                else if (sortValue1 < sortValue2)
	                    return 1;
	                else return 0;
	                break;
	            default:
	               if(sortValue1 < sortValue2)
	                    return -1;
	                else if (sortValue1 > sortValue2)
	                    return 1;
	                else return 0;
	                break;         
	        }   
	        break; 
	           
		case "PD":
			sortValue1 = parseFloat(row1.getAttribute("sortValuePD"));
			sortValue2 = parseFloat(row2.getAttribute("sortValuePD"));
			if (isNaN(sortValue1))
				sortValue1 = Number.MIN_VALUE;
			if (isNaN(sortValue2))
				sortValue2 = Number.MIN_VALUE;
			break;	
		default:
			break;			
	}		
	
	if(gSortType == "desc")
		return sortValue2 - sortValue1;
	else
		return sortValue1 - sortValue2;	
}


function phoneNumberPress(ev, count)
{
     var objEvent = (ev == null ? window.event : ev);

    var agt = navigator.userAgent.toLowerCase();
    
    var isIE = (agt.indexOf('msie') != -1);
    var isFF = (agt.indexOf('firefox') != -1);
   
    var code = 0;
    
    if(isIE)
        code = objEvent.keyCode;    
    else if(isFF)
        code = objEvent.which;
   
    var txt = document.getElementById("txtPhoneNumber");
    
    if(code == 13)
    {
        var a = document.getElementById("linkByPhone");
        if(a != null)
           a.onclick();
        else 
        {
             var a = document.getElementById("findServices");
             if(a != null)
                a.onclick();
            
        }
    }
    
    if(code < 48 || code > 57 || txt.value.length == count)
    {
        return false;      
    }
       
}

function ValidatePhoneNumber()
{
    var txt = document.getElementById("txtPhoneNumber");
    if(txt.value == 0)
    {
        txt.focus();
        return false;
    }
    if(txt.value.length < 10)
    {
        alert("מספר חייב להכיל 10 ספרות");
        return false;
    }
    
    return true;    
}

function ValidateSmsCode(id)
{
	var txt;
	if(id)
		txt = document.getElementById(id);
	else
		txt = document.getElementById("txtPhoneNumber");
		
    if(txt.value == 0)
    {
        txt.focus();
        return false;
    }
    if(txt.value.length < 6)
    {
        alert("קוד חייב להכיל 6 ספרות");
        return false;
    }
    
    return true;    
}

function ValidateProvider()
{
    var user = document.getElementById("txtProviderUN");
    var pass = document.getElementById("txtProviderPass");
    
    if(user != null && user.value.length == 0)
    {
        user.focus();
        return false;
    }
    if(pass != null && pass.value.length == 0)
    {
        pass.focus();
        return false;
    }
    
    return true;
}

function ValidateSegment()
{
    var sel = document.getElementById("selSegment");
    
    if(sel == null || sel.value == "-1") return false;
    
    return true;
}

function ShowDirectorPopup(id)
{
    if(gCurrDirectorDiv != null) return;
    
    gCurrDirectorDiv = document.getElementById("divDirectorPopup" + id);
    
    var body = document.getElementById("tbMain");
         
    if(gCurrDirectorDiv != null && body != null)
    {
       gCurrDirectorDiv.style.left = _offsetLeft(body) + ((body.width - 477) /2) + "px";
       gCurrDirectorDiv.style.top = _offsetTop(body) + 100 + "px";
       
       gCurrDirectorDiv.style.visibility = "visible";
    }
    
        
}

function CloseDirectorPopup()
{
    if(gCurrDirectorDiv == null) return;
        
    gCurrDirectorDiv.style.visibility = "hidden";
    gCurrDirectorDiv = null;
}

function Querystring(qs)
{ // optionally pass a querystring to parse
	try{
	this.params = new Object();
	this.get=Querystring_get;
	
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=');
		var name = unescape(pair[0]);

		if (pair.length == 2)
			value = unescape(pair[1]);
		else
			value = name;
		
		this.params[name] = value;
	}
	}
	catch (err)
	{
		alert(err);
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key];
	if (value==null) value=default_;
	
	return value;
}
function getQSvalues(key)
{
	qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
	var arr = new Array();
	var j=0;
	for(var i=0; i < args.length; i++)
	{
		if(args[i].split("=")[0] == key)
		{
			arr[j] = args[i].split("=")[1];
			j++;
		}	
	}
	
	return arr;		
}

function ValidateEmail(id)
{
	var email;
	if(!id)
		email = document.getElementById("txtEmail");
	else
		email = document.getElementById(id);
	
	if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(email.value))
	{
		alert("כתובת דוא\"ל אינו חוקי");
		return false;
	}
	
	return true;
}

function showHideDiv (divId, action)
{
	var div = document.getElementById(divId);
	if(div == null)
		return;
	
	div.style.display = (action == "hide" ? "none" : "");
}
function validateBusinessForm(form, title)
{
    var numerror="מספר טלפון/סלולרי לא תקין "
	var errormesage="";	
	if (trim(form.BusinessName.value).length==0)	
		errormesage+="\n" + form.BusinessName.getAttribute("validationError");				
	if (trim(form.BusinessArea.value).length==0)
		errormesage+= "\n" + form.BusinessArea.getAttribute("validationError");
	if (trim(form.BusinessID.value).length==0)
		errormesage+= "\n" + form.BusinessID.getAttribute("validationError");				
	
	if (trim(form.CandidateName.value).length==0)
		errormesage+= "\n" + form.CandidateName.getAttribute("validationError");
	if (trim(form.CandidatePhone[1].value).length==0  &&  trim(form.CandidateCellular[1].value).length==0)		
			errormesage+= "\n" + "מספר טלפון אחד לפחות של ממלא הטופס";
	if (trim(form.BusinessEmail.value).length>0)	
	{	
	if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(form.BusinessEmail.value))		
		errormesage+= "\n" + form.BusinessEmail.getAttribute("validationError");
	}			
	if (trim(form.BusinessPhone1.value).length>0)	
	{	
	if (!/^\+?\d+(-\d+)*$/.test(form.BusinessPhone1.value) )		
		errormesage+= "\n" + numerror + form.BusinessPhone1.getAttribute("validationError");
	}			
	if (trim(form.BusinessPhone2.value).length>0)	
	{	
	if (!/^\+?\d+(-\d+)*$/.test(form.BusinessPhone2.value) )		
		errormesage+= "\n" + numerror +  form.BusinessPhone2.getAttribute("validationError");
	}			
	
	if (trim(form.CandidatePhone[0].value).length>0)	
	{	
	if (!/^\+?\d+(-\d+)*$/.test(form.CandidatePhone[0].value) )		
		errormesage+= "\n" + numerror +  form.CandidatePhone[0].getAttribute("validationError");
	}			
	if (trim(form.CandidatePhone[1].value).length>0)	
	{	
	if (!/^\+?\d+(-\d+)*$/.test(form.CandidatePhone[1].value) )		
		errormesage+= "\n" + numerror +  form.CandidatePhone[1].getAttribute("validationError");
	}			
	
	if (trim(form.CandidateCellular[0].value).length>0)	
	{	
	if (!/^\+?\d+(-\d+)*$/.test(form.CandidateCellular[0].value) )		
		errormesage+= "\n" + numerror +  form.CandidateCellular[0].getAttribute("validationError");
	}			
	
	if (trim(form.CandidateCellular[1].value).length>0)	
	{	
	if (!/^\+?\d+(-\d+)*$/.test(form.CandidateCellular[1].value) )		
		errormesage+= "\n" + numerror +  form.CandidateCellular[1].getAttribute("validationError");
	}							
	
	if (errormesage!="")
		alert("יש למלא את השדות הבאים" + errormesage);
		
	if (errormesage=="")	
	return true;
	else
	return false;			
		
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function hideElement()
{
	var el = document.getElementById("divLeftSide");
		
	try
	{
		el.style.display = "none";
	}
	catch (error)
	{
			
	}
}

var isOpen=false;

function OpenCloseFAQ()

{

var Arr=new Array();

var img;

var div;

 

var FAQIDs=document.getElementById('FAQIDs').value;

var DivOpen=document.getElementById('DivOpen').value;

var DivClose=document.getElementById('DivClose').value;

 

    Arr=FAQIDs.split(",");

    

    if(isOpen==false)

    {

        // open

        for( i=0; i<Arr.length; i++)

        {

            document.getElementById("AllTextAnswer"+Arr[i]).style.display="block";

            // change pictures

            img=document.getElementById("Answer" + Arr[i]);

            img.src = "res/css/FAQ_Minus.gif";

            img.alt = "-";

            img.title = "-";

        }

        document.getElementById('CloseOpenFAQAnsvers').innerText=DivClose;

       // document.getElementById('CloseOpenFAQAnsvers').title=DivClose;

        isOpen=true;

    }

    else

    {

        //close

        for( i=0; i<Arr.length; i++)

        {

            document.getElementById("AllTextAnswer"+Arr[i]).style.display="none";

            // change pictures

            img=document.getElementById("Answer" + Arr[i]);

            img.src = "res/css/FAQ_Plus.gif";

            img.alt = "+";

            img.title = "+";

        }

        document.getElementById('CloseOpenFAQAnsvers').innerText=DivOpen;

       // document.getElementById('CloseOpenFAQAnsvers').title=DivOpen;

        isOpen=false;

    }

}

function printFAQs()

{

   //alert("hi in a print function");

   window.open('PrintFAQ','_blanck');

}
function OpenCloseSubMenu(id)
{
    var item = document.getElementById("SubLevel" + id);
	if (!item) return;	
	if(item.style.display=="none")
	    item.style.display = "";
	else
	    item.style.display = "none";
	
}
