    function popUpWin(url, winproperty){
		    day = new Date();
		    id = day.getTime();
		    eval("page" + id + " = window.open(url, '" + id + "', winproperty);");
	    }
    function RefreshGrid(){
	    grid = ISGetObject('grdObj');
	    grid.Refresh();			
    }
    function DecimalHandler()
    {
	    var KeyCode = event.keyCode;
	    var DecValue = event.srcElement.value;
	    if(!(KeyCode>=48 && KeyCode<=57)&& !(KeyCode == 8) && !(String.fromCharCode(KeyCode)==document.getElementById("DecimalSeperator").value))
	    {
		    event.keyCode = 0;
		    return;
	    }
	    if ((String.fromCharCode(KeyCode)==document.getElementById("DecimalSeperator").value) && DecValue.toString().indexOf(document.getElementById("DecimalSeperator").value) >-1 )
	    {
		    event.keyCode =0;
		    event.srcElement.value = DecValue.substring(0,DecValue.length) 
		    return;
	    }
    }
    function verifyTimeOnKeyPress(){
	        var timebox = event.srcElement;	
	        var KeyCode = event.keyCode;
        if (!(KeyCode>=48 && KeyCode<=57) && !(KeyCode == 8))
        {
            event.keyCode = 0;
            return;
        }
        else
        {
                time=event.srcElement.value;
	            if(time.length == 2 && time.indexOf(':') == -1)
		            event.srcElement.value = time + ':';
	            time=time.split(':')
	            if (time[0] >24 || time[1]>59) 
	            {
		            event.keyCode = 0;				
	                    return
	            }
	            if(event.srcElement.value.length == 4)
	            {	
		            var timeval = event.srcElement.value + String.fromCharCode(event.keyCode)
		            timeval =timeval.split(':')
			            if (timeval[0] >24 || timeval[1]>59) 
			            {
				            event.keyCode = 0;				
	        		            return
			            }
	            }
	            if(event.srcElement.value.length == 5)
	            {
		            event.keyCode = 0;
		                return;
	            }
        }
    }
    function verifyTimeOnChange(timebox)
    {
        timebox = document.getElementById(timebox);
        var time = timebox.value;
        if (!/\d{2}:\d{2}/.test(time))
           {
                timebox.value = '';
        		timebox.focus();    
                return
           }
        time =time.split(':')
        if (time[0] >24 || time[1]>59) 
        {
            timebox.value = '';
        		timebox.focus();    
                return
        }
    }
    function IntegerHandler()
    {   
	    var KeyCode = event.keyCode;
	    var DecValue = event.srcElement.value;
	    if (!(KeyCode>=48 && KeyCode<=57) && !(KeyCode == 8))
	    {
		    event.keyCode = 0;
		    return;
	    }
    }
    function Trim(sString) 
    {
        while (sString.substring(0,1) == ' '){
	        sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == ' '){
	        sString = sString.substring(0,sString.length-1);
        }
        return sString;
    }
    function ShowCustDetail(CustID,RegionID)
    {
	    var strUrl = 'CustomerDetails.aspx?CustID=' + CustID + '&RegionID=' + RegionID;
	    DPGenericWindow('Win_Customer_Details',strUrl,700,550);
    }
    
    function ShowInvoiceDetails(InvoiceNo, DealerID, RegionID)
    {
	    var strUrl = 'InvoiceDetails.aspx?InvoiceNo=' + InvoiceNo +  '&DealerID=' + DealerID + '&RegionID=' + RegionID;
        var dialogBox = ISGetObject("InvDlg");
        dialogBox.ContentURL = strUrl;
        dialogBox.ShowDialog();
    }
    function ShowDocumentFile(url){
        popUpWin(url,'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=600,left = 176,top = 132');
        //DPGenericWindow('Win_Inv_Doc',url,400,300);
    }
    function ShowInvDetailsFromRoot(InvoiceNo, DealerID, RegionID)
    {
	    var strUrl = 'InvoiceDetails.aspx?InvoiceNo=' + InvoiceNo +  '&DealerID=' + DealerID + '&RegionID=' + RegionID;
	    popUpWin(strUrl, 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=600,height=550,left = 176,top = 132');				
    }
    function GoBtnClick()
    {
        var grid =  ISGetObject('grdObj');
        if(document.getElementById('DoFullPostBack')!=null){
            if(document.getElementById('DoFullPostBack').value == 1){
                document.getElementById('DoFullPostBack').value =0;
                grid.RefreshAll();
                return false;
            }
        }
        
        grid.Refresh();
        return false;
    }
    function SetFullPostBack()
    {
        document.getElementById('DoFullPostBack').value =1;
        return true;
    }
    function popUpGraph(URL){
		    URL = "RATDLR/Forms/" + URL;
		    DPGenericWindow('Win_Dashboard_Graph',URL,400,440);}
	function ShowCustTrendGraph(URL){
		    URL = "RATDLR/Forms/" + URL;
		    DPGenericWindow('Win_Trend_Graph',URL,550,350);}
	function ShowShareImg(){DPGenericWindow('Win_SOB','CDBInfoImages.aspx?ImgType=share',513,470);}
    function ShowBehImg(){DPGenericWindow('Win_Beh','CDBInfoImages.aspx?ImgType=beh',765,532);}
	function DPGenericWindow(wndName,pageURL,Width,Height,Maximize,wndParent)
    {
        var currentWin = ISGetActiveWindow();
        var dm = currentWin.GetDesktopManager();
        if(wndParent == null)
        {
            wndParent = currentWin.Name;
        }        
        var wnd = dm.GetWindow(wndName);
        if (wnd == null)
        {
            wnd = dm.CreateWindow();
            wnd.Text = wndName;
            wnd.Name = wndName;
            wnd.ParentWin = wndParent;
            wnd.ControlBoxImage = "is_webdesktop-16.gif";
            wnd.ContentURL = pageURL;
            wnd.ContentMode = "UseIFrame";
            wnd.AllowMinimize = "No";
            wnd.AllowMaximize = "No";
            wnd.ShowInTaskBar = false;
            wnd.AllowResize = "No";
            wnd.Size = new UnitSize(Width, Height);
            dm.Windows.Add(wnd);
            wnd.Show();
            wnd.MoveToCenterDesktop();
            if(Maximize == true)
                wnd.Maximize();
            
        }
        else
        {
            wnd.SetContentURL(pageURL);
            wnd.Activate();
            wnd.Show();
        }
    }
	function DPOpenPopUpWindow(wndName,pageURL,Width,Height, Maximize, wndParent)
    {
        var currentWin = ISGetActiveWindow();
        if(wndParent == null)
        {
            wndParent = currentWin.Name;
        }
        var dm = currentWin.GetDesktopManager();
        var wnd = dm.GetWindow(wndName);
        if (wnd == null)
        {
            
            wnd = dm.CreateWindow();
            wnd.Text = wndName;
            wnd.Name = wndName;
            wnd.ControlBoxImage = "is_webdesktop-16.gif";
            wnd.ContentURL = pageURL;
            wnd.ContentMode = "UseIFrame";
            wnd.AllowMinimize = "No";
            wnd.AllowMaximize = "No";
            wnd.ShowInTaskBar = false;
            wnd.AllowResize = "No";
            wnd.Size = new UnitSize(Width, Height);
            dm.Windows.Add(wnd);
            wnd.Show();
            wnd.MoveToCenterDesktop();
            wnd.ParentWin = wndParent;
           
            if(Maximize == true)
                wnd.Maximize();
                
            
        }
        else
        {
            wnd.SetContentURL(pageURL);
            wnd.Activate();
            wnd.Show();
        }
    }
   function DPCloseWindow()
    {
         var currentWin = ISGetCurrentWindow();
         if(currentWin == null)
            currentWin = ISGetActiveWindow();
            
         currentWin.Close();
    }
   function DPGetParentWindowObject()
    {
      var currentWin = ISGetCurrentWindow();
         if(currentWin == null)
            currentWin = ISGetActiveWindow();
	   var dm = currentWin.GetDesktopManager();
	   var windName = currentWin.ParentWin;
	   var wnd = dm.GetWindow(windName);
	   var wndWindow = dm.GetIFrameWindow(wnd.Name);
       return wndWindow;
    }
    function DPGetTabedParentWindowObject()
    {
      var currentWin = ISGetCurrentWindow();
      if(currentWin == null)
          currentWin = ISGetActiveWindow();

	   var dm = currentWin.GetDesktopManager();
	   var windName = currentWin.ParentWin;
	   var wnd = dm.GetWindow(windName);
       var wndWindow = dm.GetIFrameWindow(wnd.Name);
       
       if(wndWindow.location.href.indexOf('contents.aspx') > -1 || wndWindow.location.href.indexOf('vehicles.aspx') > -1){
            var pWind = wndWindow.GetActiveWindow();
            return pWind;
       }else{
            return wndWindow;
       }
       
    }
    function DPSetWindowTitle(title){
        var currentWin = ISGetCurrentWindow();
         if(currentWin == null)
            currentWin = ISGetActiveWindow();
        currentWin.SetCaption(title);
    }
    function cboSendCustomRequest(controlId){
        var cbo = ISGetObject(controlId); 
		cbo.SendCustomRequest();
    }
	
    function HideShowClientHelp(controlId, rowType, rowElement, menuObject)
    {
        menuObject.Items.GetNamedItem('mnuHelp').Hide(); return true;
        /*for(var i=0; i<menuObject.Items.length; i++)
            alert(i + menuObject.Items[i].Name);*/
    }
 function validateEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
	}
function ShowProgress()
{
    if(document.getElementById('IsLoadingActive').value == "1") 
    {
	    document.getElementById('LoadingDiv').style.display = "block";
    }	
    document.getElementById('IsLoadingActive').value = "1"	
}	
function HideProgress()
{
    if(document.getElementById('LoadingDiv')!=null)
    {
		document.getElementById('LoadingDiv').style.display = "none";
	}
}

function ShowVehicleMgmt(custid)
{
    var rgn = document.getElementById('RegionID').value;
    var address = "Planner/Forms/CustomerandVehMgmt.aspx?rgn="+ rgn
    if(custid != null)
     address = address + "&custid="+ custid;
     
    DPGenericWindow('CustomerVehicleMgmt',address,900,550);
}
function ShowPlannerBooking(bookingno, custid, vehregno, wndParent)
{
    //alert(wndParent);
    var rgn = document.getElementById('RegionID').value;
    var address = "Planner/Forms/Booking.aspx?rgn=" + rgn;
    if(bookingno != null) 
	 address = address + "&bookingid=" + bookingno;
	if(custid != null) 
	 address = address + "&custid=" + custid;
	if(vehregno != null) 
	 address = address + "&vehregno=" + vehregno;
	 DPOpenPopUpWindow('Booking',address,900,570,null,wndParent);
}
function ShowMap(PostCode)
{   
    var address = "Planner/Forms/LocateCustomer.aspx?pocode=" + PostCode;
	 DPOpenPopUpWindow('Map',address,400,400);
}
function ShowSearchForBooking(wndParent)
{
    var rgn = document.getElementById('RegionID').value;
    var address = "Planner/Forms/NewBooking.aspx?rgn=" + rgn;
	DPGenericWindow('Search',address,900,570,null,wndParent);
}
function DPUpdateHiddenFields(fieldid, fieldvalue)
{
     document.getElementById(fieldid).value = fieldvalue;
}
function OpenVehiclePopUP(VehRegNo, Booking){
    var address = 'Forms/VehiclePopup.aspx?VehRegNo=' + VehRegNo + '&booking=' + Booking;
    DPOpenPopUpWindow('VehicleDetails', address, 700, 450);
}
function ShowInvoiceDetails(InvoiceNo, DealerID, RegionID)
{
    var strUrl = 'InvoiceDetails.aspx?InvoiceNo=' + InvoiceNo +  '&DealerID=' + DealerID + '&RegionID=' + RegionID;
    DPOpenPopUpWindow('InvoiceDetails', strUrl, 700, 450);
}
function OnVehMgmtClose(){}