﻿             function HideBlank()
				{
				
				var all = document.forms[0].all;
				//alert(all.length);
				for (var i = 0; i < all.length; ++i)
					{
					
					var nm=all[i].nodeName.toLowerCase();
					if (nm=='div' || nm=='script') 
					{
					   all[i].style.display='none';
					    all[i].style.height=0;
					 
                      //  return;
					} 
					}      
			    }
             
                                
             var _SetFocus=false;
             var _oldItem;
			 function createStyle()
				{
				var all = document.forms[0].all;
				for (var i = 0; i < all.length; ++i)
					{
					var nm=all[i].nodeName.toLowerCase();
					//alert(all[i].nodeName);
					if (nm=='input' || nm=='select' || nm=='textarea')
					{
//					        if(!_SetFocus)
//					            {
//				                    try{
//				                    //alert(all[i].tapindex);
//				                  //  if(all[i].tapindex>-1)
//				                    {
//				                     all[i].focus();
//				                    _SetFocus=true;
//				                    }
//				                    }catch(ex){}
//					            }
					       var oldColor=all[i].style.backgroundColor;
						   all[i].onfocus=function(){this.style.backgroundColor='#cee8fc';
					

						   }
						   all[i].ondeactivate = function() { this.style.backgroundColor = ''; } 
						   if (nm!='textarea')
						   {
						       all[i]. onkeydown=function(){if (event.keyCode==13) {event.keyCode=9; return event.keyCode ;}}
						   }
						   
						   
					}
					else if(nm=='img')
					{
					   
					     if(all[i].src.charAt(all[i].src.length-1)=='/')
					        all[i].style.display='none';
					
					}
				    }                
			    }
	function CloseBtn(k)
    {
    
    if(k==null)
        location.href='../Root/Default.aspx';
        else
        history.back();
    
    }
			
	 function isNumber(evt)
      {
      
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
        function isDouble(obj,evt){
	         var charCode = (evt.which) ? evt.which : event.keyCode
	         
	        
	     if(charCode== 46 & obj.value.indexOf(".") < 0)
	         return true;
        if ((charCode > 31 && (charCode < 48 || charCode > 57)) )
            return false;

         return true;
         }

			
            function PopUp(URLTarget,width,height)
            {
                window.open(URLTarget,'win',"status=yes,toolbar=no,menubar=no,location=no,directories=no,width="+width+",height="+height+" ,resizable=yes,left=0,top=0,scrollbars=yes");
            }
            
			function Back_WithQuery(id,pagename)
			{
				location.href = pagename + id;
			}
			
			function ChangeTxtDisabled()
			{			
				document.getElementById("DDLST_TenantBlackListReason").disabled=document.getElementById("ChBx_TenantBlackListN").checked
				//if(document.getElementById("DDLST_TenantBlackListReason").disabled==true)
				//	{
				//	document.getElementById("DDLST_TenantBlackListReason").value=""
				//	}
			}
			function ChangeToPostChecked(RadioID)
			{
			document.getElementById(RadioID).checked = true;
			}
			function setMirrorandRotation(divId,mirrorCase,rotatorCase,act)
			{
				var noM;
				var noR;
				if (act=="M")
				{
					noM = parseInt(document.getElementById(mirrorCase).value) +  1;
					document.getElementById(mirrorCase).value = noM ;
					if (document.getElementById(mirrorCase).value > 1)
					{
					document.getElementById(mirrorCase).value = 0;
					}
				}
				else if (act=="R")
				{
					noR = parseInt(document.getElementById(rotatorCase).value) + 1;
					document.getElementById(rotatorCase).value = noR;
					if (document.getElementById(rotatorCase).value > 3)
					{
					document.getElementById(rotatorCase).value = 0;
					}
				}
					divId.style.filter='progid:DXImageTransform.Microsoft.BasicImage(mirror=' + document.getElementById(mirrorCase).value + ',rotation=' + document.getElementById(rotatorCase).value + ')';
			}

			function IncrImage(imageID,ParentFrameID)
			{
				document.images[imageID].width +=25;
				document.images[imageID].height +=25;
				AdjustFrameHeight(ParentFrameID)
			}
			
			function DecrImage(imageID,ParentFrameID)
			{
				document.images[imageID].width -=25;
				document.images[imageID].height -=25;
				AdjustFrameHeight(ParentFrameID)
			}
			
			function CallPrint(strid,mirrorCase,rotatorCase)
			{
			 var prtContent = document.getElementById(strid);
			 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
		     WinPrint.document.write("<DIV id='divPrint' style='height:50; width:50'>" + prtContent.innerHTML + "</div><script>divPrint.style.filter='progid:DXImageTransform.Microsoft.BasicImage(mirror=" + document.getElementById(mirrorCase).value + ",rotation=" + document.getElementById(rotatorCase).value + ")'</script>");
			 WinPrint.document.close();
			 WinPrint.focus();
			 WinPrint.print();
			 WinPrint.close();
			}
			
			function resetDataGridColors(firstColor,secondColor,HoverColor,Grid) 
			{
				for (t=1; t<document.getElementById(Grid).rows.length;t++)
				{
					document.getElementById(Grid).rows(t).onmouseover= function() {this.style.backgroundColor=HoverColor}
					if(t % 2 == 0)
					{ 
						document.getElementById(Grid).rows(t).style.backgroundColor=secondColor;
						document.getElementById(Grid).rows(t).onmouseout= function() {this.style.backgroundColor=secondColor;this.style.cursor='hand';}
					}
					else
					{
						document.getElementById(Grid).rows(t).style.backgroundColor=firstColor;
						document.getElementById(Grid).rows(t).onmouseout= function() {this.style.backgroundColor=firstColor;this.style.cursor='hand';}
					}
				}
			}
		

			function TurnOffValSave(btnChLang)
			{
			try
			{
			   for(i=0; i<Page_Validators.length; i++)
				{
					ValidatorEnable(Page_Validators[i], false);
				}
				}
				catch(err){}
				document.getElementById(btnChLang).click();
			}
			
			function addrec(no)
			{
				if (document.getElementById("HiddenText").value.indexOf("-" + no + "-") >-1)
				{
					document.getElementById("A_SelectAll").checked = false;
					document.getElementById("HiddenText").value = document.getElementById("HiddenText").value.replace("-" + no + "-","") ;
				}
				else
				{
					document.getElementById("HiddenText").value += "-" + no + "-" ;			
				}
			}
			
			function confirmation()
			{
					return  confirm("هل تريدDelete  كل البيانات المختاره");
			}
			var onRowSelect=false;
			var TrueCount=0;
			var FalseCount=0;
			function CheckRow(chk)
			{
			if(chk)
			{
			TrueCount++;
			this.parentNode.parentNode.backgroundcolor='#0000000';
			}
			else
			TrueCount--;
			if(TrueCount<0)TrueCount=0;
		
			onRowSelect=(TrueCount>0);
			}
			function CheckRow(element,chk)
			{
			if(chk)
			{
			TrueCount++;
			//alert(element.parentNode.backgroundcolor);
			element.parentNode.parentNode.style.backgroundColor='#82E0FF';
			}
			else
			{
			TrueCount--;
			element.parentNode.parentNode.style.backgroundColor='';
			}
			if(TrueCount<0)TrueCount=0;
		
			onRowSelect=(TrueCount>0);
			}
			function CheckAll(chk)
			{
                var all = document.forms[0].elements;
			    for (var i = 0; i < all.length; ++i)
					    {
						    if (all[i].id.indexOf('chkSelectRow')>-1||all[i].id.indexOf('chbSelectAll')>-1)
						    {
							    all[i].checked = chk;
						    }
					    }
					 if(chk)
			         document.getElementById('chkAll').innerText="إلغاء";
			            else
			         document.getElementById('chkAll').innerText="الكل";   
			}
			var allSelected=false;
			function ChangeAllChecks() 
			{
			    allSelected=!allSelected;
			    CheckAll(allSelected);
			}
			 
			function changeCheck(chk) 
			{
				var all = document.forms[0].elements;
				//var aValue;
				//document.getElementById("ids").value = "";
				if(chk)
				{
				 	try
					{
				$get('ctl00_cp_btn_Delete').disabled=false;
				$get('ctl00_cp_btn_Delete2').disabled=false;
				}catch(ex){}
					try
					{
				$get('btn_Delete').disabled=false;
				$get('btn_Delete2').disabled=false;
				}catch(ex){}		
				 return;
				} 
	              	try
					{
				$get('ctl00_cp_btn_Delete').disabled=true;
				$get('ctl00_cp_btn_Delete2').disabled=true;
				}catch(ex){}
					try
					{
				$get('btn_Delete').disabled=true;
				$get('btn_Delete2').disabled=true;
				}catch(ex){}
					for (var i = 0; i < all.length; ++i)
					{
						if (all[i].id.indexOf('chkSelectRow')>-1)
						{
						    if(all[i].checked)
						    {
				 		try
					{
				$get('ctl00_cp_btn_Delete').disabled=false;
				$get('ctl00_cp_btn_Delete2').disabled=false;
				}catch(ex){}
					try
					{
				$get('btn_Delete').disabled=false;
				$get('btn_Delete2').disabled=false;
				}catch(ex){}
						    }
						}
					}	
				return false;
			} 
					
			function AdjustFrameHeight(frameId)
			     {
			         //			     try{
			         var browserName = navigator.appName;
			         if (browserName == "Microsoft Internet Explorer")
			         parent.document.getElementById(frameId).height = document.body.scrollHeight + 30;
				 //  parent.document.getElementById(frameId).height=document.body.scrollHeight+10;
//				 }
//				 catch(ex){}
		       	 }
		       	 
			function getime()
			{
				if (document.getElementById("lastOperation2") != null)
				{
					document.getElementById("lastOperation2").style.visibility = "hidden";
				}
				if (document.getElementById("lastOperation1") != null)
				{
					document.getElementById("lastOperation1").style.visibility = "hidden";
				}
				if (document.getElementById("lastOperation") != null)
				{
					document.getElementById("lastOperation").style.visibility = "hidden";
				}
			}
					
//			function startp()
//			{	
//				Myinterval = window.setInterval("getime()",10000);
//			}
			function ClearMsgs()
			{	
				Myinterval = window.setInterval("document.getElementById('ctl00_cp_MsgsSummary').innerText= '';",10000);
			}
		
function ShowThis2(ID)
{
	M=ID.id;
	M=M.substr(1);
	L="S"+M;
	if(ID.id.substr(0,1)=="w")
	{
		document.images[ID.id].style.display="none";
		document.getElementById(L).style.display="";	
		U="u"+M;
		document.images[U].style.display="";
	}
	if(ID.id.substr(0,1)=="u")
	{
		document.images[ID.id].style.display="none";
		document.getElementById(L).style.display="none";
		document.images[D].style.display="";
	}
}

function NullTo(txt,DefaultValue)
{
    //txt=the name of textbox
    //DefaultValue=the value to replace the null
	if(document.getElementById(txt).value==""){
	document.getElementById(txt).value=DefaultValue;
	document.getElementById(txt).select();
	}
} 
function IsNull(txt,DefaultValue)
{
    //txt=the name of textbox
    //DefaultValue=the value to replace the null
	if(txt.value==""){
	txt.value=DefaultValue;
	//document.getElementById(txt).select();
	}
} 

function hideSubPageOnError(frameId,ErrPage)
{
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if (sPage==ErrPage)
	{
	parent.document.all(frameId).height=0;
	}
}

function CreatPass()
{
           var pass="";
           for (var i=1;i<=8;i++)
            {
                var rand=Math.floor(Math.random()*2);

                if (rand==1)
                {
                var a=Math.floor(Math.random()*10+48);
                pass=pass+String.fromCharCode(a);
                }
                else
                {
                var b=Math.floor(Math.random()*26+65);
                 pass=pass+String.fromCharCode(b);
                }
               
            }
            return pass;
}

function framOpen(url)
     {
      document.getElementById('fram').src=url;
     
     }
     
     function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

     //===========================Project Functions=====================\\
     function openLetters(ContractCaseID)
     {
        var width = 300;
        var height = 300;
        var left = parseInt((screen.availWidth/2) - (width/2));
        var top = parseInt((screen.availHeight/2) - (height/2));
        var windowFeatures = "width=" + width + ",height=" + height + ",status=yes,toolbar=no,menubar=no,location=no,directories=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
        var win= window.open('../Transactions/SelectLetter.aspx?ContractCaseID='+ContractCaseID,'SelectLetter',windowFeatures)
     }
     //==================================================================\\

     function ShowStamp(TableName, ID_Key) {
         var url = '../Security/ShowStamps.aspx?TableName=' + TableName + '&ID_Key=' + ID_Key;
         var width = 700;
         var height = 350;
         var left = parseInt((screen.availWidth / 2) - (width / 2));
         var top = parseInt((screen.availHeight / 2) - (height / 2));

         var windowFeatures = "status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
         myWindow = window.open(url, "subWind", windowFeatures);
     }
     
//=================================================================================//
function checkedAll (chk) 
{
	var all= document.forms[0].all;
	for (var i =0; i < all.length; i++) 
	{
	if(all[i].id!='ctl00_cp_chkAll')
	{
	try{
	 all[i].checked = chk;}catch(ex){}
	 }
	}
}
