﻿var RECORED_NOT_SELECTED = "לפני ביצוע פעולה זו נדרש לבחור ברשומה";

var STR_ARRAY_DELIMITER = "^";
var BTN_OK = 1;
var BTN_YES = 2;
var BTN_NO = 3;
var BTN_CANCEL = 4;

var BTN_OPTIONS_OK = 1;
var BTN_OPTIONS_OK_CANCEL = 2;
var BTN_OPTIONS_YES_NO_CANCEL = 3;
var BTN_OPTIONS_YES_NO = 4;

var BTN_UPDATE_DETAILS = 1;
var BTN_SEND_RESUME = 2;

var HEIGHT_FOR_IE6= 190;
var HEIGHT_FOR_IE7 = 170;

var EMPLOYEE_LOGIN = 1;
var EMPLOYER_LOGIN = 2;

var oPopup;

var CONFIRM_WINDOW_PATH = VIRTUAL_DIRECTORY + "/Fnd/ConfirmWin/ConfirmWin.aspx";
var CONFIRM_POPUP_PATH = VIRTUAL_DIRECTORY + "/Fnd/ConfirmWin/ConfirmPopUp.aspx";


function ShowWaitMessage(sMessage ,oParentObjectForDisplay)
{
	var iDialogWidth;
	var iDialogHeight;
 	document.body.style.cursor="wait";
 	if (sMessage == "") 
 		sMessage = "אנא המתן...";
 	
	oWaitPopup = window.createPopup();
	
    var oPopupBody = oWaitPopup.document.body;
	oPopupBody.style.backgroundColor = "lightyellow";
	oPopupBody.style.border = "solid black 1px";
	
    oPopupBody.innerHTML = "<div valign=middle align=center dir=rtl style=\"font-size:15pt;font-family: Arial;\" class='clsTDTableList'>" + sMessage + "</div>";
    
    iDialogWidth = oParentObjectForDisplay.clientWidth //window.dialogWidth.substr(0,window.dialogWidth.length-2);
    iDialogHeight = oParentObjectForDisplay.clientHeight // window.dialogHeight.substr(0,window.dialogHeight.length-2);
    
    oWaitPopup.show((iDialogWidth / 2 )- 175,(iDialogHeight / 2) - 12,350, 35, oParentObjectForDisplay);   
}

function HideWaitMessage()
{
	if (oWaitPopup != null)
		oWaitPopup.hide();
	oWaitPopup = null;
	
	document.body.style.cursor="";
}

function ShowTooltip(oCell)
{
	if (oCell.children.length > 0)
	{
		if (oCell.children[0].outerHTML.indexOf("TEXTAREA") != -1)
			return;
	}
	else if ((oCell.innerText == "&nbsp;") || (oCell.innerText == "") || (oCell.innerText == " ")){
		return;
	}
	
	oPopup = window.createPopup();
	
    var oPopupBody = oPopup.document.body;
	oPopupBody.style.backgroundColor = "lightyellow";
	oPopupBody.style.border = "solid black 1px";

	var iRealHeight = 31;
	
	if (oCell.innerHTML.length > 45)
		iRealHeight = (iRealHeight * Number(oCell.innerHTML.length) / 45) + 5;
		
    oPopupBody.innerHTML = "<div dir=rtl style=\"font-size:11pt;font-family: arial;\">" + oCell.innerHTML + "</div>";
    oPopup.show(-150,20 ,300, iRealHeight, oCell);
}
function HideTooltip(oCell)
{
	if (oPopup != null) 
		oPopup.hide();
	oPopup = null;
}

function RetrieveComboValuesFromInternet(iLutEnumValue , sControlName , arrLutParams)
{
	var arrParams = new Array();
	var arrReturnParams = new Array();
	var sErrorMessage="";
	var arrNewComboDetails = new Array();
	
	var sLutParams = arrLutParams.join("^");
	
	arrParams[0] = iLutEnumValue;
	arrParams[1] = GetExistSelectAttributes(document,sControlName);
	arrParams[2] = sLutParams;

	sErrorMessage = XMLRPC("CLut","BuildLookUpHtmlSelectFromInternet",arrParams,arrReturnParams,"Taldor.Taasuka.BL","Taldor.Taasuka.BL.dll");

	if (sErrorMessage == "")
	{
		arrNewComboDetails[0] = sControlName;
		arrNewComboDetails[1] = "";
		arrNewComboDetails[2] = document;
		arrNewComboDetails[3] = arrReturnParams[0];
		ChangeOuterHTML(arrNewComboDetails);
	}
	else{
		OpenMessageWindow(sErrorMessage,BTN_OPTIONS_OK,380,120);
	}
}

function RetrieveComboValues(iLutEnumValue , sControlName , arrLutParams)
{
	var arrParams = new Array();
	var arrReturnParams = new Array();
	var sErrorMessage="";
	var arrNewComboDetails = new Array();
	
	
	var sLutParams = arrLutParams.join("^");
	
	
	
	arrParams[0] = iLutEnumValue;
	arrParams[1] = GetExistSelectAttributes(document,sControlName);
	arrParams[2] = sLutParams;
	
	
	sErrorMessage = XMLRPC("CLut","BuildLookUpHtmlSelect",arrParams,arrReturnParams,"Taldor.Taasuka.BL.Entities","Taldor.Taasuka.BL.dll");
	
	
	
	if (sErrorMessage == "")
	{
		arrNewComboDetails[0] = sControlName;
		arrNewComboDetails[1] = "";
		arrNewComboDetails[2] = document;
		arrNewComboDetails[3] = arrReturnParams[0];
		
		ChangeOuterHTML(arrNewComboDetails);
		
	}
	else
	{
		alert(sErrorMessage);
	}

}

function RetrieveComboValuesWithAttributes(iLutEnumValue , sControlName , arrLutParams , sTagAttributes)
{
	var arrParams = new Array();
	var arrReturnParams = new Array();
	var sErrorMessage="";
	var arrNewComboDetails = new Array();
	
	
	var sLutParams = arrLutParams.join("^");
	
	
	
	arrParams[0] = iLutEnumValue;
	arrParams[1] = GetExistSelectAttributesWithAttributes(document,sControlName,sTagAttributes);
	arrParams[2] = sLutParams;
	
	
	sErrorMessage = XMLRPC("CLut","BuildLookUpHtmlSelect",arrParams,arrReturnParams,"Taldor.Taasuka.BL.Entities","Taldor.Taasuka.BL.dll");
	
	
	
	if (sErrorMessage == "")
	{
		arrNewComboDetails[0] = sControlName;
		arrNewComboDetails[1] = "";
		arrNewComboDetails[2] = document;
		arrNewComboDetails[3] = arrReturnParams[0];
		
		ChangeOuterHTML(arrNewComboDetails);
		
	}
	else
	{
		alert(sErrorMessage);
	}

}

function GetStringFromXmlNode(oXmlNode)
{
	if (oXmlNode != null)
		return oXmlNode.text;
	else
		return "";
}

function CheckHoursRange(FromDate,ToDate,InnerFromHour,InnerToHour,OuterFromHour , OuterToHour,OutOfRangeErrorMessage)
{

	var iDateDiff;
	var iFromHour = Number(InnerFromHour);
	var iToHour = Number(InnerToHour);
	var iOuterFromHour = Number(OuterFromHour);
	var iOuterToHour = Number(OuterToHour);
	var HOURS_ERROR_MSG = encodeURIComponent("טווח שעות שגוי");
	var OUT_OF_RANGE_ERROR_MSG = encodeURIComponent(OutOfRangeErrorMessage);
	
	//**********************CHECK DATES************************
	iDateDiff = Date_Diff("d",ToDate,FromDate)
	
	//if from date greater than to date
	if (iDateDiff < 0 )
	{
		strError = encodeURIComponent("טווח תאריכים שגוי");
		OpenMessageWindow(VIRTUAL_DIRECTORY + "Main/confirmWin.aspx",strError,0,370,120)
		return false;
	}
	
	//if the dates are same
	if (iDateDiff == 0)
	{
		//if ta hours defined for the same day ( ex. 17:00-19:00 )
		if (iOuterFromHour <= iOuterToHour)
		{
			//from hour greater than to hour
			if (iFromHour > iToHour)
			{
				OpenMessageWindow(HOURS_ERROR_MSG,BTN_OPTIONS_OK,370,120)
				return false
			}
			
			//hours don't match the ones defined for ta
			if ((iFromHour< iOuterFromHour) || (iToHour> iOuterToHour))
			{
				OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,0,370,120)
				return false
			}
			return true
			
		}
		//ta hours spanned over more than 2 days ( for ex. : 22:00 - 03:00 )
		else
		{
			if (iFromHour >= iOuterFromHour)
			{
				if (iToHour < iFromHour )
				{
					OpenMessageWindow(HOURS_ERROR_MSG,BTN_OPTIONS_OK,370,120)
					return false
				}
				return true
			}
			else if (iFromHour> iOuterToHour)
			{
				OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,370,120);
				return false
			}
			else if (iFromHour<= iOuterToHour)
			{
				if (!(iToHour >= iFromHour && iToHour <= iOuterToHour))
				{
					OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,370,120);
					return false
				}
				return true
			}
			
		}
	}
	//if the work is more than one day
	else
	{
		//if ta hours defined for the same day ( ex. 17:00-19:00 )
		if (iOuterFromHour <= iOuterToHour)
		{
			if (iFromHour > iToHour)
			{
				OpenMessageWindow(HOURS_ERROR_MSG,BTN_OPTIONS_OK,370,120);
				return false
			}
			
			if ((iFromHour< iOuterFromHour) || (iToHour> iOuterToHour))
			{
				OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,370,120);
				return false
			}
			return true;
		}
		//ta hours spanned over more than 2 days ( for ex. : 22:00 - 03:00 )
		else
		{
			if (iFromHour>=iOuterFromHour)
			{
				if (!((iToHour>=iFromHour) || (iToHour <= iOuterToHour)))
				{
					OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,370,120);
					return false
				}
				return true;
			}
			else if (iFromHour > iOuterToHour)
			{
				OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,370,120);
				return false
			}
			else if(iFromHour <= iOuterToHour)
			{
				if (!(iToHour >= iFromHour && iToHour <= iOuterToHour))
				{
					OpenMessageWindow(OUT_OF_RANGE_ERROR_MSG,BTN_OPTIONS_OK,370,120);
					return false
				}
				return true;
			}
		}
	}
	return true;
}

/***********************************************
 porpuse: perform the main action when the enter key pressed
 inputs :
 return:
 comments:
***********************************************/

function OnEnterKeyPress(sButtonName,sEvent) 
{
   if (window.event.keyCode == 13)
   {
	   if (document.activeElement.type)
	   {
			if (document.activeElement.type.toLowerCase() != "button")
			{
				if (document.activeElement.type.toLowerCase() != "textarea")
				{
					window.event.returnValue = false 
					eval("document.frm." + sButtonName + ".fireEvent('" + sEvent + "')");
				}
				else
				{
					//window.event.returnValue = false 
				}	
			}	
	   }
	   else
	   {
		    eval("document.frm." + sButtonName + ".fireEvent('" + sEvent + "')");
	   }	
						    						
   }   
   
}

function SetString(val)
{
	if (IsNull(val))
	{
		return " ";
	}
	else
	{
		return val;
	}
}

function SetZeroIfEmpty(val)
{
	if (IsNull(val))
	{
		return 0;
	}
	else
	{
		return val;
	}
}

/*******************************************************
 porpuse: open the message window
 inputs : document
 return:  
 comments:
*******************************************************/
function OpenMessageWindow(sMessage,iBtnOptions,iWidth,iHeight)
{
	var iPressedButton = "";
	var arrParams = new Array();
	arrParams[0] = sMessage;
	var iRealHeight = 130;
	var paramspassed = new Array();

	var sRealErrorMessage = decodeURIComponent(sMessage);
	
	if (sRealErrorMessage.length > 130)
		iRealHeight = iRealHeight * Math.round(Number(sRealErrorMessage.length) / 130);
		
	if (iRealHeight > 700)
		iRealHeight = 700;
		
	iRealHeight = iRealHeight + 50;
	
	/*if(arguments.length>3)
		for(i=3;i<arguments.length;i++)
		paramspassed[paramspassed.length] = arguments[i];

	if(window.showModalDialog)
	{
		var return_value = window.showModalDialog(url,paramspassed,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;help:no;");
		//returnValueFromModal(return_value);
	}
	else
	{
		var modalWin = window.open(url,"","width="+width+"px,height="+height+"px;");
		window.onfocus = function() {
			if(modalWin && !modalWin.closed)
				modalWin.focus();
		}
		window.paramspassed = paramspassed;
	}*/

	if (browser.isIE)
	{
		iPressedButton = window.showModalDialog(CONFIRM_WINDOW_PATH+"?BtnOptions="+iBtnOptions,arrParams,"dialogWidth:" + iWidth + "px;dialogHeight:" + iRealHeight + "px;center=yes;status=no;help=0;toolbar=no;location=no;directories=no;menubar=no;resizable=0;copyhistory=no");
	}
	else
	{
		if (iBtnOptions == 1)
		{
			window.open(CONFIRM_WINDOW_PATH + '?sMessage=' + sMessage,'WinModal','height=' + iRealHeight + ',width=' + iWidth + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
		}
		else
		{
			if (window.confirm(sMessage))
				iPressedButton = 1;
			else
				iPressedButton = 4;
		}
	}
	
	return iPressedButton;
}

function OpenTitleMessageWindow(sMessage,sTitle,iBtnOptions,iWidth,iHeight)
{
	var iPressedButton = "";
	var arrParams = new Array();
	arrParams[0] = sMessage;
	var iRealHeight = 130;
	
	var sRealErrorMessage = decodeURIComponent(sMessage);
	
	if (sRealErrorMessage.length > 130)
		iRealHeight = iRealHeight * Math.round(Number(sRealErrorMessage.length) / 130);
		
	if (iRealHeight > 700)
		iRealHeight = 700;
		
	iRealHeight = iRealHeight + 50;
	
	if(browser.isIE)
		iPressedButton = window.showModalDialog(CONFIRM_WINDOW_PATH+"?BtnOptions="+iBtnOptions + "&Title=" + encodeURIComponent(sTitle),arrParams,"dialogWidth:" + iWidth + "px;dialogHeight:" + iRealHeight + "px;center=yes;status=no;help=0;toolbar=no;location=no;directories=no;menubar=no;resizable=0;copyhistory=no");
	else
	{
		if (iBtnOptions == 1)
		{
			window.open(CONFIRM_WINDOW_PATH + '?sMessage=' + sMessage,'WinModal','height=' + iRealHeight + ',width=' + iWidth + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
		}
		else
		{
			if (window.confirm(sMessage))
				iPressedButton = 1;
			else
				iPressedButton = 4;
		}
	}
		
	
	return iPressedButton;
}

function OpenModalWindow(sUrl,iWidth,iHeight)
{

	if(browser.isIE)
	{
		var iReturnValue = "";
		
		var arrParams = new Array();
		var properties = "status:no;toolbar=no;location=no;directories=no;menubar=no;resizable=0;copyhistory=no;center:yes;help:no;scroll:auto;dialogHeight:" + iHeight + "px;dialogWidth:" + iWidth + "px;";
		
		iReturnValue = window.showModalDialog(sUrl,'',properties);
		return iReturnValue;
	}
	else
	{
		
		var height = iHeight;
		var width = iWidth;
		var left = (screen.width-width)/2;
		var top = (screen.height-height)/2;
 		winHandle = window.open(sUrl,1, "modal,toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left="+left+",top="+top+",width="+width+",height="+height);
		winHandle.focus();	
		return "";
	}
}


function CheckFormError(sError)
{
	if (sError != "")
	{
		//alert(sError);
		OpenMessageWindow(sError,BTN_OPTIONS_OK,350,200);
	}
}


/*********************************
 porpuse: GetPermitTypeID
 inputs : 
 return:  
 comments:
**********************************/
function GetPermitTypeID()
{
	return document.getElementById("txtPermitTypeID").value;
}


/*********************************
 porpuse: Format
 inputs : 
 return:  
 comments:
**********************************/
function Format(total,decimals)
 {
	 total = new String(total)
	 
	  while(total.search(",") != -1) 
		total = total.replace(",","") 
		
      var num = parseFloat(total);
      
      num = Math.abs(num) 
     
      // First section sets non-number value to zero
          if (!(num = parseFloat(num)))
               num = "0.00";
      // Second section sets two decimal place format
          var Pad = "";
          num = "" + Math.floor(num * Math.pow(10,decimals + 1) + 5);
          // Pad if less than 0.10
          if(num.length < decimals+1) 
          {
               for(Count = num.length; Count <= decimals; Count++)
                    Pad += "0";
          }
          num = Pad + num;
         
     // Parse into final string
          num = num.substring(0,num.length - decimals - 1) + 
               "." + num.substring(num.length - decimals -1, num.length -1);
     // If less than 1 then add 0 to the left of the decimal
          if((num == "") || (parseFloat(num) < 1))
               num = "0" + num;
     // Final section returns formatted number
		
		num = SetNumberComma(num)
		if (eval(total) < 0)
		{
			num = "-" + num;
		}
		
          return num;
}


/********************************************************
 porpuse: Date_ToDate
 inputs : 
 return:  
 comments:
*********************************************************/
// change the date format to mm/dd/yyyy
function Date_ToDate(sDate){
	var arr
	sDate=sDate.toString()
	arr = sDate.split("/")
	if (arr.length !=1)
		// date
		var sDate= new Date (arr[1]+ '/' + arr[0] + '/' +arr[2])
	else{
		arr = sDate.split(":")
		if(arr.length==2){
			arr[2]=0 //set seconds
			arr[3]=0 // set miliseconds
		}
		if(arr.length==3)
			arr[3]=0 // set miliseconds
		
		var sDate= new Date ()
		sDate.setHours(arr[0]) 
		sDate.setMinutes(arr[1]) 
		sDate.setSeconds(arr[2]) 
		sDate.setMilliseconds(arr[3])
		
	}
	return sDate
}	

function GetProtocol()
{
	return window.location.protocol;
}

/*function ShowWaitMessage(sMessage ,oParentObjectForDisplay)
{
	var iDialogWidth;
	var iDialogHeight;
 	document.body.style.cursor="wait";
 	if (sMessage == "") 
 		sMessage = "אנא המתן...";
 	
	oWaitPopup = window.createPopup();
	
    var oPopupBody = oWaitPopup.document.body;
	oPopupBody.style.backgroundColor = "lightyellow";
	oPopupBody.style.border = "solid black 1px";
	
    oPopupBody.innerHTML = "<div valign=middle align=center dir=rtl style=\"font-size:15pt;font-family: Arial;\" class='clsTDTableList'>" + sMessage + "</div>";
    
    iDialogWidth = oParentObjectForDisplay.clientWidth //window.dialogWidth.substr(0,window.dialogWidth.length-2);
    iDialogHeight = oParentObjectForDisplay.clientHeight // window.dialogHeight.substr(0,window.dialogHeight.length-2);
    
    oWaitPopup.show((iDialogWidth / 2 )- 175,(iDialogHeight / 2) - 12,350, 35, oParentObjectForDisplay);   
}*/

/*function HideWaitMessage()
{
	if (oWaitPopup != null)
		oWaitPopup.hide();
	oWaitPopup = null;
	
	document.body.style.cursor="";
}*/


function DisplayWaitMessage()
{
	var theobject;
	
	if(document.getElementById("divWaitMessage") == null)
	{
		theobject = document.createElement("div");
		theobject.innerHTML = "<div id=\"divWaitMessage\" dir=\"rtl\" style=\"POSITION: absolute;BACKGROUND-COLOR: #c4d1e2\"><table style=\"border:#666666 1px solid;WIDTH=120px\"  cellpadding=0 cellspacing=0 border=0><tr><td class=\"NormalTextBold\" nowrap>מבצע בקשה...</td><td width=5></td><td><img width=30 height=30 src='" + VIRTUAL_DIRECTORY + "/Images/preloader.gif'></td></tr></table></div>";
		document.getElementsByTagName("body")[0].appendChild(theobject);
	}
	else
	{
		theobject = document.getElementById("divWaitMessage");
		theobject.style.visibility="visible";
	}
	
	doit=setInterval("positionit()",100);
}

function positionit()
{
	var theobject = document.getElementById("divWaitMessage");
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	if (document.all||document.getElementById)
	{
		theobject.style.left=dsocleft+"px";
		theobject.style.top=dsoctop+"px";
	}
}

function HideWaitMessage()
{
	var myDiv = document.getElementById("divWaitMessage");
	
	if(myDiv != null)
	{
		myDiv.style.visibility="hidden";
		clearInterval(doit);
	}
}

function GetQueryVariable(variable) 
{
  var sValue = null;
  
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) 
  {
	var pair = vars[i].split("=");
    if (pair[0] == variable) 
    {
	  sValue = pair[1];
      break;
    }
  }
  
  return sValue;
}


