 var qsParm = new Array();
 var query = window.location.search.substring(1);
 var parms = query.split('&');
 for (var i=0; i<parms.length; i++) 
 {
  var pos = parms[i].indexOf('=');
  if (pos > 0) 
  {
   var key = parms[i].substring(0,pos);
   var val = parms[i].substring(pos+1);
   qsParm[key] = val;
  }
 } 

 
 function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
  {
  alert('Welcome again '+username+'!');
  }
else
  {
  username=prompt('Please enter your name:',"");
  if (username!=null && username!="")
    {
    setCookie('username',username,365);
    }
  }
}


function urlstringcheck(str) 
{
 str = str.replace(".", "~1");

 return str;
}



function addfavtown(LocID) 
{

  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.onreadystatechange=function()
  {
     //alert(xmlhttp.readyState);
     //alert(xmlhttp.status);
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     if (xmlhttp.responseText=='0')
     {
      alert('Please login first to add your favorite town.');
      window.location = "/login.php?do=login"
     }else if (xmlhttp.responseText=='1'){
      document.getElementById("fav_t").src =bburl+"/qlocal_template_ext/images/AddToFavoritesIcon.jpg";
      document.getElementById("f_town").innerHTML = "Favorite";
     }else if (xmlhttp.responseText=='2'){
      document.getElementById("fav_t").src =bburl+"/qlocal_template_ext/images/AddToFavoritesIcon_g.jpg";
      document.getElementById("f_town").innerHTML = "Add Favorite";
     }


     //alert(xmlhttp.responseText);
    }
  }
 xmlhttp.open("POST",bburl+"/qlocal_template_ext/ajax/fav_t.php?LID="+LocID,true);
 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 xmlhttp.send("LID="+LocID);

}


function addhometown(LocID) 
{


  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.onreadystatechange=function()
  {

    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     if (xmlhttp.responseText=='0')
     {
      

     }else if (xmlhttp.responseText=='1'){

      document.getElementById("home_t").src = bburl+"/qlocal_template_ext/images/AddToFavoritesIcon.jpg";
      document.getElementById("h_town").innerHTML = "";

     }
    }
  }
 xmlhttp.open("POST",bburl+"/qlocal_template_ext/ajax/fav_t.php?home=1&LID="+LocID,true);
 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 xmlhttp.send("home=1&LID="+LocID);


}


function submitenter(myfield,e)
{

var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   document.forms[myfield].submit(); 
   return false;
   }
else
   return true;
}
