//this function is used to check whether only one check box is checked
	function OpenWindow(page)
	 {
		OpenWin = this.open(page, "CtrlWindow3", "top=110,left=30,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
		}


function selectOne()
		 {
			var blnResult;
		 	var ml = document.forms[0];
		    var len = ml.elements.length;	
		    blnResult = 0;
			for(var i = 0 ; i < len ; i++) 
					{
						var e=ml.elements[i];
						if (e.type == "checkbox" &&  e.checked == true )
						{
							if (blnResult == 0)
							{
								blnResult = 1;
							}
							else
							{
								return false;
							}
						}
					}
			if (blnResult == 1 )
			{
				return true;
			}
		}
		



//this function is used to check all or uncheck all the check box when a CHECK ALL check box is checked
function select_deselectAll()
		 {
		 	var ml = document.forms[0]
		    var len = ml.elements.length	
		    if (ml.chkall.checked)
				{
					for(var i = 0 ; i < len ; i++) 
							{
								var e=ml.elements[i];
								if (e.type == "checkbox" &&  !(e.id=="chkall") )
								{
									e.checked= true;
								}
							}
				}			
			else
			    {
					for(var i = 0 ; i < len ; i++) 
							{
								var e=ml.elements[i];
								if (e.type == "checkbox" &&  !(e.id=="chkall") )
								{
									e.checked= false;
								}
							}
			    }	 
		 }


//This function checks if the check box have been checked for deletion

function checknone()
		{
			var ml = document.forms[0];
		    var len = ml.elements.length;	
			for(var i = 0 ; i < len ; i++) 
				{
					var e= ml.elements[i];
					if (e.type == "checkbox" && e.checked && !(e.name=="chkall")  ) 
					{
						return true;
					}
				}
			return false;
		}
		
//This function is called when the delete button is pressed
		function confirmDelete(title)
		{
		 var ml = document.forms[0];
		 var len = ml.elements.length;
			if (false==checknone()) 
				{
					NMalert("Atleast one " + title + " has to be selected for Deletion");
					return false;
				}
			else
				{
					if (confirm("Are you sure you want to Delete?"))
					{
						return true;
					}
					else
					{
						for(var i = 0 ; i < len ; i++) 
							{
								var e=ml.elements[i];
								if (e.type == "checkbox" && e.checked)
								{
									e.checked= false;
								}
							}
							return false;
					}
				}
		  }

function strCurrentDate()
{
	var intmonth
	dtValue=new Date()
	intmonth=dtValue.getMonth()+1
	return intmonth + "/" + dtValue.getDate()+ "/" + dtValue.getFullYear() + " " + dtValue.getHours() + ":" + dtValue.getMinutes() + ":" + dtValue.getSeconds()
}

// date validation  for dd/mm/yyyy. <---START HERE---> 

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=3000;

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 isDate(dtStr)
    {
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=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){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

// date validation  for dd/mm/yyyy. <---END HERE---> 




//this function check the given value is decimal
function isDecimal(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (oRegExp.test(strString))
    {

         return true;
    }
    else
    {
   
   return false;
    }
}




//this function check the given value as correct no.of.days
/*function isNoDays(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}
*/

//this function check the given value is decimal
function isAmount(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (strString > 99999999999999999.99)
{
 return false;
}


if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}


//this function check the given value is decimal
function isNoDays(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (strString > 999.9)
{
 return false;
}


if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3  || strString.indexOf(".") == strString.length - 2 || strString.indexOf(".") == strString.length)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}


//this function check the given value is Email
function isEmail(strEmail)
{
var oRegExp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/g;
if (oRegExp.test(strEmail))
    {

         return true;
    }
    else
    {
   
   return false;
    }
}

//this function used to check the value to be empty
function isEmpty(strString)
{
if (((strString == null) || (strString.length == 0)))
{
	return true;
}
else
{
var strLen= strString.length;
var intLen=0;
	for(intLenIndex=0; intLenIndex < strLen ; intLenIndex++)
	{
		if(strString.charAt(intLenIndex)==" ")
		{
			//strString.IsValid = false;			 
			intLen=intLen+1;
		}
	}	    
	
	if (intLen==strString.length)
	{
			return true;
	}		
	else
	{	
		return false;
	}
}
}


//this function check the given value is number
function isNumber(strString)
{

var oRegExp = /(^-?\d\d*$)/;

if (oRegExp.test(strString))
    {

         return true;
    }
    else
    {
   
   return false;
    }
}


// phone number Validation <--START HERE -->

// Declaring required variables
var digits = "0123456789";

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ,";

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//Open a new URL
 function vOpen(strUrl)
			{
				window.open(strUrl) 
			}

function isPhone(strPhone)
{
	var cnt=0;
	s=stripCharsInBag(strPhone,phoneNumberDelimiters);
	if (isInteger(s))
	{
		if ((isSpecial(strPhone.charAt(0),"(")==false) && (isNumber(strPhone.charAt(strPhone.length-1))==true) )
			{
				for (i = 0; i < strPhone.length; i++)
				{
						if (strPhone.charAt(i)=="(") {cnt++;}
						if (strPhone.charAt(i)==")") {cnt--;}
				}				
				if (cnt==0)
					{return true;}
				else 
					{return false;}
			}
		else
			{
				return false;
			}
	}
	else
	{
		return false;
	}		
	
}


// phone number Validation <--END HERE -->


//this function used to check the positive decimal value
function isPositiveDecimal(strString)
{
	var blnReturn;
  	if (parseFloat(strString)>=0)
	{
		blnReturn =true;
	}
	else
	{
		blnReturn=false;
	}

return blnReturn;
}


//This function will check for blank spaces 
function isSpace(strString)
{	
	var strLen= strString.length; 	
	var blnReturn;
	blnReturn = true;
	for(intLenIndex=0; intLenIndex < strLen ; intLenIndex++)
	{
		if(strString.charAt(intLenIndex)==" ")
		{
			//strString.IsValid = false;			 
			blnReturn =false; 
		}
	}	    
	return blnReturn;  
}


//This function will check whether it contains any special characters with given chars
function isSpecial(strString,strSplChar)
{
  var blnReturn;
  var strFound;
  blnReturn=false;
  var strvalue;
   
  strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + strSplChar;
  
  for (intLoop=0;intLoop<strString.length;intLoop++)
  	{
		
	   if ((strvalue.indexOf(strString.charAt(intLoop)))<0)
	   		{ 
				blnReturn=true;
			}
	}
	return blnReturn;
}

//This function will check whether it contains any special characters with given chars
function isChar(strString,strSplChar)
{
  var blnReturn;
  var strFound;
  blnReturn=false;
  var strvalue;
     
  strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + strSplChar;
    
  for (intLoop=0;intLoop<strString.length;intLoop++)
	{
		
	   if ((strvalue.indexOf(strString.charAt(intLoop)))<0)
			{ 
				blnReturn=true;
 			}
	}
	return blnReturn;
}



//function to get the current date
function currentdate()
	    {
		  	 datX=new Date();
			 datY=new String(new Date());
					
			if (navigator.appName=="Netscape")
				{
							if (parseFloat(navigator.appVersion.substring(0,3))>4.01)
							{
								thisYear=parseInt(datY.substring(51,55))
							}
							else
							{
								thisYear=datX.getYear();
							}
				}
				else
				{
						thisYear=datX.getYear();
				}
			thisMonth=datX.getMonth()+1;
			thisDate=datX.getDate();
		  return ((thisDate+'/'+thisMonth+'/'+thisYear));
	    }		


//Date Comparison
function datecompare(arguments1, arguments2,arguments3)
		{
		 // to check date1 as valid Date
		    dategiven=arguments1;
	        datX=new Date();
			datY=new String(new Date());
			
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
		
			d1=Date.UTC(year,month,day,0,0,0,0)
			// check for second date
			dategiven=arguments2;
					datX=new Date();
					datY=new String(new Date());
						
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
			
			d2=Date.UTC(year,month,day,0,0,0,0)
							
						
			// check for date 
			if (arguments3 == "<" )
				{
					if(d1<d2)
						{ return  true;	}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '<=' )
				{
					if(d1<=d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '>' )
				{
					if(d1>d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '>=' )
				{
					if(d1>=d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
							
			if (arguments3 == "=" )
				{
					if(d1==d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
							
		  return false;  
		 
			}

//Clear all Controls in the page
	function clear()
			{
			  var blnchk 
			  blnchk=true;
			   var ml = document.forms[0]  
			  var len = ml.elements.length
			  for(var i = 0 ; i < len ; i++) 
				{ 
					var e=ml.elements[i];
					if ((e.type == "text") || (e.type=="textarea")) 
					{ 
						e.value=""
					}
					
					if (e.type == "select-one" ) 
					{ 
						e.value=0;
					}
					if (e.type == "checkbox" ) 
					{ 
					   e.checked=false;
					}
					
					if (e.type == "radio" )
					{
						if(blnchk==true)
						{
							e.checked=true;
							blnchk=false;
						}
						else
						{
							e.checked=false;
						}
					}
				}
  			}
  			
// This function will return the Selected Date to the CtrlName Control.
 function GetDate(CtrlName)
 {
	ChildWindow = window.open('../calendar/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar", "width=232,height=198,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no,minimize=no,maximise=no");    
 }
 
 
//This is used to check the currency format 
 function currencyCheck(mystr)
{
	var blnreturn;
	   	
	var c=Number(0);
	
	for(i=0;i<mystr.length;i++)
	{
		if(mystr.charAt(i)==".")
		{
			c=c+1;
				
		}
	}
	if(c>1)
	{
		return true
	}
	else
	{
		  	if ((mystr.charAt(0)==".") || (mystr.charAt(mystr.length-1)==".") )
   			{
     		//return bln=true;
				return true
			}
		  	else
   			{
				subs=mystr.substr(mystr.indexOf("."));
				if(subs.length>3)
					return true
				else
					return false
			}
	}
	
}

 
 
 
 // This function will limit the maxlength for a TextArea.it will be used like this, in Textbox tag
// onKeyDown="maxlength(document.forms[0].field,250)" onKeyUp="maxlength(document.forms[0].field,250)"
function maxlength(field,maxlimit)
			{
				if (field.value.length > maxlimit)
				field.value = field.value.substr(0, maxlimit);
			}
 
 
 
 
//This is used to Display Error Messages
   
        var  popupLoadpopupHgt, popupLoadactualHgt, popupLoadtmrId=-1, popupLoadresetTimer;
        var popupLoadtitHgt, popupLoadcntDelta, popupLoadtmrHide=-1, popupLoadhideAfter=4000, popupLoadhideAlpha;	
		var popupLoadhasFilters=true;
        var popupLoadnWin, popupLoadshowBy=null, popupLoaddxTimer=-1;
        var popupLoadnText,popupLoadnMsg,popupLoadnTitle,popupLoadbChangeTexts=false;

        
function NMalert(msg)
{
	if (navigator.appName=="Netscape")
	{
		alert(msg);
	}
	else
	{
		
		document.getElementById('popupLoad_content').innerHTML= '<br><br>' + msg;
		popupLoadespopup_winLoad();
	}
}


function popupLoadespopup_winLoad()
        {
          elCnt=document.getElementById('popupLoad_content')
          elTit=document.getElementById('popupLoad_header');
          el=document.getElementById('popupLoad');

          popupLoadtitHgt=elTit.style.height.substr(0,elTit.style.height.length-2);
          popupLoadpopupHgt=el.style.height;
          popupLoadpopupHgt=popupLoadpopupHgt.substr(0,popupLoadpopupHgt.length-2); popupLoadactualHgt=0;
          popupLoadcntDelta=popupLoadpopupHgt-(elCnt.style.height.substr(0,elCnt.style.height.length-2));

          if (true)
          {
            popupLoadresetTimer=true;
           popupLoadespopup_ShowPopup(null);
          }
        }


  function popupLoadespopup_ShowPopup(show)
        {
          if (popupLoaddxTimer!=-1) { el.filters.blendTrans.stop(); }

          if ((popupLoadtmrHide!=-1) && ((show!=null) && (show==popupLoadshowBy)))
          {
            clearInterval(popupLoadtmrHide);
            popupLoadtmrHide=setInterval(popupLoadespopup_tmrHideTimer,popupLoadhideAfter);
            return;
          }
          popupLoadshowBy=show;

          elCnt=document.getElementById('popupLoad_content')
          elTit=document.getElementById('popupLoad_header');
          el=document.getElementById('popupLoad');
          el.style.filter='';

          if (popupLoadtmrId!=-1) clearInterval(popupLoadtmrId); popupLoadtmrId=-1;
          if (popupLoadtmrHide!=-1) clearInterval(popupLoadtmrHide); popupLoadtmrHide=-1;

          document.getElementById('popupLoad_header').style.display='none';
          document.getElementById('popupLoad_content').style.display='none';

          if (popupLoadbChangeTexts)
          {
            popupLoadbChangeTexts=false;
            document.getElementById('popupLoadaCnt').innerHTML=popupLoadnMsg;
            document.getElementById('popupLoadtitleEl').innerHTML=popupLoadnTitle;
          }

          popupLoadactualHgt=0; el.style.height=popupLoadactualHgt+'px';
          el.style.visibility='';
          if (!popupLoadresetTimer) el.style.display='';
          popupLoadtmrId=setInterval(popupLoadespopup_tmrTimer,(popupLoadresetTimer?10:20));
        }

	function popupLoadespopup_tmrTimer()
        {
          el=document.getElementById('popupLoad');
          if (popupLoadresetTimer)
          {
            el.style.display='';
            clearInterval(popupLoadtmrId); popupLoadresetTimer=false;
            popupLoadtmrId=setInterval(popupLoadespopup_tmrTimer,20);
          }
          popupLoadactualHgt+=5;
          if (popupLoadactualHgt>=popupLoadpopupHgt)
          {
            popupLoadactualHgt=popupLoadpopupHgt; clearInterval(popupLoadtmrId); popupLoadtmrId=-1;
            document.getElementById('popupLoad_content').style.display='';
            if (popupLoadhideAfter!=-1) popupLoadtmrHide=setInterval(popupLoadespopup_tmrHideTimer,popupLoadhideAfter);
          }
          if (popupLoadtitHgt<popupLoadactualHgt-6)
            document.getElementById('popupLoad_header').style.display='';
          if ((popupLoadactualHgt-popupLoadcntDelta)>0)
          {
            elCnt=document.getElementById('popupLoad_content')
            elCnt.style.display='';
            elCnt.style.height=(popupLoadactualHgt-popupLoadcntDelta)+'px';
          }
          el.style.height=popupLoadactualHgt+'px';
        }
 
 function popupLoadespopup_tmrHideTimer()
        {
          clearInterval(popupLoadtmrHide); popupLoadtmrHide=-1;
          el=document.getElementById('popupLoad');
          if (popupLoadhasFilters)
          {
            backCnt=document.getElementById('popupLoad_content').innerHTML;
            backTit=document.getElementById('popupLoad_header').innerHTML;
            document.getElementById('popupLoad_content').innerHTML='';
            document.getElementById('popupLoad_header').innerHTML='';
            el.style.filter='blendTrans(duration=1)';
            el.filters.blendTrans.apply();
            el.style.visibility='hidden';
            el.filters.blendTrans.play();
            document.getElementById('popupLoad_content').innerHTML=backCnt;
            document.getElementById('popupLoad_header').innerHTML=backTit;
            
            popupLoaddxTimer=setInterval(popupLoadespopup_dxTimer,1000);
          }
          else el.style.visibility='hidden';
        }

function popupLoadespopup_dxTimer()
        {
          clearInterval(popupLoaddxTimer); popupLoaddxTimer=-1;
        }

function popupLoadespopup_Close()
        {
          if (popupLoadtmrId==-1)
          {
            el=document.getElementById('popupLoad');
            el.style.filter='';
            el.style.display='none';
            if (popupLoadtmrHide!=-1) clearInterval(popupLoadtmrHide); popupLoadtmrHide=-1;
            
          }
        }

