var Moz = (document.getElementById&&!document.all)?1:0;
var IE = (document.getElementById&&document.all)?1:0;

//************************************************************************
//   Function for Check null
//   Input : ""
//   Output: true
//   Auther : Raj kishore 
//************************************************************************
function IsNullCheck(Ctlid,FieldName)
{  
   var return_value_textbox;
   if(trimAll(document.getElementById(Ctlid).value) == "")
   {       
       WarnForBlank(FieldName);       
       document.getElementById(Ctlid).focus();
       return_value_textbox = true;
   }
   return return_value_textbox;
}

//************************************************************************
//   Function for Check unselected in dropdownlist
//   Input : 
//   Output: true
//   Auther : Raj kishore 
//************************************************************************
function IsUnSelectCheck(Ctlid,FieldName)
{  
   var return_value_dropdownlist;
   if(document.getElementById(Ctlid).selectedIndex == 0)
   {       
       WarnForUnselect(FieldName);       
       document.getElementById(Ctlid).focus();
       return_value_dropdownlist = true;
   }
   return return_value_dropdownlist;
}
//************************************************************************
//   Function for Leap year and date month check
//   e.g.day in February / months containing 30 days only
//   Input : day,month,year
//  output : true - if invalid
//           false : if valid 
//   Auther : Raj kishore 
//************************************************************************

function isDateDropDown(Ctlid_Day,Ctlid_Month,Ctlid_Year){
	
	var strDay = document.getElementById(Ctlid_Day).value;
	var strMonth = document.getElementById(Ctlid_Month).value;
	var strYear = document.getElementById(Ctlid_Year).value;
	
	var intMonth = parseInt(strMonth);
	var intDay = parseInt(strDay);
	var return_date;
	//check days for 30 days month
	if(intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11 || strMonth == "4" || strMonth == "6" || strMonth == "9" || strMonth == "11")
	{
		
		if(intDay > 30)		
		return_date = true;
	}
	//check for February
	if(strMonth == "2")
	{
		var intYear = parseInt(strYear);
		var intday  = parseInt(strDay); 
		if( ( (intYear % 4) == 0 && !(intYear % 100) == 0) ||  ( (intYear % 100) == 0 && (intYear % 400) == 0))
		{
			if(intday > 29)			
			return_date = true;
		}
		else 
		{
		  if(intday > 28)
		  {		     
			 return_date = true;
		  }	 
		}
		
	}	
	return return_date;
}

//************************************************************************
//	Email Validation function
//  Input : str - string containing email address
//  output : true - if invalid
//           false : if valid 
//	
//************************************************************************
function emailcheck(Ctlid,FieldName)
{
        var strEmail = document.getElementById(Ctlid).value;        
        //var pattern =/^.+\@.+\..+$/;
        var return_value_email; 
        var pattern =/^[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]$/;
        
        if (!pattern.test(strEmail)) 
        {         
           WarnForInvalid(FieldName);
           document.getElementById(Ctlid).select();
           return_value_email = true;
        }
        return return_value_email;       
} 

//************************************************************************
//	Makes inputted data in proper case 

//	Author : Raj kishor  
//************************************************************************
function PCase(STRING)
{
        var strReturn_Value = "";
        var iTemp = STRING.length;
        if(iTemp==0){
            return "";
        }
        var UcaseNext = false;
        strReturn_Value += STRING.charAt(0).toUpperCase();
        for(var iCounter=1;iCounter < iTemp;iCounter++)
        {
            if(UcaseNext == true)
            {
                strReturn_Value += STRING.charAt(iCounter).toUpperCase();
            }
            else
            {
                strReturn_Value += STRING.charAt(iCounter).toLowerCase();
            }
        var iChar = STRING.charCodeAt(iCounter);
        if(iChar == 32 || iChar == 45 || iChar == 46)
        {
            UcaseNext = true;
        }
        else
        {
            UcaseNext = false
        }
        if(iChar == 99 || iChar == 67)
        {
            if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109)
            {
                UcaseNext = true;
            }
        }
        } //End For

        return strReturn_Value;
 } //End Function

//************************************************************************
//	Trim all space
//  Input : integer
//  output : true - if invalid
//          
//	
//************************************************************************
function trimAll(sString) 
{

    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;

}
//************************************************************************
//	Numeric Validation function
//  Input : integer
//  output : true - if invalid
//          
//	
//************************************************************************

function IsNumeric(Ctlid)
{
   
}

//************************************************************************
//	Address field Validation function
//  Input : integer
//  output : true - if invalid
//          
//	
//************************************************************************

function IsAddressCheck(Ctlid)
{
   
}

function IsAlphaNumeric(Ctlid)
{
    var str = document.getElementById(Ctlid).value;       
    if(str != "")     
    {   
    var pattern = /^[\sa-zA-Z0-9]+$/;
    if (!pattern.test(str)) 
    {         
      alert("Please enter alphabet and number only.");
       //document.getElementById(Ctlid).select();
       setTimeout("document.form1."+ Ctlid +".select()",1);
       return false;          
    
   }
   return true;
   }
}

function IsAlphaNumericwithMaster(Ctlid)
{
    var str = document.getElementById(Ctlid).value;       
    if(str != "")     
    {   
    var pattern = /^[\sa-zA-Z0-9]+$/;
    if (!pattern.test(str)) 
    {         
      alert("Please enter alphabet and number only.");
       document.getElementById(Ctlid).select();
       //setTimeout("document.form1."+ Ctlid +".select()",1);
       return false;          
    
   }
   return true;
   }
}

function isAlphabeticName(ctlid)
    {
        var str = document.getElementById(ctlid).value;
        if(str != "" && str != null)
        {
            var pattern = /^[\sa-zA-Z\"'".\s]+$/;
           
            
            if (!pattern.test(str)) 
            {         
               alert("Please enter alphabets only.");
               //document.getElementById(ctlid).select();
               setTimeout("document.form1."+ ctlid +".select()",1);
               return false;
            }
            return true;
        }
    }

function isAlphabeticNamewithMaster(ctlid)
    {
        var str = document.getElementById(ctlid).value;
        if(str != "")
        {
            var pattern = /^[\sa-zA-Z\"'".\s]+$/;
           
            
            if (!pattern.test(str)) 
            {         
               alert("Please enter alphabets only.");
               document.getElementById(ctlid).select();
               //setTimeout("document.form1."+ ctlid +".select()",1);
               return false;
            }
            return true;
        }
    }
//For Other Selection
function OtherOptionSelection(DropDownlistId,TextBoxID)
{
    if(document.getElementById(DropDownlistId).value == "Other")
    {
        document.getElementById(TextBoxID).style.display=''
    }
    else
    {
        document.getElementById(TextBoxID).style.display='none'
        document.getElementById(TextBoxID).value = "";
    }
}

    function IsMobile(ctrlid)
    {
    var ValidChars = "0123456789+";
    var sText=document.getElementById(ctrlid).value;
    var IsNumber=true;
    var Char; 
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
		      alert("Enter numbers only.");
		      //document.getElementById(ctrlid).select();
		      setTimeout("document.form1."+ ctrlid +".select()",1);
		      return false;
        }
    }
    return IsNumber; 
    }

function isIntegerCheck(ctrlid){
        var value = document.getElementById(ctrlid).value;
	    var i;
	    for (i = 0; i < value.length; i++){   
		    // Check that current character is number.
		    var c = value.charAt(i);
		    if (((c < "0") || (c > "9")))
		    {
		      alert("Enter numbers only.");
		      //document.getElementById(ctrlid).select();
		      setTimeout("document.form1."+ ctrlid +".select()",1);
		      return false;
		    }
	    }
	    // All characters are numbers.
	    return true;
    
    }
    
function isIntegerCheckWithMaster(ctrlid){
        var value = document.getElementById(ctrlid).value;
	    var i;
	    for (i = 0; i < value.length; i++){   
		    // Check that current character is number.
		    var c = value.charAt(i);
		    if (((c < "0") || (c > "9")))
		    {
		      alert("Enter numbers only.");
		      document.getElementById(ctrlid).select();
		      //setTimeout("document.form1."+ ctrlid +".select()",1);
		      return false;
		    }
	    }
	    // All characters are numbers.
	    return true;
    
    }    
    
    //Print Preview and Print in asp page
var ModalDialogWindow;
        var ModalDialogInterval;
        var ModalDialog = new Object;
        ModalDialog.value = '';
        
        function ModalDialogMaintainFocus()
        {
          try
          {
            if (ModalDialogWindow.closed)
             {
                window.clearInterval(ModalDialogInterval);
                eval(ModalDialog.eventhandler);       
                return;
             }
            ModalDialogWindow.focus(); 
          }
          catch (everything) {   }
         }         
         
        function ModalDialogRemoveWatch()
         {
           ModalDialog.value = '';
           ModalDialog.eventhandler = '';
         }        
         
		function getPrintDialogModel(print_area)
		{		
		   //debugger;
		   ModalDialogRemoveWatch();
		   var args='width=600,height=300,left=325,top=300,toolbar=0,';
             args+='location=0,status=0,menubar=1,scrollbars=1,resizable=1';  
           ModalDialogWindow=window.open("","",args); 
           //ModalDialogWindow.document.open();            
           ModalDialogWindow.document.write('<html>');
           ModalDialogWindow.document.write('<head>');
           ModalDialogWindow.document.write('<style media="screen,print" type="text/css">\n');
           //ModalDialogWindow.document.write('.noPrint{display: none;}\n');
           ModalDialogWindow.document.write('.noPrint{display: none;}\n');
           //ModalDialogWindow.document.write('.noPrint1{colspan:1;\n');
           ModalDialogWindow.document.write('body{margin-left:1px;margin-right:1px;padding:0;background-color: #FBFBFB;font-family: Arial;	font-size: 12px;vertical-align:top;	text-align:left;width: 750px;}\n');
           ModalDialogWindow.document.write('table{	font-family: Arial;	font-size: 12px; border-width: 1px;	border-color: #000000;}\n');
           ModalDialogWindow.document.write('td{font-family: Arial;	font-size: 12px; border-width: 1px; border-color: #000000; }\n');
	       ModalDialogWindow.document.write('th{font-family: Arial;	font-size: 12px; font-weight: normal; background-color: #F8A863; color: #000000; border-width: 1px; text-align: center; border-color: #000000; }\n');
	       ModalDialogWindow.document.write('\n');
           ModalDialogWindow.document.write('</style>\n');
           ModalDialogWindow.document.write('<style media="print" type="text/css">\n');
	       //ModalDialogWindow.document.write('th{font-family: Arial;	font-size: 12px; font-weight: normal; background-color: #F8A863; color: #000000; border-width: 1px; text-align: center; border-color: #000000; }\n');
           ModalDialogWindow.document.write('\n');
           ModalDialogWindow.document.write('</style>\n');
//           ModalDialogWindow.document.write('<title> PrintPreview </title>');
           ModalDialogWindow.document.write('<script language="JavaScript">');
           ModalDialogWindow.document.write('function CloseForm(Response) ');
           ModalDialogWindow.document.write('{ ');
           ModalDialogWindow.document.write(' window.opener.ModalDialog.value = Response; ');
           ModalDialogWindow.document.write(' window.close(); ');
           ModalDialogWindow.document.write('} ');
           ModalDialogWindow.document.writeln(' ');
           ModalDialogWindow.document.writeln('var test = true;');
           ModalDialogWindow.document.write('</script>');
           ModalDialogWindow.document.write('<base target="_self">');        
           ModalDialogWindow.document.write('</head>');   
           ModalDialogWindow.document.write('<body onblur="if(test) {self.focus();}" onfocus="test=true;">');           
           ModalDialogWindow.document.write('<form  method="post">');
		   ModalDialogWindow.document.write('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:test=false; window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
		   ModalDialogWindow.document.write(document.getElementById(print_area).innerHTML);
		   ModalDialogWindow.document.write('</form></body></HTML>');   
		   ModalDialogWindow.document.close(); 
           ModalDialogWindow.focus(); 
           //ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5);
        }   