//------------------------------
//Used in Procedured selection to manage pairs of procedures.
function ArrayContainsSubstr(SubStr){
	try{
		var count = pair.length;
		var i4;
		for(i4=0;i4<count;i4++){
			if(pair[i4].indexOf(SubStr) > -1){
				return pair[i4];
			}
		}
	}catch(e){}
	return "";
}
function FuncDisableConflictingChkBox(chkBoxRef){
	var myPair ="";
	var myID = chkBoxRef.id;
	myPair = ArrayContainsSubstr( myID + ":")
	myPair = myPair + "";
	if(myPair.length > 0){
		chkBoxRef.disabled = true;
	}
}
function FuncEnableConflictingChkBox(chkBoxRef){
	var myPair ="";
	var myID = chkBoxRef.id;
	myPair = ArrayContainsSubstr( ":" + myID)
	myPair = myPair + "";
	if(myPair.length > 0){
		var otherChkBoxID = myPair.substring(0, myPair.indexOf(":"));
			var chkAry = document.forms[0].procOption;
			var count =chkAry.length;
			var i2;
			for(i2=0; i2<count; i2++){
				if (otherChkBoxID == chkAry[i2].id){
					if (chkBoxRef.checked == false && chkAry[i2].checked == true ){
						chkAry[i2].checked = false;
					}
					chkAry[i2].disabled = (!chkBoxRef.checked);
					i2=count;
				}
			}
	}
}

function CheckAllChkBoxes(){
	var chkAry = document.forms[0].procOption;
	var count =chkAry.length;
	var i3;
	for(i3=0; i3<count; i3++){
		FuncDisableConflictingChkBox(chkAry[i3]);
	}
}

//------------------------------
function moveToShortcut(myVal){
if(myVal == '301^'){
		window.location.href = "ProcedureSelect.aspx?tab=2&CPID=301&PID=3204";
	}
	else{
		var cmb=document.getElementById("cmbNav");
		var numEle = cmb.options.length;
		for(i=0; i< numEle; i++){
			val = cmb.options[i].value;
			if(val.indexOf(myVal) == 0 ){
				cmb.options[i].selected = true;
				shortcut();
				return;
			}
		}
	}
}
function disablebackspace() {
		if (window.focus){
			document.onkeydown=catchbackspace;
			document.onkeyup=catchbackspace;
			//document.oncontextmenu = nocontextmenu;
			//document.onmousedown = norightclick;
			//document.onmousedown=norightclick;
	  }
}
var eBckBtn;
function catchbackspace() {
		if (window.focus){
			  if (!eBckBtn){
					eBckBtn=window.event;
			  }
			  var bDontSuppress  = (
			  (eBckBtn.srcElement.tagName == "INPUT") 
			  ||
			  (eBckBtn.srcElement.tagName == "TEXTAREA") 
			  );
			  if(!bDontSuppress){
				  if (eBckBtn.keyCode==8){
						return false;
				  }
				  if (eBckBtn.keyCode==93){
						//alert("Button disabled due to security reasons.");
						return false;
				  }
				  if (eBckBtn.keyCode==37){
						return false;
				  }
				  if (eBckBtn.keyCode==122){
						return false;
				  }			
			  		if (event.keyCode == 13) {	// ENTER
			  			return false;
			  			/*if(window.location.href.indexOf("ProcedureSelect.aspx") == -1 ){
							alert(event.srcElement.tagName);
						}*/
					}				  
			  }
			  else{
			  	if (event.keyCode == 13) {	// ENTER
			  		return false;
			  		/*if(window.location.href.indexOf("ProcedureSelect.aspx") == -1 ){
							if(event.srcElement.type == "submit"){
							}
					}*/
				}
			  }
		  
		}
}
function norightclick(eRigthBtn) {

  if (window.Event)
  {
	if(eRigthBtn == null) return false;
    if (eRigthBtn.which == 2 || eRigthBtn.which == 3) return false;
  }
  else if (event.button == 2 || event.button == 3) 
  {
	if (window.event.srcElement.tagName == "INPUT" || 
		window.event.srcElement.tagName == "TEXTAREA" ||
		window.event.srcElement.tagName == "CODE")
	{
		event.cancelBubble = false, event.returnValue = true;
		return true;
	}
	else
	{
		var txt = (document.all) ? document.selection.createRange().text : document.getSelection();
		try
		{
			if (txt.length > 0)
			{
				event.cancelBubble = false, event.returnValue = true;
				return true;
			}
			else
			{
				event.cancelBubble = true, event.returnValue = false;
				return false;
			}
		}
		catch(ex)
		{
		}
	}
  }
}
function nocontextmenu() 
{
	//window.status = window.event.srcElement.tagName;
	if (window.event.srcElement.tagName == "INPUT" || 
		window.event.srcElement.tagName == "TEXTAREA" ||
		window.event.srcElement.tagName == "CODE")
	{
		event.cancelBubble = false, event.returnValue = true;
		return true;
	}
	else
	{
		var txt = (document.all) ? document.selection.createRange().text : document.getSelection();
		try
		{
			if (txt.length > 0)
			{
				event.cancelBubble = false, event.returnValue = true;
				return true;
			}
			else
			{
				event.cancelBubble = true, event.returnValue = false;
				return false;
			}
		}
		catch(ex)
		{
		}
	}
} 
//disablebackspace();
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function GoToLE(LicenseNr){
	NewPopUpWindow('../../Pages/TradeLicense/LicenseEnquiry.aspx?hh=Y&cpid=7000&tab=2&QSParams=&value=_&TLN=' + LicenseNr ,
			'PersonDetail','800','600','yes');
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function DEDWinResize(){
	return true;
	//
	var Location = window.location.href;
	if(Location.indexOf("RulesMsgs.aspx")> -1 ){
		return;
	}
	if(Location.indexOf("Expand=false")> -1 ){
		return;
	}
	var winname = window.name + "";
	var CallOpenWindowRestricted = false;
	var isIFramePresent =( 
	( (parent.frames.PaymentOrderPrintView1_IReportFrame) + "" =="[object]")
		||
	 ( (parent.frames.CPV_IReportFrame) + "" =="[object]")
	 || 
	 ( (parent.frames.IReportFrame) + "" =="[object]")
	 ||
	 ((parent.frames.PaymentOrderReprint1_IReportFrame ) + "" =="[object]")
	 ||
	 ((parent.frames.MunicipalityFee1_PrintMunicipalityFee1_IReportFrame)+ "" =="[object]")
	 ||
	 ((parent.frames.ReceiptWraper1_IReceiptFrame)+ "" =="[object]")
	 
		)
		if (isIFramePresent == false)
		{
			CallOpenWindowRestricted = true;
		}
		else{	
			CallOpenWindowRestricted = false;
		}
		//alert(isIFramePresent + " " + " isIFramePresent 73");
		//alert(CallOpenWindowRestricted + " " + "CallOpenWindowRestricted 74");
	if (isIFramePresent)
	{
		ranNr = Math.floor(Math.random()*1111111111);
		window.name="DEDWIN" + ranNr;
		winname = window.name;
	}
		//alert(winname + " " + "winname 81");
	if(winname.indexOf("DEDWIN") == -1 ) {
			if(CallOpenWindowRestricted){
			//window.screenTop  : 23
			var wst = window.screenTop;
			if (wst > 23 ) {
				window.moveTo(0, 0);
				wst = window.screenTop;
				if (wst > 23 ) {
					OpenWindowRestricted() ;
				}
			}
		}
	}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function OpenWindowRestricted() 
{
	var winname = window.name + "";
	var CallOpenWindowRestricted = false;
	var isIFramePresent =( 
	( (parent.frames.PaymentOrderPrintView1_IReportFrame) + "" =="[object]")
		||
	 ( (parent.frames.CPV_IReportFrame) + "" =="[object]")
	 || 
	 ( (parent.frames.IReportFrame) + "" =="[object]")
	 	||
	 ((parent.frames.PaymentOrderReprint1_IReportFrame ) + "" =="[object]")
	||
	 ((parent.frames.MunicipalityFee1_PrintMunicipalityFee1_IReportFrame)+ "" =="[object]")
	 )
		if (isIFramePresent == false)
		{
			CallOpenWindowRestricted = true;
		}
		else{
			CallOpenWindowRestricted = false;
		}	
		//alert(isIFramePresent + " " + " isIFramePresent 114");
		//alert(CallOpenWindowRestricted + " " + "CallOpenWindowRestricted 115");

	if (isIFramePresent)
		{
			ranNr = Math.floor(Math.random()*1111111111);
			window.name="DEDWIN" + ranNr;
			winname = window.name;
		}
		if(winname.indexOf("DEDWIN") == -1 ) {
			if (CallOpenWindowRestricted)
			{
				var ranNr ="";
				ranNr = Math.floor(Math.random()*1111111111)
				mypage = window.location.href;
				var width = (screen.availWidth-5);
				var height = (screen.availHeight-50);
				winprops = 'height='+height+',width='+width+',top=0,left=0' + ',status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'
				myname="DEDWIN" + ranNr;
				win11 = window.open(mypage, myname, winprops)
				win11.window.focus();
				window.location.href="../../Pages/Common/TradeLicense.html";
			}
		}
}
/*------------------------------------*/
function GoBack(){
	history.go(-2);
}
//
function FocusOnAnchor(anchorName) {
/*
	try{
			
	var loca = window.location.href;
		if (loca.indexOf("#" + anchorName) == -1){	
				if (loca.indexOf("#") > -1){
					loca = loca.substring(0, loca.indexOf("#") );
				}
				loca = loca + '#'+ anchorName;
				window.location.href = loca ;
		}
	
	}
	catch(e){
	}
    */
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function NewWindowBig(mypage) 
{
	//does not reuse an open window
	var w = (screen.width - 10) ;
	var h = (screen.height - 100) ;	
	var Left = 50;
	var Top = 20;
	var scroll = "yes"
	myname = "SearchWin";
	winprops = 'height='+h+',width='+w+',top='+Top+',left='+Left+',scrollbars='+scroll+',resizable'
	var win4 = window.open(mypage, "DEDWIN" + myname, winprops)
	win4.focus();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function NewWindowBig2(mypage) 
{
	//does not reuse an open window
	var w = (screen.width - 150) ;
	var h = (screen.height - 150) ;	
	var Left = 75;
	var Top = 45;
	var scroll = "yes"
	myname = "SearchWina";
	winprops = 'height='+h+',width='+w+',top='+Top+',left='+Left+',scrollbars='+scroll+',resizable'
	var win4a = window.open(mypage, "DEDWIN" + myname, winprops);
	win4a.focus();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 function SelAllChkBoxesReqDocs(chkBoxRef){
	 try{	
		var chkNmAry = chkBoxNameList.split(",");
		var len = chkNmAry.length;
		var evalStr ="";
		for(i=0;i<len; i++){
			evalStr = "document.forms[0]." + chkNmAry[i] + ".checked = " + chkBoxRef.checked ;
			eval(evalStr);
		}
	 }
	 catch(e){
	 }
 }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function FocusOnControl(controlName){
	/*
	if(controlName.length > 0){
		try{

				eval("document.forms[0]." + controlName + ".focus();");
				eval("document.forms[0]." + controlName + ".select();");
		}
		catch(e){
		}
	}
	*/
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//document.onkeydown = function ()
function onEnterKey(){
	var obj =null;
	var valResult = true;
	var bExit = false;
	try{
			if (event.keyCode == 13) {	// ENTER
			//ProcedureList1:ProcedureListNav1:DEDBtnStartProcedure
				obj =  document.forms[0].ProcedureList1_ProcedureListNav1_DEDBtnStartProcedure;
				if ( !bExit && obj != null ){
					bExit = true;
					__doPostBack("ProcedureList1:ProcedureListNav1:DEDBtnStartProcedure","");
					//return;
				}
				//ProcedureList1:ProcedureListNav1:DEDBtnContinue
				obj = document.forms[0].ProcedureList1_ProcedureListNav1_DEDBtnContinue;
				if ( !bExit && obj != null){
						 bExit = true;
					__doPostBack("ProcedureList1:ProcedureListNav1:DEDBtnContinue","");
					//return;
				}				
				obj = document.forms[0].WizBaseNavigation1_DEDBtnContinue;
				if ( !bExit && obj != null){
						 bExit = true;
					if(typeof(Page_ClientValidate) == 'function'){
					valResult = Page_ClientValidate(); 
					}
					if (valResult){__doPostBack("WizBaseNavigation1$DEDBtnContinue","");}
					//return;
				}				
				obj = document.forms[0].WizBaseNavigation1_DEDBtnFinish;
				if ( !bExit && obj != null){
						 bExit = true;
					if(typeof(Page_ClientValidate) == 'function'){
					valResult = Page_ClientValidate(); 
					}						 
					if (valResult){__doPostBack("WizBaseNavigation1:DEDBtnFinish","");}
					//return;
				}				
			}
	}	catch(e){	}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function delActivity(rad){

	//added as per Business Owner Request Mar 15 2005 : Ali Abdullah
	if (rad.checked == true){
		__doPostBack('TLBizAct$DEDHLDelete','');
	}
}
//
function delCmrcActivity(rad){
	//added as per Business Owner Request Mar 15 2005 : Ali Abdullah
	if(rad.checked == true){
		__doPostBack('TLBizAct$DEDHLDelete','');
	}
}
// 
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function SelAct(actvStr){
	if (actvStr.length >0 ) {
		var actvArray = actvStr.split(',');
		var count = actvArray.length ;
		var chkBoxArray ;
		eval('chkBoxArray = document.forms[0].BizChqActAvl');
		var isArray = false;
		var countArrayLen = 0;
		try{
			if(chkBoxArray.length > 0){
				isArray = true;
				countArrayLen = chkBoxArray.length;
			}
		}
		catch(e){
		}
		var found;
		var myCheckBox;
		var currentVal;
		for (i=0; i < count; i++){
			eval("currentVal = actvArray[" + i + "]");
			try{
				if(isArray){
					var j;
					for(j=0;j<countArrayLen; j++){
						eval("myCheckBox = chkBoxArray[" + j + "]");
						if(currentVal == myCheckBox.value){
							myCheckBox.checked = true;
						}
					}
				}
				else{
						eval('chkBoxArray' + '.checked = true;');
				}
			}
			catch(e){
			}
		}
	}
}

function EngToArabic(){
	try{
	
	var latinKeys = new Array(1584, 1588, 1575, 1572, 1610, 1579, 1576, 1604, 1575, 1607, 1578, 1606, 1605, 1577, 1609, 1582, 1581, 1590, 1602, 1587, 1601, 1593, 1585, 1589, 1569, 1594, 1574);
	var shftLatinKeys = new Array(1617, 1616, 1570, 125, 93, 1615, 91, 1571, 1571, 247, 1600, 1548, 47, 8271, 1570, 215, 1563, 1614, 1612, 1613, 1573, 8216, 123, 1611, 1618, 1573, 126);
	var specialKeys = new Array(new Array(39, 44, 46, 47, 59, 91, 93, 126, 40, 41, 123, 125, 58, 34, 60, 62, 63), new Array(1591, 1608, 1586, 1592, 1603, 1580, 1583, 1617, 41, 40, 60, 62, 58, 34, 44, 46, 1567));
	var sd;
		 var seek = 0;
    var addL = false;

    if (event.keyCode == 13) {
        return false;
    }
    if (event.keyCode > 47 && event.keyCode < 59) {
        if (indianNumberFormat) {
            event.keyCode += 1584;
        }
        return false;
    }
    else if (event.keyCode > 95 && event.keyCode < 123) {
        seek = 96;
    }
    else if (event.keyCode > 64 && event.keyCode < 91)
        seek = 64;
    if (event.keyCode == 98 || event.keyCode == 66 || event.keyCode == 71 || event.keyCode == 84)
        addL = true;
    if (seek > 0) {
        if (event.shiftKey)
            event.keyCode = shftLatinKeys[event.keyCode - seek];
        else {
            event.keyCode = latinKeys[event.keyCode - seek];

        }
        if (addL)
            event.srcElement.value += String.fromCharCode(1604);
    }
    else {
        for (var i = 0; i < specialKeys[0].length; i++) {
            if (specialKeys[0][i] == event.keyCode) {
                event.keyCode = specialKeys[1][i];
                break;
            }
        }
    }
	}catch(e){}
	return "";
}

