//Java Script

//Cursor postion insert for text area
function insertAtCursor(myField, myValue)
{
	myField.focus();
	var sel = document.selection.createRange();
	sel.text = myValue;
	
}
//End


// Restrict Text Area to enter text beyond MaxLen 
function ChkTextAreaMaxLength(Control, MaxLen)
{
  return (Control.value.length <= MaxLen);
}
// End


//Checking Blank value
function isBlank(strControl)
{
    var vControl=document.getElementById(strControl);   
    
    if(vControl.value == '' || vControl.value == null)
    {
        alert(BLANK_STRING);
        vControl.focus();
        return 0;
    }
    return 1;
}
//End Blank Validation

//Checking Numeric value
function isNumeric(strControl)
{
    var chkStr = '1234567890.';
    var vControl=document.getElementById(strControl);
    var strValue = vControl.value;
    
    if(! isBlank(strControl))
        return 0;

    for(i=0 ; i < strValue.length ; i++)
        if(chkStr.indexOf(strValue.charAt(i).toUpperCase()) == -1)
        {
            alert("Invalid Number");
            return 0;
        }
    return 1;
}
//End Checking Numeric value

//Checking String value
function isString(strControl,nMinLength,nMaxLength)
{
    var chkStr;
    var vControl=document.getElementById(strControl);
    if(! isBlank(strControl))
        return false;
    if(vControl.length < nMinLength)
    {
        alert(MIN_LENGTH_REQUIRE + nMinLength );
        return false;
    }   
    if(vControl.length > nMaxLength)
    {
        alert(MAX_LENGTH_REQUIRE + nMaxLength );
        return false;
    }   
    return true;
}
//End Checking String value

//Hover for Button
function HoverMe(theControl)
{
    
    theControl.style.borderStyle='groove'; 
    theControl.style.cursor='pointer';   
}
//End

//UndoHover for Button
function UndoHoverMe(theControl)
{
    
    theControl.style.borderStyle='solid';   
    theControl.style.cursor='auto';
}
//End


//Check Number

function checkNumber(e)
{
	var numbers = '01234567890';

	e = window.event;
	obj = e.srcElement;
	e.cancelBubble = true;
		if ((numbers.search(String.fromCharCode(e.keyCode))==-1))
			e.returnValue = false;
}
//End

//Check Numeric

function checkNumeric(e)
{
	e = window.event;

	if(e.keyCode < 48 || e.keyCode > 57)   
      {
      	e.returnValue = false;
      } 
}
//End

//Check Time Numeric

function checkTimeNumeric(e)
{
	e = window.event;

	if(e.keyCode < 48 || e.keyCode > 58)   
      {
      	e.returnValue = false;
      } 

}
//End

// Time Validation
function timeValidate(strTime)
{
    var strArray = strTime
                
    var strIp = strArray.split(":");
        
    var strIpLength = strIp.length   
      
    if(strIpLength > 3)
    {
		alert("Incorrect Time format")
		return false
    }    

    var strIpSub="";
    var strHrMin="";
        
    for (var i=0 ; i<3 ; i++)
    {
	   	strIpSub = strIp[i]

        if(strIpSub.length > 3)
        {
            return false		
        }
            
        if(i==0)
        {
            strHrMin=23
        }    
        else
        {
            strHrMin=59  
        }  
            
        if(strIpSub>=0 && strIpSub<=strHrMin)
        {

        }
        else 
        {
           // alert("Invalid Time format")
            return false
        }
    }
    return true;
}
// End

// Time Compare Function

function timeCompare(strTime1, strTime2)
{
        var strArray1 = strTime1
        var strArray2 = strTime2
                
        var strIp1 = strArray1.split(":");
        var strIp2 = strArray2.split(":");
    	
                
        var check="false"
        var check1="false"

	  if(strIp1[0]<strIp2[0])
        {
            return true;
        }    
	  else if(strIp1[0]==strIp2[0])
	  {
            check="true";
	  }
	  else
        {
            alert("From Time cannot be greater than To Time")
            return false;
	  }

if(check)
{
     	if(strIp1[1]<strIp2[1])
	{
	      return true;
	}
	else if(strIp1[1] == strIp2[1])
	{
		check1="true";
	}
	else
	{
		alert("From Time cannot be greater than To Time")
		return false;
	}
}

if(check1)
{
	if(strIp1[2]<strIp2[2])
	{
    		return true;
	}
	else if(strIp1[2] == strIp2[2])
	{	
                alert("From Time & To Time are equal")
	        return false;	
	}
	else
	{
		alert("From Time cannot be greater than To Time")
		return false;	
	}
}		
        check="false"
        check1="false"	

        return true;
}

// End

// Check String 
// For Alpabet --------- checkString(e, true, false, '')
// For Alpabet With Space --------- checkString(e, true, false, ' ')
// For Email --------- checkString(e, true, false, '@.')
// For Number --------- checkString(e, false, true, '')
// For Decimal Number --------- checkString(e, false, true, '.')
// For Address --------- checkString(e, true, false, '_-@. ')
// For only number----------checkStringAdv(e,false,true,'')
function checkStringAdv(e, allowAlpha, allowNum, specialChar)
{
	var checkStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';

	e = window.event;

	obj = e.srcElement;

        if(specialChar=="" && e.keyCode == 46)
        {
            e.returnValue = false;
        }

        if ((specialChar.search(String.fromCharCode(46))==1))    // For Space " . "
            e.returnValue = false;

	  if ((specialChar.search(String.fromCharCode(32))==1))    // For Space " "
            e.returnValue = true;

        if(e.keyCode == 8 || e.keyCode == 13 || e.keyCode == 3 || e.keyCode == 22 || e.keyCode == 26)
        {

            e.returnValue = false;
        }

        if(allowAlpha && allowNum)
        {
            if(specialChar!="")
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" + specialChar
            }
            else
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
            }
        }
        else if(allowAlpha)
        {
            if(specialChar!="")
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + specialChar
            }
            else
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
            }
        }
        else if(allowNum)
        {
            if(specialChar!="")
            {
                checkStr = "1234567890" + specialChar
            }
            else
            {
                checkStr = "1234567890"
            }
        }
        else
        {
            checkStr = specialChar
        }

        if(checkStr=="")
        {
            e.returnValue = true;
        }

        var varChar=String.fromCharCode(e.keyCode);

	e.cancelBubble = true;
   if((checkStr.indexOf(varChar, 0))>-1)
{
   // alert(true)
    e.returnValue = true;
    return
}

e.returnValue = false;
}

function checkString(e, allowAlpha, allowNum, specialChar)
{
	var checkStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';

	e = window.event;
         
	obj = e.srcElement;
	        
        if(specialChar=="" && e.keyCode == 46)
        {
            e.returnValue = false;
        }    
           
        if ((specialChar.search(String.fromCharCode(46))==1))    // For Space " . "
            e.returnValue = false;
        
	  if ((specialChar.search(String.fromCharCode(32))==1))    // For Space " "
            e.returnValue = true;

        if(e.keyCode == 8 || e.keyCode == 13 || e.keyCode == 3 || e.keyCode == 22 || e.keyCode == 26)
        {

            e.returnValue = false;
        } 
        
        if(allowAlpha && allowNum)
        {    
            if(specialChar!="")
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" + specialChar
            }    
            else
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
            }        
        }
        else if(allowAlpha)
        {    
            if(specialChar!="")
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + specialChar
            }    
            else
            {
                checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
            }  
        }    
        else if(allowNum)
        {    
            if(specialChar!="")
            {
                checkStr = "1234567890" + specialChar
            }    
            else
            {
                checkStr = "1234567890"
            }    
        }    
        else
        {
            checkStr = specialChar
        }    
        
        if(checkStr=="")
        {
            e.returnValue = true;
        }    
               
	e.cancelBubble = true;
		if ((checkStr.search(String.fromCharCode(e.keyCode))==-1))
			e.returnValue = false;
        
}

// end

//For Active Button
function changeImgButton(theControl,tempImg)
{
	theControl.style.cursor='pointer';   
	theControl.style.backgroundImage="url('images/"+tempImg+"')";
}
//End

//For Page Loading
function hideLoadingPage() 
{ 

	if (document.getElementById)
	{
	 // DOM3 = IE5, NS6 
	 
	 document.getElementById('hidepage').style.visibility = 'hidden'; 
	} 
	else
	{

		if (document.layers) 
		{
			// Netscape 4 
		  document.hidepage.visibility = 'hidden'; 
		} 
		else
	    { 
			// IE 4 
		  document.all.hidepage.style.visibility = 'hidden'; 
		} 
	} 
}

//For Page Loading
function showLoadingPage()
{ 
alert("showLoadingPage()")
	if (document.getElementById)
    { 
		// DOM3 = IE5, NS6 
		document.getElementById('hidepage').style.visibility = 'visible'; 
	} 
	else 
	{ 
		if (document.layers)
		{
			// Netscape 4 
		   document.hidepage.visibility = 'show'; 
		} 
		else 
	    { 
			// IE 4 
		   document.all.hidepage.style.visibility = 'visible'; 
	    } 
	} 
}



