// JavaScript Document

/*****************************************************************************\
+-----------------------------------------------------------------------------+
| Project        : Keycharge.com			                                  |
| FileName       : formvalidation.js        	                              |
| Version        : 1.0                                                        |
| Developer      : Pinal Sakarvadia                                           |
| Created On     : 22-03-2007                                                 |
| Modified On    : 22-03-2007                                                 |
| Modified By    : Pinal Sakarvadia                                           |
| Authorised By  : Pinal Sakarvadia                                           |
| Comments       : This file will conatain basic form validaion regular exp.  |
| Email          : pinalsakarvadia@greymatterindia.com                        |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

function isurl(obj,stmnt)
{
	var objRegExp  =  /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i;
	var test = objRegExp.test(dotrim(obj.value));
	
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;	
}

function isprice(obj,stmnt)
{
	var objRegExp  =  /^\d+\.\d{2}$/;
	var test = objRegExp.test(dotrim(obj.value));
	
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;	
}

function dotrim(strComp)
{
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}
			
function ischecked(obj,stmnt,i)
{
	flag = false;

	for(j=0;j<=i;j++)
		if(obj[j].checked == true)
			flag = true;

	if(flag == false)
	{
		alert(stmnt);
		obj[0].focus();
		return false;			
	}
	return true;
}

function ischeckedbox(obj,stmnt,i)
{
	flag = false;	

	if(obj.checked == true)
		flag = true;

	if(flag == false)
	{
		alert(stmnt);
		obj.focus();
		return false;			
	}
	return true;
}

function isselected(obj,stmnt)
{
	if(obj.options[obj.selectedIndex].value == "")
	{
		alert(stmnt);
		obj.focus();
		return false;		
	}
	return true;
}

function isblank(obj,stmnt)
{
	if(dotrim(obj.value) == "")
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

function isnumber(obj,stmnt)
{ 
	var objRegExp  =  /(^-?\d\s\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	var test = objRegExp.test(dotrim(obj.value));
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}
function isnotnumber(obj,stmnt)
{ 
	var objRegExp  =  /(^-?\d\s\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	var test = objRegExp.test(dotrim(obj.value));
	if(test == true)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

function isemail(obj,stmnt)
{ 
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	var test = objRegExp.test(dotrim(obj.value));
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}