var popwindow;

function closePDF() 
{
    if(popwindow != null)
	{ 
	    popwindow.close();	
	}
}

function openPDF(location)
{   
if(popwindow!=null) 
{           
    alert(popwindow.closed)
    closePDF()
 }   
    popwindow =window.open(location,'AAA','dependent=yes,toolbar=no,resizable=yes,width=800,height=600,top=50,left=50');        
          
}


/*
--------------------------------------------------------------------------------
	'Function Name: closePopup
	'Description: Used to Close the PopUp window 
	'Input: None
	'Return: None
	'Written By: Swapna
	'Written date: 31-May-2006.
--------------------------------------------------------------------------------	
*/

var version4 = (navigator.appVersion.charAt(0) == "4");
		var popupHandle;
		
		
		function closePopup() {
			if(popupHandle != null && !popupHandle.closed) popupHandle.close()
		}
		

/*
--------------------------------------------------------------------------------
	'Function Name: dispalyPopup
	'Description: Used to display the Popup window with specified width and height and URL 
	              and at the location based on the event fired.
	'Input: URL, Posiiton, name, Height, Width Event
	'Return: None
	'Written By: Swapna
	'Written date: 31-May-2006.
--------------------------------------------------------------------------------	
*/

		function displayPopup(URL,position,name,height,width,evnt)
		{						
			    
			    
			   
				var properties = "toolbar=0,scrollbars=yes,location=0,height="+height
				properties = properties+",width="+width

				var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt

				if(navigator.appName == "Microsoft Internet Explorer")
				{
					screenY = document.body.offsetHeight 
					screenX = window.screen.availWidth 
				}
				else
				{ 
					screenY = screen.height;
					screenX = screen.width;
				}

				if(position == 1)	// if POPUP not CENTER
				{
					cursorX = evnt.screenX 
					cursorY = evnt.screenY 
										
					padAmtX = 10
					padAmtY = 10
			
					if((cursorY + height + padAmtY) > screenY)						
					{
						padAmtY = (-30) + (height*-1);	
					}
					if((cursorX + width + padAmtX) > screenX)
					{
						padAmtX = (-30) + (width*-1);					
					}
					if(navigator.appName == "Microsoft Internet Explorer")
					{
						leftprop = cursorX + padAmtX
						topprop = cursorY + padAmtY
					}
					else
					{ 
						leftprop = (cursorX - pageXOffset + padAmtX)
						topprop = (cursorY - pageYOffset + padAmtY)
					}
				}
			else	// CENTER
			{
					leftvar = (screenX - width) / 2
					rightvar = (screenY - height) / 2
				
					if(navigator.appName == "Microsoft Internet Explorer")
					{
						leftprop = leftvar
						topprop = rightvar
					}
					else
					{ 
						leftprop = (leftvar - pageXOffset)
						topprop = (rightvar - pageYOffset)
					}
			}

		if(evnt != null)
		{
			properties = properties+",left="+leftprop			
			properties = properties+",top="+topprop

		}
		closePopup()
		
		popupHandle = open(URL+escape(evnt.srcElement.value),name,properties)	
		   
		popupHandle.document.close();
			
}


/*
--------------------------------------------------------------------------------
	'Function Name: validateUser
	'Description: Used to validate UserName and Password (Not allows null values) in LoginForm page
	'Input: UserName, PassWord, ErrorMessage Label
	'Return: None
	'Written By: Swapna
	'Written date: 26-Jan-2005.
--------------------------------------------------------------------------------	
*/
function validateUser(ctlToValidate1,ctlToValidate2,lblErrMsg)
{
	
		if(ctlToValidate1.value=="" && ctlToValidate2.value!="")
		{
			lblErrMsg.innerHTML= ctlToValidate1.name + " should not be null."
			ctlToValidate1.focus()
		}
		
		else if(ctlToValidate1.value!="" && ctlToValidate2.value=="" )
		{
			lblErrMsg.innerHTML= ctlToValidate2.name + " should not be null."
			ctlToValidate2.focus()
		}
		else if(ctlToValidate1.value=="" && ctlToValidate2.value=="" )
		{
			lblErrMsg.innerHTML= ctlToValidate1.name + " and " + ctlToValidate2.name + " should not be null."
			ctlToValidate1.focus()
		}	 
		else if(ctlToValidate1.value!="" && ctlToValidate2.value!="" )
		{
			lblErrMsg.innerHTML= "" 
		} 
   		
}

/*
--------------------------------------------------------------------------------
	'Function Name: validateInput
	'Description: Used for not allowing null values for the specified input.
	'Input: SiteName, Error Message Label
	'Return: None
	'Written By: Swapna
	'Written date: 26-Jan-2005.
--------------------------------------------------------------------------------	
*/
function validateInput(ctlToValidate1,lblErrMsg)
{
		
		if (ctlToValidate1.value=="" )  
		{
			lblErrMsg.innerHTML=ctlToValidate1.name + " should not be null."
			ctlToValidate1.focus()
		}				
		else
		{
			lblErrMsg.innerHTML=""
		}		
		
}

/*
--------------------------------------------------------------------------------
	'Function Name: IsNumeric
	'Description: Used to allow only numeric values
	'Input: SiteName, Error Message Label
	'Return: None
	'Written By: Swapna
	'Written date: 11-Feb-2005.
--------------------------------------------------------------------------------	
*/

function IsNumericCheck(ctlToValidate,lblErrMsg)
{
   var strValidChars = "0123456789";
   var strChar;
   var strString=ctlToValidate.value;
     
 if (strString.length == 0) 
	{
		lblErrMsg.innerHTML=ctlToValidate.name + " should not be null."
		ctlToValidate.focus()
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			lblErrMsg.innerHTML=ctlToValidate.name + " should be numeric."
			ctlToValidate.focus()
			break;
         }
        else
			lblErrMsg.innerHTML="";
	  }
	   
   } 

}

/*
--------------------------------------------------------------------------------
	'Function Name: calculateEquPrice
	'Description: Used to Calculate equivalent prices in REO
	'Input: Price, Exchange Rate, Equivalent price
	'Return: None
	'Written By: Swapna
	'Written date: 15-Mar-2005.
--------------------------------------------------------------------------------	
*/

function calculateEquPrice(ctl1,ctl2,ctl3)
{
	
	DecimalCheck(ctl2)
	var a=parseFloat(ctl1.value)
	var b=parseFloat(ctl2.value)
	var c=a*b;
	ctl3.innerHTML=c;
}

/*
--------------------------------------------------------------------------------
	'Function Name: isLeapYear
	'Description: Function to check whether the year is a Leap or not
	'Input: to handle the extra date in February
	'Return: None
	'Written By: Sampath
	'Written date: 22-May-2006.
--------------------------------------------------------------------------------	
*/
function isLeapYear(pyear)
{
	year = parseInt(pyear);

	if(year%4 == 0)
	{
		if(year%10 != 0)
		{
			return true;
		}
		else
		{
			if(year%400 == 0)
				return true;
			else
				return false;
		}
	}
	return false;
}

/*
--------------------------------------------------------------------------------
	'Function Name: calCriticalDate
	'Description: Used to Calculate Critical Date, Action Date and Planning Date
	'Input: Reference Date, Lead Value and Control to place 
	'Return: None
	'Written By: Swapna
	'Written date: 16-Mar-2005.
--------------------------------------------------------------------------------	
*/

function calCriticalDate(ctlReference,ctlLead,ctlToPlace,ctlToFocus, strClientID,lblErrMsg)
{


if(ValidateDateSpan(ctlReference,lblErrMsg))
{
	if(!NumericCheckSpan(ctlLead,lblErrMsg))
	{
		var numberOfDays
		if (ctlLead.value=="")
		{
			numberOfDays =0	
		}	
		else
		{
			if(ctlToPlace.name==strClientID+"_txtCriticalDate")
				numberOfDays =parseInt(ctlLead.value)
			if(ctlToPlace.name==strClientID+"_txtActionDate")
				numberOfDays =parseInt(ctlLead.value)+parseInt(document.getElementById(strClientID+ "_txtCriticalDateLead").value)
			if(ctlToPlace.name=="txtPlanningDate")
				numberOfDays =parseInt(ctlLead.value)+parseInt(document.getElementById(strClientID+"_txtCriticalDateLead").value)+parseInt(document.getElementById(strClientID+"_txtActionDateLead").value)
			
		}
	
		if (ctlReference.value!="")
		{		
			var theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - numberOfDays )
			ctlToPlace.value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			
			var numberOfDays1,numberOfDays2,numberOfDays3
		
			numberOfDays1 =parseInt(document.getElementById(strClientID+"_txtCriticalDateLead").value)
			numberOfDays2 =parseInt(document.getElementById(strClientID+"_txtActionDateLead").value)
			numberOfDays3 =parseInt(document.getElementById(strClientID+"_txtPlanningDateLead").value)
			
			var theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - numberOfDays1 )
			document.getElementById(strClientID+"_txtCriticalDate").value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - (numberOfDays2+numberOfDays1))
			document.getElementById(strClientID+"_txtActionDate").value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - (numberOfDays3+numberOfDays2+numberOfDays1) )
			document.getElementById(strClientID+"_txtPlanningDate").value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			
			ctlToFocus.focus()
			
			
		}
		else
		{
			ctlToPlace.value = ""
		}
	}
	else
	{
		ctlLead.focus()
	}
  }
  else
  {
	ctlReference.focus()
  }
}
/*
--------------------------------------------------------------------------------
	'Function Name: calCriticalDate
	'Description: Used to Calculate Critical Date, Action Date and Planning Date
	'Input: Reference Date, Lead Value and Control to place 
	'Return: None
	'Written By: Swapna
	'Written date: 16-Mar-2005.
--------------------------------------------------------------------------------	
*/

function calCriticalDateForReference(ctlReference,ctlToFocus, strClientID,lblErrMsg)
{

if(ValidateDateSpan(ctlReference,lblErrMsg) && ctlReference.value!="")
{
	if(!NumericCheckSpan(document.getElementById(strClientID+ "_txtCriticalDateLead"),lblErrMsg))
	{
		var numberOfDays1,numberOfDays2,numberOfDays3
		
			numberOfDays1 =parseInt(document.getElementById(strClientID+ "_txtCriticalDateLead").value)
			numberOfDays2 =parseInt(document.getElementById(strClientID+ "_txtActionDateLead").value)
			numberOfDays3 =parseInt(document.getElementById(strClientID+ "_txtPlanningDateLead").value)
		
		if (ctlReference.value!="")
		{		
			var theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - numberOfDays1 )
			document.getElementById(strClientID+ "_txtCriticalDate").value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - (numberOfDays2+numberOfDays1))
			document.getElementById(strClientID+ "_txtActionDate").value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			theDate= new Date(ctlReference.value)
			theDate.setDate( theDate.getDate() - (numberOfDays3+numberOfDays2+numberOfDays1) )
			document.getElementById(strClientID+ "_txtPlanningDate").value= (theDate.getMonth()+1) + "/" + theDate.getDate() + "/" + theDate.getFullYear()
			ctlToFocus.focus()
		}
		else
		{
			document.getElementById(strClientID+ "_txtCriticalDate").value = "";
			document.getElementById(strClientID+ "_txtActionDate").value = "";
			document.getElementById(strClientID+ "_txtPlanningDate").value = "";
		}
	}

} // end of outer if

else
{
		    document.getElementById(strClientID+ "_txtCriticalDate").value = "";
			document.getElementById(strClientID+ "_txtActionDate").value = "";
			document.getElementById(strClientID+ "_txtPlanningDate").value = "";

} // end of outer else

}
/*
--------------------------------------------------------------------------------
	'Function Name: calculateEquPrice
	'Description: Used to Calculate equivalent prices in Vouchers
	'Input: Price, Exchange Rate, Equivalent price
	'Return: None
	'Written By: Vamsi
	'Written date: 23-Mar-2005.
--------------------------------------------------------------------------------	
*/

function calculatePaymentAmount(ctl1,ctl2,ctl3,ctl4,ctl5,lblErrorMessage)
{
    
	var myRegExp =/,/;
	
    lblErrorMessage.innerHTML=""
    
    var check = true; 
    var strValidChars = "0123456789.";
    var strChar;   
	
    var strString=ctl1.value.replace(myRegExp,"");
         
    if (strString.length == 0) 
	{
		ctl1.value=0.00;
		check=true;
	}
    else
   {
       for (i = 0; i<strString.length; i++)
       {
          strChar = strString.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
			    lblErrorMessage.innerHTML="*Value should be Decimal."
			    ctl1.focus()
			    check=false;   			
			    break;
             }
            else
             {    			
			    lblErrorMessage.innerHTML=""
			    check=true;			
		      }
    		   
	     }	   	    
    } 
   
   if (check == true)
   {
	    strString=ctl2.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctl2.value=0.00;		    
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctl2.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
	if (check == true)
   {
	    strString=ctl3.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctl3.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctl3.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
    if (check == true)
   {
	    strString=ctl4.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctl4.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctl4.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
	
     if(check==true)
     {           
        	 var ExpAmt=parseFloat(ctl1.value.replace(myRegExp,""))
	         var CreditsUsed=parseFloat(ctl2.value.replace(myRegExp,""))
	         var TaxAmt=parseFloat(ctl3.value.replace(myRegExp,""))
	         var DutyAmt=parseFloat(ctl4.value.replace(myRegExp,""))
	         ctl4.value=DutyAmt.toFixed(2)
	         var PymtAmt=(ExpAmt)-(CreditsUsed)+(TaxAmt)+(DutyAmt)
	         ctl5.value=PymtAmt.toFixed(2)
	         conversiontofloatAndSeperatorSpan(ctl4,lblErrorMessage)
	         conversiontofloatAndSeperatorSpan(ctl5,lblErrorMessage)
	}
	
	if(check==false)
	{
	    lblErrorMessage.innerHTML="*Value should be Decimal."
	    return;
	}
}
/*
--------------------------------------------------------------------------------
	'Function Name: calculateEquAmount
	'Description: Used to Calculate equivalent prices in Vouchers
	'Input: Price, Exchange Rate, Equivalent price
	'Return: None
	'Written By: Vamsi
	'Written date: 23-Mar-2005.
--------------------------------------------------------------------------------	
*/

function calculateEquAmount(ctrl1,ctrl2,ctrl3,ctrl4,ctrl5,ctrl6,ctrl7,ctrl8,lblErrorMessage)
{
	
	var myRegExp =/,/;
	
    lblErrorMessage.innerHTML=""
    
    var check = true; 
    var strValidChars = "0123456789.";
    var strChar;   
	
    var strString=ctrl1.value.replace(myRegExp,"");
         
    if (strString.length == 0) 
	{
		ctrl1.value=0.00;
		check=true;
	}
    else
   {
       for (i = 0; i<strString.length; i++)
       {
          strChar = strString.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
			    lblErrorMessage.innerHTML="*Value should be Decimal."
			    ctrl1.focus()
			    check=false;   			
			    break;
             }
            else
             {    			
			    lblErrorMessage.innerHTML=""
			    check=true;			
		      }
    		   
	     }	   	    
    } 
   
   if (check == true)
   {
	    strString=ctrl2.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctrl2.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctrl2.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
    
	if (check == true)
   {
	    strString=ctrl3.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctrl3.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctrl3.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
	if (check == true)
   {
	    strString=ctrl4.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctrl4.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctrl4.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
    if (check == true)
   {
	    strString=ctrl5.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctrl5.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctrl5.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
       if (check == true)
   {
	    strString=ctrl6.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctrl6.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctrl6.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
       if (check == true)
   {
	    strString=ctrl7.value.replace(myRegExp,"");
             
        if (strString.length == 0) 
	    {
		    ctrl7.value=0.00;
		    check=true;
	    }
        else
       {
           for (i = 0; i<strString.length; i++)
           {
              strChar = strString.charAt(i);
              if (strValidChars.indexOf(strChar) == -1)
                 {
			        lblErrorMessage.innerHTML="*Value should be Decimal."
			        ctrl7.focus()
			        check=false;   			
			        break;
                 }
                else
                 {    			
			        lblErrorMessage.innerHTML=""
			        check=true;			
		          }
        		   
	         }	   	    
        } 
    }
    
 
    if(check==true)
    {
           
          var ExpenseAmt=parseFloat(ctrl1.value.replace(myRegExp,""))
	      var CreditsUsed=parseFloat(ctrl2.value.replace(myRegExp,""))
	      var TaxAmt=parseFloat(ctrl3.value.replace(myRegExp,""))
	      var DutyAmt=parseFloat(ctrl4.value.replace(myRegExp,""))
	      var TaxExchange=parseFloat(ctrl5.value.replace(myRegExp,""))
	      var DutyExchange=parseFloat(ctrl6.value.replace(myRegExp,""))
	      ctrl6.value=DutyExchange.toFixed(2)
	      var ExchangeRate=parseFloat(ctrl7.value.replace(myRegExp,""))
	      var Equivalent=(((ExpenseAmt)-(CreditsUsed))*(ExchangeRate))+((TaxAmt)*(TaxExchange))+((DutyAmt)*(DutyExchange))
	      ctrl8.value=Equivalent.toFixed(2)
	      conversiontofloatAndSeperatorSpan(ctrl6,lblErrorMessage)
	      conversiontofloatAndSeperatorSpan(ctrl8,lblErrorMessage)	      
	
	}
	if(check==false)
	{
	
	    lblErrorMessage.innerHTML="*Value should be Decimal."	
	    return;
	}
	
}
/*
--------------------------------------------------------------------------------
	'Function Name: calculateEquAmount
	'Description: Used to Calculate equivalent prices in Vouchers
	'Input: Price, Exchange Rate, Equivalent price
	'Return: None
	'Written By: Vamsi
	'Written date: 23-Mar-2005.
--------------------------------------------------------------------------------	
*/

function conversiontofloatSpan(ctlToValidate,ctlToPlace)
{
	 ctlToPlace.innerHTML=""
   var strValidChars = "0123456789.";
   var strChar;
   
   var myRegExp =/ /;
	//var ExpAmt=parseFloat(ctl1.value.replace(myRegExp,""))
	
   var strString=ctlToValidate.value.replace(myRegExp,"");
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0.00;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			ctlToPlace.innerHTML="*Value should be Decimal."
			ctlToValidate.focus()
			check=false;
			
			break;
         }
        else
         {
			
			ctlToPlace.innerHTML=""
			check=true;			
		  }
		   
	   }
	   	    
   } 
   
   if (check==true)
   {
		var val1=parseFloat(ctlToValidate.value)
		ctlToValidate.value=val1.toFixed(8)	
	}
}
//dated on 23-05-05 by Vamsi
function Delete(ctrl1)
{
	var val1=ctrl1.name
	alert(val1);
	
}


//dated on 22-05-05 by Vamsi

function conversiontofloatAndSeperator(ctrl1)
{
	
	var ctrlstr=ctrl1.value;
	var str1="";
	var str2="";
	var str="";
	var dot="0";
	var minus = "";
	
	if(ctrlstr.length<1)
	{
	  ctrl1.value="0.00";
	}
	else
	{
	  for(var i=0; i<ctrlstr.length;i++)
	  {
	     var c = ctrlstr.charAt(i);
	     
	     if ((c == "-") && (i==0))
         {
           minus ="-";
         }
         
         if ((c >= "0") && (c <= "9") && (dot=="0"))
         {
           str1=str1+c;                    
         }
         else if(parseInt(dot)>2)
         {
			break;
         }
         else if((c >= "0") && (c <= "9") && (parseInt(dot) >0))
         {
			str2=str2 + c;
			dot=parseInt(dot)+1;
         }
         else if(c == ".")
         {
			dot=parseInt(dot)+1;
         }         
         
	  }
	if(str1.length <1)
	{
		str1="0";
	}
	else if(str1.length <=3)
	{}
	else
	{
	
	//--------
		var str11="";
		var c=""; 
		var ccount="0";
		var j = 0;
		
		var r = str1.length % 3;
		
		if (r!=0)
		{
			
			for (var i=0; i<r; i++)
			{
				c = c+str1.charAt(i);
			}
			c = c+ ",";
		
		}
		
		for ( var i = r ; i<str1.length ; i++)
		{
			
			c = c + str1.charAt(i);
			
			j = j+1 ;
			
			if ((j == 3) && (i<str1.length-1))
			{
				c = c + ",";
				j = 0;
			}
		}
		
		str1 = c;
		
	}
	str=str1+ "." + str2;
	if(str2.length==0)
		str=str + "00";
	else if(str2.length==1)
		str=str + "0";
		
	//alert(str);
ctrl1.value= minus+str;
	}
}
/*
--------------------------------------------------------------------------------
'Function Name :DateValidation
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

  




/*
--------------------------------------------------------------------------------
'Function Name :DateValidation
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
    var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate1(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

/*
function ValidateForm(CtlToValidate,ErrorMessage){
	//var dt=document.frmSample.txtDate
	if (isDate1(CtlToValidate.value)==false){				
		dt.focus()
		return false;
	}
    return true;
 }

*/

function isDate(dtStr,lblErrorMessage)
{	  
			
	if(dtStr!="" && dtStr!=null)
	{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1)
	{
		 self.focus()
		
		lblErrorMessage.innerHTML= "The date format should be : mm/dd/yyyy";	
		document.getElementById(event.srcElement.name).focus()	
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12)
	{
		  self.focus()
		 
		lblErrorMessage.innerHTML="Please enter a valid month";		
		document.getElementById(event.srcElement.name).focus()
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		 self.focus()
		 
		lblErrorMessage.innerHTML="Please enter a valid day"		
		document.getElementById(event.srcElement.name).focus()
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		  self.focus()
		 
		lblErrorMessage.innerHTML="Please enter a valid 4 digit year between "+minYear+" and "+maxYear		
		document.getElementById(event.srcElement.name).focus()
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){		
		 self.focus()
		 
		lblErrorMessage.innerHTML="Please enter a valid date"		
		document.getElementById(event.srcElement.name).focus()
		return false
	}
  }
return true
}

function ValidateForm(CtlToValidate,lblErrorMessage)
{
	//var dt=document.frmSample.txtDate
	if (isDate(CtlToValidate.value,lblErrorMessage)==false)
	{		
		CtlToValidate.focus();
		return false;
	}
	lblErrorMessage.innerHTML="";
    return true;
    
 }

/*
--------------------------------------------------------------------------------
'Function Name :Check for datagrid row selection
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

function CheckDataGridRadioButton()
    {
		var temp = false;
	
		for(i = 0; i < document.aspnetForm.elements.length; i++)
         {
             elm = document.aspnetForm.elements[i]		            
                       
            if (elm.type == 'radio')
			{
				 temp = true;
				 document.aspnetForm.elements[i].checked = true;
				 break;
            }     
           
		  }
		 
	}
	
	
	/*
--------------------------------------------------------------------------------
'Function Name :Check for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

function ValidateMandatoryFields(ctlToValidate1,ctlErrorMsg)
{
	
	
	// Validating sitename
	
	if (ctlToValidate1.name.indexOf("SiteName")!=-1)
	{

		if(ctlToValidate1.value=="")
		{
			ctlErrorMsg.innerHTML = "*SiteName Should Not be Null.";
			ctlToValidate1.focus();
		}
		else
		ctlErrorMsg.innerHTML = "";
	}
	
	// Validating Title Held By
	
	if (ctlToValidate1.name.indexOf("txtTitleHeldBy")!=-1)
	{
		if(ctlToValidate1.value=="")
		{
			ctlErrorMsg.innerHTML = "*TitleHeldBy Should Not be Null.";
			ctlToValidate1.focus();
		}
		else
		ctlErrorMsg.innerHTML = "";
	}
	
	
	
	// Validating Lessee
	
	if (ctlToValidate1.name.indexOf("txtLessor")!=-1 )
	{
		if(ctlToValidate1.value=="")
		{
			ctlErrorMsg.innerHTML = "*Lessor Name Should Not be Null.";
			ctlToValidate1.focus();
		}
		else
		ctlErrorMsg.innerHTML = "";
	}
}

   
/*
--------------------------------------------------------------------------------
'Function Name :Check for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/



function ValidateDateInput(ctlToValidate1,ctlToValidate2)
{
		
		
		if (ctlToValidate1.value=="" ||ctlToValidate2.value=="" )  
		{
			alert("Select Begin Date and End Date from the Calender.");
			ctlToValidate1.focus()
		}				
		
}
/*
--------------------------------------------------------------------------------
'Function Name :Check for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/
function ValidateInputTextboxes(ctlToValidate1)
{
		
		if (ctlToValidate1.value=="" )  
		{
	         alert("Insert SiteName");		
	  		ctlToValidate1.focus()
		}				
		
		
}
function ValidateTitleHeldBy(ctlToValidate1)
{
		
		if (ctlToValidate1.value=="" )  
		{
	         alert("Insert TitleHeldBy field.");		
	  		ctlToValidate1.focus()
		}				
		
		
}
 function ValidateLessor(ctlToValidate1)
{
		
		if (ctlToValidate1.value=="" )  
		{
	         alert("Insert Lessor ");		
	  		ctlToValidate1.focus()
		}				
		
		
}
function ValidateLessee(ctlToValidate1)
{
		
		if (ctlToValidate1.value=="" )  
		{
	         alert("Insert Lessee ");		
	  		ctlToValidate1.focus()
		}				
		
		
}

function ValidateItem(ctlToValidate1)
{
		
		if (ctlToValidate1.value=="" )  
		{
	         alert("Insert Item");		
	  		ctlToValidate1.focus()
		}				
		
		
}
/*
--------------------------------------------------------------------------------
'Function Name :Add One Month for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

function GetMonth(ctrl1,ctrl2,ctrl3,ctrl4,ctrl5,lblErrorMessage)
{
				
	var dtStr=ctrl1.value;
	var dtCh= "/";
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var strYr;
if( ValidateForm(ctrl1,lblErrorMessage)==true)
{
	if((strMonth=="3" || strMonth=="5" || strMonth=="8" || strMonth=="10" )&&(strDay=="31"))
	{
		strDay="30";
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		lblErrorMessage.innerHTML=" Date in  (MM/DD/YYYY)";
	}
	if((ctrl1.value!="")&&(strDay<=31 && strDay>=0) && (strMonth<=12 && strMonth >0 && strYear.length==4))
	{
	    lblErrorMessage.innerHTML="";
			if(parseInt(strMonth)==1 && parseInt(strDay)> 28)
			{
				if(parseInt(strYear)%4==0)
				{
					strDay="29";
				}
				else
				{
					strDay="28";
				}
			}
			if(strMonth<0 || strMonth>12)
			{
			lblErrorMessage.innerHTML="Enter Valid Month";
			}
			else
			{
				if(strMonth==12 )
				{
				strYear=parseInt(strYear)+1;
				strMonth="1";
				}
				else
				{
				strMonth=parseInt(strMonth)+1;
				}
			}
			if(strYear.length<4 || strYear.length>4 )
			{
				lblErrorMessage.innerHTML="Enter Valid Year";
			}
				dtStr=strMonth+dtCh+strDay+dtCh+strYear;
				//dtStr=strMonth+dtCh+(strDay-1)+dtCh+strYear;
			if(dtStr!=null)
			{
			ctrl2.value=dtStr;
			ctrl3.value=ctrl1.value;
			ctrl4.value="0.00"
			ctrl5.value="1";
			}
				
    }
	return true;
				    
 }
 else
 {
	return false;
 }    	

}

/*
--------------------------------------------------------------------------------
'Function Name :Add One Month1 for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/


function GetMonth1(ctrl1,ctrl2,ctrl3,lblErrorMessage)
{
				
	var dtStr=ctrl1.value;
	var dtCh= "/";
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var strYr;
if( ValidateForm(ctrl1,lblErrorMessage)==true)
{
	if((strMonth=="3" || strMonth=="5" || strMonth=="8" || strMonth=="10" )&&(strDay=="31"))
	{
		strDay="30";
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		lblErrorMessage.innerHTML=" Date in  (MM/DD/YYYY)";
	}
	if((ctrl1.value!="")&&(strDay<=31 && strDay>=0) && (strMonth<=12 && strMonth >0 && strYear.length==4))
	{
	    lblErrorMessage.innerHTML="";
			if(parseInt(strMonth)==1 && parseInt(strDay)> 28)
			{
				if(parseInt(strYear)%4==0)
				{
					strDay="29";
				}
				else
				{
					strDay="28";
				}
			}
			if(strMonth<0 || strMonth>12)
			{
			lblErrorMessage.innerHTML="Enter Valid Month";
			}
			else
			{
				if(strMonth==12 )
				{
				strYear=parseInt(strYear)+1;
				strMonth="1";
				}
				else
				{
				strMonth=parseInt(strMonth)+1;
				}
			}
			if(strYear.length<4 || strYear.length>4 )
			{
				lblErrorMessage.innerHTML="Enter Valid Year";
			}
				dtStr=strMonth+dtCh+strDay+dtCh+strYear;
			if(dtStr!=null)
			{
			 ctrl2.value=dtStr;
			 ctrl3.value="0.00"
			}
	 }
		return true;
}
 else
 {
  return false;
 }    	

}

/*
--------------------------------------------------------------------------------
'Function Name :Add One CalCulateDate for Rentand Expenses in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/
function  CalDate1( ctrl1,ctrl2,ctrl3,lblErrorMessage)
    {
      alert("Enter Valid Date");
	  var dt =ctrl1.value;
	  
	  var X = new Date(dt);
	  alert(X);
	  var year = X.getFullYear();
	  alert(year);
	  var date = X.getDate();
	  var month = X.getMonth();
	  alert(month);
	  /*X.setDate(date-1);
	  X.setFullYear(year+1);
	  */alert(X);
	  month = parseInt(X.getMonth())+1;
	  year = X.getFullYear();
	 alert(year);
	  date = parseInt(X.getDate());
	 alert("Process");
	  var Y =String(month +"/"+ date +"/"+ year);
	 alert(Y);
     /* ctrl2.value=Y;
      ctrl3.value=ctrl1.value;*/
      
  }
    
    
/*
--------------------------------------------------------------------------------
'Function Name :Add One Month1 for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

function GetMonth2(ctrl1,ctrl2,ctrl3,lblErrorMessage)
{
				
	var dtStr=ctrl1.value;
	var dtCh= "/";
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var strYr;
if( ValidateForm(ctrl1,lblErrorMessage)==true)
{
	if((strMonth=="3" || strMonth=="5" || strMonth=="8" || strMonth=="10" )&&(strDay=="31"))
	{
		strDay="30";
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		lblErrorMessage.innerHTML=" Date in  (MM/DD/YYYY)";
	}
	if((ctrl1.value!="")&&(strDay<=31 && strDay>=0) && (strMonth<=12 && strMonth >0 && strYear.length==4))
	{
	    lblErrorMessage.innerHTML="";
			if(parseInt(strMonth)==1 && parseInt(strDay)> 28)
			{
				if(parseInt(strYear)%4==0)
				{
					strDay="29";
				}
				else
				{
					strDay="28";
				}
			}
			if(strMonth<0 || strMonth>12)
			{
			lblErrorMessage.innerHTML="Enter Valid Month";
			}
			else
			{
				if(strMonth==12 )
				{
				strYear=parseInt(strYear)+1;
				strMonth="1";
				}
				else
				{
				strMonth=parseInt(strMonth)+1;
				}
			}
			if(strYear.length<4 || strYear.length>4 )
			{
				lblErrorMessage.innerHTML="Enter Valid Year";
			}
				dtStr=strMonth+dtCh+strDay+dtCh+strYear;
			if(dtStr!=null)
			{
				ctrl2.value=dtStr;
				ctrl3.value=ctrl1.value;
			}
				
	}
    return true;
}
else
	{
	 return false;
	}    	

}


/*
--------------------------------------------------------------------------------
'Function Name :Checking for the  Year for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/

    
     function  CheckDate(ctlName,lblErrorMessage)
    {			 	
		 lblErrorMessage.innerHTML="";
		 var a=ctlName.name;
	          var b=a.substr(0,a.length-1)
	          
	          var dt = document.getElementById(a).value;
	          
	          
	          var X = new Date(dt);
	          var year = X.getFullYear();
	          var date = X.getDate();
	          var month = X.getMonth();
	          X.setDate(date-1);
	          month = parseInt(X.getMonth())+1;
	          year = parseInt(X.getFullYear())+1;
	          date = parseInt(X.getDate());
        	  
	          //Leap year check
		        if (!isLeapYear(year))
		        {
			        if(month == 2 && date == 29)
				        date = 28;
		        }
        		
	          var Y =String(month +"/"+ date +"/"+ year);

              var c= b+1;

              var endDate = document.getElementById(c).value;
	        if (endDate==null || endDate =="")
			        document.getElementById(c).value = Y;


              c = b+3;

              c = b+4;
              
              var NxtPymtDate = document.getElementById(c).value
        		
		        if (NxtPymtDate==null || NxtPymtDate=="")
			        document.getElementById(c).value = dt;
        			      
              return true;			  

 }
 
    function  CheckDate1(ctlName,lblErrorMessage)
    {		
	 
	    lblErrorMessage.innerHTML="";
		var a=ctlName.name;
		var b=a.substr(0,a.length-1)
		var dt = document.getElementById(a).value;
		var X = new Date(dt);
		var year = X.getFullYear();
		var date = X.getDate();
		var month = X.getMonth();
		X.setDate(date-1);
		month = parseInt(X.getMonth())+1;
		year = parseInt(X.getFullYear())+1;
		date = parseInt(X.getDate());
		
		//Leap year check
		if (!isLeapYear(year))
		{
			if(month == 2 && date == 29)
				date = 28;
		}
		
		var Y =String(month +"/"+ date +"/"+ year);
		var c= b+1;
		var endDate = document.getElementById(c).value
		if (endDate==null || endDate=="")
			document.getElementById(c).value = Y;

		c = b+3;

		c = b+4;
		var NxtPymtDate = document.getElementById(c).value
		
		
		if (NxtPymtDate==null || NxtPymtDate=="")
			document.getElementById(c).value = dt;	
			
			return;	 					  			
  
 }
 
    
function  CheckDate2(ctlName,lblErrorMessage)
    {
	  lblErrorMessage.innerHTML="";	
	  var a=ctlName.name;
	  var b=a.substr(0,a.length-1)
	  var dt = document.getElementById(a).value;
	  var X = new Date(dt);
	  var year = X.getFullYear();
	  var date = X.getDate();
	  var month = X.getMonth();
	  X.setDate(date-1);
	  month = parseInt(X.getMonth())+1;
	  year = parseInt(X.getFullYear())+1;
	  date = parseInt(X.getDate());
	  
	  //Leap year check
		if (!isLeapYear(year))
		{
			if(month == 2 && date > 28)
				date = 28;
		}
		
	  var Y =String(month +"/"+ date +"/"+ year);
      var c= b+5;
      
      var NxtPymtDate = document.getElementById(c).value
		
		if (NxtPymtDate==null || NxtPymtDate=="")
			document.getElementById(c).value = Y;
			
      c = b+1;
      
      return;
     
    }
    

function  CheckDate3(ctlName,lblErrorMessage)
    {
	  
	  lblErrorMessage.innerHTML="";
	  var a=ctlName.name;
	  var b=a.substr(0,a.length-1)
	  var dt = document.getElementById(a).value;
	  var X = new Date(dt);
	  var year = X.getFullYear();
	  var date = X.getDate();
	  var month = X.getMonth();
	  X.setDate(date-1);
	  month = parseInt(X.getMonth())+1;
	  year = parseInt(X.getFullYear())+1;
	  date = parseInt(X.getDate());
	 //Leap year check	
		if (!isLeapYear(year))
		{
			if(month == 2 && date > 28)
				date = 28;
		}
		
	  var Y =String(month +"/"+ date +"/"+ year);
      var c= b+1;

	var endDate = document.getElementById(c).value;
	if (endDate==null || endDate =="")
			document.getElementById(c).value = Y;

      
    	c = b+2;

        c = b+3;

        c = b+4;

        c = b+5;

        c = b+7;

        c = b+8;
      
       var NxtPymtDate = document.getElementById(c).value
		
		if (NxtPymtDate==null || NxtPymtDate=="")
			document.getElementById(c).value = dt;			
           
    }
    
    

    

/*
--------------------------------------------------------------------------------
'Function Name :Add One Month5 for DateEntry in the Textboxes
 Writen by: Vamsi
 -------------------------------------------------------------------------------
*/


function GetMonth2(ctrl1,lblErrorMessage)
{
				
	var dtStr=ctrl1.value;
	var dtCh= "/";
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var strYr;
if( ValidateForm(ctrl1,lblErrorMessage)==true)
{
	if((strMonth=="3" || strMonth=="5" || strMonth=="8" || strMonth=="10" )&&(strDay=="31"))
	{
		strDay="30";
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		lblErrorMessage.innerHTML=" Date in  (MM/DD/YYYY)";
	}
	if((ctrl1.value!="")&&(strDay<=31 && strDay>=0) && (strMonth<=12 && strMonth >0 && strYear.length==4))
	{
	    lblErrorMessage.innerHTML="";
			if(parseInt(strMonth)==1 && parseInt(strDay)> 28)
			{
				if(parseInt(strYear)%4==0)
				{
					strDay="29";
				}
				else
				{
					strDay="28";
				}
			}
			if(strMonth<0 || strMonth>12)
			{
			lblErrorMessage.innerHTML="Enter Valid Month";
			}
			else
			{
				if(strMonth==12 )
				{
				strYear=parseInt(strYear)+1;
				strMonth="1";
				}
				else
				{
				strMonth=parseInt(strMonth)+1;
				}
			}
			if(strYear.length<4 || strYear.length>4 )
			{
				lblErrorMessage.innerHTML="Enter Valid Year";
			}
				dtStr=strMonth+dtCh+strDay+dtCh+strYear;
				
	}
    return true;
}
else
	{
	 return false;
	}    	

}



/*
--------------------------------------------------------------------------------
	'Function Name: IsNumeric
	'Description: Used to allow only numeric values
	'Input: SiteName, Error Message Label
	'Return: None
	'Written By: Swapna
	'Written date: 11-Feb-2005.
--------------------------------------------------------------------------------	
*/

function NumericCheck(ctlToValidate)

{
	
   var strValidChars = "0123456789";
   var strChar;
   var strString=ctlToValidate.value;
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      
		if (strValidChars.indexOf(strChar) == -1)
			{
				alert("Value should be numeric.")
				ctlToValidate.focus()				
				check=false;
				return true;
				break;
	        
			}			   
	  }
	       
   } 

}
/*
--------------------------------------------------------------------------------
	'Function Name: IsFloat
	'Description: Used to allow only decimal values
	'Input: SiteName, Error Message Label
	'Return: None
	'Written By: Swapna
	'Written date: 11-Feb-2005.
--------------------------------------------------------------------------------	
*/

function DecimalCheck(ctlToValidate)

{
	
   
   var strValidChars = "0123456789.";
   var strChar;
   var strString=ctlToValidate.value;
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0.00;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			alert("Value should be Decimal.")
			ctlToValidate.focus()
			check=false;
			
			break;
         }
         else
         {
			check=true;
			var val1=parseFloat(ctlToValidate.value)
			ctlToValidate.value=val1.toFixed(2)	
		  }
		   
	   }
	   	    
   } 

}
function ValidateDate(CtlToValidate)
{
	
	var strString = CtlToValidate.value
	
	if (strString=="1/1/0001")
	{
		strString =""
		CtlToValidate.value=""
		return true;
	}
	
	if (strString.length != 0 ) 
	{
		if (isDate1(CtlToValidate.value)==false)
		{
			CtlToValidate.focus()
			return false
		}
    return true
    }
 }
 
 
 
function ValidateDateSpan(CtlToValidate,ctlToPlace){
	
	//var dt=document.frmSample.txtDate
	
	 var myRegExp =/ /;
	//var ExpAmt=parseFloat(ctl1.value.replace(myRegExp,""))
	
	var strString = CtlToValidate.value.replace(myRegExp,"")
	
//	alert(strString)
	//ctlToPlace.innerHTML = "Invalid Date Formata."
	if (strString=="1/1/0001")
	{
		
		//alert(strString)
		strString =""
		CtlToValidate.value=""
		return true;
	}
	
	if (strString.length != 0 ) 
	{
		
		//alert(strString)
		//ctlToPlace.innerHTML = "Invalid Date Format."
		if (isDate(strString,ctlToPlace)==false)
		{
		
			//alert(strString)
			ctlToPlace.innerHTML = "Invalid Date Format."
			CtlToValidate.focus()
			return false
		}
		else
		{
			ctlToPlace.innerHTML = ""
		}
    return true
    }
 }
 
  function NumericCheckSpan(ctlToValidate,ctlToPlace)

{
	
   ctlToPlace.innerHTML=""
   var strValidChars = "0123456789";
   var strChar;
   var strString=ctlToValidate.value;
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      
		if (strValidChars.indexOf(strChar) == -1)
			{
				ctlToPlace.innerHTML="*Value should be numeric."
				ctlToValidate.focus()				
				check=false;
				return true;
				break;
	        
			}			   
	  }
	       
   } 

}

 
  function NegativeNumericCheckSpan(ctlToValidate,ctlToPlace)

{
	
   ctlToPlace.innerHTML=""
   var strValidChars = "0123456789-";
   var strChar;
   var strString=ctlToValidate.value;
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      
		if (strValidChars.indexOf(strChar) == -1)
			{
				ctlToPlace.innerHTML="*Value should be numeric/Negative numeric."
				ctlToValidate.focus()				
				check=false;
				return true;
				break;
	        
			}			   
	  }
	       
   } 

}

 
function DecimalCheckSpan(ctlToValidate,ctlToPlace)

{
	ctlToPlace.innerHTML=""
   var strValidChars = "0123456789.";
   var strChar;
   
   var myRegExp =/ /;
	//var ExpAmt=parseFloat(ctl1.value.replace(myRegExp,""))
	
   var strString=ctlToValidate.value.replace(myRegExp,"");
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0.00;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			ctlToPlace.innerHTML="*Value should be Decimal."
			ctlToValidate.focus()
			check=false;
			
			break;
         }
        else
         {
			
			ctlToPlace.innerHTML=""
			check=true;			
		  }
		   
	   }
	   	    
   } 
   
   if (check==true)
   {
		var val1=parseFloat(ctlToValidate.value)
		ctlToValidate.value=val1.toFixed(2)	
	}

}


function conversiontofloatAndSeperatorSpan(ctrl1,ctlToPlace)
{		
	
	var ctrlstr=ctrl1.value;
	
	var str1="";
	var str2="";
	var str="";
	var dot="0";
	var minus = "";
	
	
		ctlToPlace.innerHTML=""
		var strValidChars = "0123456789.-";
		var strChar;
   
		var myRegExp =/,/;
		var s = ctrl1.value;	
	
	var ctrlstr= replaceSubstring(ctrl1.value,",","") ;
    var strString=replaceSubstring(ctrl1.value,",","") ;
    var check = true;    
   
  if (strString.length == 0) 
	{
		ctrl1.value=0.00;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      
      if (strValidChars.indexOf(strChar) == -1)
         {
						
			check=false;					
			ctrl1.focus();		
			ctlToPlace.innerHTML="*Value should be Decimal."	
			break;
         }
         else
         {
			
			ctlToPlace.innerHTML=""
			check=true;
		  }
		   
	   }
	   	    
   } 
 
 if (check==true)
 {
   
	if(ctrlstr.length<1)
	{
	  ctrl1.value="0.00";
	}
	else
	{
	  for(var i=0; i<ctrlstr.length;i++)
	  {
	     var c = ctrlstr.charAt(i);
	     
	     if ((c == "-") && (i==0))
         {
           minus ="-";
         }
         
         if ((c >= "0") && (c <= "9") && (dot=="0"))
         {
           str1=str1+c;                    
         }
         else if(parseInt(dot)>2)
         {
			break;
         }
         else if((c >= "0") && (c <= "9") && (parseInt(dot) >0))
         {
			str2=str2 + c;
			dot=parseInt(dot)+1;
         }
         else if(c == ".")
         {
			dot=parseInt(dot)+1;
         }         
         
	  }
	if(str1.length <1)
	{
		str1="0";
	}
	else if(str1.length <=3)
	{}
	else
	{
	
	//--------
		var str11="";
		var c=""; 
		var ccount="0";
		var j = 0;
		
		var r = str1.length % 3;
		
		if (r!=0)
		{
			
			for (var i=0; i<r; i++)
			{
				c = c+str1.charAt(i);
			}
			c = c+ ",";
		
		}
		
		for ( var i = r ; i<str1.length ; i++)
		{
			
			c = c + str1.charAt(i);
			
			j = j+1 ;
			
			if ((j == 3) && (i<str1.length-1))
			{
				c = c + ",";
				j = 0;
			}
		}
		
		str1 = c;
		

	}
	str=str1+ "." + str2;
	if(str2.length==0)
		str=str + "00";
	else if(str2.length==1)
		str=str + "0";
		

	ctrl1.value= minus+str;
	
	}
 }
 else
 {
	ctrl1.focus();	
	ctrl1.select();	
	ctlToPlace.innerHTML="*Value should be Decimal."				
	
 }
	
}

function DateDifference(ctlTar,ctlAct,ctlDel,txtOutput)
{
	
	var txtTar = document.getElementById(ctlTar)
	var txtAct = document.getElementById(ctlAct)
	var txtDel = document.getElementById(ctlDel)
	var txtOutput = document.getElementById(txtOutput)
	
	if (txtTar!=null && txtAct!=null && txtDel!=null)
	{
	if (txtTar.value!="" && txtAct.value!="")
	{
		if (ValidateDateSpan(txtTar,txtOutput) && ValidateDateSpan(txtAct,txtOutput))
		{
			txtOutput.innerHTML="";						
			
			var TarDate = new Date(txtTar.value)
			var ActDate = new Date(txtAct.value)
			a = Math.round((ActDate -TarDate)/1000/60/60/24)
			txtDel.value = a;
			txtDel.disabled = true;
		}
		else
		{
			txtDel.value="";
			txtDel.disabled=true;
		}
	}
	else
	{
		txtDel.value="";
		txtDel.disabled=true;
	}
	}
}

function DecimalDifference(ctlTar,ctlAct,ctlDel,txtOutput)
{
	
	var txtTar = document.getElementById(ctlTar)
	var txtAct = document.getElementById(ctlAct)
	var txtDel = document.getElementById(ctlDel)
	var txtOutput = document.getElementById(txtOutput)
	
	if (txtTar!=null)
	{	
	if (txtTar.value!="")
	{

		txtTar.value = replaceSubstring(txtTar.value,",","");
		conversiontofloatAndSeperatorSpan(txtTar,txtOutput)
	}
	}
	
	if (txtOutput.innerHTML!="")
	    return;
	    
	if (txtAct!=null)
	{	
	if (txtAct.value!="")
	{

		txtAct.value = replaceSubstring(txtAct.value,",","");
		conversiontofloatAndSeperatorSpan(txtAct,txtOutput)
	}
	}
	
	if (txtOutput.innerHTML!="")
	    return;
	
	if (txtTar!=null && txtAct!=null && txtDel!=null)
	{	
	if (txtTar.value!="" && txtAct.value!="" )
	{							
			
			if (txtOutput.innerHTML=="")
			{
				
				if (txtOutput.innerHTML=="")
				{
				
					 var myRegExp =/,/;
				
				
					var TarValue = parseFloat(replaceSubstring(txtTar.value,",",""));
					var ActValue = parseFloat(replaceSubstring(txtAct.value,",",""));
					
					a = ActValue - TarValue
					txtDel.value = a
					txtDel.value = parseFloat(replaceSubstring(txtDel.value,",",""));
					conversiontofloatAndSeperator(txtDel,txtOutput)
					txtDel.disabled=true;
				}
				else
				{
				
					txtDel.value="";
					txtDel.disabled=true;
				}
			}
			else
			{
				txtDel.value="";
				txtDel.disabled=true;
			}
	}
	else
	{
		txtDel.value="";
		txtDel.disabled=true;
	}
 }
	
}

function DecimalDiff(ctlTar,ctlAct,ctlDel,txtOutput)
{
	
	var txtTar = document.getElementById(ctlTar)
	var txtAct = document.getElementById(ctlAct)
	var txtDel = document.getElementById(ctlDel)
	var txtOutput = document.getElementById(txtOutput)
	
	if (txtAct!=null)
	{	
	if (txtAct.value!="")
	{

		txtAct.value = replaceSubstring(txtAct.value,",","");
		conversiontofloatAndSeperatorSpan(txtAct,txtOutput)
	}
	}
	
	if (txtOutput.innerHTML!="")
	    return;
	
	if (txtTar!=null)
	{	
	if (txtTar.value!="")
	{

		txtTar.value = replaceSubstring(txtTar.value,",","");
		conversiontofloatAndSeperatorSpan(txtTar,txtOutput)
	}
	}
	
	if (txtOutput.innerHTML!="")
	    return;
	
	if (txtTar!=null && txtAct!=null && txtDel!=null)
	{	
	if (txtTar.value!="" && txtAct.value!="")
	{	
						
			if (txtOutput.innerHTML=="")
			{
				
				if (txtOutput.innerHTML=="")
				{
				
					 var myRegExp =/,/;
					
					var TarValue = parseFloat(replaceSubstring(txtTar.value,",",""));
					var ActValue = parseFloat(replaceSubstring(txtAct.value,",",""));
					
					
					a = ActValue - TarValue
					txtDel.value = a
					
					txtDel.value = parseFloat(replaceSubstring(txtDel.value,",",""));
					conversiontofloatAndSeperator(txtDel,txtOutput)
					txtDel.disabled=true;
				}
				else
				{
				
					txtDel.value="";
					txtDel.disabled=true;
				}
			}
			else
			{
				txtDel.value="";
				txtDel.disabled=true;
			}
	}
	else
	{
		txtDel.value="";
		txtDel.disabled=true;
	}
	}
}

function DaysRemaining(ctlTar,ctlDays, txtOutput)
{
	var txtTar = document.getElementById(ctlTar)
	var txtDays = document.getElementById(ctlDays)
	
	if (txtTar!=null)
	{
	if (txtTar.value!="")
	{
		if (ValidateDateSpan(txtTar,txtOutput))
		{
			txtOutput.innerHTML="";
			
			 var myRegExp =/ /;
			//var ExpAmt=parseFloat(ctl1.value.replace(myRegExp,""))
				
			
			var TarDate = new Date(txtTar.value.replace(myRegExp,""))
			var TodaysDate = new Date()
			a = Math.round((TarDate-TodaysDate)/1000/60/60/24)
			txtDays.value = a;
			txtDays.disabled = true;
			return;
		}
		else
		{
			txtDays.value="";
			txtDays.disabled=true;
		}
	}
	else
	{
		txtDays.value="";
		txtDays.disabled=true;
	}
	}
}

function replaceSubstring(inputString, fromString, toString) 
{     
	var temp = inputString;     
    if(fromString == "") 
    { 
		return inputString;     
    }        
     if (toString.indexOf(fromString) == -1)
     {  
		while(temp.indexOf(fromString) != -1) 
		{       
			var    toTheLeft = temp.substring(0, temp.indexOf(fromString));  
			var    toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);  
			temp = toTheLeft + toString + toTheRight;        
		}     
	} 
	    
	else    
	{ 
		var    midStrings = new Array("~", "`","_" ,"^" ,"#"); 
		var    midStringLen = 1   ;  
		var    midString = ""   ;        
		while(midString == "") 
		{
		for( var i=0; i < midStrings.length; i++) 
		{                 
			var    tempMidString = ""   ;         
			for(var  j=0; j < midStringLen; j++) 
			{ 
				tempMidString += midStrings[i]; 
			}              
			if(fromString.indexOf(tempMidString) == -1)
			{                 
				midString = tempMidString;                 
				i = midStrings.length + 1;              
			}           
		}        
		} 
		while(temp.indexOf(fromString) != -1) 
		{     
			var    toTheLeft = temp.substring(0, temp.indexOf(fromString)); 
			var    toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);     
			temp = toTheLeft + midString + toTheRight;        
		}     
		while(temp.indexOf(midString) != -1   ) 
		{               
			var    toTheLeft = temp.substring(0, temp.indexOf(midString));
			var    toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);           
			temp = toTheLeft + toString + toTheRight;        
		}
       
	} 
  
		  return  temp; 
    
}

function Decimal4Digits(ctlToValidate,ctlToPlace)
{
	ctlToPlace.innerHTML=""
   var strValidChars = "0123456789.";
   var strChar;
   var strString=ctlToValidate.value;
   var check = true; 
     
  if (strString.length == 0) 
	{
		ctlToValidate.value=0.0000;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			ctlToPlace.innerHTML="*Value should be Decimal."
			ctlToValidate.focus()
			check=false;
			
			break;
         }
         else
         {			
			    check=true;			 			
		  }		   
	   }
	   	    
   } 
   if(check==false)
    {
            ctlToPlace.innerHTML="*Value should be Decimal."
			ctlToValidate.focus()
    }
    else
    {
            ctlToPlace.innerHTML=" "
			 var val1=parseFloat(ctlToValidate.value)
			  ctlToValidate.value=val1.toFixed(4)	
    }

}
function openXML(ClientID,SiteRecordID,ExtractItem)
{
	var newwindow = window.open("ShowXML.aspx?ClientID="+ClientID + "&SiteRecordID="+SiteRecordID + "&ExtractItem="+ExtractItem, "DocumentViewer", "location=no,toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,fullscreen=no");
	
}

function opendoc(DocTypeID,DocID)
{
	var newwindow = window.open("ShowDocument.aspx?DocTypeID="+DocTypeID + "&DocID="+DocID, "DocumentViewer", "location=no,toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,fullscreen=no");
	
}

function openImage(ImageID)
{
	var newwindow = window.open("../ShowImage.aspx?ImageID="+ImageID + "&ImageType='ORIGINAL'", "ImageViewer", "location=no,toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes,fullscreen=no");
	
}
function openLogo(ClientID)
{
	var newwindow = window.open("../ShowLogo.aspx?ClientID="+ClientID + "&ImageType='ORIGINAL'", "ImageViewer", "location=no,toolbar=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes,fullscreen=no");
	
}
function openExcel(ClientID1, BegDateCtl, EndDateCtl)
{
	var BegDate = BegDateCtl.value;
	var EndDate = EndDateCtl.value;
	
	var newwindow = window.open("ShowExcel.aspx?ClientID="+ClientID1 + "&BegDate="+BegDate + "&EndDate="+EndDate , "DocumentViewer", "location=no,toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,fullscreen=no");		
}

function  SessionCheck(lblSession)
{	 
	 if (history.length>0)
	 {
		lblSession.innerHTML="Your Session has expired. Please Login again";
	}
	else
		lblSession.innerHTML="";	
}	 

function PreCallBack() 
{
			if (!confirm('You are about to delete the selected record and its associated records. Do you want to proceed?')) 
			{
				return false;
			}
			else
			{
			    return true;
			}
}

var TotalAllocPer=0

function calc(perAlloc,hidPerAlloc,TotalArea, AreaAlloc,rowCnt,strClientID)
 {
  
  var StrClientID=strClientID;
  var myRegExp =/,/;
  var vperAlloc =0;
  
  var strValidChars = "0123456789.";
  var strString= perAlloc.value.replace(myRegExp,"");
  
   myRegExp1 =/.00/;
   myRegExp2 =/%/;
  strString= perAlloc.value.replace(myRegExp1,"").replace(myRegExp2,""); 
  
   var check = true; 
   
   var strChar;
   var vperAlloc ;
   
   if (strString.length == 0) 
	{
		vperAlloc=0.00;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {     
      strChar = strString.charAt(i);
      
      if (strValidChars.indexOf(strChar) == -1)
         {						
			check=false;			
			
			document.getElementById(StrClientID+"_ErrorMsg").innerHTML="*Value should be Decimal."
			perAlloc.focus();	
			break;
         }
         else
         {			
			check=true;
		  }
		   
	   }
	   	    
   } 
  
  
  if(check==false)
  {     
        var perAllocVal = perAlloc.value
         document.getElementById(StrClientID+"_ErrorMsg").innerHTML="*Value should be Decimal."		         
         perAlloc.value =perAllocVal        		
  }
  else
  {                 
          if (perAlloc.value!="")
          {
          	//vperAlloc =parseFloat(perAlloc.value);       
            myRegExp1 =/.00/;
            myRegExp2 =/%/;
            var VAR1= perAlloc.value.replace(myRegExp1,"").replace(myRegExp2,"");
            vperAlloc =parseFloat(VAR1/100);
          }
          var vTotalArea = parseFloat(replaceSubstring(TotalArea.innerHTML,",",""));
          //var vAreaAlloc = Math.round(vperAlloc * vTotalArea*100)/100 ;          
          
          var vAreaAlloc =  (vperAlloc * vTotalArea).toFixed(2)
          AreaAlloc.value = vAreaAlloc ;
          hidPerAlloc.value = vperAlloc;
          var percAlloc = (vperAlloc *100).toFixed(2)         
          perAlloc.value = percAlloc + "%"                    
          
          TotalAllocPer =0
          var TotalAllocArea =0	
        		
	        for(var i=1;i<=rowCnt;i++)
	        {
		        var ctlName = StrClientID+ "_hidPerAlloc"+i+2;
		        TotalAllocPer = TotalAllocPer + parseFloat(document.getElementById(ctlName).value) ;
		        var ctlName1 = StrClientID+ "_txtAreaAlloc"+i+4;
		        TotalAllocArea = TotalAllocArea + parseFloat(replaceSubstring(document.getElementById(ctlName1).value,",","")) ;
        		
		        conversiontofloatAndSeperator1(ctlName1);
		        document.getElementById(ctlName1).disabled= true;
        		
	        }  
        	
	        var temp = TotalAllocPer*100
        	
           document.getElementById(StrClientID+ "_lblTotalAllocPer").innerHTML =temp.toFixed(2)+ "%" 
           document.getElementById(StrClientID+ "_lblUnAllocPer").innerHTML =(100-temp).toFixed(2)+ "%" 
          
           document.getElementById(StrClientID+ "_lblTotalAllocArea").innerHTML =TotalAllocArea.toFixed(2)
           document.getElementById(StrClientID+ "_lblUnAllocArea").innerHTML =(vTotalArea-TotalAllocArea).toFixed(2)
                   
           conversiontofloatAndSeperatorlbl(StrClientID+ "_lblTotalAllocArea")
	        conversiontofloatAndSeperatorlbl(StrClientID+ "_lblUnAllocArea")
        	
           return false;
   }
}

function ActAlloc(perAlloc,hidPerAlloc)
{    
    if(perAlloc.value =="")
    {
	    if(hidPerAlloc.value !="")
		    perAlloc.value = hidPerAlloc.value ;
	    else
		    perAlloc.value=0;
	}
}
function AreaCalc(rowCnt,strClientID)
{
	 var myRegExp =/,/;	 
	 TotalAllocPer = 0
	 var TotalAllocArea =0	
	 var StrClientID=strClientID;	 
	
	var vTotalArea = TotalAllocArea + parseFloat(replaceSubstring(document.getElementById(StrClientID+"_lblTotalSpace").innerHTML,",","")) ;
	
	for(var i=1;i<=rowCnt;i++)
	{
		var ctlName = StrClientID+"_hidPerAlloc"+i+2;
		TotalAllocPer = TotalAllocPer + parseFloat(document.getElementById(ctlName).value) ;
		var vperAlloc =parseFloat(document.getElementById(ctlName).value);
		var percAlloc = (vperAlloc *100).toFixed(2)
		
		var ctlName2 = StrClientID+"_txtPerAlloc"+i+3;
		document.getElementById(ctlName2).value = percAlloc + "%"
			
		
		 var vAreaAlloc =  (vperAlloc * vTotalArea).toFixed(2)
		var ctlName1 =StrClientID+ "_txtAreaAlloc"+i+4;
		
		document.getElementById(ctlName1).value = vAreaAlloc;
		
		TotalAllocArea = TotalAllocArea + parseFloat(replaceSubstring(document.getElementById(ctlName1).value,",","")) ;
		var AreaAlloc = parseFloat(document.getElementById(ctlName1).value).toFixed(2);		
		document.getElementById(ctlName1).value = AreaAlloc;
		
		conversiontofloatAndSeperator1(ctlName1);
		document.getElementById(ctlName1).disabled=true;
		
	}  
	
	var temp = TotalAllocPer*100
	
   document.getElementById(StrClientID+"_lblTotalAllocPer").innerHTML =temp.toFixed(2)+ "%" 
   document.getElementById(StrClientID+"_lblUnAllocPer").innerHTML =(100-temp).toFixed(2)+ "%" 
  
   document.getElementById(StrClientID+"_lblTotalAllocArea").innerHTML =TotalAllocArea.toFixed(2)
   document.getElementById(StrClientID+"_lblUnAllocArea").innerHTML =(vTotalArea-TotalAllocArea).toFixed(2)
   
	conversiontofloatAndSeperatorlbl(StrClientID+"_lblTotalAllocArea")
	conversiontofloatAndSeperatorlbl(StrClientID+"_lblUnAllocArea")

}

function conversiontofloatAndSeperatorlbl(ctrl1)
{
	
	var ctrlstr=document.getElementById(ctrl1).innerHTML;
	
	var str1="";
	var str2="";
	var str="";
	var dot="0";
	var minus = "";
	
	if(ctrlstr.length<1)
	{
	  document.getElementById(ctrl1).value="0.00";
	}
	else
	{
	  for(var i=0; i<ctrlstr.length;i++)
	  {
	     var c = ctrlstr.charAt(i);
	     
	     if ((c == "-") && (i==0))
         {
           minus ="-";
         }
         
         if ((c >= "0") && (c <= "9") && (dot=="0"))
         {
           str1=str1+c;                    
         }
         else if(parseInt(dot)>2)
         {
			break;
         }
         else if((c >= "0") && (c <= "9") && (parseInt(dot) >0))
         {
			str2=str2 + c;
			dot=parseInt(dot)+1;
         }
         else if(c == ".")
         {
			dot=parseInt(dot)+1;
         }         
         
	  }
	if(str1.length <1)
	{
		str1="0";
	}
	else if(str1.length <=3)
	{}
	else
	{
	
//	//--------
//		var str11="";
//		var c=""; 
//		var ccount="0";
//		if(str1.length % 2 ==0)//even
//		{
//			for(var i=0; i<str1.length;i++)
//			{
//				c = str1.charAt(i);
//				str11=str11 + c;
//				if(i%2==0)
//				{
//					if((str1.length-2)/2 >= ccount+1)
//					{
//						str11=str11+ ",";
//						ccount=parseInt(ccount)+ 1;
//					}
//				}
//			}
//		}
//		else if(str1.length % 2 ==1)//odd
//		{
//			for(var i=0; i<str1.length;i++)
//			{
//				c = str1.charAt(i);
//				str11=str11 + c;
//				if(i%2==1)
//				{
//					if((str1.length-2)/2 >= ccount+1)
//					{
//						str11=str11+ ",";
//						ccount=parseInt(ccount)+ 1;
//					}
//				}				
//			}
//		
//		}
//		
//		str1=str11;
//	//--------


        var str11="";
		var c=""; 
		var ccount="0";
		var j = 0;
		
		var r = str1.length % 3;
		
		if (r!=0)
		{
			
			for (var i=0; i<r; i++)
			{
				c = c+str1.charAt(i);
			}
			c = c+ ",";
		
		}
		
		for ( var i = r ; i<str1.length ; i++)
		{
			
			c = c + str1.charAt(i);
			
			j = j+1 ;
			
			if ((j == 3) && (i<str1.length-1))
			{
				c = c + ",";
				j = 0;
			}
		}
		
		str1 = c;
		
	}
	str=str1+ "." + str2;
	if(str2.length==0)
		str=str + "00";
	else if(str2.length==1)
		str=str + "0";
		
	//alert(str);
document.getElementById(ctrl1).innerHTML= minus+str;
	}
}


function conversiontofloatAndSeperator1(ctrl1)
{
	
	var ctrlstr=document.getElementById(ctrl1).value;
	
	var str1="";
	var str2="";
	var str="";
	var dot="0";
	var minus = "";
	
	if(ctrlstr.length<1)
	{
	  document.getElementById(ctrl1).value="0.00";
	}
	else
	{
	  for(var i=0; i<ctrlstr.length;i++)
	  {
	     var c = ctrlstr.charAt(i);
	     
	     if ((c == "-") && (i==0))
         {
           minus ="-";
         }
         
         if ((c >= "0") && (c <= "9") && (dot=="0"))
         {
           str1=str1+c;                    
         }
         else if(parseInt(dot)>2)
         {
			break;
         }
         else if((c >= "0") && (c <= "9") && (parseInt(dot) >0))
         {
			str2=str2 + c;
			dot=parseInt(dot)+1;
         }
         else if(c == ".")
         {
			dot=parseInt(dot)+1;
         }         
         
	  }
	if(str1.length <1)
	{
		str1="0";
	}
	else if(str1.length <=3)
	{}
	else
	{
	
	//--------
//		var str11="";
//		var c=""; 
//		var ccount="0";
//		if(str1.length % 2 ==0)//even
//		{
//			for(var i=0; i<str1.length;i++)
//			{
//				c = str1.charAt(i);
//				str11=str11 + c;
//				if(i%2==0)
//				{
//					if((str1.length-2)/2 >= ccount+1)
//					{
//						str11=str11+ ",";
//						ccount=parseInt(ccount)+ 1;
//					}
//				}
//			}
//		}
//		else if(str1.length % 2 ==1)//odd
//		{
//			for(var i=0; i<str1.length;i++)
//			{
//				c = str1.charAt(i);
//				str11=str11 + c;
//				if(i%2==1)
//				{
//					if((str1.length-2)/2 >= ccount+1)
//					{
//						str11=str11+ ",";
//						ccount=parseInt(ccount)+ 1;
//					}
//				}				
//			}
//		
//		}
//		
//		str1=str11;
	//--------
	
	
	var str11="";
		var c=""; 
		var ccount="0";
		var j = 0;
		
		var r = str1.length % 3;
		
		if (r!=0)
		{
			
			for (var i=0; i<r; i++)
			{
				c = c+str1.charAt(i);
			}
			c = c+ ",";
		
		}
		
		for ( var i = r ; i<str1.length ; i++)
		{
			
			c = c + str1.charAt(i);
			
			j = j+1 ;
			
			if ((j == 3) && (i<str1.length-1))
			{
				c = c + ",";
				j = 0;
			}
		}
		
		str1 = c;
		
	
	}
	str=str1+ "." + str2;
	if(str2.length==0)
		str=str + "00";
	else if(str2.length==1)
		str=str + "0";
		
	//alert(str);
document.getElementById(ctrl1).value= minus+str;
	}
}

function Check(HiddenCheck,strClientID)
{
	var StrClientID=strClientID;
	var a=0
	if (TotalAllocPer>1)
	{	
		document.getElementById(StrClientID+"_ErrorMsg").innerHTML="Total %Allocation should not be more than 100%";
		document.getElementById(StrClientID+"_txtPerAlloc13").focus();
		a = 0
	}
	else
	{
		a =1
	}
	var hidCheck = document.getElementById(StrClientID+"_HiddenCheck")
	hidCheck.value = a
	
}
			
function ConvertionToFloatValue1(rowCnt,StrClientID)
{
	
	for(var i=1;i<=rowCnt;i++)
	{
		var ctlName = StrClientID+ "_tr"+i+"c"+3;
	
	if(document.getElementById(ctlName).length<1)
	{
	  document.getElementById(ctlName).value="0.00";
	}
	
	}  	
}
	
function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal)
     {

        re = new RegExp(aspCheckBoxID)  //generated control	name starts with a colon

        for(i = 0; i < document.forms[0].elements.length; i++)
         {

            elm = document.forms[0].elements[i]

            if (elm.type == 'checkbox') {

                if (re.test(elm.name)) {

                    elm.checked = checkVal

                }
            }
        }
    }		
    
    
    
    //Added by Vijay
    
    
    
    function calcRevenueSharing(pPerc,pBasis,pMinRent,pMaxRent,pRevenueSharing)
 {
   var vBasis = 0.00;
   var vMinRent = 0.00;  
   var vMaxRent =  0.00;
   var vPerc = 0.00;
   vRevenueSharing =  0.00;

   vBasis = (pBasis.value <= 0) ? 0:pBasis.value;
   vMinRent =  (pMinRent.value <= 0) ? 0:pMinRent.value;
   vMaxRent =  (pMaxRent.value <= 0) ? 0:pMaxRent.value;
   vPerc = (pPerc.value <= 0) ? 0:eval(pPerc.value/100);
	
	
	 var myRegExp =/,/;
	 var n =0;
	 var i=1;
	 	
	n = parseInt((vBasis.length-3+1)/3)
	for(i=1; i<n; i++)
	{
		vBasis= replaceSubstring(vBasis,",","")
	}
	
	n = parseInt((vMinRent.length-3+1)/3)	
	for(i=1; i<n; i++)
	{
		vMinRent=replaceSubstring(vMinRent,",","")
	}
	
	n = parseInt((vMaxRent.length-3+1)/3)	
	for(i=1; i<n; i++)
	{
		vMaxRent=replaceSubstring(vMaxRent,",","")
	}
	
	
	n = parseInt((vPerc.length-3+1)/3)	
	for(i=1; i<n; i++)
	{
		vPerc=replaceSubstring(vPerc,",","")
	}
	
   vRevenueSharing=(((vBasis*vPerc) < vMinRent) ? 
	  0 :
	  ((vMaxRent==0) ? (vBasis * vPerc)- vMinRent : 
	  ((vBasis * vPerc) > vMaxRent) ?	
	  (vMaxRent - vMinRent):
          ((vBasis * vPerc)-(vMinRent))));

   pRevenueSharing.value = vRevenueSharing;
   return false;
}

function ConvertionToFloatValueRevenueSharing(rowCnt,StrClientID)
{
	
	for(var i=1;i<=rowCnt;i++)
	{
		var ctlName = StrClientID+ "_tr"+i+"c"+2;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";
	    
	    ctlName = StrClientID+ "_tr"+i+"c"+3;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";    
	      
	    ctlName = StrClientID+ "_tr"+i+"c"+4;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";
	      
	     ctlName = StrClientID+ "_tr"+i+"c"+5;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";
	      
	     ctlName = StrClientID+ "_tr"+i+"c"+7;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";
	
	}  	
	
}
    
 function calcScheduleCredits(pPerc,pBasis,pMinRent,pMaxRent,pRevenueSharing)
 {
   var vBasis = 0.00;
   var vMinRent = 0.00;  
   var vMaxRent =  0.00;
   var vPerc = 0.00;
   vRevenueSharing =  0.00;

   vBasis = (pBasis.value <= 0) ? 0:pBasis.value;
   vMinRent =  (pMinRent.value <= 0) ? 0:pMinRent.value;
   vMaxRent =  (pMaxRent.value <= 0) ? 0:pMaxRent.value;
   vPerc = (pPerc.value <= 0) ? 0:eval(pPerc.value/100);

   vRevenueSharing=(((vBasis*vPerc) < vMinRent) ? 
	  0 :
	  ((vMaxRent==0) ? (vBasis * vPerc)- vMinRent : 
	  ((vBasis * vPerc) > vMaxRent) ?	
	  (vMaxRent - vMinRent):
          ((vBasis * vPerc)-(vMinRent))));

   pRevenueSharing.value = vRevenueSharing;
   return false;
}

function ConvertionToFloatValueCredits(rowCnt,StrClientID)
{	
	
	for(var i=1;i<=rowCnt;i++)
	{
		var ctlName = StrClientID+ "_tr"+i+"c"+3;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";	    	   
	}  	
	
	
}
function ConvertionToFloatValueDeposites(rowCnt,StrClientID)
{
	
	for(var i=1;i<=rowCnt;i++)
	{
		var ctlName = StrClientID+ "_tr"+i+"c"+1;
	
	    if(document.getElementById(ctlName).length<1)	    
	      document.getElementById(ctlName).value="0.00";	   	  
	}  	
			
}	
function conversiontto6decimalplaces(ctrl1,ctlToPlace)
    {
	
	var ctrlstr=ctrl1.value;
	
	var str1="";
	var str2="";
	var str="";
	var dot="0";
	var minus = "";
	
	
		ctlToPlace.innerHTML=""
		var strValidChars = "0123456789.-";
		var strChar;
   
		var myRegExp =/,/;
		var s = ctrl1.value;	
	
	var ctrlstr= replaceSubstring(ctrl1.value,",","") ;
    var strString=replaceSubstring(ctrl1.value,",","") ;
    var check = true;    
   
  if (strString.length == 0) 
	{
		ctrl1.value=0.00;
		check=true;
	}
 else
   {
   for (i = 0; i<strString.length; i++)
      {
      strChar = strString.charAt(i);
      
      if (strValidChars.indexOf(strChar) == -1)
         {
						
			check=false;					
			ctrl1.focus();		
			ctlToPlace.innerHTML="*Value should be Decimal."	
			break;
         }
         else
         {
			
			ctlToPlace.innerHTML=""
			check=true;
		  }
		   
	   }
	   	    
   } 
 
 if (check==true)
 {
	
	var ctrlstr=ctrl1.value;
	var str1="";
	var str2="";
	var str="";
	var dot="0";
	var minus = "";
	
	if(ctrlstr.length<1)
	{
	  ctrl1.value="0.000000";
	}
	else
	{
	  for(var i=0; i<ctrlstr.length;i++)
	  {
	     var c = ctrlstr.charAt(i);
	     
	     if ((c == "-") && (i==0))
         {
           minus ="-";
         }
         
         if ((c >= "0") && (c <= "9") && (dot=="0"))
         {
           str1=str1+c;                    
         }
         else if((c >= "0") && (c <= "9") && (parseInt(dot) >0))
         {
			str2=str2 + c;
			dot=parseInt(dot)+1;
         }
         else if(c == ".")
         {
			dot=parseInt(dot)+1;
         }         
         
	  }
	if(str1.length <1)
	{
		str1="0";
	}
	else if(str1.length <=3)
	{}
	else
	{
	

		var str11="";
		var c=""; 
		var ccount="0";
		var j = 0;
		
		var r = str1.length % 3;
		
		if (r!=0)
		{
			
			for (var i=0; i<r; i++)
			{
				c = c+str1.charAt(i);
			}
			c = c+ ",";
		
		}
		
		for ( var i = r ; i<str1.length ; i++)
		{
			
			c = c + str1.charAt(i);
			
			j = j+1 ;
			
			if ((j == 3) && (i<str1.length-1))
			{
				c = c + ",";
				j = 0;
			}
		}
		
		str1 = c;
		
	}
	str=str1+ "." + str2;
	if(str2.length==0)
		str=str + "000000";
	else if(str2.length==1)
		str=str + "00000";
	else if(str2.length==2)
		str=str + "0000";
	else if(str2.length==3)
		str=str + "000";
	else if(str2.length==4)
		str=str + "00";
	else if(str2.length==5)
		str=str + "0";
	

ctrl1.value= minus+str;
	}
 }
 else
 {
    ctlToPlace.innerHTML="*Value should be Decimal."	
 }
}

function openMapURL(URLString)
{
	var newwindow = window.open(URLString, "Map Address", "location=no,toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,fullscreen=no");
	
}

var IsFormChanged = false;
function externalLinks() {
    
     if (!document.getElementsByTagName) return;		
	var hiddenFieldName="ctl00_ctl00_LeftContentPlaceHolder_bodyContentPlaceHolder_Navigate";		
	if (!document.getElementById(hiddenFieldName)) return;
	
      var elems = new Array();  
      var elems = document.forms[0].elements
    
        for (var j=0;j<elems.length;j++)
        {
            var elem = elems[j];
            
           
            if(elem.type=="text" || elem.type=="textarea" 
            || elem.type=="file")
            {                            
                 document.getElementById(elem.id).onchange=  FormChanged
            }
             if(elem.type=="password")
            {                            
                 document.getElementById(elem.id).onblur=  FormChanged
            }
            if(elem.type=="radio" )
            {                            
                 document.getElementById(elem.id).onclick =  FormChanged                        
            }
             if(elem.type=="checkbox" )
            {                     
                document.getElementById(elem.id).onclick =  FormChanged       
            }
        }
        
       if (event.srcElement.type=="select-one" || event.srcElement.type=="select-multiple" )
       {
            IsFormChanged=true 
       }
        if(event.srcElement.type=="checkbox" || event.srcElement.type=="radio" )            
        {
                IsFormChanged=true   
        }
  
	
	
	var hiddenFieldValue = document.getElementById(hiddenFieldName).value;
        
	var anchors = document.getElementsByTagName("a");
		
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];	   			
		   

    	    if ( (event.srcElement.type==null || event.srcElement.type=="" ) && anchor==event.srcElement && 
    	         (hiddenFieldValue=="false" && IsFormChanged==true) && 
    	          (anchor.id==null || anchor.id=="") )
    	    {     	    
               var agree= confirm("There are changes on the form.Would you like to save the changes or not?");                               
                if (agree)
                    return false;
                 else
                   return true;                  
            }
             if (  (event.srcElement.type==null || event.srcElement.type=="" ) && anchor==event.srcElement
             && hiddenFieldValue=="true" )
    	    {     	    
               alert("The changes are updated.");                               
            }
                        
		}
		 
		 if ( event.srcElement.type!="select-one" && event.srcElement.type!="select-multiple" &&
		 event.srcElement.type!="checkbox" && event.srcElement.type!="radio" )
       {
            IsFormChanged = false;
       }
        
		
}


function  FormChanged() 
{
    IsFormChanged =  true;    
}

function PostCallBack() 
{
	alert('The changes are Updated.')		
}


