function keypress(e,func){
  var keynum;   
  if(window.event) {keynum=e.keyCode;}// IE
  else if(e.which){keynum=e.which;} // Netscape/Firefox/Opera
  if (keynum==13){
    if (func=="login"){login();}
	else if (func=="search"){adsearch();}
  }
}

function adsearch(countryurl,stateurl,cityurl){
  var country = document.getElementById("hidcountryurl").value;
  var state = document.getElementById("hidstateurl").value;
  var city = document.getElementById("hidcityurl").value;
  var q = document.getElementById("q").value;	
  if (q!=""){    
    window.location="http://www.youadlist.com/search/"+country+"-"+state+"-"+city+"/All/All/"+q+"_.html"
  }
}

function login(){ 
  var username = document.getElementById("txtloginemail").value;
  var password = document.getElementById("txtloginpassword").value;
  var Ajaxlogin=null
  if (window.XMLHttpRequest) {Ajaxlogin=new XMLHttpRequest()}
  else if (window.ActiveXObject) {Ajaxlogin=new ActiveXObject("Microsoft.XMLHTTP")}
  if (Ajaxlogin==null) {alert("Your browser does not support http request.  Please update your browser.")}  
  var url="http://www.youadlist.com/scripts/ajax/login.php?x="+username+"&y="+password+"&sid="+Math.random()
  Ajaxlogin.onreadystatechange=function(){
    if (Ajaxlogin.readyState==4 || Ajaxlogin.readyState=="complete"){
	  if (Ajaxlogin.responseText==0){
		alert("Incorrect username and/or password.");
	  }
	  else if (Ajaxlogin.responseText==1){
		window.location="http://www.youadlist.com/member.php";
	  }
	  else{
	    window.location="http://www.youadlist.com/verify_email.php?email="+Ajaxlogin.responseText;
	  }
	} 
  }
  Ajaxlogin.open("GET",url,true)
  Ajaxlogin.send(null)
}

function change_countrystate(x,n){
  var pAjax=null
  if (window.XMLHttpRequest) {pAjax=new XMLHttpRequest()}
  else if (window.ActiveXObject) {pAjax=new ActiveXObject("Microsoft.XMLHTTP")}
  if (pAjax==null) {alert("Your browser does not support http request.  Please update your browser."); return} 
  
  document.getElementById("imgchangeloc").src="/img/loading.gif"; 
  document.getElementById("imgchangeloc").onClick=""; 
  var y=x.split("|");
  var url="/scripts/ajax/change_loc.php?x="+y[0]+"&loc="+n+"&sessid="+Math.random();

  
  pAjax.onreadystatechange=function(){
    if (pAjax.readyState==4 || pAjax.readyState=="complete"){
      document.getElementById("divcountry").innerHTML=pAjax.responseText;
	  document.getElementById("imgchangeloc").onClick="go_changeloc()"; 
    } 
  }
  pAjax.open("GET",url,true)
  pAjax.send(null)
}

function change_loc(cid){  
  document.getElementById("divlogin").style.visibility="hidden"; 
  document.getElementById("imgcountrybutton").src="/img/country-button2.gif";
  change_countrystate(cid+'|','selcountry');
  doSlide("divcountry", cid);
}

function doSlide(id,cid){
  timeToSlide = 10; // in milliseconds
  obj = document.getElementById(id);
  obj.style.visibility = "hidden";
  obj.style.display = "block";
  obj.style.overflow = "hidden";
  height = obj.offsetHeight;
  obj.style.height="0px";
  obj.style.visibility = "visible";
  pxPerLoop = height/timeToSlide;
  slide(obj,0,height,pxPerLoop,cid);
}

function slide(obj,offset,full,px,cid){
	if(offset < full){
		obj.style.height = offset+"px";
		offset=offset+px;
		setTimeout((function(){slide(obj,offset,full,px);}),1);
	} else {
	  obj.style.height = "auto";
	}
}