// JavaScript Document
var xmlhttp = null;
function ajaxFunction()
{
	var xmlhttp = null;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }
	 return xmlhttp;
	 
}


function showOptions(val,path)
{
	if(val.length==0){
	 //alert("Please select option");
	  return;
  	}
	else{
	 document.getElementById("div_searchoptions").innerHTML="Please Wait...";	 
	}
	
	xmlhttp=ajaxFunction();

	if(xmlhttp==null){
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	 }
	
	if(path == 'admin'){
		var url="../seachoption.php";
	}else{
		var url="seachoption.php";
	}
	
	url=url+"?val="+val;
	//url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged()
{
	if (xmlhttp.readyState==4){
	  document.getElementById("div_searchoptions").innerHTML=xmlhttp.responseText;
  	}
	else{
		return;
	}
}

function makeEmpty(idz){
	var val = document.getElementById(idz).value;
	if(val == "Friend's Email" || val == "Your Email"){
		document.getElementById(idz).value='';	
	}
}

function makeFilled(idz){
	var val = document.getElementById(idz).value;
	
	if(val == '' || val == "Friend's Email")
		document.getElementById(idz).value="Friend's Email";
	
}

function makeFilled2(idz){
	var val = document.getElementById(idz).value;	
	
	if(val == '' || val == "Your Email")
		document.getElementById(idz).value="Your Email";	
}




//for the main search
function makeEmptyBox(idz){
	
	var val = document.getElementById('search').value;
	if(val == 'Enter Keyword')
		document.getElementById('search').value='';	
}

function makeNonEmpty(diz){
	var val = document.getElementById('search').value;
	
	if(val == '' || val == 'Enter Keyword')
		document.getElementById('search').value='Enter Keyword';	
}


// for the news
function makeEmptyEmailBox(idz){
	
	var val = document.getElementById(idz).value;
	if(val == 'Enter Email Address')
		document.getElementById(idz).value='';	
}

function makeNonEmailEmpty(idz){

	var val = document.getElementById(idz).value;
	
	if(val == '' || val == 'Enter Email Address')
		document.getElementById(idz).value='Enter Email Address';	
}

/*********EMAIL VALIDATAE**/

function do_validate_first(){
	var email = document.form.email.value;
	
	if(email == ""){
		alert(' Please enter your Email address ') ;
		 document.form.email.focus();
		 return false;
	}		
	if(!validateEmail(email)){
		alert(' Please enter valid Email address ') ;
		document.form.email.focus();
		return false;
	}	
	return true;
}


function dovalidate(){
	var email = document.eform.friendemail.value;
	var email2 =	document.eform.myemail.value;
	var comments =	document.eform.comments.value;
	
	//document.eform.saved_url.value=location.href;
	
	if(email == ""){
		alert(' Please enter your Email address ') ;
		 document.eform.friendemail.focus();
		 return false;
	}	
	
	if(!validateEmail(email)){
		alert(' Please enter valid Email address ') ;
		document.eform.friendemail.focus();
		return false;
	}
	if(email2 == ""){
		alert(' Please enter your Email address ') ;
		 document.eform.myemail.focus();
		 return false;
	}	
	
	if(!validateEmail(email2)){
		alert(' Please enter valid Email address ') ;
		document.eform.myemail.focus();
		return false;
	}	

	
	if(comments == ""){
		alert(' Please enter your message ') ;
		document.eform.comments.focus();
		return false;
	}
	
	
	return true;	
}

function validateEmail(str){
var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(str.match(emailRegEx)){
		return true;
	}else{	
	return false;
	}
}

/***************/