function validatemail(str,name) 
{
	var txt=str.value;
	var retval=true;

	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt))	
	 retval=true;		
	else
	 retval=false;		
	
	 
	if(!retval)
	{
		alert ("Enter a valid "+name);
		str.focus();
	}
	return retval;
}

function validateintegers(str,name) 
{
	var validchar="1234567890";
	var txt=str.value;
	var retval=true;
	for (var i=0;i<txt.length;i++)
	{
		var ex=validchar.indexOf(txt.substring(i,i+1));
		if(ex==-1)
		{
		alert ("invalid "+ name);
		retval=false;		
		str.focus();
		break;

		}	
	}
	return retval;	
}
function validateintalp(str,name) 
{
	var validchar="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var txt=str.value;
	var retval=true;
	for (var i=0;i<txt.length;i++)
	{
		var ex=validchar.indexOf(txt.substring(i,i+1));
		if(ex==-1)
		{
		alert ("invalid "+ name);
		retval=false;		
		str.focus();
		break;

		}	
	}
	return retval;	
}


function validatephone(str,name) 
{
	var validchar="1234567890+-";
	var txt=str.value;
	var retval=true;
	for (var i=0;i<txt.length;i++)
	{
		var ex=validchar.indexOf(txt.substring(i,i+1));
		if(ex==-1)
		{
		alert ("invalid "+ name);
		retval=false;		
		str.focus();
		break;

		}	
	}
	return retval;	
}

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") 
   {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ")
    {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1)
    {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue;
}


function validempty(txt,name)
{
	val=txt.value;
	var retval=true;
	if (trim(val)=="")
	{
	alert ("Please enter the "+name);
	txt.focus();
	retval=false;
	}
	return retval; 
}

function validemptyCombo(cbo,name)
{
	val=cbo.value;
	var retval=true;
	if (val=="0" || val=="-1")
	{
	alert ("Please Select "+name);
	cbo.focus();
	retval=false;
	}
	return retval; 
}


function validcompare(txt1,txt2)
{
	var val1=txt1.value;
	var val2=txt2.value;
	
	var retval=true;
	if (val1!=val2)
	{
	alert ("Passwords did not matched");
	txt2.focus();
	retval=false;
	}
	return retval; 
}

	function CheckUncheckAll(form)
	{
		var SelectAll=form.SelectAll;
		for (var i=0;i<form.elements.length;i++)
		{
			var e=form.elements[i];
			if (SelectAll.checked)
				e.checked=true;
			else
				e.checked=false;
		}
	
	}

function validemptyCheck(txt,name)
{
	var retval=true;
	if (!txt.checked)
	{
	alert ("Please You Must "+name);
	txt.focus();
	retval=false;
	}
	return retval; 
}
function validemptyherefor(txt1,txt2,txt3,name)
{
	var retval=true;
	if ( (!txt1.checked)&&(!txt2.checked)&&(!txt3.checked) )
	{
	alert ("Please You Must "+name);
//	txt.focus();
	retval=false;
	}
	return retval; 
}

// getting the selected index of the radio group
function getSelectedIndex(radgroup)
{
	/* Returns back the id of selected radio button in a radio button group  */
	var j = -1;
	for( i=0; i < radgroup.length; i++ )
	{
		if( radgroup[i].checked )
		{
			j = i;
		}
	}
	return j;
}
