var xmlhttp;

var xmlDoc;

var l1=0;

var l2=10;

var myurl="/test/dir#"

var str;

function getData()

{



document.getElementById("result").innerHTML='<center><br /><br /><img src="images/spinner2.gif" /></center>';

str=document.forms[0].q.value;

document.title=str+" -Webmarked Search";



old_query=str;

xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Browser does not support HTTP Request");

  return;

  }

	var url="searcher.php";

var params ="q="+str+"&sid="+Math.random()+"&l1="+l1+"&l2="+l2+"";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange=stateChanged;

//xmlhttp.send(null);

xmlhttp.send(params);

Increment();



}





function stateChanged()

{

if (xmlhttp.readyState==4)

  {

  	var i=0;

	

	var length=xmlhttp.responseXML.documentElement.getElementsByTagName("details").length;

	document.getElementById("result").innerHTML="";



  while(i<length)

  {

  xmlDoc=xmlhttp.responseXML;   

  firstname1=xmlDoc.getElementsByTagName("firstname")[i].childNodes[0].nodeValue;

  //var reportlink='<a href="#" onclick="reportIt(\''+firstname1+'\',\''+firstname1+'\')">Report</a>';

   //var reportlink='<a href="#" onclick="reportIt('+firstname1+','+firstname1+')">Report</a>';



  var reportlink='<span class="report"><a href="#" onclick="reportIt(\''+xmlDoc.getElementsByTagName("firstname")[i].childNodes[0].nodeValue+'\',\''+xmlDoc.getElementsByTagName("middlename")[i].childNodes[0].nodeValue+'\',\''+xmlDoc.getElementsByTagName("lastname")[i].childNodes[0].nodeValue+'\',\''+xmlDoc.getElementsByTagName("place")[i].childNodes[0].nodeValue+'\',\''+xmlDoc.getElementsByTagName("stdcode")[i].childNodes[0].nodeValue+'\',\''+xmlDoc.getElementsByTagName("telephone")[i].childNodes[0].nodeValue+'\',\''+xmlDoc.getElementsByTagName("mobile")[i].childNodes[0].nodeValue+'\')">Report it</a></span>';

  document.getElementById("result").innerHTML+="<p class=\"number\">"+xmlDoc.getElementsByTagName("firstname")[i].childNodes[0].nodeValue+" "+xmlDoc.getElementsByTagName("middlename")[i].childNodes[0].nodeValue+" "+xmlDoc.getElementsByTagName("lastname")[i].childNodes[0].nodeValue+reportlink+"<br />"+xmlDoc.getElementsByTagName("place")[i].childNodes[0].nodeValue+"<br />Tel:-"+xmlDoc.getElementsByTagName("stdcode")[i].childNodes[0].nodeValue+" "+  xmlDoc.getElementsByTagName("telephone")[i].childNodes[0].nodeValue+"<span class=\"right\">Mobile:- "+xmlDoc.getElementsByTagName("mobile")[i].childNodes[0].nodeValue+"<span></p>";  

  i++;

  }

  if(length<10)

	{// no more  result 

	document.getElementById("result").innerHTML+='<p class="index"><font color="red">No more results to display for '+str+'.</font></p><p>Have you added your contact to the directory? If not ,please <a href="#" onclick="loadXMLDoc(\'register_form.php\');document.title=\'Add your contact  to Webmarked.net Directory\';">Add your contact now</a></p><br />';

	}

	if(length<10 && l1!=10)

	{	

	// next disabled

	document.getElementById("result").innerHTML+='<div class="navigator"><input type="submit" name="previous" id="previous1" value="Previous" onClick="setLimit(0)"  /><input type="submit" name="next" class="next"   id="next1" value="Next" disabled="disabled" onClick="setLimit(1)" /></div>';

	}

	else if(length==10 && l1==10)

	{// itr 1  prev disabled

	document.getElementById("result").innerHTML+='<div class="navigator"><input type="submit" name="previous" disabled="disabled"  id="previous1" value="Previous" onClick="setLimit(0)"  /><input type="submit" name="next" class="next"   id="next1" value="Next" onClick="setLimit(1)" /></div>';

	}  

 	else if(length<10 && l1==10)

	{// both disabled  when less than 10 results in itr 1

	document.getElementById("result").innerHTML+='<div class="navigator"><input type="submit" name="previous" disabled="disabled"  id="previous1" value="Previous" onClick="setLimit(0)"  /><input type="submit" name="next" class="next" disabled="disabled"   id="next1" value="Next" onClick="setLimit(1)" /></div>';

	}  

	else 

	{

		

		document.getElementById("result").innerHTML+='<div class="navigator"><input type="submit" name="previous" id="previous1"   value="Previous" onClick="setLimit(0)"  /><input type="submit" name="next" class="next"   id="next1" value="Next" onClick="setLimit(1)" /></div>';

	

	}

	



  }

}



function GetXmlHttpObject()

{

if (window.XMLHttpRequest)

  {

  // code for IE7+, Firefox, Chrome, Opera, Safari

  return new XMLHttpRequest();

  }

if (window.ActiveXObject)

  {

  // code for IE6, IE5

  return new ActiveXObject("Microsoft.XMLHTTP");

  }

return null;

}

function setLimit(t)

{

if(t==0)// sets the limir

{

	l1-=20;

	

}

getData();



}// end function setLimit

function Increment()

{

l1+=10;

}

function processForm()

{



document.getElementById('error').innerHTML="";

var myplace="";





if(document.register.fname.value==""||!document.register.fname.value.match(/^[a-zA-Z]+$/))

{

document.getElementById('error').innerHTML="<br />Invalid or blank first name";

return false;

}

if(!document.register.mname.value.match(/^[a-zA-Z\s]*$/)&& document.register.mname.value!="")

{

document.getElementById('error').innerHTML+="<br />Invalid  middle name";return false;

}

if(document.register.lname.value==""||!document.register.lname.value.match(/^[a-zA-Z\s]+$/))

{

document.getElementById('error').innerHTML+="<br />Invalid or blank last name";return false;

}

if(!document.register.email.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/))

{

document.getElementById('error').innerHTML+="<br />Email specified is incorrect";return false;

}

if(document.register.place1.value!="others") {myplace=document.register.place1.value;}

else {myplace=document.register.place2.value}

if(myplace==""||!myplace.match(/^[\w]{1,}[\w\s]/))

{

document.getElementById('error').innerHTML+="<br />Invalid or blank city name";return false;

}

if(!document.register.telephone.value.match(/^[0-9]{4,}$/)&& document.register.telephone.value!=""){document.getElementById('error').innerHTML+="<br />Invalid telephone number";return false;}

if(!document.register.stdcode.value.match(/^[0-9]{3,}$/)&& document.register.stdcode.value!=""){document.getElementById('error').innerHTML+="<br />Invalid STD code";return false;}

if(!document.register.mobile.value.match(/^[0-9]{10}$/) && document.register.mobile.value!=""){document.getElementById('error').innerHTML+="<br />Invalid cellphone number";return false;}

if((document.register.telephone.value==""||document.register.stdcode.value=="")&& document.register.mobile.value=="" )

{

document.getElementById('error').innerHTML+="<br />Both telephone Number and mobile Number cannot be null";return false;

}

document.getElementById("wait").innerHTML="<span>Processing.....</span>"; 



xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Browser does not support HTTP Request");

  return;

  }

var url="form1.php";

var params ="fname="+document.register.fname.value+"&sid="+Math.random()+"&mname="+document.register.mname.value+"&lname="+document.register.lname.value+"&type="+document.register.type.value+"&email="+document.register.email.value+"&place="+myplace+"&stdcode="+document.register.stdcode.value+"&telephone="+document.register.telephone.value+"&mobile="+document.register.mobile.value+"";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange=checkstate;

xmlhttp.send(params);

return true;



}

function checkstate()

{

if (xmlhttp.readyState==4)

  {

 

  	var length1=xmlhttp.responseXML.documentElement.getElementsByTagName("success").length;

	//var length2=xmlhttp.responseXML.documentElement.getElementsByTagName("failure").length;



	if(length1>0)

	{

	document.getElementById('result').innerHTML="<br /><div class=\"suc\">Congratulations! You have successfully been listed with our directory. You will shortly receive an email containing instructions to finalise your registration process.</div>";

	}

	else

	{

	

	document.getElementById('result').innerHTML="<div class=\"fail\">Some error prevented us from processing your request. Please try once again</div>";



	}//end else



  document.getElementById("wait").innerHTML="&nbsp;"; 



    }//end xmlhttp

return true;



}// end function



function processFeedbackForm()

{



document.getElementById('error').innerHTML="";

if(document.feedback.mname.value==""||!document.feedback.mname.value.match(/^[a-zA-Z\s\.]+$/))

{

document.getElementById('error').innerHTML="<br />Invalid or blank  name";

return false;

}

if(!document.feedback.memail.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/))

{

document.getElementById('error').innerHTML="<br />Email specified is incorrect";return false;

}	

if(!document.feedback.msg.value.match(/^[a-zA-Z\s\.\,\@\%\&]*$/)&&document.feedback.msg.value!="")

{

document.getElementById('error').innerHTML="Please enter only valid characters in the messaage.";

return false;	

}

document.getElementById("wait").innerHTML="<span>Processing.....</span>"; 



xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Browser does not support HTTP Request");

  return;

  }

var url="feedback.php";

var params ="mname="+document.feedback.mname.value+"&sid="+Math.random()+"&memail="+document.feedback.memail.value+"&msg="+document.feedback.msg.value+"";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange=checkFeedbackState;

xmlhttp.send(params);

return true;









}// end processFeedbackFunction()

function checkFeedbackState()

{

if (xmlhttp.readyState==4)

  {

 document.getElementById('result').innerHTML='<div class="suc">We have received your feedback. We thank you for sharing your ideas with us.</div>';

 document.getElementById("wait").innerHTML="&nbsp;"; 



  

  }//end xmlhttp

return true;



}// end function



function resetLimits()

{ l1=0;}



function la()

{

	

}

/*

function loadXMLDoc(url)

{

document.getElementById("loading").innerHTML='<span>Loading</span>';



if (window.XMLHttpRequest)

{

xmlhttp=new XMLHttpRequest();

}

else

{

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

//document.getElementById("result").innerHTML='<center><br /><br /><img src="images/spinner2.gif" /></center>';

xmlhttp.open("GET",url,false);

xmlhttp.onreadystatechange=checkLoadState;

xmlhttp.send(null);

//la();

document.getElementById("loading").innerHTML='';

}

*/

function loadXMLDoc(url)

{

document.getElementById("wait").innerHTML="<span>Please wait.....</span>"; 

document.getElementById("result").innerHTML='<center><br /><br /><img src="images/spinner2.gif" /></center>';





if (window.XMLHttpRequest)

{

xmlhttp=new XMLHttpRequest();

}

else

{

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

var params ="";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange=checkLoadState;

xmlhttp.send(params);

return true;

}



function checkLoadState()

{	

if (xmlhttp.readyState==4)

{



document.getElementById("result").innerHTML="";

document.getElementById('result').innerHTML=xmlhttp.responseText;

document.getElementById("wait").innerHTML="&nbsp;"; 

}

return true;

}

function index()

{

document.title="Webmarked Online Directory-Home";

document.getElementById('result').innerHTML='<div id="ac" ><input class="but" type="submit" value="Add your contact now" onclick="loadXMLDoc(\'register_form.php\');document.title=\'Add your contact  to Webmarked Online Directory\';"/></div><div id="useful"><h2>WOD is incomplete without your contacts</h2></div>';

}



function processFriendsForm()

{

document.getElementById('error').innerHTML="";

if(document.tellfriends.mname.value==""||document.tellfriends.memail.value=="")

{

document.getElementById('error').innerHTML="Please enter your name and email";

return false;	

}

if(document.tellfriends.name1.value==""||document.tellfriends.email1.value==""||(!document.tellfriends.email1.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)))

{

document.getElementById('error').innerHTML="You must provide at least one email and name correctly";

return false;	

}

if((document.tellfriends.name2.value!=""&&(!document.tellfriends.email2.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)))||(document.tellfriends.name3.value!=""&&(!document.tellfriends.email3.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)))||(document.tellfriends.name4.value!=""&&(!document.tellfriends.email4.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)))||(document.tellfriends.name5.value!=""&&(!document.tellfriends.email5.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/))))

{

document.getElementById('error').innerHTML="When you provide the contact name, you must provide the email of the contact. ";

return false;	

}

// to be uncommented after the url is ready

document.getElementById("wait").innerHTML="<span>Processing.....</span>"; 





xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Browser does not support HTTP Request");

  return;

  }

var url="tellfriends.php";

var params ="mname="+document.tellfriends.mname.value+"&sid="+Math.random()+"&memail="+document.tellfriends.memail.value+"&name1="+document.tellfriends.name1.value+"&email1="+document.tellfriends.email1.value+"&name2="+document.tellfriends.name2.value+"&email2="+document.tellfriends.email2.value+"&name3="+document.tellfriends.name3.value+"&email3="+document.tellfriends.email3.value+"&name4="+document.tellfriends.name4.value+"&email4="+document.tellfriends.email4.value+"&name5="+document.tellfriends.name5.value+"&email5="+document.tellfriends.email5.value+"";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange=stateofFriendChanged;

xmlhttp.send(params);

document.getElementById("result").innerHTML="Your have succesfully notified your friends about our service";



return true;

}

function stateofFriendChanged()

{

document.getElementById("wait").innerHTML="&nbsp;"; 



return true;	

	

}

var firstname,middlename,lastname,place,stdcode,telephone,mobile;

function reportIt(firstname,middlename,lastname,place,stdcode,telephone,mobile)

{

document.title="Report it doubtful- Webmarked Directory";

document.getElementById('result').innerHTML='<form name="reportit" action="#" method=post onsubmit="processReportForm();return false;"><p class="index">Help us make this online directory better by eliminating out fake entries</p><div id="error"></div><table><tr><td>First Name</td><td><input type="text" name="fname" value="'+firstname+'" disabled="disabled" /></td></tr><td>Middle Name</td><td><input type="text" name="mname" value="'+middlename+'" disabled="disabled" /></td></tr><td>Surname</td><td><input type="text" name="lname" value="'+lastname+'" disabled="disabled" /></td></tr><td>Place</td><td><input type="text" name="place" value="'+place+'" disabled="disabled" /></td></tr><td>STD Code</td><td><input type="text" name="stdcode" value="'+stdcode+'" disabled="disabled" /></td></tr><td>Telephone</td><td><input type="text" name="telephone" value="'+telephone+'" disabled="disabled" /></td></tr><td>Mobile</td><td><input type="text" name="mobile" value="'+mobile+'" disabled="disabled" /></td></tr><tr><td>Your Name</td><td><input  type="text" name="yname" /></td></tr><tr><td>Your email</td><td><input type="text" name="yemail" /></td></tr><tr><td>Let  us know on what grounds do <br /> you suspect this result(Optional)<br /><i>Maximum 250 characters.Use valid characters like A-Z, a-z,0-9,.,@ etc. only.</i></td><td><textarea name="msg" rows="10"  cols="40"></textarea></td></tr><tr><td></td><td><input type="submit" name="submit" value="Submit"/></td></tr></table></form>';

}



function processReportForm()

{

document.getElementById('error').innerHTML="";

if(document.reportit.yname.value==""||document.reportit.yemail.value=="")

{document.getElementById('error').innerHTML="Please enter your name and email";

return false;	

}

if(!document.reportit.yname.value.match(/^[a-zA-Z\s\.]*$/)||(!document.reportit.yemail.value.match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)))

{

document.getElementById('error').innerHTML="Invalid name or  email";

return false;	

}

if(!document.reportit.msg.value.match(/^[a-zA-Z\s\.\,\@\%\&]*$/)&&document.reportit.msg.value!="")

{

document.getElementById('error').innerHTML="Please enter only valid characters in the messaage.";

return false;	

}

document.getElementById("wait").innerHTML="<span>Processing.....</span>"; 



xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Browser does not support HTTP Request");

  return;

  }

var url="reportit.php";

var params ="fname="+document.reportit.fname.value+"&sid="+Math.random()+"&mname="+document.reportit.mname.value+"&lname="+document.reportit.lname.value+"&place="+document.reportit.place.value+"&stdcode="+document.reportit.stdcode.value+"&telephone="+document.reportit.telephone.value+"&mobile="+document.reportit.mobile.value+"&yname="+document.reportit.yname.value+"&yemail="+document.reportit.yemail.value+"&msg="+document.reportit.msg.value+"";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange=Reported;

xmlhttp.send(params);

return true;



}



function Reported()

{

	document.getElementById("result").innerHTML="<b>Thank You </b>for reporting it to us.We shall soon verify the concerned contacts."; 

	document.getElementById("wait").innerHTML="&nbsp;"; 



	return true;

}
