var Page_Validators_Copy;
var clickedButton;
var currentSaved = null;

// Plays with the Focus.Begin ====================================================================
var FocusControl;

function GetFocusControl()
{
	if (FocusControl==null) 
	{
		var input = document.getElementsByTagName("input");
		for (i=0; i<input.length; i++) 
		{
			if (input[i].id.indexOf("FocusControl",0) > 0) 
			{ 
				FocusControl = document.getElementById(input[i].id);
				return FocusControl;
			} 
		}
	}
	return FocusControl;
}
function SetSaveFocus()
{
	var select = document.getElementsByTagName("select");
	for (i=0; i<select.length; i++) 
	{
		select[i].attachEvent("onfocus", function(){SaveFocus()});
	}
	SetFocus();
}
function SaveFocus()
{
	FocusControl = GetFocusControl();
	if (FocusControl!=null) 
	{ 
		FocusControl.value = window.event.srcElement.id;
	}
}
function SetFocus()
{
	FocusControl = GetFocusControl();
	if (FocusControl!=null) 
	{ 
		try
		{
			document.getElementById(FocusControl.value).focus();
		}
		catch(e){}
	}
}
// Plays with the Focus.End ======================================================================


function ComboSearch(dropdownlist,caseSensitive) 
{
	// check the keypressBuffer attribute is defined on the dropdownlist
	var undefined;
	if (dropdownlist.keypressBuffer == undefined) 
	{ 
		dropdownlist.keypressBuffer = ''; 
	}
	// get the key that was pressed 
	var key = String.fromCharCode(window.event.keyCode); 
	dropdownlist.keypressBuffer += key;
	if (!caseSensitive) 
	{
		// convert buffer to lowercase
		dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
	}
	// find if it is the start of any of the options 
	var optionsLength = dropdownlist.options.length; 

	for (var n=0; n < optionsLength; n++) 
	{ 
		var optionText = dropdownlist.options[n].text; 
		if (!caseSensitive) 
		{
			optionText = optionText.toLowerCase();
		}
		if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) 
		{ 
			dropdownlist.selectedIndex = n; 
			return false; // cancel the default behavior since we have selected our own value 
		} 
	} 
	// reset initial key to be inline with default behavior 
	dropdownlist.keypressBuffer = key; 
	return true; // give default behavior 
}

function SetFilter() 
{
	var keyCode = window.event.keyCode;

	if (keyCode < '0'.charCodeAt(0) || keyCode > '9'.charCodeAt(0) )
	{
	   window.event.returnValue = false;
	}
	else
	{
	   window.event.returnValue = true;
	}
}
//added by raf 17.6.10 for CQU00073925
function SetFilter_OnLine() 
{
	var keyCode = window.event.keyCode;

	//alert(keyCode);
	
	if (keyCode != 13)
	{
	   window.event.returnValue = true;
	}
	else
	{
	   window.event.returnValue = false;
	}
}
function GetAjaxObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer'){
        ro = new ActiveXObject('Microsoft.XMLHTTP');
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

function SetScrollbar() 
{
	var ScrollBar				= document.getElementById("ScrollBar");
	var ScrollBarDisplayNone	= document.getElementById("ScrollBarDisplayNone");
	var wizardtableTD			= document.getElementById("wizardtableTD");
	var PlaceHolder				= document.getElementById("PlaceHolder");
	var PlaceHolderHeight;

	if (PlaceHolder!=null) PlaceHolderHeight = PlaceHolder.offsetHeight;;
		ScrollBar.style.height	= wizardtableTD.offsetHeight;
		ScrollBar.children(0).swapNode(ScrollBarDisplayNone.children(0));
	if (PlaceHolder!=null) PlaceHolder.style.height= PlaceHolderHeight;
}
 
function ReSetScrollbar(flag) 
{
	var ScrollBar				= document.getElementById("ScrollBar");
	var ScrollBarDisplayNone	= document.getElementById("ScrollBarDisplayNone");
	var wizardtableTD			= document.getElementById("wizardtableTD");

	if (ScrollBarDisplayNone==null) return;

	// Unbelievably, but it works!
	if (flag)
	{
		ScrollBarDisplayNone.children(0).swapNode(ScrollBar.children(0));
		ScrollBar.style.height = 0;
	}	
	else
	{
		ScrollBar.style.height = wizardtableTD.offsetHeight;
		ScrollBar.children(0).swapNode(ScrollBarDisplayNone.children(0));
	}	
}


   function ValidZipeCode(source,args)
    {
          var patern="^\\d{5}$"
          var regEx = new RegExp(patern);
          args.IsValid=regEx.test(args.Value);
          return;
         
    }
    function ValidTelephone(source,args)
    {
        
         var patern ="^0[23489]{1}(\\-)?[^0\\D]{1}\\d{6}$"
          var regEx = new RegExp(patern);
           args.IsValid=regEx.test(args.Value);
           return;
           
    }
    function ValidMobilePhone(source,args)
    {
         var patern ="^0(5[0247]){1}(\\-)?[^0\\D]{1}\\d{6}$"
          var regEx = new RegExp(patern);
          args.IsValid=regEx.test(args.Value);
          return;   
    }
    
    function ValidIsraelyID(source,args)
    {
		var idnum=args.Value;
		
		// YuraT - if we use a non digital sign
			var patern="^\\d{9}$"
			var regEx = new RegExp(patern);
			args.IsValid=regEx.test(idnum);
			if (!args.IsValid) return;
		// End YuraT		
		
       while (idnum.length<9)
       {
        idnum="0"+idnum;
       }
        idnum1=idnum.substr(0,1)*1;
        idnum2=idnum.substr(1,1)*2;
        idnum3=idnum.substr(2,1)*1;
        idnum4=idnum.substr(3,1)*2;
        idnum5=idnum.substr(4,1)*1;
        idnum6=idnum.substr(5,1)*2;
        idnum7=idnum.substr(6,1)*1;
        idnum8=idnum.substr(7,1)*2;
        idnum9=idnum.substr(8,1)*1;
 
        if (idnum1>9) idnum1=(idnum1%10)+1
        if (idnum2>9) idnum2=(idnum2%10)+1
        if (idnum3>9) idnum3=(idnum3%10)+1
        if (idnum4>9) idnum4=(idnum4%10)+1
        if (idnum5>9) idnum5=(idnum5%10)+1
        if (idnum6>9) idnum6=(idnum6%10)+1
        if (idnum7>9) idnum7=(idnum7%10)+1
        if (idnum8>9) idnum8=(idnum8%10)+1
        if (idnum9>9) idnum9=(idnum9%10)+1
         var sumval=idnum1+idnum2+idnum3+idnum4+idnum5+idnum6+idnum7+idnum8+idnum9;
         sumval=sumval%10
         if (sumval>0)
         {
           args.IsValid=false;
         }
         else{
           args.IsValid=true;
         }
   } 
  function  ValidCaseID(source,args)
  {
      return true;
  }
  function ValidEmail(source,args)
  {
      var patern ="^([\\w\\-\\.]+)@((\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|(([\\w\\-]+\\.)+)([a-zA-Z]{2,4}))$"
          var regEx = new RegExp(patern);
          args.IsValid=regEx.test(args.Value);
          return;
            
  }
  
 
function FillFileField(object)
{	 
	if (event.propertyName!="value") return;
	
	var parentSpan		= object.parentNode;
	var fileField		= parentSpan.childNodes[0];  
	var ImageBrows		= parentSpan.childNodes[1];	
	var txtfileField	= parentSpan.childNodes[3]; 

	txtfileField.value	= fileField.value;
	if (object.attributes["AutoPostBackEvent"].value =="True")
	{       
		ImageBrows.click();
	}  
}


function caseStatusGrid()
{   
    if(document.all.caseStatusGrid.style.display=='block')
    {
	       document.all.caseStatusGrid.style.display='none'
	       document.all["buttonA"].style.backgroundImage="url(../images/But/ButA_Open.gif)";
	}
    else
    {
	      document.all.caseStatusGrid.style.display='block'
	      document.all["buttonA"].style.backgroundImage="url(../images/But/ButA_Close.gif)";
	}
}

function Document_onclick()
{ 
  alert("רפא טרם העביר אלי מסמך בנושא");
}

function ShowCalendar(source)
{ 
	// debugger;
	window.showModalDialog('http://localhost/NGCS.Web.Site/CommonUI/BasicControls/WebCalendar.htm', '01/01/2005','dialogTop:100px;dialogLeft:200px;dialogHeight:230px;dialogWidth:200px;status:0; help:0;scroll: 0');
}


// Function generates client and server messages
   var messPopup = window.createPopup();
   function createPopUp(icon,message)
   {
			mIcon = "";
   
   		//	Asterisk = 64; Error = 16;Exclamation = 48;	Hand = 16;Information = 64;	None = 0;Question = 32;	Stop = 16; Warning = 48;
			if(icon == 1)
			{
				mIcon = NGCSPath +"/Images/Dialog/I_Info.gif";
			}
			if(icon == 16)
			{
				mIcon = NGCSPath +"/Images/Dialog/I_Eror.gif";
			}
			if(icon == 64)
			{
				mIcon = NGCSPath + "/Images/Dialog/I_Info.gif";
			}
			if(icon == 48)
			{
				mIcon = NGCSPath + "/Images/Dialog/I_warning.gif";
			}
			if(icon == 32)
			{
				mIcon = NGCSPath + "/Images/Dialog/I_Help.gif";
			}   
	//debugger; 
  	var str = "";
  	var h = 30;
	var charMax = 30;
	var lineCount = (message.length/charMax + 1)|0;
	var temp = new Array();
		temp = message.split("<br>");
		
		if ((temp.length-1)!=0){
			lineCount = lineCount + (temp.length-1);
		}
		if (lineCount > 1)
		{
			h = h * lineCount;
		}
	
	var height = h + 112;
	var messPopBody = messPopup.document.body;
	str+= "<div id='content' STYLE='BACKGROUND:white; FILTER:progid:DXImageTransform.Microsoft.Shadow(color=\"#000000\", Direction=135, Strength=3); FONT:12px Ariel; POSITION:absolute'>\n";
	str+= "<TABLE id='Table1' cellSpacing='0' cellPadding='0' width='350' height='129' border='0' dir='rtl'	bgcolor='#F5FAFF' style='BORDER-RIGHT: #f5faff 1px solid; BORDER-TOP: #f5faff 1px solid; BORDER-LEFT: #f5faff 1px solid; BORDER-BOTTOM: #f5faff 1px solid; BORDER-COLLAPSE: collapse'>\n";
	str+= "<TR height='20' style='BACKGROUND-ATTACHMENT: scroll; BACKGROUND-IMAGE: url("+ NGCSPath +"/Images/Dialog/DialogBarBG.gif); BACKGROUND-REPEAT: repeat-x'>\n";
	str+= "<td valign='middle' style='PADDING-RIGHT: 7px'></td>\n";
	str+= "<td valign='middle'><IMG style='CURSOR: hand; MARGIN-LEFT: 7px' onclick='parent.messPopup.hide();' hspace='0'";
	str+= "src='"+ NGCSPath +"/Images/Dialog/DialogClose.gif' align='left' vspace='0' height='16' width='16'></td>\n";
	str+= "</TR>"
	str+= "<TR>"
	str+= "<TD vAlign='middle' colspan='2'>\n"
	str+= "<TABLE id='Table2' height='100%' cellSpacing='0' cellPadding='0' width='100%' border='1'	borderColor='#F5FAFF' style='BORDER-COLLAPSE: collapse'>\n";
	str+= "<TR>\n";
	str+= "<TD style='WIDTH: 7px; HEIGHT: 7px; BACKGROUND-COLOR: #F5FAFF' width='7' height='7'></TD>\n";
	str+= "<TD height='7' style='HEIGHT: 7px'></TD>\n";
	str+= "<TD style='WIDTH: 7px; HEIGHT: 7px; BACKGROUND-COLOR: #F5FAFF' width='7' height='7'></TD>\n";
	str+= "</TR>\n";
	str+= "<TR>\n";
	str+= "<TD height='95' width='6'></TD>\n";
	str+= "<TD valign='middle'>\n"
	str+= "<TABLE id='Table3' cellSpacing='0' cellPadding='0' width='100%' height='100%' border='1' borderColor='#6698C5' rules='none' style='BORDER-COLLAPSE: collapse'>\n";
	str+= "<TR>"
	str+= "<TD height='15'></TD>\n";
	str+= "</TR>\n";
	str+= "<TR>\n";
	str+= "<TD>\n";
	str+= "<table border='0' width='100%'  style='BORDER-COLLAPSE: collapse'>\n";
	str+= "<tr>\n";
	str+= "<td style='WIDTH: 15px'>&nbsp;</td>\n"
	str+= "<td width='32'><IMG hspace='0' id = 'mIcon' align='right' vspace='0'  hspace = '0' border='0' src = '" + mIcon +"'></td>"
	str+= "<td align='right' valign = 'bottom' style='PADDING-RIGHT: 10px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #333366; DIRECTION: rtl; LINE-HEIGHT: 30px; FONT-FAMILY: Arial'><div id = 'content'>"+ message +"</div></td>\n";
	str+= "<td style='WIDTH: 15px'>&nbsp;</td>\n";
	str+= "</tr>\n";
	str+= "</table>\n";
	str+= "</TD>\n";
	str+= "</TR>\n";
	str+= "<TR>\n";
	str+= "<TD align='left'>\n";
	str+= "<table border=0 style='MARGIN-TOP: 15px; MARGIN-BOTTOM: 15px; BORDER-COLLAPSE: collapse'	width='100%'>\n";
	str+= "<tr valign='middle'>\n";
	str+= "<td>&nbsp;</td>\n";
	if(icon == 1)
		{ str+= "<td></td>\n"; }
	else
		{ str+= "<td style='FONT-WEIGHT: normal; FONT-SIZE: 12px; BACKGROUND-ATTACHMENT: scroll; BACKGROUND-IMAGE: url(" + NGCSPath + "/Images/But/ButSmall.gif); CURSOR: hand; COLOR: #333366; BACKGROUND-REPEAT: no-repeat; FONT-FAMILY: Arial' onclick='parent.messPopup.hide();parent.HaveWaited()' align='center' valign='middle' width='81' height = '20' dir='rtl'>אישור</td>\n"; }
	str+= "<td style='WIDTH: 15px'>&nbsp;</td>\n";
	str+= "</tr>\n";
	str+= "</table>\n";
	str+= "</TD>\n";
	str+= "</TR>\n";
	str+= "</TABLE>\n";
	str+= "</TD>\n";
	str+= "<TD height='95' width='6'></TD>\n";
	str+= "</TR>\n";
	str+= "<TR>\n";
	str+= "<TD style='WIDTH: 7px; HEIGHT: 7px; BACKGROUND-COLOR:#F5FAFF' width='7' height='7'></TD>\n";
	str+= "<TD height='7' style='HEIGHT: 7px'></TD>\n";
	str+= "<TD style='WIDTH: 7px; HEIGHT: 7px; BACKGROUND-COLOR: F5FAFF' width='7' height='7'></TD>\n";
	str+= "</TR>\n";
	str+= "</TABLE>\n";
	str+= "</TD>\n";
	str+= "</TR>\n";
	str+= "</TABLE>\n";
	str+= "</div>"
	messPopBody.innerHTML = str;
	messPopup.show(337, 298, 353, height);
	
	// YuriT: Resize messPopup
	var content = messPopup.document.getElementById('content')
	height  = content.offsetHeight;
	messPopup.hide();	
	messPopup.show(337, 298, 353, height);
}

function NGCSMsgBox(title,message,mode)
{
	createPopUp(mode,message)
}

function BuildPageValidators(ControlsToValidate)
{
	if (Page_Validators_Copy==null)
	{
		Page_Validators_Copy = new Array().concat(Page_Validators);
	}
	var counter = 0;
	Page_Validators = new Array();	
	
	var index = 0;
	var id;
	var re;

    for (var i = 0; i < ControlsToValidate.length; i++)
    {
		index = 0;
        for (index; index < Page_Validators_Copy.length; index++)
		{
			id = Page_Validators_Copy[index].id;
			re = new RegExp( "(\S*ctl\S*){0,1}" + ControlsToValidate[i],"i");

			if (id.search(re)>=0)
			{
				Page_Validators[counter++] = Page_Validators_Copy[index];			
			}
		}
    }    	
}

//debuger;
function WaitPlease(val)
{//	document.body.style.cursor = "wait";
	document.body.runtimeStyle.cursor = "wait";

	var buttons = document.body.all.tags("a");
	for(var i = 0; i < buttons.length; i++)
	{
		// ========= Style Reservation & Definition ==========================================
		if (buttons[i].className=="ButtonsSmall")
		{
			buttons[i].setAttribute("classNameSaved", buttons[i].className);    
			buttons[i].className = "ButtonsSmallDisabled";
		}
		else if (buttons[i].className=="ButtonsMedium")
		{
			buttons[i].setAttribute("classNameSaved", buttons[i].className);    
			buttons[i].className = "ButtonsMediumDisable";
		}
		else if (buttons[i].className=="ButtonsTiny")
		{
			buttons[i].setAttribute("classNameSaved", buttons[i].className);    
			buttons[i].className = "ButtonsTinyDisabled";
		}
		else if (buttons[i].className=="ButtonsLarge")
		{
			buttons[i].setAttribute("classNameSaved", buttons[i].className);    
			buttons[i].className = "ButtonsLargeDisable";
		}
		
		// ========= Event Reservation =======================================================
		buttons[i].onClickSaved = buttons[i].onclick;
		buttons[i].onclick = null;
		
		// ========= Href Reservation ========================================================
		buttons[i].hrefSaved = buttons[i].href;
		if (val!=buttons[i].id)
		{
			buttons[i].removeAttribute("href",0);
		}
		else
		{
			clickedButton = buttons[i]; // remove Attribute in webuivalidation.js
		}
	}
	//
	var Wait = document.getElementById(val).getAttribute("Wait");
	if (Wait!=null)
	{
		if (Wait.toLowerCase()=="true")
		{
			createPopUp(1,"אנא המתן...");
		}
	}
}
function HaveWaited()
{
//	document.body.style.cursor = "default";
	document.body.runtimeStyle.cursor = "default";
 
	var buttons = document.body.all.tags("a");
	for(var i = 0; i < buttons.length; i++)
	{
		// ========= Style Restoration =======================================================
		if (buttons[i].getAttribute("classNameSaved")!= null) 
		{
			buttons[i].className = buttons[i].getAttribute("classNameSaved");
			buttons[i].removeAttribute("classNameSaved",0);
		}
		// ========= Event Restoration =======================================================
		if (buttons[i].onClickSaved!= null)
		{
			buttons[i].onclick=buttons[i].onClickSaved
			buttons[i].onClickSaved = null;
		}
		// ========= Href Restoration ========================================================
//		if (buttons[i].getAttribute("hrefSaved")!= null) 
//		{
//			buttons[i].setAttribute("href", buttons[i].getAttribute("hrefSaved"));
//			buttons[i].removeAttribute("hrefSaved",0);
//		}


//if (buttons[i].id == "navigationLowerToolBar_nextButton") debugger;;




		if (buttons[i].hrefSaved!= null)
		{
			buttons[i].href = buttons[i].hrefSaved;
			buttons[i].hrefSaved = null;
		}
		








	}
}

function StrToFun(val)
{
	if (typeof(val.evaluationfunction) == "string") 
	{
		eval("val.evaluationfunction = " + val.evaluationfunction + ";");
	}
}

function ClearDataInAllChildElements(container)
{
	if (container.getAttribute('ClearOnOpen')==null) return;
	if (container.getAttribute('ClearOnOpen').toLowerCase()!='true') return;

	for (i = 0; i < container.all.length; i++) 
	{
		var control = container.all[i];
		switch(control.tagName.toLowerCase())
		{
			case "input":
				switch(control.type.toLowerCase())
				{
					case "text":
						control.value = "";
						break;
					case "hidden":
						control.value = "";
						break;
					case "radio":
						control.checked = false;
						break;
					case "checkbox":
						control.checked = false;
						break;
				}
				if (control.getAttribute('EnabledOnOpen')!=null && control.getAttribute('EnabledOnOpen').toLowerCase()=='true') control.readOnly = false;
				break;
			case "select":
				control.value = "-1";
				if (control.getAttribute('EnabledOnOpen')!=null && control.getAttribute('EnabledOnOpen').toLowerCase()=='true') control.disabled = false;	
				break;
			case "textarea":
				control.value = "";
				break;
		}
	}
}

function SetTabIndex()
{
	if (document.body==null) return;
	
	for(var i = 0; i < document.body.all.length; i++)
	{
		current	= document.body.all[i];
		tag		= current.tagName;
		type	= current.type
		
		if (tag.toLowerCase() == "input" || tag.toLowerCase() == "a" || tag.toLowerCase() == "select" )
		{		
			if (!current.readOnly)
			if (!current.disabled)
			if (type.toLowerCase()!="hidden")
			{
				current.tabIndex = i;
				if (current.name.toLowerCase().indexOf("oldcasenumbertextbox")>0 || current.name.toLowerCase().indexOf("oldyeartextbox")>0)
				{
					if (currentSaved==null)
					{
						currentSaved			= current;
					}
					else
					{
						current.tabIndex		= currentSaved.tabIndex
						currentSaved.tabIndex	= i;
						currentSaved			= null;
					}			
				}
			}
		}
	}
}

//debuger;
function PrintDocument()
{
	document.body.focus();
	try
	{
		IEWB.ExecWB (6, 1);
	}
	catch(e)
	{
		window.alert("Nothing Printed");
	}
}

//Inserted by Ety at 09/08/2011 - BaseCMActivity CQU00081376 (Change 72125) - Start
function ConfirmWordDocDownload()
{
	HaveWaited();	
	return confirm("?Word האם לבצע הורדת המסמכים כמסמכי");	
}

function ConfirmPDFDocDownload()
{
	HaveWaited();	
	return confirm("?PDF האם לבצע הורדת המסמכים כמסמכי");
}
// End

//window.history.forward(100); 
SetTabIndex()


