﻿var AfterDeletBaseID = null;
var AppName = "TMIS"
function DeleteItem(FileName, MasterCode, DelList)
{
	AskResult = confirm("حذف شود؟")

	if(AskResult){
		window.onbeforeunload = '';
		window.location.href=FileName + '?DelList=' + DelList + '&Code=' + MasterCode
	}
}

function Gotolist(Code)
{
  window.frames["fraMainBody"].location = 'Forms/Contracts/EditContracts.aspx?BaseID=Contracts&Code=' + Code;
}

var http_request = null;
var DelObj = null;
function startRequest(url, Func, Method, Param, UpdateObj) { 
    DelObj = UpdateObj;
    if (window.XMLHttpRequest) { 
       http_request = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) { 
       http_request = new ActiveXObject('Microsoft.XMLHTTP'); 
    } 
    url = url + '&rnd=' + Math.random();
//    alert(url)
    http_request.onreadystatechange = Func; 
    http_request.open(Method, url, true); 
    if( Method == 'GET')
       http_request.send(null); 
    else
       http_request.send(Param); 
} 
function DelComplete()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(result == "Success")
	                DelObj.style.display = 'none';
	            else
	                alert(result);
	            document.body.style.cursor='auto';
            }
       }
   }
}
 
 
       function CheckNumericValue(Obj) {
            if (Obj.value == "0" || Obj.value == "00" || Obj.value == "000" || Obj.value == "0000" || Obj.value == "00000" || Obj.value == "000000" || Obj.value == "0000000" || Obj.value == "00000000" ) {
                alert("مقدار وارد شده صحیح نمی باشد");
                Obj.value = '';
            }                
        }
        
        function CheckNumeric(obj)
        {
        
          var myregexp = /^[0]+$/;
	       if (obj.value.search(myregexp) == 0) {
	       alert('مقدار وارد شده صحیح نمی باشد ');
	       return false;
	       }
	       else if(obj.value.search(myregexp) == -1)
	       {	       
	       myregexp = /^\d+$/i;
		    if (obj.value.search(myregexp)== 0) {		    
    		alert('مقدار وارد شده صحیح نمی باشد ');
    		return false;
		    }
		    else if(obj.value.search(myregexp)== -1)
		    return true;    	        
	       }
        }
 
function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function PrintJournal()
{
	window.print()
}
function DeleteFromEditForm(BaseID, DelCode)
{
    AskDel = confirm("آیا از حذف این رکورد مطمئن هستید ؟")
    if(AskDel)
    {
        DelUrl = '/jsGetBrowse.aspx?BaseID=' + BaseID + "&DelCode=" + DelCode 
        AfterDeletBaseID = BaseID
        startRequest(DelUrl, ShowDeleteComplete, 'GET', null, null);
    }

}
function ShowDeleteComplete()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(result=="DELETED")
	            {
	                alert('رکورد با موفقیت حذف شد')
	                if(AfterDeletBaseID != null)
	                    window.location.href = '/Main/Default.aspx?BaseID='+ AfterDeletBaseID
	                else
	                    window.location.href = '/Portal';
	            }
	            else if(result.indexOf("FK_")>0)
	                alert('این رکورد دارای اطلاعات مرتبط میباشد و قابل حذف نیست');
	                else if(result.indexOf("مفاصا")>0)
	                alert('بعد از صدور مفاصاحساب مالیاتی امکان حذف قرارداد وجود ندارد');
	                
	            document.body.style.cursor='auto';
            }
       }
   }
}

function IsOnlyNumber()
{

var returnValue = false;
var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;

    
if ( ((keyCode >= 48) && (keyCode <= 57)) ||
(keyCode == 8) || 
(keyCode == 9) || 
(keyCode == 46) || 
(keyCode == 13) ) 
returnValue = true;
if(!ExceptSomeCharachter())
   returnValue = false;

if ( window.event.returnValue )
window.event.returnValue = returnValue;
return returnValue;
}
function IsOnlyNumberAndSlash()
{
var returnValue = false;
var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;
if ( ((keyCode >= 47) && (keyCode <= 57)) ||
(keyCode == 8) || 
(keyCode == 9) || 
(keyCode == 13) ) 
returnValue = true;

if ( window.event.returnValue )
window.event.returnValue = returnValue;

return returnValue;
}


function ConfirmUnload()
{
    event.returnValue = "تغییرات نادیده گرفته شود؟";
}
function GetInfo(InputObj, BaseID)
{
	Code = InputObj.value
	document.body.style.cursor='wait';
	
	// Create an instance of the XML HTTP Request object
	var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
		
	// Prepare the XMLHTTP object for a HTTP POST to our validation ASP page
	var sURL = "../Seminars/GetInfo.asp?Code=" + Code + '&BaseID=' + BaseID
	oXMLHTTP.open( "POST", sURL, false );
	
	// Execute the request
	oXMLHTTP.send();
	
	rsl = oXMLHTTP.responseText
	InputObj.parentNode.parentNode.cells(2).childNodes(0).value = rsl
	if(rsl == 'رکورد مورد نظر یافت نشد')
		InputObj.parentNode.parentNode.cells(1).childNodes(0).value = ''
	document.body.style.cursor='auto';
	
}
function ImgOver(ImgObj)
{
	ImgObj.style.borderWidth = 1
	ImgObj.style.borderColor = 'black'
}
function ImgOut(ImgObj)
{
	ImgObj.style.borderWidth = 0
}

function DoPrint()
{
	window.print()
}
function AskDelete(Code)
{
	AskResult = confirm("رکورد حذف شود؟")
	if(AskResult){
		form1.DelValue.value = Code;
		form1.action = "index.asp"
		form1.submit()
	}
}

function AskDeleteDetail(FromAction, MasterCode, Code)
{
	AskResult = confirm("رکورد حذف شود؟")
	if(AskResult){
		window.onbeforeunload = '';
		form1.DelList.value = Code;
		form1.Code.value = MasterCode ;
		form1.action = FromAction
		form1.submit()
	}
}

function GotoLink(FormAction)
{
	if( FormAction != "undefined")
		form1.action = FormAction
	form1.submit();
}

function GotoUrl(Url)
{
    window.location.href = Url
}

function PickDate(DateFieldName, InitVal, Section)
{
	InitVal = InitVal.replace("/", "");
	InitVal = InitVal.replace("/", "");
	
	X =  window.event.clientX
	Y =  window.event.clientY + 100
	if ( InitVal.length != 8)
		InitVal = '';
	whn = 	window.open('../DatePicker.asp?FFN=' + DateFieldName + '&InitDate=' + InitVal + '&Section=' + Section,'DatePicker','width=200,height=185,menubar=no,status=no,titlebar=no,resizable=no,top=' + Y + ',left=' + X );
}

function UploadPic(FileName)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=580,height=150,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowTree(FileName, BaseID, FFN, InitCode)
{
		whList = window.open(FileName + '?BaseID=' + BaseID + '&FFN=' + FFN + '&InitGroup=' + InitCode,'PersonTree','width=580,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowFile(FileName, FieldName, Code)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=620,height=450,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowFile3(FileName, FieldName, Code)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=620,height=450,menubar=yes,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowFile2(PathName)
{
	whList = window.open(PathName,'','width=620,height=450,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowSizedFile(FileName, FieldName, Code,w, h)
{
	whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width='+ w + ',height=' + h + ',menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}
function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;

	
	if (!isChild(CSE,getObj('AccessPanel')))
	{
	    try
	    {
		    if(!isChild(CSE,getObj('AccessPanel')))
			    getObj('AccessPanel').style.display='none';
		}
		catch(e)
		{
		    //alert(e.description);
		}
	}
}
function ShowNews(NewsCode)
{
    window.open("Forms/News/ShowNews.aspx?Code=" + NewsCode, 'News','width=700,height=600,top=10')
}
function OpenList(BaseID, ImgObj, AbsPath)
{
    var LookupObj = new XMLBrowse()

    if (AbsPath != undefined)
        LookupObj.AbsPath = AbsPath;
        
	if( getObj('LookupResults'))
	{
        getObj('LookupResults').style.display='none';
	}
    ShowMode = 'List';
    FormFieldCode = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[1].childNodes[0];
    if(ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes.length > 1)
        FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[1];
    else    
        FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0];
    LookupObj.ViewEdit = 'Edit'
    LookupObj.CreateBrowse(BaseID, ShowMode);
    //BrowseObj = new XMLBrowse(BaseID, ShowMode);

//	whList = window.open('../List.aspx?BaseID=' + BaseID + '&FFC=' + FormFieldCode + '&FFN=' + FormFieldName ,'','scrollbars=yes, width=650,height=450,menubar=no,status=no,titlebar=no,resizable=yes,top=200,left=150');
}

function OpenListMaster(BaseID, ImgObj, MasterCode)
{
    if(MasterCode == '')
    {
        alert('error (empty mastercode)')
        return false;
    }
        FormFieldCode = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[1].childNodes[0].name;
        FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[1].name;

		whList = window.open('../List.aspx?MasterCode=' + MasterCode + '&BaseID=' + BaseID + '&FFC=' + FormFieldCode + '&FFN=' + FormFieldName ,'','scrollbars=yes, width=650,height=450,menubar=no,status=no,titlebar=no,resizable=yes,top=200,left=150');
}

function OpenTree(BaseID, ImgObj)
{
       // FormFieldCode = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[1].childNodes[0].name;
       // FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[1].name;

		whList = window.open('/GetTree.aspx?GetVal=1&BaseID=' + BaseID  ,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function OpenTree2(BaseID, Width, Height,GroupCode)
{
		whList = window.open('/GetTree.aspx?MultiSelect=1&BaseID=' + BaseID + '&GroupCode=' + GroupCode ,'','width=' + Width + ',height=' + Height + ',menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function List2(BaseID, FormFieldName,Section, FN, FV)
{
		whList = window.open('../Admin/List.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section + '&FN=' + FN + '&FV=' + FV,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ListMulti(BaseID, FormFieldName,Section)
{
		whList = window.open('../Admin/ListMulti.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section ,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}


function ShowList(FileName, BaseID, FilterCols, FilterVals)
{
	if(FilterCols == undefined)
		FilterCols = ""
	if(FilterVals == undefined)
		FilterVals = ""
		whList = window.open(FileName + '?BaseID=' + BaseID + '&FN=' + FilterCols + '&FV=' + FilterVals,'','width=500,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function GetLeftCenter(WinHeight, WinHeight)
{

	if (screen.width == 1024)
	{
		RTop = (768 - WinHeight) / 2
		Result = "top=" + RTop + ",left=213"
	}
	else
	{
		RTop = (600 - WinHeight) / 2
		Result = "top=" + RTop + ",left=20"
	}
		return Result
}



function ShowBrowse(BaseID, MasterID, Section)
{
	if(MasterID == '')
		alert('ابتدا ذخیره کنید')
	else
			//window.location.href = '../Browse.aspx?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section;
			whList = window.open('../BrowsePopup.aspx?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section,'','width=790,height=420,menubar=no,status=no,titlebar=no,scrollbars,resizable=no,top=200,left=150');
}

function ShowGeneralList(BaseID, MasterID, Section)
{
	if(MasterID == '')
		alert('ابتدا ذخیره کنید')
	else
			whList = window.open('../GeneralList.asp?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section,'','width=700,height=370,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}


function ShowPics(BaseID, MasterID, MediaType)
{
		whList = window.open('Album.asp?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&MediaType=' + MediaType,'','width=600,height=510,menubar=no,status=no,titlebar=no,resizable=no,top=100,left=150');
}

function DoMask(MaskFormat, str,textbox,loc,delim)
{
//	try{
	
	DoNothing = 0

	CurrentPos = textbox.value.length;
	var locs = loc.split(',');	

	KeyCode = event.keyCode
	if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey) {
		if ((KeyCode > 47 && KeyCode < 58) || (KeyCode > 95 && KeyCode < 106)) {
			MaxL = MaskFormat.length + locs.length 
			if (textbox.value.length >= MaxL) {
					event.returnValue = false
					return false;
			}
			if (KeyCode > 95) KeyCode -= (95-47);
		} else if (KeyCode != 8 && KeyCode != 46 ) {
			event.returnValue = false
			return false;
		}
	}

	CurrentChar = String.fromCharCode(KeyCode)

	for (var i = 0; i <= locs.length; i++){
		for (var k = 0; k <= str.length; k++){
		 if (k == locs[i]){
		  if (str.substring(k, k+1) != delim){
		    str = str.substring(0,k) + delim + str.substring(k,str.length)
			textbox.value = str
		  }
		 }
		}
	 }

	if(CurrentPos < MaskFormat.length + locs.length)
	{
		if(MaskFormat.charAt(CurrentPos) == 'N')
		{
			if( !isNaN(CurrentChar))
			{
				DoNothing = 0
			}
			else
			{
				DoNothing = 1
			}
		}
		else if(MaskFormat.charAt(CurrentPos) == '/')
		{
			if( CurrentChar == '/')
			{
				DoNothing = 0
			}
			else
			{
				DoNothing = 1
			}
		}
		else if(MaskFormat.charAt(CurrentPos) == 'L')
		{
			if( !isNaN(CurrentChar))
			{
				DoNothing = 1
			}
			else
			{
				DoNothing = 0
			}
		}

	}	
	else
		DoNothing = 1
	

	if(DoNothing == 1)
		event.keyCode = 0
	return true;
//	}
//	catch(e)
//	{
//	}
}


function OpenDate(DivObj)
{

    //InitVal = TDObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0].name;
    InitVal = DivObj.parentNode.parentNode.childNodes[1].childNodes[0].value;
    FFN = DivObj.parentNode.parentNode.childNodes[1].childNodes[0].name;
	InitVal = InitVal.replace("/", "");
	InitVal = InitVal.replace("/", "");
	X =  window.event.clientX 
	Y =  window.event.clientY
	if ( InitVal.length != 8)
		InitVal = '';


    DatePan.style.left = X - 32 + document.body.scrollLeft;
    DatePan.style.top = Y + 2 + document.body.scrollTop + document.documentElement.scrollTop;
//    alert(document.body.offsetHeight)
    DatePan.style.display = "block"
    Init(1)
//    window.resizeTo(X + DatePan.offsetWidth,Y + DatePan.offsetHeight+70)
//    document.body.scrollIntoView(true)
//    
//    alert(document.body.offsetHeight)
}


var http_request = null;
var DelObj = null;
function startRequest(url, Func, Method, Param, UpdateObj) { 
    DelObj = UpdateObj;
    if (window.XMLHttpRequest) { 
       http_request = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) { 
       http_request = new ActiveXObject('Microsoft.XMLHTTP'); 
    } 
    url = url + '&rnd=' + Math.random();
//    alert(url)
    http_request.onreadystatechange = Func;
    http_request.open(Method, url, true); 
    if( Method == 'GET')
       http_request.send(null); 
    else
       http_request.send(Param); 
} 

function DelComplete()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(result == "Success")
	                DelObj.style.display = 'none';
	            else
	                alert(result);
	            document.body.style.cursor='auto';
            }
       }
   }
}


function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=0');
 WinPrint.document.write("<link href=\"/styles/main.css\" rel=\"stylesheet\" type=\"text/css\">" +  prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();

//alert(WinPrint.document.getElementById("ctl00_cphMain_tblList").offsetHeight)
WinPrint.resizeTo(document.getElementById("ctl00_cphMain_tblList").offsetWidth + 30,document.getElementById("ctl00_cphMain_tblList").offsetHeight + 180 );
 WinPrint.print();
 WinPrint.close();
}


function OpenWin(Link, Width, Height)
{
//	X =  window.event.clientX
//	Y =  window.event.clientY + 100
//alert(screen.width)
leftVal = (screen.width - Width) / 2;
topVal = (screen.height - Height) / 2;

	window.open(Link,'','width=' + Width + ',height=' + Height + ',menubar=no,status=no,titlebar=no,scrollbars=yes,resizable=yes,top=' + topVal + ',left=' + leftVal );
}
function ResizeWin()
{
    MainEditObj = document.getElementById('dvMainEdit');
    var w=MainEditObj.offsetWidth;
    var h=MainEditObj.offsetHeight;
    alert(h)
    if ((w!=null) && (h!=null))
    {
    window.resizeTo(w,h);
//    var winX = (screen.width - w) / 2;
//    var winY = (screen.height - h) / 2;
//    window.moveTo(winX,winY);
    }

}


function OnClicking(sender, eventArgs)
{  
    var item = eventArgs.get_item();
    var itemValue = item.get_value();
    var GroupCode = document.getElementById('ctl00_hfGroupCode');

	if (itemValue != "") 
	{
	    switch(itemValue)
	    {
	    
	        case "MoshaverAmlakPaymentList":
                 window.frames["fraMainBody"].location = 'Report/MoshaverAmlakPaymentList.aspx';           
                break;
	        case "MoshaverAmlakPaymentCount":
                 window.frames["fraMainBody"].location = 'Report/MoshaverAmlakPaymentCount.aspx';           
                break;
            case "ContractHelp":
                window.open('Help/ContractHelp.pdf', '_blank', 'height=600,width=750,status=yes,resizable=yes');               
                break;
            case "RegContractOperator":
                    window.frames["fraMainBody"].location= 'Forms/Contracts/EditContractByOperator.aspx';;
                    break;
	        case "SearchAllContracts":
	            window.frames["fraMainBody"].location= 'Forms/Contracts/SearchAllContracts.aspx';;
	            break;
	          
	        case "UserGuide":
	            window.frames["fraMainBody"].location= 'Files/help.pdf';
	            break;
	            
	        case "Introduction":
	            window.frames["fraMainBody"].location= 'Help/Introduction.htm';
	            break;
	            
	        case "Logout":
	            window.location.href = 'Logout.aspx';
	            break;
	    
	        case "Resources":
                window.frames["fraMainBody"].location = 'Forms/AccessLevel/ResourceTree.aspx';
	            break;
	            
	            
	    
	        case "MobaiehNameh":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditMobaiehNameh.aspx?ContractType=1';
	            break;
	            
	        case "EjarehName":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditEjarehVTamlik.aspx?ContractType=2';
	            break;
	    
	        case "EjarehTamlik":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditEjarehVTamlik.aspx?ContractType=3';
	            break;
	    
	        case "Sarghofli":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditOtherContracts.aspx?ContractType=4';
	            break;
	    
	        case "PishForoosh":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditOtherContracts.aspx?ContractType=5';
	            break;

	        case "Vaghf":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditOtherContracts.aspx?ContractType=7';
	            break;

	        case "NewRegUser":
                window.frames["fraMainBody"].location = 'Forms/OnlineReg/EditMemberOnlineReg.aspx';
	            break;
	            
            case "NewRegMobasher":
                window.frames["fraMainBody"].location = 'Forms/OnlineReg/EditMobasherOnlineReg.aspx';
	            break;
	            
	        case "NewRegMoreMoshaver":
                window.frames["fraMainBody"].location = 'Forms/OnlineReg/EditMoreRealEstateOnlineReg.aspx';
	            break;
	                
	        case "SelectNewMobasher":
                window.frames["fraMainBody"].location = 'Forms/Mobasherin/frmPersonSerach.aspx';
	            break;
	            
	        case "NewMoshaverAmlaak":
                window.frames["fraMainBody"].location = 'Forms/OnlineReg/EditRealEstateOnlineReg.aspx';
	            break;
            case "AboutUs":
                window.frames["fraMainBody"].location = 'AboutUs.aspx';
	            break;

            case "UnderConstruction":
                window.frames["fraMainBody"].location = 'UnderConstruction.html';
                break;
            
            case "SendMessage":
                window.frames["fraMainBody"].location = 'Forms/Message/SendMessage.aspx';
                break;

            case "ChangePass":
                window.frames["fraMainBody"].location = 'Forms/Users/ChangePass.aspx';
                break;
            case "ChangeUserPass":
                window.frames["fraMainBody"].location = 'Forms/Users/ChangeUserPass.aspx';
                break;
                
             case "SearchContract":
                window.frames["fraMainBody"].location = 'Forms/Contracts/SearchContract.aspx';
                break;
                
             case "MyInfo":
                window.frames["fraMainBody"].location = 'Forms/Users/MyInfo.aspx';
                break;

             case "Moshaverin_perState_state":
	            window.frames["fraMainBody"].location = 'Report/MoshaverinPerState_state.aspx';
	            break; 
	            
	             case "ModiranEjrayee":
	            window.frames["fraMainBody"].location = 'Report/ModiranEjrayeeRep.aspx';
	            break;
	            
	            
	            case "MoshaverinPerCityStat":
	            window.frames["fraMainBody"].location = 'Report/MoshaverinPerCityStat.aspx';
	            break;
	            
	        case "ContractCancel":
                window.frames["fraMainBody"].location = 'Forms/Contracts/SearchContractCancel.aspx';
                break;
                
            case "MoshaverinPerStateChart":
                window.frames["fraMainBody"].location = 'Report/MoshaverinPerStateChart.aspx';
                break;
	         
	           case "UserDesktop":
                window.frames["fraMainBody"].location = 'Forms/UsersDesktop/UserDesktop.aspx';
                 break;
                
                 case "Zone":
                window.frames["fraMainBody"].location = 'Forms/Zones/Zone.aspx';
               break;
               
             case "ContractsPerState":
               window.frames["fraMainBody"].location = 'Report/ContractsPerState.aspx';
                break;
                
                case "MoshaverinAmarPerState":
               window.frames["fraMainBody"].location = 'Report/MoshaverinAmarPerState.aspx';
                break;
	         
	          case "RepresentCompanyList":
               window.frames["fraMainBody"].location = 'Forms/RepresentCompany/RepresentCompanyList.aspx';
                break;

                case "ContractsPerProv":
                 window.frames["fraMainBody"].location = 'Report/ContractsPerProv.aspx';
                break;
                
             case "ContractsPerCity":
	            window.frames["fraMainBody"].location = 'Report/ContractsPerCity.aspx';
                break;
                
                
                case "ContractsPerCountry":
                window.frames["fraMainBody"].location = 'Report/ContractsPerCountry.aspx';
                break;
              
                case "MobayenPriceByCountry":
                 window.frames["fraMainBody"].location = 'Report/MobayenPriceByCountry.aspx';
                break;
                
                 case "MobayenPriceByCity":
                window.frames["fraMainBody"].location = 'Report/MobayenPriceByCity.aspx';
                break; 
                 
                      case "MobayenPriceByManategh":
               window.frames["fraMainBody"].location = 'Report/MobayenPriceByManategh.aspx';
                break;
                
          
                 case "RentPriceByManategh":
               window.frames["fraMainBody"].location = 'Report/RentPriceByManategh.aspx';
                break;
                
                 case "RepresentCompanies":
	            window.frames["fraMainBody"].location = 'Forms/RepresentCompany/RepresentCompanies.aspx';
                break;
                
                  case "RentInCountry":
                window.frames["fraMainBody"].location = 'Report/RentInCountry.aspx';
            break;

            case "MobayenInCountry":
                window.frames["fraMainBody"].location = 'Report/MobayenInCountry.aspx';
            break;

            case "RentInProvince":
                window.frames["fraMainBody"].location = 'Report/RentInProvince.aspx';
            break;

            case "MobayenInProvince":
                window.frames["fraMainBody"].location = 'Report/MobayenInProvince.aspx';
            break;

            case "RentInPart":
                window.frames["fraMainBody"].location = 'Report/RentInPart.aspx';
            break;

            case "MobayenInPart":
                window.frames["fraMainBody"].location = 'Report/MobayenInPart.aspx';
            break;

            case "DownloadFonts":
	            window.frames["fraMainBody"].location = 'Forms/Help/DownloadFonts.aspx';
                break;

            case "DownloadCertificate":
	            window.frames["fraMainBody"].location = 'Forms/Help/DownloadCertificate.aspx';
                break;
            case "AdvancedSearch":
	            window.frames["fraMainBody"].location = 'Report/AdvancedSearch.aspx';
                break;
            case "MoshaverRegedContracts":
	            window.frames["fraMainBody"].location = 'Report/MoshaverRegedContracts.aspx';
                break;
            case "ContractSidesReport":
	            window.frames["fraMainBody"].location = 'Report/ContractSides.aspx';
                break;
            case "RepresentCompany":
                window.frames["fraMainBody"].location = 'Main/Default.aspx?BaseID=Organizations';
                break;
            case "ConfirmImage":
                window.frames["fraMainBody"].location = 'Forms/Persons/frmConfirmImage.aspx';
                break;
            case "FilterContracts":
                window.frames["fraMainBody"].location = 'Forms/Contracts/FilterContracts.aspx';
                break;
                 case "OtherGroupsReport":
                window.frames["fraMainBody"].location = 'Report/OtherGroupsReport.aspx';
                break;
                case "OPeratorsReport":
                window.frames["fraMainBody"].location = 'Report/OperatorsGroupReport.aspx';
                break;
                
                case "NewSarbargAsign":
                window.frames["fraMainBody"].location = 'Forms/Sarbarg/SarbargAsign.aspx';
                break;
                 case "GetPostCode":
                window.frames["fraMainBody"].location = 'Forms/PostCode/GetAddress.aspx';
                break;
                case "ContractsWithMofasaHesabDone":
                window.frames["fraMainBody"].location = 'Report/ContractsWithMofasaHesabDone.aspx';
                break;
                
                case "PriceRateChanges":
                window.frames["fraMainBody"].location = 'Report/PriceRateChanges.aspx';
                break;
                
                case "ExpertsReport":
                window.frames["fraMainBody"].location = 'Report/ExpertReport.aspx';
                break;
                
                case "TaxOfficeFiles":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditTaxOfficeFiles.aspx';
                break;
                
                 case "ContractsWithMofasaHesabDoneByOStan":
                window.frames["fraMainBody"].location = 'Report/ContractsWithMofasaHesabDoneByOStan.aspx';
                break;

                 case "DigitalSignRep":
                window.frames["fraMainBody"].location = 'Report/DigitalSignRep.aspx';
                break;
                
                
                case "MoshaverinContractsCount":
                window.frames["fraMainBody"].location = 'Report/MoshaverinContractsCount.aspx';
                break;
                case "RegSerialNoReport":
                window.frames["fraMainBody"].location = 'Report/RegSerialNoReport.aspx';
                break;
                
                case "ContractsBetweenTwoDate":
                window.frames["fraMainBody"].location = 'Report/RegedContractsBetweenTwoDate.aspx';
                break;
                
                 case "ForgetPass":
                window.frames["fraMainBody"].location = 'ForgetPass.aspx';
                break;
                
                 case "DigitalSignRepPerCity":
                window.frames["fraMainBody"].location = 'Report/DigitalSignRepPerCity.aspx';
                break;
                
                 case "PersonsContractsCount":
                window.frames["fraMainBody"].location = 'Report/PersonsContractsCount.aspx';
                break;
                
                
                 case "ContractCountByDate":
                window.frames["fraMainBody"].location = 'Report/ContractCountByDate.aspx';
                break;
                 case "SamanehReport":
                window.frames["fraMainBody"].location = 'Report/SamanehReport.aspx';
                break;
                 case "JamBandiAmarReport":
                window.frames["fraMainBody"].location = 'Report/JamBandiAmarReport.aspx';
                break;
                 case "editContratbyCard":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditContractFromCard.aspx';
                break;
                
                 case "ContractWithCard":
                window.frames["fraMainBody"].location = 'Forms/Contracts/EditContractFromCard.aspx';
                break;
                
                case "SakhtemanPostCode":
                window.frames["fraMainBody"].location = 'Forms/PostCode/SakhtemanPostCode.aspx';
                break;

                case "SuccessfulTrnsWithoutSettle":
                window.frames["fraMainBody"].location = 'Forms/Contracts/SuccessfulTrnsWithoutSettle.aspx';
                break;
                
	        default :
	        {
	               
	         if ((itemValue != undefined) && (itemValue != null))
	                window.frames["fraMainBody"].location = 'Main/Default.aspx?BaseID='  + itemValue;
	        }
	    } 
	    return false;
	}
} 

function ShowHideTop()
{
    TopObj = document.getElementById('TopHeader')
    if(TopObj.style.display != 'none')
    {
        TopObj.style.display = 'none'
        document.getElementById('TDMainTD').className = ''
        document.getElementById('TDMain').className = 'cTblMainTD2'
    }
    else
    {
        TopObj.style.display = 'block'
        document.getElementById('TDMainTD').className = 'cTblMainTD'
        document.getElementById('TDMain').className = 'cTblMainEdit'
    }            
    
}

function CorrectText(str)
{
    return str.replace('ي', 'ی').replace('ي', 'ی').replace('ى', 'ی').replace('ك', 'ک')
            .replace('٠', '۰').replace('١', '۱').replace('٢', '۲').replace('٣', '۳').replace('٤', '۴')
            .replace('٥', '۵').replace('٦', '۶').replace('٧', '۷').replace('٨', '۸').replace('٩', '۹')
}
var lblUpdateObj = null;
function ShowLabel(FeildName, Code)
{
    lblUpdateObj = event.srcElement;
    startRequest('ShowLabel.aspx?FullFieldName=' + Fieldname + '&DetailCode=' + Code, PutLabelString, 'GET', null, lblUpdateObj);
}
function PutLabelString()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(lblUpdateObj != null)
	                lblUpdateObj.innerHTML = result;
	            document.body.style.cursor='auto';
            }
       }
   }
}

function PrintStr()
{
    CallPreviewPrint('PrintArea');
}

function CallPreviewPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','PrintPage','letf=0,top=0,width=950,height=800,toolbar=0,scrollbars=1,status=0,resizeable=true');
 
 StrBody = "<body style=\"background-color:white\" dir=rtl>";
 StrBody += "<link id=\"ctl00_Link1\" href=\"/styles/main.css\" rel=\"stylesheet\" type=\"text/css\" />";
 StrBody += "<script src=\"/js/main.js\" type=\"text/javascript\"></script>";
 StrBody += "<div id=\"PrintArea\">" + prtContent.innerHTML + "</div><br /><a href=\"#\" class=\"cPrint2\" onclick=\"CallPrint('PrintArea')\"><img src=\"/images/spacer.gif\" alt=\"Print\" class=\"cPrint2\" /></a></body>"
 WinPrint.document.write(StrBody);
 WinPrint.document.close();
 WinPrint.focus();

}
function PrintPage(strid)
{
     var prtContent = document.getElementById(strid);
     var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=0');
     WinPrint.document.write("<link href=\"/styles/main.css\" rel=\"stylesheet\" type=\"text\/css\" /><body dir=rtl>" + prtContent.innerHTML + "</body>");
     WinPrint.print();
     WinPrint.document.close();
     WinPrint.focus();

}
function UserIcon(objtxt,  txtName)
{
    objtxt.value = ''
    alert(' لطفا برای انتخاب ' + txtName + ' از آیکون انتخاب شهر استفاده کنید ');
    return false;
}

function doSaveAs(){
	if (document.execCommand){
		document.execCommand("SaveAs")
	}
	else {
		alert("Save-feature available only in Internet Exlorer 5.x.")
	}
}

function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=0');
 WinPrint.document.write("<body dir=rtl>" + prtContent.innerHTML + "</body>");
 WinPrint.document.close();
 WinPrint.focus();

//alert(WinPrint.document.getElementById("grdPrint").offsetHeight)
//WinPrint.resizeTo(document.getElementById("grdPrint").offsetWidth + 30,document.getElementById("grdPrint").offsetHeight + 180 );
WinPrint.print();
WinPrint.close();
}

function ToggleSelection(ChkObj)
{
    tblObj = ChkObj.parentNode.parentNode.childNodes[1]
    for(i=0; i < tblObj.rows.length; i++)
    {
        for(j=0; j < tblObj.rows[i].cells.length; j++)
        {
             CurCheckBox = tblObj.rows[i].cells[j].childNodes[0]   
             if(ChkObj.checked)
                CurCheckBox.checked = true;
             else
                CurCheckBox.checked = false;
                     
        }
    }

}
function ProcessRadKey()
{
    event.keyCode ="";
}
function ProcessRadKeyDown()
{
   if ((event.keyCode == 8) || (event.keyCode == 46) || (event.keyCode == 37 && event.altKey) || (event.keyCode == 39 && event.altKey))
    {
     event.cancelBubble=true;
     event.returnValue=false;

    }
}
function  HandleClose(sender, eventArgs)
{
    if (eventArgs.get_domEvent() != null && eventArgs.get_domEvent().x==undefined) //if no item selected the condition is true
    {
        eventArgs.set_cancel(true);
        event.cancelBubble=true;
        event.returnValue=false;
            
        sender.disableEvents();
        sender.set_text('');
        if (sender._selectedItem!=null)
            sender._selectedItem._text="";

     }
}

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);
}

function ProcessClientClick(node, args) 
{ 
    
    var ComboID ="";
    var t=args._node._parent.get_attributes()._data.ttt;
    var IsShahrestan = t!=undefined?t: args._node._parent._parent.get_attributes()._data.ttt;
    
    try 
    {
    ComboID = node.get_element().parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode[0].parentNode.id;
    }
    catch(e)
    {
    ComboID =node.get_element().parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
    }
    ComboID = ComboID.replace("_i0_treZones", "");
    //var comboBox = $find('<%=cboZoneCode.ClientID %>'); 
    var comboBox = $find(ComboID); 
    var node = args.get_node();
    comboBox.set_text(node.get_text());
    event.cancelBubble=true;

    
}  
function OnBlurCombo(combo)
{
    var comboBox  = $find(combo.id);
    comboBox.set_text(comboBox._originalText);
}



// ----------------------- AJAX --------------------------------
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function GetValue(root,field)
{
    var response = xmlHttp.responseXML.documentElement;
    if (response != null)
    {
        x=response.getElementsByTagName(root);
        if (x.length>0 && x[0].getElementsByTagName(field)[0]!=null && x[0].getElementsByTagName(field)[0].firstChild!=null)
            if (x[0].getElementsByTagName(field)[0].firstChild.nodeValue!='#ERR#')
                    return x[0].getElementsByTagName(field)[0].firstChild.nodeValue;
    }
    return '';
      
}
function SetValues(root,field,ctrl)
{
    var response = xmlHttp.responseXML.documentElement;
    if (response != null)
    {
    x=response.getElementsByTagName(root);
    if (x.length>0 && x[0].getElementsByTagName(field)[0]!=null && x[0].getElementsByTagName(field)[0].firstChild!=null)
            {
            if (x[0].getElementsByTagName(field)[0].firstChild.nodeValue!='#ERR#')
            {
                if (document.getElementById(ctrl)!=null && x[0].getElementsByTagName(field)[0].firstChild.nodeValue != '')
                    document.getElementById(ctrl).innerText=x[0].getElementsByTagName(field)[0].firstChild.nodeValue;
             }
             else 
             {
                 document.getElementById(ctrl).innerText='';
              }

            }
            else
               document.getElementById(ctrl).innerText='';
      }
}

function SetValuesCombo(root,fieldVal,Combo)
{
    ZoneRadCombo = document.getElementById(Combo);
    var response = xmlHttp.responseXML.documentElement;
    if (response != null)
    {
        x=response.getElementsByTagName(root);
        if (x.length>0 && x[0].getElementsByTagName(fieldVal)[0]!=null)
            if (x[0].getElementsByTagName(fieldVal)[0].firstChild!=null)
                if (x[0].getElementsByTagName(fieldVal)[0].firstChild.nodeValue!='#ERR#')
                    if (ZoneRadCombo!=null && x[0].getElementsByTagName(fieldVal)[0].firstChild.nodeValue != '' )
                        ZoneRadCombo.value=x[0].getElementsByTagName(fieldVal)[0].firstChild.nodeValue;
                 
//                 else 
//                     ZoneRadCombo.value='-1';
//            else  ZoneRadCombo.value='-1';
      }
}

function SetValuesTelerikCombo(root,fieldVal,fieldText,ZoneRadCombo)
{
    var response = xmlHttp.responseXML.documentElement;
    if (response != null)
    {
        x=response.getElementsByTagName(root);
        if (x.length>0 && x[0].getElementsByTagName(fieldVal)[0]!=null)
          {
                if (x[0].getElementsByTagName(fieldVal)[0].firstChild.nodeValue!='#ERR#')
                {
                    if (ZoneRadCombo!=null)
                        ZoneRadCombo.set_value(x[0].getElementsByTagName(fieldVal)[0].firstChild.nodeValue);
                 }
                 else 
                 {
                     ZoneRadCombo.set_value('');
                 }
                 
                if (x[0].getElementsByTagName(fieldText)[0].firstChild.nodeValue!='#ERR#')
                {
                    if (ZoneRadCombo!=null)
                        ZoneRadCombo.set_text(x[0].getElementsByTagName(fieldText)[0].firstChild.nodeValue);
                 }
                 else 
                 {
                     ZoneRadCombo.set_text('');
                 }
                 
           }
            else ZoneRadCombo.set_text('');
      }
}



//--- FOR UC_Tenements
function AjaxCodePosti(code)
{

if (code!="")
{
xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null && xmlHttp2==null) 
    alert('Error');
  else
  {

    var url="/HttpHandler/AjaxHandlers/Tenement.ashx";
     var params = "code=" + code + "&BaseID=tenements&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
     xmlHttp.open("POST",url,false);
     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp.setRequestHeader("Content-length", params.length);
     xmlHttp.setRequestHeader("xmlhttprequest", "true");
     xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.onreadystatechange=CodePosti_stateChanged;    
    xmlHttp.send(params);
   }                     
   }
}
function CodePosti_stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    {
    //
    // 
        SetValues('ENTTenements','Code','ctl00_cphMain_UCTenements1_hdnIsNewMode');
        SetValues('ENTTenements','AddressMM','ctl00_cphMain_UCTenements1_txtAddressMM');
        SetValues('ENTTenements','Area','ctl00_cphMain_UCTenements1_txtArea');
        SetValues('ENTTenements','Farei','ctl00_cphMain_UCTenements1_txtFarei');
        SetValues('ENTTenements','Farei1','ctl00_cphMain_UCTenements1_txtFarei1');
        SetValues('ENTTenements','Farei2','ctl00_cphMain_UCTenements1_txtFarei2');
        SetValues('ENTTenements','PelakSabti','ctl00_cphMain_UCTenements1_txtPelakSabti');
        SetValues('ENTTenements','TelMM','ctl00_cphMain_UCTenements1_txtTelMM');
        SetValues('ENTTenements','ZoneCode','ctl00_cphMain_UCTenements1_hfShahrBakhshCode');
        SetValues('ENTTenements','HozehSabti','ctl00_cphMain_UCTenements1_txtHozehSabti');
        SetValues('ENTTenements','SaleSakht','ctl00_cphMain_UCTenements1_txtSaleSakht');
 
        SetValuesCombo('ENTTenements','HCTelStatusCode','ctl00_cphMain_UCTenements1_cboHCTelStatusCode');
        SetValuesCombo('ENTTenements','HCTelStatusCode','ctl00_cphMain_UCTenements1_cboHCFrameType');
        
        
        document.getElementById('ctl00_cphMain_UCTenements1_txtArea_text').value = GetValue('ENTTenements','Area');
        document.getElementById('ctl00_cphMain_UCTenements1_txtArea_Value').value = GetValue('ENTTenements','Area');
        document.getElementById('ctl00_cphMain_UCTenements1_txtArea').value = GetValue('ENTTenements','Area');
        
        document.getElementById('ctl00_cphMain_UCTenements1_txtMantagheShahrdari_text').value = GetValue('ENTTenements','MantagheShahrdari');
        document.getElementById('ctl00_cphMain_UCTenements1_txtMantagheShahrdari_Value').value = GetValue('ENTTenements','MantagheShahrdari');
        document.getElementById('ctl00_cphMain_UCTenements1_txtMantagheShahrdari').value = GetValue('ENTTenements','MantagheShahrdari');
        
        
        
        ////alert(document.getElementById('ctl00_cphMain_UCTenements1_hfShahrBakhshCode').value);
        
//        SetValuesTelerikCombo('ENTTenements','ZoneCode','ZoneName',$find('ctl00_cphMain_UCTenements1_cboZoneCode_cboZoneCode'));
        //ctl00_cphMain_UCTenements1_cboZoneCode_drpOstan
        xmlHttp=GetXmlHttpObject();
    }
}
//-----------END
function AjaxPassportAndGreenkard(kardno, passno)
{
if ((kardno != "") && (passno != ""))
{
    xmlHttp=null;
    xmlHttp=GetXmlHttpObject();
   
    if (xmlHttp==null) 
       alert('error');
    else
      {
      
        var url="/HttpHandler/AjaxHandlers/Person.ashx";
         var params = "KardNo=" + kardno + "&PassNo=" + passno + "&BaseID=PersonsByOtherNationality&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
         xmlHttp.open("POST",url,false);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("xmlhttprequest", "true");
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.onreadystatechange=AjaxPassportNo_stateChanged;
        
        xmlHttp.send(params);
       }                     
   }
}
 function AjaxPassportNo_stateChanged() 
{ 

    if (xmlHttp.readyState==4)
    { 
        SetValues('Person','Name','ctl00_cphMain_txtName');
        SetValues('Person','Family','ctl00_cphMain_txtFamily');
        SetValues('Person','LatinName','ctl00_cphMain_txtLatinName');
        SetValues('Person','LatinFamili','ctl00_cphMain_txtLatinFamili');
        SetValues('Person','FatherName','ctl00_cphMain_txtFatherName');
        //SetValues('Person','IDNumber','ctl00_cphMain_txtIDNumber');
        SetValues('Person','IDNumberSerialUnder','ctl00_cphMain_ucIDSerial1_txtIDNumberSerialUnder');
        SetValues('Person','IDNumberSerial','ctl00_cphMain_ucIDSerial1_txtIDNumberSerial');
        SetValues('Person','Address','ctl00_cphMain_txtPersonAddress');
        SetValues('Person','PostCode','ctl00_cphMain_txtPersonPostCode');
        SetValues('Person','Tel','ctl00_cphMain_txtPersonTel');
        SetValues('Person','Fax','ctl00_cphMain_txtFax');
        SetValues('Person','Mobile','ctl00_cphMain_txtMobile');
        SetValues('Person','Email','ctl00_cphMain_txtEmail');
        SetValues('Person','BirthDate','ctl00_cphMain_dteBirthDate_dteBirthDate_txtDate');
        
        
        var BirthZoneCode=GetValue('Person','BirthZoneCode');
        var HCZoneCodelevel = GetValue('Person','HCZoneCodelevel');
        var ContactZoneCode=GetValue('Person','ContactZoneCode');

        SetValuesCombo('Person','HCIDTypeCode','ctl00_cphMain_cboHCIDTypeCode');
        SetValuesCombo('Person','HCIDNumberSerialAlphabeticCode','ctl00_cphMain_ucIDSerial1_cboHCIDNumberSerialAlphaBeticCode');
        SetValuesCombo('Person','HCGenderCode','ctl00_cphMain_cboHCGenderCode');
        SetValuesCombo('Person','HCAcademicDegreeCode','ctl00_cphMain_cboHCAcademicDegreeCode');
        //SetValuesCombo('Person','NationalityCode','ctl00_cphMain_cboNationalityCode');
        SetValuesCombo('Person','BirthZoneCode','ctl00_cphMain_txtBirthZoneCode');

        if (BirthZoneCode != '')
            {
            if(HCZoneCodelevel.value == "2")
            SetValuesCombo('Person','BirthZoneCode','ctl00_cphMain_cboBirthCountry');
            else{
              AjaxCodePostiZone(document.getElementById('ctl00_cphMain_cboBirthZoneCode_drpOstan'),BirthZoneCode);
              document.getElementById('ctl00_cphMain_cboBirthZoneCode_hfShahrestan').value = BirthZoneCode;
              }
            }
        if (ContactZoneCode != '')
            {
              AjaxCodePostiZone(document.getElementById('ctl00_cphMain_cboContactZoneCode_drpOstan'),ContactZoneCode);
              document.getElementById('ctl00_cphMain_cboContactZoneCode_hfShahrBakhsh').value = ContactZoneCode;
            }
        
        xmlHttp=GetXmlHttpObject();
    }
}

function AjaxNationalCode(nationalCode, idNumber)
{
if ((nationalCode != "") && (idNumber != ""))
{
    xmlHttp=null;
    xmlHttp=GetXmlHttpObject();
   
    if (xmlHttp==null) 
       alert('error');
    else
      {
        var url="/HttpHandler/AjaxHandlers/Person.ashx";        
         var params = "code=" + nationalCode + "&idNumber=" + idNumber + "&BaseID=person&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
         xmlHttp.open("POST",url,false);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("xmlhttprequest", "true");
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.onreadystatechange=AjaxNationalCode_stateChanged;        
        xmlHttp.send(params);
       }                     
   }
}
function AjaxNationalCode_stateChanged() 
{ 
  
    if (xmlHttp.readyState==4)
    { 
        SetValues('Person','Name','ctl00_cphMain_txtName');
        SetValues('Person','Family','ctl00_cphMain_txtFamily');
         SetValues('Person','Name','ctl00_cphMain_hfName');
        SetValues('Person','Family','ctl00_cphMain_hfFamily');
        SetValues('Person','LatinName','ctl00_cphMain_txtLatinName');
        SetValues('Person','LatinFamili','ctl00_cphMain_txtLatinFamili');
        SetValues('Person','FatherName','ctl00_cphMain_txtFatherName');
        //SetValues('Person','IDNumber','ctl00_cphMain_txtIDNumber');
        SetValues('Person','IDNumberSerialUnder','ctl00_cphMain_ucIDSerial1_txtIDNumberSerialUnder');
        SetValues('Person','IDNumberSerial','ctl00_cphMain_ucIDSerial1_txtIDNumberSerial');
        SetValues('Person','Address','ctl00_cphMain_txtPersonAddress');
        SetValues('Person','PostCode','ctl00_cphMain_txtPersonPostCode');
        SetValues('Person','Tel','ctl00_cphMain_txtPersonTel');
        SetValues('Person','Fax','ctl00_cphMain_txtFax');
        SetValues('Person','Mobile','ctl00_cphMain_txtMobile');
        SetValues('Person','Email','ctl00_cphMain_txtEmail');
        SetValues('Person','BirthDate','ctl00_cphMain_dteBirthDate_dteBirthDate_txtDate');
        
        
        var BirthZoneCode=GetValue('Person','BirthZoneCode');
        var HCZoneCodelevel = GetValue('Person','HCZoneCodelevel');
        var ContactZoneCode=GetValue('Person','ContactZoneCode');
        
        SetValues('Person','ContactZoneCode','ctl00_cphMain_hfContactZone');

        SetValuesCombo('Person','HCIDTypeCode','ctl00_cphMain_cboHCIDTypeCode');
        SetValuesCombo('Person','HCIDNumberSerialAlphabeticCode','ctl00_cphMain_ucIDSerial1_cboHCIDNumberSerialAlphaBeticCode');
        SetValuesCombo('Person','HCGenderCode','ctl00_cphMain_cboHCGenderCode');
        SetValuesCombo('Person','HCAcademicDegreeCode','ctl00_cphMain_cboHCAcademicDegreeCode');
        SetValuesCombo('Person','NationalityCode','ctl00_cphMain_cboNationalityCodeExcepRent');
        SetValuesCombo('Person','BirthZoneCode','ctl00_cphMain_txtBirthZoneCode');
        
      

        if (BirthZoneCode != '')
            {
              if(HCZoneCodelevel.value == "2")
            SetValuesCombo('Person','BirthZoneCode','ctl00_cphMain_cboBirthCountry');
            else{
              AjaxCodePostiZone(document.getElementById('ctl00_cphMain_cboBirthZoneCode_drpOstan'),BirthZoneCode);
              document.getElementById('ctl00_cphMain_cboBirthZoneCode_hfShahrestan').value = BirthZoneCode;
              }
            }
        if (ContactZoneCode != '')
            {
              AjaxCodePostiZone(document.getElementById('ctl00_cphMain_cboContactZoneCode_drpOstan'),ContactZoneCode);
              document.getElementById('ctl00_cphMain_cboContactZoneCode_hfShahrBakhsh').value = ContactZoneCode;
            }
        
        xmlHttp=GetXmlHttpObject();
    }
}
function AjaxCodePostiZone(comboOstan,code)
{
    if (code!="")
    {
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null && xmlHttp2==null) 
        alert('error');
      else
      {
            var url="/HttpHandler/AjaxHandlers/Zone.ashx";
             var params = "code=" + code + "&BaseID=ThreeZoneCodes&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
              xmlHttp.open("POST",url,false);
             xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
             xmlHttp.setRequestHeader("Content-length", params.length);
             xmlHttp.setRequestHeader("xmlhttprequest", "true");
             xmlHttp.setRequestHeader("Connection", "close");
            xmlHttp.onreadystatechange= function ()
            {

                if (xmlHttp.readyState==4)
                { 
                    var ThreeZoneCodes= xmlHttp.responseXML.documentElement.getElementsByTagName('ThreeZoneCodes')[0];
                    
                    var OstanCode = ThreeZoneCodes.childNodes[0].text;
                    comboOstan.value=OstanCode;
                    drpOstan_SelectedIndexChanged(comboOstan);
                    comboOstan.fireEvent('onchange');
                    
                    var ShahrestanCode=ThreeZoneCodes.childNodes[1].text;
                    var comboShahrestan = comboOstan.parentNode.parentNode.childNodes[2].childNodes[0];
                    comboShahrestan.value=ShahrestanCode;
                    drpShahrestan_SelectedIndexChanged(comboShahrestan);
                    comboShahrestan.fireEvent('onchange');
                    
                    var comboShahrBakhsh = comboShahrestan.parentNode.parentNode.childNodes[3].childNodes[0];
                    var ShahrBakhshCode=ThreeZoneCodes.childNodes[2].text;
                    comboShahrBakhsh.value=ShahrBakhshCode;
                    comboShahrBakhsh.fireEvent('onchange');
                    xmlHttp=GetXmlHttpObject();
                }

            };   
        xmlHttp.send(params);
       }                     
    }
    else //Clear all if code is empty
    {
     var comboShahrestan = comboOstan.parentNode.parentNode.childNodes[2].childNodes[0];
     ClearShahrBakhsh(comboShahrestan);
     ClearShahrestan(comboOstan);
     comboOstan.value=-1;
    }
}


////// ----------- CODE FOR ZONE AJAX ////////////
    var xmlHttp = GetXmlHttpObject();

// ---Clear
        function ClearShahrestan(comboOstan) {
            var comboShahrestan = comboOstan.parentNode.parentNode.childNodes[2].childNodes[0];
            if ( comboShahrestan.options != undefined)
                for (var count = comboShahrestan.options.length - 1; count > 0; count--)
                   comboShahrestan.options[count] = null;
       }
       function ClearShahrBakhsh(comboShahrestan) {
           if (comboShahrestan.parentNode.parentNode.childNodes[3].childNodes.length > 0) {
               var comboShahrBakhsh = comboShahrestan.parentNode.parentNode.childNodes[3].childNodes[0];
               if (comboShahrBakhsh.options != undefined) 
               {
                   for (var count = comboShahrBakhsh.options.length - 1; count >= 0; count--)
                   {
                       comboShahrBakhsh.options[count] = null;
                   }
                   comboShahrBakhsh.options[0] = new Option('شهر/بخش', -1, false, false);
               }
           }
       }
//-------
    //-- BEGIN drpOstan
       function drpOstan_SelectedIndexChanged(comboOstan) {
       
           var OstanCode = comboOstan.value;
           if (OstanCode == -1) {
               ClearShahrestan(comboOstan);
               var comboShahrestan = comboOstan.parentNode.parentNode.childNodes[2].childNodes[0];
               ClearShahrBakhsh(comboShahrestan);
               
           }
           else
           {
           xmlHttp2 = GetXmlHttpObject();
           if (xmlHttp == null && xmlHttp2 == null)
               alert('error');               
           else {
                if (OstanCode=='') return;
               var url = "/HttpHandler/AjaxHandlers/Zone.ashx";
                var params = "code=" + OstanCode + "&BaseID=Zone&sid=" + Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
                xmlHttp2.open("POST", url, false);
                 xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                 xmlHttp2.setRequestHeader("Content-length", params.length);
                 xmlHttp2.setRequestHeader("xmlhttprequest", "true");
                 xmlHttp2.setRequestHeader("Connection", "close");
               
               xmlHttp2.onreadystatechange = function() {
                   if (xmlHttp2.readyState == 4)
                       drpOstan_SelectedIndexChanged_stateChanged(comboOstan);
                        
               };
               xmlHttp2.send(params);
           }
           }
       }
        function drpOstan_SelectedIndexChanged_stateChanged(comboOstan) {

            var OstanCode = comboOstan.value;

            var comboShahrestan = comboOstan.parentNode.parentNode.childNodes[2].childNodes[0];
            var ShahrestanOptions = xmlHttp2.responseXML.documentElement.getElementsByTagName('Zone');
            if (xmlHttp2.responseXML.documentElement == null) return;
            ClearShahrestan(comboOstan);
            comboShahrestan.options[0] = new Option('شهرستان', -1, false, false);

            for (var i = 0; i < ShahrestanOptions.length; i++) {
                var val = ShahrestanOptions[i].firstChild.text;
                var txt = ShahrestanOptions[i].childNodes[1].text;
                var optionItem = new Option(txt, val, false, false);
                comboShahrestan.options[i+1] = optionItem;

            }
            
            ClearShahrBakhsh(comboShahrestan);
        }
        //--END drpOstan

       function drpShahrestan_SelectedIndexChanged(comboShahrestan,hfvalue) {
            var ShahrestanCode = comboShahrestan.value;
           if (ShahrestanCode=="") ShahrestanCode=hfvalue;
           if (ShahrestanCode == -1) {
               ClearShahrBakhsh(comboShahrestan);
           }
           else
           {
         xmlHttp = GetXmlHttpObject();
         if (xmlHttp == null && xmlHttp2 == null)
             alert('error');
         else {
             var url = "/HttpHandler/AjaxHandlers/Zone.ashx";
              var params = "code=" + ShahrestanCode + "&BaseID=Zone&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
              xmlHttp.open("POST", url, false);
             xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
             xmlHttp.setRequestHeader("Content-length", params.length);
             xmlHttp.setRequestHeader("xmlhttprequest", "true");
             xmlHttp.setRequestHeader("Connection", "close");
             
             xmlHttp.onreadystatechange = function() {
                 if (xmlHttp.readyState == 4) {
                     drpShahrestan_SelectedIndexChanged_stateChanged(comboShahrestan);
                 }
             };
             xmlHttp.send(params);
             }
         }

         function drpShahrestan_SelectedIndexChanged_stateChanged(comboShahrestan) {
                    var SharestanCode = comboShahrestan.value;
            if (comboShahrestan.parentNode.parentNode.childNodes[3].childNodes.length > 0) {
                var comboShahrBakhsh = comboShahrestan.parentNode.parentNode.childNodes[3].childNodes[0];

                var ShahrBakhshOptions = xmlHttp.responseXML.documentElement.getElementsByTagName('Zone');
                if (xmlHttp.responseXML.documentElement == null) return;

                if (comboShahrBakhsh.options!= undefined)
                {
                    ClearShahrBakhsh(comboShahrestan); //clear old values
                    comboShahrBakhsh.options[0] = new Option('شهر/بخش', -1, false, false);

                    for (var i = 0; i < ShahrBakhshOptions.length; i++) {
                        var val = ShahrBakhshOptions[i].firstChild.text;
                        var txt = ShahrBakhshOptions[i].childNodes[1].text;
                        var optionItem = new Option(txt, val, false, false);
                        comboShahrBakhsh.options[i+1] = optionItem;

                    }
                }
            }
         }

    }
///// ----------END CODE FOR ZONE AJAX ///////////

    function GetHF(comboOstan, hfShahrestan, hfShahrBakhsh) {
   
        if (comboOstan != null && hfShahrestan.value != "") {
            drpOstan_SelectedIndexChanged(comboOstan);
            var comboShahrestan = comboOstan.parentNode.parentNode.childNodes[2].childNodes[0];
            //if (hfShahrestan.value != "")
                comboShahrestan.value = hfShahrestan.value;

            if (hfShahrBakhsh.value != "") {
                var comboShahrBakhsh = comboShahrestan.parentNode.parentNode.childNodes[3].childNodes[0];
                drpShahrestan_SelectedIndexChanged(comboShahrestan,hfShahrestan.value);
                comboShahrBakhsh.value = hfShahrBakhsh.value;
            }
        }
    }
        function PersistShahrestanValue(ShahrestanCombo) {
        var hf = ShahrestanCombo.parentNode.childNodes[2];
        hf.value = ShahrestanCombo.value;
        
    }
    function PersistShahrBakhshValue(ShahrBakhshCombo) {
        var hf = ShahrBakhshCombo.parentNode.childNodes[2];
        hf.value = ShahrBakhshCombo.value;
    }
    
/******************************/    
/* BEGIN VALIDATION FUNCTIONS */
    function AddressValidator(id,value)
    {
        if (value.toString().length<10 && value.toString().length>0)
        {
           alert('کاربر گرامی, آدرس حداقل باید ده کاراکتر باشد')
           document.getElementById(id).innerText='';
           return;
        }
        if (IsNumeric(value) && value.toString().length>0)   
        {
            alert('کاربر گرامی عدد به تنهایی مورد قبول نمی باشد');   
            document.getElementById(id).innerText='';
            return;
        }
         if(IsCharactersSame(id,value))
           return;
        
    }
    function IsValidAddress(value)
    {        
      var key = window.event.keyCode;    
      if(key==45 || key==47 || key==46 || key== 92)      
        if(value.length ==0)
           return;
           
           return true;
    }
    function MobileValidator(id,value)
    {
        if (value.toString().length<11 && value.toString().length>0)
        {
           alert('کاربر گرامی, شماره تلفن همراه یازده کاراکتر می باشد')
           document.getElementById(id).innerText='';
           return;
        }
        if (!IsValidMobile(value))
        {
            alert('کاربر گرامی,شماره تلفن همراه صحیح نیست');   
            document.getElementById(id).innerText='';
        }
    }

    function IsNumeric(sText)
    {
        var ValidChars = "0123456789.۱۲۳۴۵۶۷۸۹۰";
        var IsNumber=true;
        var Char;
        for (i = 0; i < sText.length && IsNumber; i++)
        {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1)
                IsNumber = false;
        }
        return IsNumber;
    }
 
    function  IsValidMobile(value)
    {
        if (value.toString().length==0) return true;
        if (value.toString().length < 11  || value.toString().substring(0,2) != '09')
            return false;
        return true;
    }

    function keyp_just_Persian_Letter(e)
    {
	    if (e.keyCode>=48 && e.keyCode<=57) // Numbers
	        e.keyCode=0;
    }

   function ZipCodeValidator(id,value)
   {
       var ArrNum = new Array(10);
       var Char;
       var k=0;
       var SMRCount=1; //SIMILAR Count
           if (value.toString().length<10 && value.toString().length>0)
           {
               alert('کاربر گرامی , کدپستی ده رقم می باشد');
               document.getElementById(id).innerText='';
               return;
            }
            else
            {
               for (j=0;j<=9;j++)
               {
                 ArrNum[j] = value.toString().charAt(j);
                 //alert(ArrNum[j]);
                //sum += parseInt( ArrNum[j]);
               }                 
              for(d=0;d<=9;d++)
               {
                   if (ArrNum[0]==ArrNum[d+1])
                   {
                   SMRCount++;
                   
                   }
                
               }
               if (SMRCount==10)
               {
               alert('کاربر گرامی , کدپستی وارد شده معتبر نمی باشد');
                document.getElementById(id).innerText='';
                return;
               }
                              
                for(i=0;i<=9;i++)
               {
               
                 if(ArrNum[i]== "0" || ArrNum[i]== "2")
                 {
                     alert('کاربر گرامی , کدپستی وارد شده معتبر نمی باشد');
                     document.getElementById(id).innerText='';
                     return;
                 }
               }
              
                 
              }
               
           
       
   } 
    
   function ZeroRejecter(id,value)
   {
       if (value.toString()=='0')
        document.getElementById(id).innerText='';
   }
 
    
function ValidateDate(txtDate) {
    var EnteredDate = txtDate.value;
    var IsValid = true;
    if (EnteredDate != '') //Not empty
    {
        var dates_arr = EnteredDate.split("/");
        if (dates_arr.length != 3) {
            IsValid = false;
        }
        else {
            var year = parseInt(dates_arr[0], 10);
            var month = parseInt(dates_arr[1], 10);
            var day = parseInt(dates_arr[2], 10);
            if (isNaN(year) || isNaN(month) || isNaN(day) || year < 1287 || year > 1450 || month > 12 || month < 1 || day > 31 || day < 1 || (month > 6 && day > 30))
                IsValid = false;
            else
            {
                //سیستم کبیسه خورشیدی : باقیمانده تقسیم سال به 33 یکی از این عدد ها باشد : 1 و 5 و 9 و 13 و 17 و 22 و 26 و 30
                var kabise = year % 33;
                switch (kabise)
                {
                    case 1:
                    case 5:
                    case 9:
                    case 13:
                    case 17:
                    case 22:
                    case 26:
                    case 30:
                    break;
                    default: //kabise nist
                        if (month == 12 && day > 29) IsValid = false; 
                    break;
                }
            }
        }
        
    }
    if (!IsValid)
    {
        alert('تاریخ وارد شده صحیح نیست. لطفاً دوباره وارد کنید');
        txtDate.value='';
    }
    return IsValid;
}

/* END VALIDATION FUNCTIONS */
/****************************/

function ChangeEnc(str)
{
    var Result = "";
    for (var i = 0; i <= str.toString().length; i++)
    {
        var CurChar = str.toString().substring(i, 1);
        switch (CurChar)
        {
            case "0":
                Result += "۰";
                break;
            case "1":
                Result += "۱";
                break;
            case "2":
                Result += "۲";
                break;
            case "3":
                Result += "۳";
                break;
            case "4":
                Result += "۴";
                break;
            case "5":
                Result += "۵";
                break;
            case "6":
                Result += "۶";
                break;
            case "7":
                Result += "۷";
                break;
            case "8":
                Result += "۸";
                break;
            case "9":
                Result += "۹";
                break;
            default:
                Result += CurChar;
                break;
        }
    }
    return Result;
} 

function CallClientValidate(validationGroup) {
    try
    {
        Page_InvalidControlToBeFocused = null;
        if (typeof(Page_Validators) == "undefined") {
            return true;
        }
        var i;
        for (i = 0; i < Page_Validators.length; i++) {
            ValidatorValidate(Page_Validators[i], validationGroup, null);
        }
        Page_BlockSubmit = !Page_IsValid;    
        return Page_IsValid;
    }
    catch(e)
    {
        return true;
    }
}

var strError = '';
var AsterikError= false;
function MyPageClientValidate(validationGroup) {    
    Page_InvalidControlToBeFocused = null;
    if (typeof(Page_Validators) == "undefined") {
        return true;
    }
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i], validationGroup, null);
        if(!Page_Validators[i].isvalid) 
        {
            if (Page_Validators[i].innerText != '*')
                strError = strError + Page_Validators[i].innerText + '\r\n';
            else if (!AsterikError) 
                AsterikError= true;
         }
    }
    ValidatorUpdateIsValid();
    //ValidationSummaryOnSubmit(validationGroup);
    Page_BlockSubmit = !Page_IsValid;
    return Page_IsValid;
}

function CheckValidateForSubmitForm(validationGroup) {
    MyPageClientValidate(validationGroup);
    Page_BlockSubmit = !Page_IsValid;
    if(!Page_IsValid)
        AlertErrors();
        
    return Page_IsValid;
}

var gPageMode;
function setPageMode(pageMode)
{
    gPageMode = pageMode;
}
var previousTabIndex;
var canChanged;
var currentGroupName;
var curTabStripObj;
function setOwnValidation(tabStripId , selGroupName) {    
    tabObj = $find('ctl00_cphMain_' + tabStripId)
    var groupName = tabObj.get_selectedTab()._attributes._data.ValidationGroup;
    if(gPageMode == 'Edit')
    {
        canChanged = true;
        return;
    }
    if(groupName != null && groupName != '')
    {
        CurSelIndex = tabObj.get_selectedIndex();
        currentGroupName = groupName;
        previousTabIndex = CurSelIndex;
        canChanged = MyPageClientValidate(groupName);
        curTabStripObj = tabObj;
    }
    else
       canChanged = true;
    
    if(selGroupName != null && selGroupName != '' && !canChanged) {        
        canChanged = Page_ClientValidate(selGroupName);    
    }   
    if(!canChanged)
        AlertErrors();
    
}
function AlertErrors()
{
    var msg = '';
    if (AsterikError) 
            msg = 'لطفاً اطلاعاتی را که با ستاره مشخص شده‌اند وارد کنید\r\n';
    if (strError!='') 
        msg = msg + strError;
        
    strError='';
    AsterikError =false;
    
    alert(msg);
}

function mySelectedChanged() {   
    if(canChanged == null)
        return;
        
    if (!canChanged) {
        curTabStripObj.set_selectedIndex(previousTabIndex);
        Page_ClientValidate(currentGroupName);
    }
    else
    {
        var groupName = tabObj.get_selectedTab()._attributes._data.ValidationGroup;
        if(groupName != null && groupName != '')
            Page_ClientValidate(groupName);
    }
}


function CustomValidateCombo(source, clientside_arguments) 
{
    var combo = document.getElementById(source.controltovalidate);
    clientside_arguments.IsValid = combo !=null && combo.value != '-1';       
}



//Get vahedCount by ParvanehBldNO



function AjaxParvaneSakht(ParvanehBldNO, IssueDate, IssueZone)
{
if ((ParvanehBldNO != "") && (IssueDate != "")&& (IssueZone != "-1"))
{
    xmlHttp=null;
    xmlHttp=GetXmlHttpObject();
   
    if (xmlHttp==null) 
       alert('error');
    else
      {
        var url="/HttpHandler/AjaxHandlers/Contract.ashx";
         var params = "parvanehBldNO=" + ParvanehBldNO + "&issueDate=" + IssueDate +"&issueZone=" + IssueZone + "&BaseID=ParvanehSakhteman&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
         xmlHttp.open("POST",url,false);
         xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         xmlHttp.setRequestHeader("Content-length", params.length);
         xmlHttp.setRequestHeader("xmlhttprequest", "true");
         xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.onreadystatechange=AjaxParvaneSakht_stateChanged;        
        xmlHttp.send(params);
       }                     
   }
   else
   alert('لطفاً اطلاعات ستاره دار را کامل نمایید');
}
   function AjaxParvaneSakht_stateChanged() 
{ 
  if (xmlHttp.readyState==4)
    { 
      if (xmlHttp.status == 200) {

     var validate=GetValue('ParvanehSakhteman','Valid');
     
       if(validate == 'True'){
 
      var RemainVahed=GetValue('ParvanehSakhteman','remainingVahed');
         document.getElementById('ctl00_cphMain_hfShowpnlSpec').value = "1";
         
        if(RemainVahed != -1)
       {  
        if(RemainVahed == 0)
       {  
        alert(' واحدی جهت فروش از این شماره پروانه ساختمان باقی نمانده است' );
        document.getElementById('ctl00_cphMain_lblVahedCount').style.display = "block";
        SetValues('ParvanehSakhteman','remainingVahed','ctl00_cphMain_lblVahedCount');
       // SetValues('ParvanehSakhteman','remainingVahed','ctl00_cphMain_txtVahedCount');
      //  document.getElementById('ctl00_cphMain_lblVahedCount').innerText = RemainVahed;
        //document.getElementById("<%=txtVahedCount.ClientID%>").style.visibility = "hidden";
        document.getElementById('ctl00_cphMain_divVahedCount').style.visibility = "hidden";
        document.getElementById('ctl00_cphMain_hdfParvanehCode').value = GetValue('ParvanehSakhteman','Code');
        document.getElementById('ctl00_cphMain_hfShowpnlSpec').value = "0";
        document.getElementById('ctl00_cphMain_pnlspec').style.display ='none';
        return;
        
        }
        
        alert('تعداد ' + RemainVahed + ' واحد مسکونی از این شماره پروانه ساختمان باقی مانده است' );
        document.getElementById('ctl00_cphMain_lblVahedCount').style.display = "block";
        SetValues('ParvanehSakhteman','remainingVahed','ctl00_cphMain_lblVahedCount');
        document.getElementById('ctl00_cphMain_lblVahed').value = 'تعداد واحدهای موجود:';
       document.getElementById('ctl00_cphMain_hfRemainingVahed').value = RemainVahed; 
       // SetValues('ParvanehSakhteman','remainingVahed','ctl00_cphMain_txtVahedCount');
      //  document.getElementById('ctl00_cphMain_lblVahedCount').innerText = RemainVahed;
        //document.getElementById("<%=txtVahedCount.ClientID%>").style.visibility = "hidden";
        document.getElementById('ctl00_cphMain_divVahedCount').style.visibility = "hidden";
         document.getElementById('ctl00_cphMain_divPishfrooshVahedNo').style.display ='block';
        
        document.getElementById('ctl00_cphMain_hdfParvanehCode').value = GetValue('ParvanehSakhteman','Code');
        document.getElementById('ctl00_cphMain_hfAllVahedCount').value = GetValue('ParvanehSakhteman','VahedCount');
        
        document.getElementById('ctl00_cphMain_pnlspec').style.display ='block';
        }
        
        else 
        {
        alert('کاربر گرامی لطفا تعداد کل واحدهای مسکونی مربوط به این شماره پروانه ساختمان را وارد کنید');
        document.getElementById('ctl00_cphMain_divVahedCount').style.display = "block";
        document.getElementById('ctl00_cphMain_divPishfrooshVahedNo').style.display ='block';

        //alert(document.getElementById('divVahedCount').style.display);
       // document.getElementById('ctl00_cphMain_txtVahedCount').style.visibility = "visible";
       // ValidatorEnable(document.getElementById('ctl00_cphMain_rqvVahedCount'), true); 
        document.getElementById('ctl00_cphMain_txtVahedCount').value = "";
        document.getElementById('ctl00_cphMain_lblVahedCount').style.visibility = "hidden";
        document.getElementById('ctl00_cphMain_hdfParvanehCode').value = "-1";
        document.getElementById('ctl00_cphMain_pnlspec').style.display ='block';
        
       }
       }
       else 
       {
        alert('اطلاعات پروانه ساخت مغایرت دارد');
        document.getElementById('ctl00_cphMain_hfShowpnlSpec').value = "-1";
       }
      }
      xmlHttp=GetXmlHttpObject();
       
    }
   // 
        
      
}


function AjaxPishFrooshVahedNO(ParvanehCode, PishFrooshVahedNO)
{
if ((ParvanehCode != "") && (PishFrooshVahedNO != ""))
{
    xmlHttp=null;
    xmlHttp=GetXmlHttpObject();
   
    if (xmlHttp==null) 
       alert('error');
    else
      {
        var url="/HttpHandler/AjaxHandlers/Contract.ashx";
         var params = "ParvanehCode=" + ParvanehCode + "&PishFrooshVahedNO=" + PishFrooshVahedNO + "&BaseID=PishFrooshVahedNO&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
         xmlHttp.open("POST",url,false);
         xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         xmlHttp.setRequestHeader("Content-length", params.length);
         xmlHttp.setRequestHeader("xmlhttprequest", "true");
         xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.onreadystatechange=AjaxPishFrooshVahedNO_stateChanged;        
        xmlHttp.send(params);
       }                     
   }
}

 function AjaxPishFrooshVahedNO_stateChanged() 
{ 
   if (xmlHttp.readyState==4)
    { 
       var ExistVahedNO = GetValue('PishfrooshVahedNO','ExistsPVN');
        if(ExistVahedNO == 'True')
      {  alert('این واحد قبلا فروخته شده است');
        document.getElementById('ctl00_cphMain_txtPishfrooshVahedNo').value ="";
      }
      
      xmlHttp=GetXmlHttpObject();
       
    }
        
}

function AjaxPostCodeWebService(PostCode)
{
if ((PostCode != "") )
{
    xmlHttp=null;
    xmlHttp=GetXmlHttpObject();
   
    if (xmlHttp==null) 
       alert('error');
    else
      {
      
        var url="/HttpHandler/AjaxHandlers/Post.ashx";
         var params = "PostCodeForWebService=" + PostCode + "&BaseID=WebServicePostCode&sid=" +  Math.random()  + "&PageCheck="   + document.getElementById("ctl00_cphMain_PageCheck").value ;
         xmlHttp.open("POST",url,false);
         xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         xmlHttp.setRequestHeader("Content-length", params.length);
         xmlHttp.setRequestHeader("xmlhttprequest", "true");
         xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.onreadystatechange=AjaxPostCodeWebService_stateChanged;        
        xmlHttp.send(params);
       }                     
   }
}

 function AjaxPostCodeWebService_stateChanged() 
{ 

   if (xmlHttp.readyState==4)
    { 
    
     var CityCode = GetValue('WebServicePostCode','shahrCode');
      
       var Address = GetValue('WebServicePostCode','Address');
    //   var PostCode = GetValue('WebServicePostCode','PostCode');
       //AjaxPostCodeForRaahbar(PostCode,Address);
       
       SetValues('WebServicePostCode','PostError','ctl00_cphMain_UCTenements1_hfPostError');
       if(Address != '-1')
       SetValues('WebServicePostCode','Address','ctl00_cphMain_UCTenements1_txtAddressMM');
       else
       {
       document.getElementById('ctl00_cphMain_UCTenements1_txtAddressMM').value = "";
       document.getElementById('ctl00_cphMain_UCTenements1_txtAddressMM').setAttribute('readOnly', false);
       alert('آدرس این کد پستی پیدا نشد');
       
       }
     if (CityCode != 0)
            {
              AjaxCodePostiZone(document.getElementById('ctl00_cphMain_UCTenements1_cboZoneCode_drpOstan'),CityCode);
              document.getElementById('ctl00_cphMain_UCTenements1_hfCityCode').value = CityCode;
            }
            else
            document.getElementById('ctl00_cphMain_UCTenements1_hfCityCode').value = '0';
      xmlHttp=GetXmlHttpObject();
       
    }
        
}

function ExceptSomeCharachter()
{

        var key = window.event.keyCode;     
        if(key == 33 || key== 47 || key == 92 || key==63 || key== 46 || key== 44 || key==39 || key== 45 || key== 61 || key == 42 || key == 43 )
        {
         alert('لطفاً فقط از کاراکتر های حرفی و عددی استفاده نمائید');
         return false;         
         }
  return true;	
}
function IsCharactersSame(id,Value)
{

  var tempArr = [];
  var returnVal = false;  
  if(Value.length > 0)
  { 
   
    for(var i=(Value.length) ;0 < (i-3) ; i--)
    {
      tempArr[0] = Value.substring((i-1),i);
      tempArr[1] = Value.substring((i -2),(i-1));
      tempArr[2] = Value.substring((i -3),(i -2));
      tempArr[3] = Value.substring((i -4),(i -3));
      if(tempArr[0] == tempArr[1] && tempArr[1] == tempArr[2] && tempArr[2]==tempArr[3])
      {
                alert('لطفاً کاراکتر تکراری وارد نفرمائید');
                document.getElementById(id).innerText = '';
                document.getElementById(id).focus();
                returnVal = true;
                break;
       }
    }
  }
  return returnVal;  
}
function PlakSabtiValidator(id,value)
{
 if(value.length > 0)
 {
  if(value.substring(0,1) =='/' || value.substring(0,1) == '-' || value.substring((value.length),(value.length-1)) =='/' || value.substring((value.length),(value.length-1)) == '-')
  {
    alert('لطفا از کاراکترهای /  به عنوان کاراکتر میانی استفاده نمایید');
    document.getElementById(id).innerText = '';
    document.getElementById(id).focus();
    return;
  }
 
  
 }
}
function CheckContractChanged() 
{ 
    if(document.getElementById("ctl00_cphMain_hfNewMode") != null)    
    {
        var NewMode = document.getElementById("ctl00_cphMain_hfNewMode").value;
        
        if (NewMode == 'False') 
            document.getElementById("ctl00_cphMain_hfIsContractChanged").value = 'True';                           
    }
}
function CheckPersonInfoChanged() 
{ 
debugger;     
if(document.getElementById("ctl00_cphMain_hfIsPersonChanged")!=null && document.getElementById("ctl00_cphMain_hUpdatePersonFlag")!=null)
if(document.getElementById("ctl00_cphMain_hUpdatePersonFlag").value != "true")
    {
     document.getElementById("ctl00_cphMain_hfIsPersonChanged").value = true; 
     document.getElementById("ctl00_cphMain_hUpdatePersonFlag").value = true;   
     }
}
//function AjaxPostCodeForRaahbar(PostCode,address)
//{
//if ((PostCode != "") )
//{
//    xmlHttp=null;
//    xmlHttp=GetXmlHttpObject();
//   
//    if (xmlHttp==null) 
//       alert('error');
//    else
//      {
//        var url="/HttpHandler/AjaxHandlers/Post.ashx?PostCodeForRaahbar=" + PostCode + "&AddressForRaahbar="+address+ "&BaseID=PostCodeForRaahbar&sid="+Math.random();
//       // xmlHttp.onreadystatechange=AjaxPostCodeWebService_stateChanged;
//        xmlHttp.open("GET",url,false);
//        xmlHttp.send(null);
//       }                     
//   }
//}

