// JavaScript Document

function check(val){
	f = document.contact;
	if(val == 'S'){
		document.getElementById('company').style.display="none";
		document.getElementById('college').style.display="none";
	}
	else if(val == 'CM'){
		document.getElementById('company').style.display="block";
		document.getElementById('college').style.display="none";
	}
	else if(val == 'CP'){
		document.getElementById('company').style.display="none";
		document.getElementById('college').style.display="block";
	}
	else if(val == 'O'){
		document.getElementById('company').style.display="none";
		document.getElementById('college').style.display="none";
	}
	
}
function valid()
{
	f= document.contact;
	if(Trim(f.txtname.value) == ""){
		alert("Please Enter The Name");
		f.txtname.value="";
		f.txtname.focus();
		return false;
	}
	if(isAlpha(f.txtname.value) ==""){
		alert("Please Enter The Valid Name");
		f.txtname.value="";
		f.txtname.focus();
		return false;
	}
	if(Trim(f.txtplocation.value) == ""){
		alert("Please Enter The Location");
		f.txtplocation.value="";
		f.txtplocation.focus();
		return false;
	}
	if(isAlpha(f.txtplocation.value) ==""){
		alert("Please Enter The Valid Location");
		f.txtplocation.value="";
		f.txtplocation.focus();
		return false;
	}
	if(f.category[1].checked == true){
		if(Trim(f.txtcompany.value) == ""){
			alert("Please Enter The Company Name");
			f.txtcompany.value="";
			f.txtcompany.focus();
			return false;
		}
		if(isAlpha(f.txtcompany.value) ==""){
			alert("Please Enter The Valid Company Name");
			f.txtcompany.value="";
			f.txtcompany.focus();
			return false;
		}
	}
	if(f.category[2].checked == true){
		if(Trim(f.txtcollege.value) == ""){
			alert("Please Enter The College Name");
			f.txtcollege.value="";
			f.txtcollege.focus();
			return false;
		}
		if(isAlpha(f.txtcollege.value) ==""){
			alert("Please Enter The Valid College Name");
			f.txtcollege.value="";
			f.txtcollege.focus();
			return false;
		}
	}
	if(Trim(f.txtpmobile.value) == ""){
		alert("Please Enter The Mobile Number");
		f.txtpmobile.value="";
		f.txtpmobile.focus();
		return false;
	}
	if((isNaN(f.txtpmobile.value)) || (f.txtpmobile.value == 0)|| (f.txtpmobile.value.length>15)){
		alert("Please Enter The Valid Mobile Number");
		f.txtpmobile.value="";
		f.txtpmobile.focus();
		return false;
	}
	if(Trim(f.txtpemail1.value) == ""){
		alert("Please Enter The Email ID");
		f.txtpemail1.value="";
		f.txtpemail1.focus();
		return false;
	}
	if(isEmail(f.txtpemail1.value) == ""){
		alert("Please Enter The Valid Email Id");
		f.txtpemail1.focus();
		return false;
	}
	if(Trim(f.txtpaddress.value) == ""){
		alert("Please Enter The Query");
		f.txtpaddress.value="";
		f.txtpaddress.focus();
		return false;
	}
	if(Trim(f.txtpconfirm.value) == ""){
		alert("Please Enter The Security Code in the Above Image");
		f.txtpconfirm.value="";
		f.txtpconfirm.focus();
		return false;
	}
	
	return true;
}

function Trim(str)
			{   
					while(str.charAt(0) == (" ") )
					   {  
						str = str.substring(1);
						
					    }
				while(str.charAt(str.length-1) == " " )
				   {  
						str = str.substring(0,str.length-1);
						
					}
				return str;
			}

function isEmail ( string ) 
{
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function isAlpha( string )
{
	if(string.search(/^[A-Za-z,\.\'\-_\\ ]{1,}$/) != -1)
		return true;
    else 
		return false;
}

function isAlphaNumeric( string )
{
	if(string.search(/^[A-Za-z0-9\#\.\'\-_\\ ]+$/) != -1)
		return true;
    else 
		return false;
}