// JavaScript Document
function objectcreate() {
	var page;
	if (window.XMLHttpRequest) {
		page = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		page= new ActiveXObject("Microsoft.XMLHTTP");
	} else { alert('Browser doesn\'t support AJAX'); }	
	return page;
}

function trim1(stringToTrim){
 return stringToTrim.replace(/^\s+|\s+$/g, '');
}

function searchSubmit(){
	if (trim1(document.frmSearch.txtsearch.value) != ""){
		
		document.frmSearch.submit();
	}else{
		alert('Enter keyword to search!');
		document.frmSearch.txtsearch.value = '';
		document.frmSearch.txtsearch.focus();
		return false;
	}
}

function searchSubmit_1(){
	if (trim1(document.frmSearch.txtsearch.value) != ""){
		
		document.frmSearch.submit();
	}else{
		//alert('Enter keyword to search!');
		document.frmSearch.txtsearch.value = '';
		document.frmSearch.txtsearch.focus();
		//return false;
	}
}

function openpage(pagename) {
	
	var pagecontent = objectcreate();
	pagecontent.onreadystatechange = statechange;
	pagecontent.open('GET',pagename,true);
	pagecontent.send(null);
	
	function statechange() {
		if(pagecontent.readyState == 4) {
			document.getElementById('innerdiv').innerHTML = pagecontent.responseText;
		}
	}	
	
	if (pagename == 'blank.php') { document.getElementById('subtopic').innerHTML=''; }
}


function clearfield()
{
	document.f1.admin.value="";
	document.f1.password.value="";
}

function validateMyForm() {

	if ((document.f1.admin.value) == "") 

	{

		alert('Please enter the email');

		document.f1.admin.focus();

		return false;

	}
   var emailID=document.f1.admin
		
	if ((emailID.length>0)||(emailID.value!="")){
		
		if (echeck(emailID.value)==false){
			
			emailID.value=""
			emailID.focus()
			return false
		}
		
	}

	if ((document.f1.password.value) == "") 

	{

		alert('Please enter the password');

		document.f1.password.focus();

		return false;

	}	
	if (((document.f1.admin.value) != "") && ((document.f1.password.value) != ""))
	{ return true; }

}

function validateMyForm1() {

	if ((document.f2.admin.value) == "") 

	{

		alert('Please enter the user name');

		document.f2.admin.focus();

		return false;

	}

	if ((document.f2.password.value) == "") 

	{

		alert('Please enter the password');

		document.f2.password.focus();

		return false;

	}	
	if (((document.f2.admin.value) != "") && ((document.f2.password.value) != ""))
	{ return true; }

}

function submitform()
{
var login = validateMyForm();

	if (login == true) {
		document.f1.submit();
	 }	

}

function AllowOnlyNumeric()
{
	var key = window.event.keyCode;
	
	if ( key == 13)
	{ submitform(); } 
}

function validate()
{
	if(document.feed.cname.value == "") { alert("Please, Enter your Name?"); document.feed.cname.focus(); return false;}
	if(document.feed.subject.value == "") { alert("Please, Enter the Subject?"); document.feed.subject.focus(); return false;}	
	if(document.feed.email.value == "") { alert("Please, Enter your Email Id?"); document.feed.email.focus(); return false;}	
	if(document.feed.comments.value == "") { alert("Please, Enter the Comments?"); document.feed.comments.focus(); return false;}	

	var emailID=document.feed.email
		
	if ((emailID.length>0)||(emailID.value!="")){
		
		if (echeck(emailID.value)==false){
			
			emailID.value=""
			emailID.focus()
			return false
		}
	
	}
	
	if(document.feed.cname.value !="" && document.feed.subject.value !="" && document.feed.email.value !="" && document.feed.comments.value !="")
	{
		openpage('feedback.php?username='+document.feed.username.value+'&cname='+document.feed.cname.value+'&subject='+document.feed.subject.value+'&email='+document.feed.email.value+'&comments='+document.feed.comments.value+'&user='+document.feed.l_name.value);
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function for_validate()
{
	if (document.forgot.email.value == "" )	{ alert("Please, Enter Email Address!"); return false; }
	
	var emailID=document.forgot.email;
		
	if ((emailID.length>0)||(emailID.value!="")){
		
		if (echeck(emailID.value)==false){
			
			emailID.value="";
			emailID.focus();
			return false;
		}
		else {
			if(document.forgot.missing_opt(0).checked) 
			{ var opt = "password"; }
			if(document.forgot.missing_opt(1).checked) 
			{ var opt = "username"; }
			openpage('forgot.php?miss_opt='+opt+'&email='+document.forgot.email.value);
		}
	}
}

function validate_step1()
{
	if(document.step1.firstname.value=="") { alert("Please, Enter Firstname!");document.step1.firstname.focus(); return false; }
	if(document.step1.lastname.value=="") { alert("Please, Enter Lasttname!");document.step1.lastname.focus(); return false; }
	if(document.step1.email.value=="") { alert("Please, Enter Email Address!");document.step1.email.focus(); return false; }
	if(document.step1.username.value=="") { alert("Please, Enter Username!");document.step1.username.focus(); return false; }
}
function validate_step2()
{
	if(document.step2.company_name.value==""){ alert("Please, Enter Company Name!"); document.step2.company_name.focus(); return false; }
}

