/*
function OpenPostingPickerPopUp()
{
	winId = window.open("<%=Request.ApplicationPath%>/Controls/PostingPickerPopUp.aspx","PostingPicker","height=600,width=500,left=100,top=100,scrollbars=1;status=0,menubar=0");
}
*/
function openIPIX(IPIXName)
{

	var sPath="/Rashat/Popups/IPIX.aspx?sPicSrc="+IPIXName;
	winId = window.open(sPath,"IPIX","height=500,width=700,scrollbars=0;status=0,menubar=0");
}
//this function called from themplates
//UserCode = 
//			1. Main - call openMap function with no params. do not send UserCulture
//			2. Name of map. send UserCulture.
//			3. code location like: t-g-3. do not send UserCulture
//UserCulture = heb or eng
function setMap(UserCode, UserCulture)
{
	UserCode = UserCode.replace(' ','');
	
	if(UserCode.toUpperCase == "MAIN")
	{
		openMap(); 
	}
	else if(UserCode.substr(0,1) == "#")//find sign '#' in position 0
	{	
		openFlow(UserCode.substr(1),UserCulture);
	}	
	else if(UserCode.indexOf("mitkan") != -1)
	{
		openParkingLots(UserCode, UserCulture);
	}
	else if(UserCode.indexOf("-")!= -1 || UserCode.indexOf("_")!= -1)//find sign '-' or '_' => code location
	{
		openElement(UserCode,UserCulture);
	}
	else //user pass name of map
	{
		openMap(UserCode,UserCulture);
	}	
}

function openFlow (flowId,lang)
{
	mapWin = window.open("/Rashat/map.aspx?mapId=Terminal3&flowId=" + flowId + "&lang=" + lang ,"mapWin","width=780, height=537");
	mapWin.focus();
}

function openMap(mapId,lang)
{
	if(lang==undefined){
		lang="heb";
	}
	if(mapId==undefined){
		mapId="Israel";
	}
	mapWin = window.open("/Rashat/map.aspx?mapId="+mapId+"&lang="+lang,"mapWin","width=780, height=537");
	mapWin.focus();
}
function openElement(markElement,lang)
{
	mapWin = window.open("/Rashat/map.aspx?elementId="+markElement+"&lang="+lang,"mapWin","width=780, height=537");
	mapWin.focus();
}

function openParkingLots(UserCode,lang)
{
	var splitChar = "#";
	var arr	= UserCode.split(splitChar);
	if (arr.length == 2)
	{
		mapWin = window.open("/Rashat/map.aspx?mapView="+arr[0]+"&elementId="+arr[1]+"&lang="+lang,"mapWin","width=780, height=537");
		mapWin.focus();
	}
}

//FLIGHTS 
function ChkAndSetImgSize(img, maxWidth, maxHeight)
{
	if(img.width > maxWidth) img.width = maxWidth;
	if(img.height > maxHeight) img.height = maxHeight;
}

//Get a referece to tr and highlights all its tds(class hilite)
function SetHighLight(tr)
{
	$(tr).addClass('trHilight');			
			
	$(tr).addClass('toolTipContainer');		
	
	if($.browser.msie == true)
	{
		$(tr).addClass('toolTipContainerIE');		
	}
	
}
//Get a referece to tr and set all its td's classes to arial12
function SetDeHighLight(tr)
{
	$(tr).removeClass('trHilight');
	$(tr).removeClass('toolTipContainer');
	
	if($.browser.msie == true)
	{
		$(tr).removeClass('toolTipContainerIE');		
	}
	
}

function HideLastTableColumn(table)
{
	var i = 0;
	for(i=0 ; i < table.rows.length ; i++)
	{
		table.rows[i].cells[table.rows[i].cells.length - 1].style.display=none;
	}
}
//END FLIGHTS


function CheckLicensedDealerNumber(src, args)
{		
	fieldValue = (document.getElementById(src.controltovalidate)).value;
	
	var regExDealerNumber = new RegExp("^[0-9]{5,10}$");			
		
	var match = regExDealerNumber.exec(fieldValue);
			
	if(match != null && match.length > 0)
	{
	}
	else
	{		
		args.IsValid = false;		
	}
	
	
	
}


function newImage(arg) 
{
	if (document.images) 
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
	
function checkKey(objToClick)
{
	if(event.keyCode==13)
	{
		try
		{
			var o;
			o=document.getElementById(objToClick);
			if(typeof(o)=="object")
				o.click();
		}
		catch(e)
		{
			//error
		}
		finally
		{
			event.returnValue=false;
			event.cancelBubble=true;
		}
	}
}
$('body').keypress(function(event) {
	if(event.keyCode==13)
	{
		try
		{
			var o;
			o=document.getElementById(objToClick);
			if(typeof(o)=="object")
				o.click();
		}
		catch(e)
		{
			//error
		}
		finally
		{
			event.returnValue=false;
			event.cancelBubble=true;
		}
	}
});
 

function fixPagerForAccesibillity()
{
	$(".Pagers a[disabled] span").css("color","#ffc600");
		
	$(".Pagers td:first a[disabled] span").css("color","#ffc600");	
	$(".Pagers td:last-child a[disabled] span").css("color","#ffc600");				
	
	
	$(".Pagers a[disabled]").attr("disabled","");
	
	
	$(".Pagers td:first a:first").attr("title",FirstPageStrInLang);
		
	$(".Pagers td:first a:last").attr("title",PreviousPageStrInLang);
		
	$(".Pagers td:last-child a:first").attr("title",NextPageStrInLang);
		
	$(".Pagers td:last-child a:last").attr("title",LastPageStrInLang);
	
	
	//$(".Pagers tr:first td:first").attr("align","right").attr("width","30%");
	//$(".Pagers tr:first td:last").attr("align","left").attr("width","30%");
	
	$(".Pagers tr:first td:first").attr("align","center").attr("width","30%");
	$(".Pagers tr:first td:last").attr("align","center").attr("width","30%");
	
	$(".Pagers tr td:eq(1)").attr("width","40%");
	
	$(".Pagers tr:first td:eq(1) a").css("margin","0 2px");
	$(".Pagers tr:first td:first a,.Pagers tr:first td:last a").css("margin","0 3px");
}



function timedRefresh(RefreshTimeInMinutes, RefreshMessageTimeInSeconds) 
{			
			var timeToShowMessageInMS = ((RefreshTimeInMinutes * 60)	- RefreshMessageTimeInSeconds) * 1000;
						
			setTimeout("ChangeMessageOfRefresh(" + timeToShowMessageInMS + ");", timeToShowMessageInMS);          
			
}
function SetFocus(ctrlId)
{
	$(ctrlId).focus();				
}


function ChangeTextSizeFlights(size, saveInSession, language)
{
	ChangeTextSize(size, saveInSession);
	
	if(size == 1)
	{
		//נחיתות
		if($("#tdArrivalFlightsMenuTabsContainer").length > 0)
		{
			$("#tdArrivalFlightsMenuTabsContainer").attr("style", $("#tdArrivalFlightsMenuTabsContainerBg").val() );
			
			$("#tabArr1").attr("style", "width:114px");
			$("#tabArr2").attr("style", "width:100px");
			$("#tabArr3").attr("style", "width:120px;");
			
		}
		//המראות
		
		
		if($("#tdFlightsMenuTabsContainer").length > 0)
		{			
			$("#tdFlightsMenuTabsContainer").attr("style", $("#tdFlightsMenuTabsContainerBg").val() );
			$("#tab1").removeAttr("style");
			$("#tab2").removeAttr("style");
			$("#tab3").removeAttr("style");
		}
	}
	else
	{
		//נחיתות
		if($("#tdArrivalFlightsMenuTabsContainer").length > 0)
		{
			$("#tdArrivalFlightsMenuTabsContainer").removeAttr("style");
			
			switch(language.toLowerCase())
			{
				case "he-il":
					$("#tabArr1").attr("style", "width:114px;background:#00203b");
					$("#tabArr2").attr("style", "width:100px;background:#104a73");
					$("#tabArr3").attr("style", "width:120px;background:#104a73");
				break;
				case "en-us":
					$("#tabArr1").attr("style", "width:110px;background:#00203b");
					$("#tabArr2").attr("style", "width:120px;background:#104a73");
					$("#tabArr3").attr("style", "width:120px;background:#104a73");
				break;
				case "ar":
					$("#tabArr1").attr("style", "width:114px;background:#00203b");
					$("#tabArr2").attr("style", "width:100px;background:#104a73");
					$("#tabArr3").attr("style", "width:120px;background:#104a73");
				break;
			}

			
		}
		
		//המראות
		if($("#tdFlightsMenuTabsContainer").length > 0)
		{
			$("#tdFlightsMenuTabsContainer").removeAttr("style");
			$("#tab1").attr("style", "background:#104a73");
			$("#tab2").attr("style", "background:#00203b");
			$("#tab3").attr("style", "background:#104a73");
		}
	}
}

//when coming from client
function ChangeTextSize(size)			
{
	ChangeTextSizeFonts(size, "true")			
}

function ChangeTextSizeFonts(size, saveInSession)			
{	
	
	
	switch(size)
	{
		case 1:
		{
			$("body").addClass("bodySmall");
			$("body").removeClass("bodyMedium");
			$("body").removeClass("bodyBig");
			break;
		}
		case 2:
		{
			$("body").addClass("bodyMedium");
			$("body").removeClass("bodySmall");
			$("body").removeClass("bodyBig");
			break;
		}
		case 3:
		{
			$("body").addClass("bodyBig");
			$("body").removeClass("bodySmall");
			$("body").removeClass("bodyMedium");
			break;
		}
		default:
		{
			alert("wrong size of font : " + size);
		}
	}
	
	$("#hdnTextSize").val(size);
	
	if(saveInSession == "true")
	{
		SetSessionTextSize(size);		
	}
	
}

function SetSessionTextSize(size)
{
	 matrix_httpRequest (window.location.href, "TextSize", size + "")
}

function FireFlightsSearch1()
{
	
	if(event.keyCode == 13)
	{
		$("#imgBtnSearch").click();
	}
}

function FireFlightsSearch(eSender, e, btn)
{
	currentEvent = e;
	
    
    var ch = GetCahrFromEvent();
	
	if (ch == 13) {
		StopEvent(e);	
        $("#" + btn).click();
    }    
    else
    {
		
    }                  
	
}
		
function showPopupCalendar(eSender, e, lang) {
    
    currentEvent = e;
    var needToShow = false;
    var ch = GetCahrFromEvent();
    
    
    if (ch) {
        if (ch == 13) {
            needToShow = true;
        }
        else {
            return true;
        }              
    }
    else {
        if (window.event || e.type == "click") {
            needToShow = true;
        }
        else {
            return true;
        }
    }

    if (needToShow == true) {
        var value = $("#" + eSender).val();

		/*
        var xyPos = $("#" + eSender).position();
        var xPos = xyPos.left;
        var yPos = xyPos.top;
        xPos -= 30;
        if (window.event) {
            yPos += 50;
        }
        else {
            yPos += 100;
        }
        xPos = 400;        
        
        
        
        var arguments = "toolbar=no, width=250, height=220, menubar=no, scrollbars=no, status=no";        
        arguments += ",top=" + yPos + ", left=" + xPos;
        */
        
        var url = "/RASHAT/Calender.aspx?sender=" + eSender + "&value=" + value + "&lang=" + lang;

		var dialogHeight	= "250";
		var dialogWidth		= "240";
		
		if($.browser.msie == true && $.browser.version == "6.0")
		{
			dialogHeight	= "260";
			dialogWidth		= "250";		
		}		
		else if($.browser.mozilla)
		{			
			dialogWidth		= "260";		
		}
		else if($.browser.safari)
		{			
			dialogHeight	= "220";
			dialogWidth		= "240";		
		}
		                        
        var arguments = "dialogWidth:" + dialogWidth + "px; dialogHeight:" + dialogHeight + "px; dialogtop:200px; dialogLeft:300px;";
        
        
        
        try
        {			
			var result;
			
			if($.browser.opera)
			{
				//result = window.open(url, "calenderWin", arguments); 
				result = window.open(url, "calenderWin", "width=260, height=260, Top=250, Left=350"); 
			}
			else
			{			
				result = window.showModalDialog(url, "calenderWin", arguments); 			
			}					
			
			var arr = result.split("|");
        
			$("#" + arr[0]).val(arr[1]);
        }
        catch(ex)
        {
			//do nothing
        }
        
       
        
        
        return false;   
                       
    }
}


function GetCahrFromEvent() {
    var ch;
    var e = window.event || currentEvent;
    if (e == currentEvent) {
        //Mozila
        if (e.type == "click") {
            ch = 0;
        }
        else {
            ch = e.which;
        }
    }
    else {
        //IE
        ch = e.keyCode;
    }
    return ch;
}

function StopEvent(e) {
   if (window.event) {
       window.event.cancelBubble = true;
       window.event.returnValue = false;
   }
   else {
       e.stopPropagation();
       e.preventDefault();
       e.returnValue = false;
   }
  }
  
  
  function ShowModalAccessiblePage(url)
	{
		if($.browser.opera)
		{			
			window.open(url, "OnlineFlightAcc","width=650, height=750, Top=200, Left=300");								
		}
		else
		{
			dialogHeight = "790px";
			
			if($.browser.msie == true && $.browser.version == "6.0")
			{
				dialogHeight = "850px";
			} 
			//ATTENTION!!! - if change height have to change OffsetLeft in jquery.autocomplete.js also;
			window.showModalDialog(url, "OnlineFlightAcc","dialogWidth:650px; dialogHeight:" + dialogHeight + "; dialogTop:200px; dialogLeft:300px; resizable: yes;");
			
			return false;
		}
	}
	
	function SetCtrlsMarkFocus()
	{
		$("input").bind("focus", function(){
							SetFocus(this);
		});															
		$("input").bind("blur", function(){
			Blur(this);
		});
		
		$("a").bind("focus", function(){
			SetFocus(this);
		});	
		$("a").bind("blur", function(event){
			Blur(this);
		});
		
		$("img").bind("focus", function(){
			SetFocus(this);
		});	
		$("img").bind("blur", function(event){
			Blur(this);
		});
	}
	
	function SetFocus(ctrl)
	{					
		$(ctrl).addClass("onFocus");
	}
	function Blur(ctrl)
	{		
		$(ctrl).removeClass("onFocus");
	}
	
	function ShowHiddenField(ctrlId)
	{					
		$("#" + ctrlId).addClass("hiddenFieldsForAccessibilityShown");						
		
		if($("#Header1_trFlightsHeader").length > 0)
		{
			$("#Header1_trFlightsHeader").css("line-height", "1em");
		}
	}
	function HideHiddenField(ctrlId)
	{				
		$("#" + ctrlId).removeClass("hiddenFieldsForAccessibilityShown");
		if($("#Header1_trFlightsHeader").length > 0)
		{
			$("#Header1_trFlightsHeader").css("line-height", "0px");
		}
		
	}
	
	String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}

	
	//this two arrays contains area - num of digits after.
	var javaScript_array_rfBezeqArea  = "02:7,03:7,04:7,06:7,07:7,08:7,09:7,077:7,072:7,073:7,074:7,1800:6,1-800:6,1700:6,151:9";
	var javaScript_array_rfMobileArea = "052:7,050:7,053:7,054:7,057:7";
	function IsPhone(p_source, p_arguments)
	{
		var isValid   = false; 
		var arrPhone  = p_arguments.Value.split('-');
		var arrBezeq  = javaScript_array_rfBezeqArea.split(',');
		
		//try to fix the phone number, add "-" in the right place
		if( arrPhone.length < 2 || isNaN(arrPhone[0]) || isNaN(arrPhone[1]) )
		{
			for(var i=0; (i < arrBezeq.length) ; i++)
			{
				var areaCode  = arrBezeq[i].split(':')[0];
				
				if(p_arguments.Value.startsWith(areaCode))
				{
					arrPhone  = p_arguments.Value.replace(areaCode, areaCode + "-").split('-');
					
					if(arrPhone[1].length <8)
						break;
						
				}
			}
		}

		if( arrPhone.length < 2 || isNaN(arrPhone[0]) || isNaN(arrPhone[1]) )
		{
			p_arguments.IsValid = false;
			return;
		}
		else if ( arrPhone.length == 3 ) //check if length is more then 2 (case of 1-800-111111 ...)
		{
			arrPhone = new Array(arrPhone[0] + '-' + arrPhone[1], arrPhone[2]);
		}

		for(var i=0; (i < arrBezeq.length) && (!isValid); i++)
		{
			var areaCode  = arrBezeq[i].split(':')[0];
			var numDigits = arrBezeq[i].split(':')[1];

			if( arrPhone[0] == areaCode )
				isValid = (arrPhone[1].length == numDigits);
		}

		p_arguments.IsValid = isValid;
		return;
	} 
	
    function IsMobile(val)
	{
		var arrMobile = javaScript_array_rfMobileArea.split(',');
		var arrPhone  = val.split('-');
		var isMobile = false;

		for(var i=0; i < arrMobile.length; i++)
		{
			var areaCode  = arrMobile[i].split(':')[0];
			var numDigits = arrMobile[i].split(':')[1];

			if( arrPhone[0] == areaCode )
				isMobile = (arrPhone[1].length == numDigits);
		}
    
		return isMobile;
	} 
	
	function IsJustDigits(sender,args)
	{
		
		var isWhole_re =/^\s*\d+\s*$/;

		if(String(args.Value).search(isWhole_re) != -1)
			args.IsValid=true;
		else
			args.IsValid=false;
		
	}
  
	//recorsive function, enable or disable (depending on the flag) all the validators in obj
	//run over all childes in the obj if recognize validate control so disable him
	function EnableDisableValidation(objId, flag, deleteControlContent)
	{  
		if( objId != "" && typeof(Page_Validators) != 'undefined' )
		{  
			for(var i=0; i < Page_Validators.length; i++)
			{
				if( Page_Validators[i].controltovalidate ==  objId)
				{
					Page_Validators[i].enabled = flag;
					if (!flag)
					{
						Page_Validators[i].isvalid = true;
						//eval(Page_Validators[i].evaluationfunction(Page_Validators[i], !flag));
					}
				}    
			}
		}
	}

 
 /* all this functions belongs to WinningTenders*/       
function chkLite_CheckedChanged(obj)
{	
	if(obj.checked == 1)
	{
		AddItem(obj.title,	  obj.value);
	}
	else
	{
		DeleteItem(obj.title, obj.value);
	}
}

function DeleteItem(title,	value)
{
	var id		 =	value;
	var list	 =	document.getElementById("lsbWinnings");
	var len		 =	list.length;
	
	for(var i=0;i<len;i++)
	{
		if(list[i].value == id)
		{
			list.remove(i);
			break;
		}
	}

	document.getElementById('txtSelectedWinningsNames').value = document.getElementById('txtSelectedWinningsNames').value.replace(value + ';', '');
}

function AddItem(title,	value)
{
	var list		=	document.getElementById("lsbWinnings");
	var option		=	document.createElement("option");
	
	option.text		=	title;
	option.value	=	value;
	
	list.add(option);
	
	document.getElementById('txtSelectedWinningsNames').value += value + ';';
}

function ltrim(s)
{
	var l=0;
	var e=0;
	while(l<s.length-1)
	{
		if(s.substring(l,l+1)=='-')
		{
			e=l;
		}
		l++;
	}
	return s.substring(0,e);
}
   
