﻿var FirstTimeSiteLoad="";
//var MsgToUser="";
var str_FirstFocusControl="";
var str_ApplicationRoot;
var str_ApplicationRoot1;
var str_AddItemToListURL="";
var str_LastOpendLayerWithFrame="";
var str_LastOpendLayerWithFrameLink="";
getRootPath();
function getRootPath()
{ 
 var path = self.location.href; 
 var i = path.indexOf("WorkWebProjects"); 
 if (i>1)
 {
   str_ApplicationRoot1="http://localhost/WorkWebProjects/020_Flex/Flex"
 }
 else
 {
   str_ApplicationRoot1="http://www.flex.co.il" 
 } 
} 

/////////////////////////////////////////
//Numbers ///////////////
/////////////////////////////////////////

function Round_2Dec(number) 
	{ 
		return Math.round(number*100)/100; 
	} 
function FormatDec(str_Value) 
	{ 
		num = str_Value * 1 ; 
		digits = Math.round(num * 100) + "" ; 
		while (digits.length < 3) 
		{ 
			digits = "0" + digits ; 
		} 
		result="." + digits.substr(digits.length - 2,digits.length) 
		digits=digits.substr(0,digits.length - 2) 
		while (digits.length > 3) 
		{ 
			result="," + digits.substr(digits.length - 3,digits.length) + result 
			digits=digits.substr(0,digits.length - 3) 
		} 
		return digits + result 
	} 
			
function IsNumeric(Value)
	{
		if (isNaN(Value)) 
		{ 
			return false;
		} 
		else
		{
			return true;
		}				
	}

function RemoveComma(str_Value) { 
  str_Value = str_Value.replace(/,/g, ""); 
  return str_Value; 
} 


/////////////////////////////////////////
//Post Back a Form ///////////////
/////////////////////////////////////////

function PostBackForm(EventName, EventArg) {
	document.getElementById('txt_EventName').value =EventName;
	document.getElementById('txt_EventArg').value =EventArg;
	document.forms[0].submit();

//	var theform;
//	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
//		theform = document.form1;
//	}
//	else {
//		theform = document.forms["form1"];
//	}
//	theform.txt_EventName.value = EventName;
//	theform.txt_EventArg.value = EventArg;
//	theform.submit();
}

/////////////////////////////////////////
//Hot Keys ///////////////
/////////////////////////////////////////

function DoKeyDown()
{ 
	current_key = event.keyCode; 
	//alert(current_key);
	if (current_key==27 | current_key==112 | current_key==113 | current_key==114 | current_key==115 | current_key==119 | current_key==123)
	{
		switch(window.event.keyCode)
		{
			case 27:  
			    {   
			        if (str_LastOpendLayerWithFrame!='')
			        {
			            ClosePopUpWin()
			        }
			        ; break
			    }			    //esc
			case 112: {ShowHideLayerWithFrame("div_PopUpWin",str_ApplicationRoot1+"/080_Common/900_Help.aspx?PageName="+str_PageName+"&PageTitle="+str_PageTitle);return false; break}			//f1
			case 113: {ShowHideLayerWithFrame("div_PopUpWin",str_ApplicationRoot1+"/080_Common/800_InnerCalculator.aspx");return false; break}		//f2
			case 115: {alert("Print"); break}		    //f4
			case 123: {GoTo_AddItemtoListURL(); break}	//f12
		}	
		event.keyCode = 0; 
		event.returnValue = false; 
		event.cancelBubble = true; 
		return false; 
	}
}

document.onkeydown = DoKeyDown;
document.onhelp = 
   function () { 
    return false; 
   }; 

function ClosePopUpWin(Str_ExtraInfo)
{
    if (str_LastOpendLayerWithFrameLink.indexOf('AddPayment')>0)
    {
	    DCM_DeletePaymentRow(CurrentPaymentsTableNumOfRows-1)        
    }
    ShowHideLayerWithFrame(str_LastOpendLayerWithFrame,'');
}

/////////////////////////////////////////
//Go To Add Item to List ///////////////
/////////////////////////////////////////
function GoTo_AddItemtoListURL()
{
  if (str_AddItemToListURL!="")
  {
	location.href = str_AddItemToListURL;  
  }
}

/////////////////////////////////////////
//Show or Hide Layer With Frame ///////////////
/////////////////////////////////////////
function ShowHideLayerWithFrame(lay,FileName)
{
	if (document.getElementById(lay).style.visibility=="visible")
	{
	    str_LastOpendLayerWithFrame="";
	    str_LastOpendLayerWithFrameLink="";
		document.getElementById(lay).style.visibility = "hidden";
        ShowHideLayer('div_WinBlocker');
	}
else
	{
	    str_LastOpendLayerWithFrame=lay;
	    str_LastOpendLayerWithFrameLink=FileName;
		document.getElementById("PopUpWinFrame").src=FileName;
        var iframeElement = parent.document.getElementById('PopUpWinFrame'); 		
        iframeElement.style.height = 440;
        iframeElement.style.width = 630;				
		var DivFrameLast_Top=document.body.scrollTop + (document.body.clientHeight/2)-(220);
		var DivFrameLast_Left=(document.body.clientWidth/2)-(315);
		document.getElementById(lay).style.top = DivFrameLast_Top;
		document.getElementById(lay).style.left = DivFrameLast_Left;
		document.getElementById(lay).style.visibility = "visible";
		if (document.body.clientHeight>document.body.scrollHeight)
		{
		    div_WinBlocker.style.height=document.body.clientHeight;
		}
		else
		{
		    div_WinBlocker.style.height=document.body.scrollHeight;
		}
		div_WinBlocker.style.width=document.body.scrollWidth;
        ShowHideLayer('div_WinBlocker');
	}
}



/////////////////////////////////////////
//Show or Hide Layer ///////////////
/////////////////////////////////////////
function ShowHideLayer(lay)
{
	if (document.getElementById(lay).style.visibility=="visible"){
		HideLayer(lay);
	}
else{
		ShowLayer(lay);
		if (lay=="Layer_SearchBar"){
		    //ישן, אולי צריך למחוק את זה - 21/10/2010
		    document.getElementById('sBar_txtSearch').select();
		}
	}
}

function ShowLayer(lay)
{
	document.getElementById(lay).style.visibility = "visible";
}

function HideLayer(lay)
{
	document.getElementById(lay).style.visibility = "hidden";

}
function Hide_div_Processing_Layer_WithTimeOut()
{
	setTimeout("Do_Hide_div_Processing_Layer_WithTimeOut()", 500);

}
function Do_Hide_div_Processing_Layer_WithTimeOut()
{
  HideLayer('div_Processing');
}
function ShowAndHide_div_Processing_Layer()
{
  ShowLayer('div_Processing');
  setTimeout("Do_Hide_div_Processing_Layer_WithTimeOut()", 500);
}

/////////////////////////////////////////
//Open Modal Window ///////////////
/////////////////////////////////////////
function OpenModalWin(PageName){
	var Args="status:no; resizable:no; help:no; center:yes; dialogWidth:650px; dialogHeight:450px;"
	window.showModalDialog(PageName,window,Args);
}

/////////////////////////////////////////
//Open Window ///////////////
/////////////////////////////////////////
function OpenWin(PageName,WinName,WinSize){
	var Args;
	Args="alwaysRaised=yes;dependent=yes,width=600,height=400,left=150,top=130,titlebar=no,scrollbars=yes";
	if (WinSize=='Small'){
		Args="alwaysRaised=yes;dependent=yes,width=400,height=300,left=170,top=150,titlebar=1,scrollbars=1,status=1";
	}
	var Win=window.open(PageName,WinName,Args);
	Win.focus();
	}

/////////////////////////////////////////
//Show Hide Menu Items after clicks ///////////////
/////////////////////////////////////////
function ShowHideMenuItems(ItemNumber,SetFocusObj) {
	if (eval("MenuHeader"+ItemNumber).style.display =='') {
		HideAllMenuHeaders();
		//createCookie("LastMenuItem","0");
	}
	else {
		HideAllMenuHeaders();
 		eval("MenuHeader"+ItemNumber).style.display='';
 		if (typeof(SetFocusObj)!='undefined' && SetFocusObj!=null && SetFocusObj!="")
 		{
 		  document.getElementById(SetFocusObj).focus();
 		}
 		//createCookie("LastMenuItem",ItemNumber);	
	}
}
function HideAllMenuHeaders()
{
 		for (x=1; x<50; ++x)
 		{
			try 
			{ 
				eval("MenuHeader"+x).style.display = 'none';
			} 
			catch ( e ) 
			{ 
				continue;
			} 
 			
 		}  
}

/////////////////////////////////////////
//Confirm Delete of a row ///////////////
/////////////////////////////////////////
function DoConfirmDelete(ObjId)
{
	var answer = confirm(ConfirmDeleteMsg);
	if (answer==true)
	{
		strLink=PageURLForDelete+ObjId;
		self.location.href=strLink;
	}
}
function DoConfirmPostFormDelete(ObjId)
{
	var answer = confirm(ConfirmDeleteMsg);
	if (answer==true)
	{
		PostBackForm('DelRec',ObjId);
	}
}
/////////////////////////////////////////
//Confirm Post of a Form ///////////////
/////////////////////////////////////////
function DoConfirmPostForm(ConfirmText){
	if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
	if (Page_IsValid==true)
	{ 
		var answer = confirm(ConfirmText);
		if (answer==true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	
} 

/////////////////////////////////////////
//Confirm Post of a Form With No Validation ///////////////
/////////////////////////////////////////
function DoConfirmPostForm_With_No_Validation(ConfirmText){
		var answer = confirm(ConfirmText);
		if (answer==true)
		{
			return true;
		}
		else
		{
			return false;
		}
} 

/////////////////////////////////////////
//Set row Cursor and update cookies ///////////////
///////////////////////////////////////////////////
var Old_Tr_ObjId;
function TR_SetCursor(New_Tr_ObjId){
	if (Old_Tr_ObjId!=null){
		//Delete All
		document.images["CursorImg_"+Old_Tr_ObjId].src=str_ApplicationRoot1+'/900_Resources/001_Images/001_IconsControls/Cursor_Fake.gif';
	}
	if (document.images["CursorImg_"+New_Tr_ObjId]!=null){
		//Add New Cursor
		document.images["CursorImg_"+New_Tr_ObjId].src=str_ApplicationRoot1+'/900_Resources/001_Images/001_IconsControls/Cursor.gif';
		Old_Tr_ObjId=New_Tr_ObjId;
		createCookie(Page_Cursor_CookieName,New_Tr_ObjId);
	}
}

///////////////
//DblClick event of the row ///////////////
//////////////////////////////////////////
function TR_RowDblClick(LinkURL){
	varLink=LinkURL
	self.location.href=varLink;
}

///////////////////////////////////////////
//Tran On Or Off row color ///////////////
//////////////////////////////////////////
function TranOn_TR_Color(src){
  src.className="GridRow_HighLight";
} 
function TranOff_TR_Color(src,str_CssName){
  src.className=str_CssName;
} 

///////////////////////////////////////////
//Tran On Or Off row color with ToolTip text ///////////////
////////////////////////////////////////////////////////////
function TranOnOrOff_TR_ToolTip(StartText,src,TheColor,ObjName,ObjId){
	src.bgColor=TheColor;
	var TheValue;
	if (StartText=="")
	{
	  TheValue=document.getElementById(ObjName+ObjId).value;
	}
	else
	{
	  TheValue="<strong><u>"+StartText+"</u></strong><br/> " + document.getElementById(ObjName+ObjId).value;
	}
	
	var ele = document.getElementById("div_TipBox");
	ele.style.top=10;
	var str_Left=GetWindowWidth()-740;
	ele.style.right=str_Left;
	
	if(ele.style.visibility == "visible") 
	{
	  ele.style.visibility = "hidden";
      ele.innerHTML = TheValue;
  	}
	else 
	{
      ele.style.visibility = "visible";	
      ele.innerHTML = TheValue;	  
	}
}


function GetWindowWidth()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
}

 
////////////////////////////////////////////////////////////
//Tran On Or Off Help Tip text ///////////////
////////////////////////////////////////////////////////////
function TranOnOrOff_TR_HelpTip(StartText,TheText,src,TheColor){
	var TheValue;
	if (StartText=="")
	{
	  TheValue=TheText;
	}
	else
	{
	  var TheValue="<strong><u>"+StartText+"</u></strong><br/>"+TheText;
	}
	
	var ele = document.getElementById("div_TipBox");
	ele.style.top=10;
	var str_Left=GetWindowWidth()-740;
	ele.style.right=str_Left;
	
	if(ele.style.visibility == "visible") 
	{
	  ele.style.visibility = "hidden";
      ele.innerHTML = TheValue;
  	}
	else 
	{
      ele.style.visibility = "visible";	
      ele.innerHTML = TheValue;	  
	}	
} 

////////////////////////////////////////////////////////////
//Convert VbCrLf to <br/> ///////////////
////////////////////////////////////////
function Convert_CrLf_To_BR(inStr)
{
 var tpArray = inStr.split(String.fromCharCode(10));
 var escMsg;
 if (tpArray.length > 1)
   escMsg = tpArray.join("<br/>");
 else
   escMsg = inStr;
 return escMsg;
}

/////////////////////////////////////////
//Trim function ///////////////
///////////////////////////////
function trim(s) 
{
  //http://www.vermontsoftware.com/Javascript/trim.html
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;  
}
///////////////////////////////
//Check Pop Up Blocker ////////
///////////////////////////////
  function CheckPopUpBlocker() 
	{ 
	    alert("CheckPopUpBlocker");
		var zWin;   	
		zWin = window.open("","TestWin","width=100,height=100,top=5000,left=5000"); 
		if (zWin && 'null' != zWin.document)
		{ 
			zWin.close(); 
		} 
		else
		{
			var strLink=str_ApplicationRoot+"/050_ErrorMsg/100_PopUpBlockerMsg.aspx"
			self.location.href=strLink;	
		}
	} 
///////////////	
//Create Cookie ///////////////
///////////////////////////////
	function createCookie(CookieName,value)
	{
        var expires = "";
		document.cookie = CookieName+"="+value+";path=/";
	}
	
//////////////////////////////
//Read Cookie ///////////////
/////////////////////////////
	function readCookie(CookieName)
		{
			var nameEQ = CookieName+"=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++)
			{
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}	
//////////////////////////////
//Cut Off User ///////////////
/////////////////////////////
	function CutOffUser()
		{
			var strLink=str_ApplicationRoot+"100_General/030_LogInOut/010_LogOut.aspx?CutOffUser=yes"
			self.location.href=strLink;	
		}	
		
//////////////////////////////
//Show And Hide Done Msg /////
/////////////////////////////		
		
    function ShowAndHideDoneMsg()
    {
        div_Done.style.display = "block";
        opacity("div_Done", 0, 100, 1000);
        setTimeout('opacity("div_Done", 100, 0, 500);', 2000)  
        setTimeout('div_Done.style.display = "none";', 3000)  
    }
    
    
//////////////////////////////
// opacity ///////////////////
//////////////////////////////

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
		
						

/***********************************************
*               תפריט פופ-אפ
* Pop-it menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

    var defaultMenuWidth="100px" // רוחב התפריט
    var linkset=new Array()
    function GetLinkes_0_Values(str_TheLink)
    {
        linkset[0]='<table width="100" cellspacing="0" cellpadding="2"><tr class="PopUpMenuItem" onmouseover=this.className="PopUpMenuItem_Over"; onmouseout=this.className="PopUpMenuItem"; onclick=window.open("'+str_TheLink+'&DocType=Excel");><td width=30 align=center><img src="'+str_ApplicationRoot1+'/900_Resources/001_Images/002_Icons/WinDoc_Excel.gif"</td><td>אקסל</td></tr></table>'
        linkset[0]+='<table width="100" cellspacing="0" cellpadding="2"><tr class="PopUpMenuItem" onmouseover=this.className="PopUpMenuItem_Over"; onmouseout=this.className="PopUpMenuItem"; onclick=window.open("'+str_TheLink+'&DocType=HTML");><td width=30 align=center><img src="'+str_ApplicationRoot1+'/900_Resources/001_Images/002_Icons/WebSite.gif"</td><td>דף אינטרנט</td></tr></table>'
    }

    function GetLinkes_1_Values(str_TheLink)
    {
        linkset[1]='<table width="100" cellspacing="0" cellpadding="2"><tr class="PopUpMenuItem" onmouseover=this.className="PopUpMenuItem_Over"; onmouseout=this.className="PopUpMenuItem"; onclick=window.open("'+str_TheLink+'&WithExtraInfo=False");><td width=30 align=center><img src="'+str_ApplicationRoot1+'/900_Resources/001_Images/002_Icons/Limited.gif"</td><td>מצומצמת</td></tr></table>'
        linkset[1]+='<table width="100" cellspacing="0" cellpadding="2"><tr class="PopUpMenuItem" onmouseover=this.className="PopUpMenuItem_Over"; onmouseout=this.className="PopUpMenuItem"; onclick=window.open("'+str_TheLink+'&WithExtraInfo=True");><td width=30 align=center><img src="'+str_ApplicationRoot1+'/900_Resources/001_Images/002_Icons/Extended.gif"</td><td>מורחבת</td></tr></table>'
    }

    var ie5=document.all && !window.opera
    var ns6=document.getElementById

if (ie5||ns6)
    document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest(){
    return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, which, optWidth){
    if (!document.all&&!document.getElementById)
    return
    clearhidemenu()
    menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
    menuobj.innerHTML=which
    menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
    menuobj.contentwidth=menuobj.offsetWidth
    menuobj.contentheight=menuobj.offsetHeight
    eventX=ie5? event.clientX : e.clientX
    eventY=ie5? event.clientY : e.clientY
    //Find out how close the mouse is to the corner of the window
    var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
    var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<menuobj.contentwidth)
        //move the horizontal position of the menu to the left by it's width
        menuobj.style.left=ie5? iecompattest().scrollLeft-70+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
    else
        //position the horizontal position of the menu where the mouse was clicked
        menuobj.style.left=ie5? iecompattest().scrollLeft-70+eventX+"px" : window.pageXOffset+eventX+"px"
        
    //same concept with the vertical position
    if (bottomedge<menuobj.contentheight)
        menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
    else
        menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
        menuobj.style.visibility="visible"
    return false
}

function contains_ns6(a, b) {
    //Determines if 1 element in contained in another- by Brainjar.com
    while (b.parentNode)
    if ((b = b.parentNode) == a)
    return true;
    return false;
}

function hidemenu(){
    if (window.menuobj)
    menuobj.style.visibility="hidden"
}

function dynamichide(e){
    if (ie5&&!menuobj.contains(e.toElement))
    hidemenu()
    else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
    hidemenu()
}

function delayhidemenu(){
    delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
    if (window.delayhide)
    clearTimeout(delayhide)
}

if (ie5||ns6)
    document.onclick=hidemenu



