
//*****************************************
function ignoreChar(string, ch) 
{
	var temp = "";
	string = '' + string;
	splitstring = string.split(ch);
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}

function insertChar(string, ch) 
{
	var temp = "";
	temp=string.substring(0, 3) + ch;
	//alert (string.substring(0, 3));
	//alert (string.substring(3, 6));
	//alert (string.substring(6, 10));
	temp+=string.substring(3, 6) + ch+string.substring(6, 10);

	//alert (temp);
	return temp;
}
//**********check Zip Code************

function CheckZip(obj)
{
		var sValue=obj.value;
		var iDigits = obj.value.length;
		var GoodChars = "0123456789"
		var i = 0
		if( !(iDigits==5 || iDigits==0))
			//alert("Please enter valid zip code4 digits.");
			return false;
        if( (iDigits==5))
        {
		   for (i =0; i <= iDigits -1; i++) 
		   {
			if (GoodChars.indexOf(sValue.charAt(i)) == -1) 
			{
				//alert("Please 2.");
				return false;
			} 
		   } 
		}
	return true;

}

//***********check For Spaces*************************

function SpacesOnly(field)
{
	//alert ('so');
	if (field.length != 0)
	 {
		
	  foundchar = false
	  for (i = 0; i <= field.length - 1; i++)
	   {
	   
	    if (field.substring(i,1) != ' ')
	    //alert ('in loop');
		 {
			
		  foundchar = true;
		  break;
		 }
	   }
	   if (foundchar)
		return false;
	 }
	return true;
}

//***********check Email******************
	function CheckUsrEmail()
	{
	//alert("email");
	var email=document.forms[0].Usr_Email.value.toLowerCase();
	if (email.length == 0 || SpacesOnly(email))
		{
		document.forms[0].Usr_Email.focus;	
		return false;
		}
		
	if (email.indexOf("@")==-1) 
		{			
		document.forms[0].Usr_Email.value="";
		document.forms[0].Usr_Email.focus;
		return false;
		}
	if (email.indexOf("..")!=-1) 
		{			
		document.forms[0].Usr_Email.value="";
		document.forms[0].Usr_Email.focus;
		return false;
		}	
	if (email.indexOf("@.")!=-1) 
		{			
		document.forms[0].Usr_Email.value="";
		document.forms[0].Usr_Email.focus;
		return false;
		}	
	if (email.charAt(0)=="@") 
		{			
		document.forms[0].Usr_Email.value="";
		document.forms[0].Usr_Email.focus;
		return false;
		}
	if (email.charAt(email.length-1)==".") 
		{			
		document.forms[0].Usr_Email.value="";
		document.forms[0].Usr_Email.focus;
		return false;
		}
	if (email.indexOf(".gov")==-1 && email.indexOf(".com")==-1 && email.indexOf(".us")==-1
		&& email.indexOf(".net")==-1 && email.indexOf(".edu")==-1 && email.indexOf(".org")==-1)
		{			
		document.forms[0].Usr_Email.value="";
		document.forms[0].Usr_Email.focus;
		return false;
		}
		
		return true;
	
	}



//***********check Email******************
	function CheckFrndEmail()
	{
	//alert("email");
	var email=document.forms[0].Frnd_Email.value.toLowerCase();
	if (email.length == 0 || SpacesOnly(email))
		{
		document.forms[0].Frnd_Email.focus;	
		return false;
		}
		
	if (email.indexOf("@")==-1) 
		{			
		document.forms[0].Frnd_Email.value="";
		document.forms[0].Frnd_Email.focus;
		return false;
		}
	if (email.indexOf("..")!=-1) 
		{			
		document.forms[0].Frnd_Email.value="";
		document.forms[0].Frnd_Email.focus;
		return false;
		}	
	if (email.indexOf("@.")!=-1) 
		{			
		document.forms[0].Frnd_Email.value="";
		document.forms[0].Frnd_Email.focus;
		return false;
		}	
	if (email.charAt(0)=="@") 
		{			
		document.forms[0].Frnd_Email.value="";
		document.forms[0].Frnd_Email.focus;
		return false;
		}
	if (email.charAt(email.length-1)==".") 
		{			
		document.forms[0].Frnd_Email.value="";
		document.forms[0].Frnd_Email.focus;
		return false;
		}
	if (email.indexOf(".gov")==-1 && email.indexOf(".com")==-1 && email.indexOf(".us")==-1
		&& email.indexOf(".net")==-1 && email.indexOf(".edu")==-1 && email.indexOf(".org")==-1)
		{			
		document.forms[0].Frnd_Email.value="";
		document.forms[0].Frnd_Email.focus;
		return false;
		}
		
		return true;
	
	}
	
//**********check empty text and select objects********

	function CheckEmptyText(obj)
	{
		if (obj.type=="select-one")
			st=new String(obj.options[obj.selectedIndex].value);
		else
			st=new String(obj.value);
		if (st.length == 0 || SpacesOnly(st))
		{	
			obj.focus();
			return false;
		}
		else
			return true;
	}	

//***********check empty Radio objects****************

function getRadioSelectionIndex(radioArray) 

{
	if (radioArray.length == null) radioArray = new Array(radioArray);
	for (var i = 0; i < radioArray.length; i++)
		if (radioArray[i].checked) return i;
	return -1;
}

//********* Validate Form ********************     
   
function ValidateForm() {
//alert ("val");
    var form = document.forms[0];
    
	
  if((ignoreChar(form.Usr_Name.value, " ") == "") || (form.Usr_Name.value == null)) {
  		alert("Please enter your name.");
  		form.Usr_Name.value="";
		form.Usr_Name.focus();
        return false;
	}
	
   if (!CheckUsrEmail())
	{alert("Please, enter your valid e-mail address"); return false;}  
	
  if((ignoreChar(form.Frnd_Name.value, " ") == "") || (form.Frnd_Name.value == null)) {
  		alert("Please enter your friends name.");
  		form.Frnd_Name.value="";
		form.Frnd_Name.focus();
        return false;
	}
   
  if (!CheckFrndEmail())
	{alert("Please, enter your Friends valid e-mail address"); return false;}   
} 

//**************************************************


	