/*
* Name: jscode.js
* Author: Kumar Chetan
* Dated: 19-Mar-05(11:23:07)
* Description:this file holds some Javascript functions.
*/

/*
* Simple. It will send u to a 'url' on an event.
*/
function go2url(url)
{
	window.location = url;
}

/*
* Name: d()
* Parameters: mixed
* Author: Kumar Chetan
* Description: This function is an alias for document.write() method.
*/
function d(w)
{
	document.write(w);
}

/*
* Name: checkdate()
* Parameters: ints
* Author: Kumar Chetan
* Description: This function looks for valid date input.
*/
function checkdate(y,m,d)
{
leapy = 0;
if((y%4)==0) leapy = 1;
if((leapy==1) &&(m==2) && (d>29))
{
  return(false);
}else if((leapy==0) &&(m==2) && (d>28)){
  return(false);
}else if(((m==4) || (m==9) || (m==11)) && (d>30)){
  return(false);
}else{
return (true);
}
}

/*
* Name: isEmpty()
* Parameters: string
* Author: Kumar Chetan
* Description: This tiny function is based on regular expressions. Checks whether
* input is empty or contains logical values. This function can be tweaked to check 
* for invalid chars in input.
*/
function isEmpty(val)
{
	var re = /^\s*$/;
	return re.test(val.value);
}

/*
* Name: isValidEmai()
* Parameters: string
* Author: Kumar Chetan
* Description: This function is based on regular expressions and is a take on PHP 
* function. Checks whether input email address is valid or not. 
*/
function isValidEmail(field)
{
	var re = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
	return re.test(field.value);
}

/*
* Name: openmywin()
* Parameters: string (URL)
* Author: Kumar Chetan
* Description: This function 
* a) checks if user name is not empty
* b) if not empty then fires another browser window of specific size and the URL.
*/
function openmywin(myURL)
{
	if(document.frm_registration.userid.value=="" || isEmpty(document.frm_registration.userid)){
		alert("Please enter the username.");
		document.frm_registration.userid.focus();
	}else{
		window.open(myURL+"?userid="+document.frm_registration.userid.value, "checkusernameavailability", "width=200,height=200");
	}
}
function isphonenum(ndoc) 
{ 
	var nlen=ndoc.length;
	
	var i;
	for(i=0; i<nlen; i++)
	{
		var nch=ndoc.charAt(i)
		if(!(((nch>='0') && (nch<='9')) || (nch==' ' || nch=='(' || nch==')' || nch=='-' ))){return false;}
	}
	return true;
}

function isalphabet(fdoc) 
{ 
	var len=fdoc.length;
	var i;
	for(i=0; i<len; i++)
	{
		var ch=fdoc.charAt(i)
		if(!(((ch>='a') && (ch<='z'))|| ((ch>='A') && (ch<='Z')) || (ch==' ') || (ch=='-'))){return false;}
	}
	return true;
}