/******************************************************
	Date Created: 30th May, 2008
	Created By: Pravin kucha
	Purpose of this (page/form/module): This page is used for the javascript funtion.
	Last Modified: 
	Modified By: Pravin kucha
******************************************************/

/* Read Only Function*/
function make_readonly()
{
	alert("Please Use Browse Button");
	return false;
}//End of Function

/* Checks for blank text boxes*/
function checkBlank(ctl,msgName)
{
	if(Trim(ctl.value)=="")	
    {
		alert(''+msgName+'' + "cannot be blank");
		ctl.focus();
		return (false);
    }
}//End of Function


/* Checks for unselected select boxes*/
function checkSelect(ctl,msgName)
{
	if(ctl.selectedIndex<=0)	
    {
		alert('Please select '+msgName);
		ctl.focus();
		return (false);
    }
	else
    {
    	return (true);
    }
}//End of Function


/* Checks for the entered email id is in a proper format*/
function ValidateEmail(ctl)
{
	var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) ) 
	{
		error = 1;
		alert("Email address is not formatted properly.");
		ctl.focus();
		return (false);
	}
}//End of Function


function checkEmail(ctl)
{
	var id=ctl;
	var str=id.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(str))
		testresults=true
	else
	{
		alert("Email address is not formatted properly.");
		ctl.focus();
		testresults=false
	}
	
	return (testresults)
	
}



/* Checks for password entered is same or not*/
function confirmPassword(ctl1,ctl2)
{
	if(ctl1.value != ctl2.value)
	{
   		alert("Password and confirm password must be same");
   		ctl1.focus();
   		return(false);
   }
}//End of Function


/* Function for changing of password*/
function confirmPassword_change(ctl1,ctl2)
{
	if(ctl1.value != ctl2.value)
	{
   		alert("New Password and Confirm Password do not match");
   		ctl1.focus();
   		return(false);
   }
}//End of Function


/* Function to validate the radio button*/
function radio_validate(formObj) 
{
    var isOK = false;
    for (i=0;i<formObj.elements.length;i++) 
	{
		currElem = formObj.elements[i]
        if (currElem.type == "radio"  &&  currElem.checked) 
		{
            isOK=true;
			break;
        }
    }
    
	if (!isOK) 
		alert("You need to select a option !");
    return isOK;
}//End of Function


/* Function to remove the leading and trailing spaces*/
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}//End of Function


/* Funtion for Numbers Only and Disables all other key*/
function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
		//unicode!=8;
	if (unicode!=9)
	{ //if the key isn't the backspace key (which we should allow)
		if ((unicode<48||unicode>57) && unicode != 46 && unicode != 8) //if not a number
		return false //disable key press
	}
}//End of Function

/* Funtion for Numbers Only and Disables all other key*/
function numbersonly1(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
		//unicode!=8;
			
	if (unicode!=9)
	{ //if the key isn't the backspace key (which we should allow)
		if ((unicode<49||unicode>57)  && unicode != 8) //if not a number
		return false //disable key press
	}
}//End of Function
/* Function moves the cursor from one text box to another after 3 characters*/
function valuedata(data,movedata)
{ 
	if(data.length == 3)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function

 
/* Function moves the cursor from one text box to another after 2 characters*/
function valuedata1(data,movedata)
{
	if(data.length == 2)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function


/* Funtion for Characters Only and Disables all other key*/

function alphaCharacters(event)
{
	
	/********
	FOR IE
	*********/
	if(document.all)
	{
		if(event.keyCode>=65 && event.keyCode<=90)
		{
			return true;
		}
		else if(event.keyCode>=97 && event.keyCode<=122)
		{
			return true;
		}
		else if(event.keyCode==32)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/************************************
	OTHER BROWSER LIKE FIREFOX,NETSCAPE
	*************************************/
	if ((!document.all )&& (document.getElementById)) 
	{
		if(event.which>=65 && event.which<=90)
		{
			return true;
		}
		else if(event.which>=97 && event.which<=122)
		{
			return true;
		}
		else if(event.which==32)
		{
			return true;
		}
		else if(event.which==0 || event.which==8)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}//End of Function