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.toGMTString())+"; path=/; domain=.pinoylist.net";
}
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;
    c_name=(document.cookie.substring(c_start,c_end));
    return (c_name.replace(/\+/g, ' '));
  }
}
return "";
}
function trim(word) { return word.replace(/^\s+|\s+$/g,""); }
// get last city
function getlastcity() {
var newcity = {id:'',name:'',ccid:''};
var plc = getcookie('plc');
if (plc == "") return newcity;
plc = unescape(plc);
var ct = plc.split(':');newcity = {id:ct[0],name:ct[1],ccid:ct[2]};
return newcity;
}
// get and print full city list
function printcities() {
subhtml='';lasthtml='';
var newcity=getlastcity();
var plt = getcookie('plt');
if (plt == "" && newcity.id == '') return subhtml;
if (newcity.id!= '') lasthtml='<p style="font-size:1.2em">Your last location was <a href="/'+newcity.ccid+'/'+newcity.id+'/">'+newcity.name+'</a> // go there now <a href="/'+newcity.ccid+'/'+newcity.id+'/"><img src="/images/next.gif" alt="next"></a></p>';
plt = unescape(plt);
var arr = plt.split('|');
var cities=new Array();
if (plt!= '') {
for (i=0; i < arr.length; i++) {
  var ct = arr[i].split(':');
  cities[i]='<a href="/'+ct[2]+'/'+ct[0]+'/">'+unescape(ct[1])+'</a>';
}
if (cities.length>0) subhtml='<p>You recently checked these locations: (<small><a href="#" onclick="delhistory();return false;">delete history</a></small>)</p>'+cities.join(", ")+'';
}
if (newcity.id!='' && subhtml=='') {setcookie('plt',newcity.id+':'+newcity.name+':'+newcity.ccid,365)}
subhtml=lasthtml+subhtml;
return subhtml;
}
// city unda?
function iscitythere(cid) {
var plt = getcookie('plt');
if (plt == "") return 0;
plt = unescape(plt);
var arr = plt.split('|');
for (i=0; i < arr.length; i++) {
  var ct = arr[i].split(':');
  if (ct[0] == cid) return 1;
}
return 0;
}
// add city to array
function addcity(cid,cname,ccid) {
var plt = unescape(getcookie('plt'));
var ct = cid+':'+cname+':'+ccid;
if (plt == '') setcookie('plt',ct,365); else {
  newcity=getlastcity();
  if (iscitythere(cid)) {
    if (newcity.id!=cid) {setcookie('plc',ct,365)}
  } else {
    setcookie('plt',ct+'|'+plt,365);
  }
}
}
// add category
function addcat(catid,catname) {
var pla = unescape(getcookie('pla'));
var cat = catid+':'+catname;
if (pla == '') setcookie('pla',cat,365);
}
// get category
function getcategory() {
var newcat={id:'',name:''};
var pla=getcookie('pla');
if (pla == "") return newcat;
pla=unescape(pla);
var cat=pla.split(':');newcat={id:cat[0],name:cat[1]};
return newcat;
}
// right nav
/* new function - 24 July 2009 */
function getcities(sec) {
var subhtml="";
if (sec != "") sec="/"+sec;
var plt=getcookie('plt');
if (plt == "") return "<ul><li> no cities yet -</li></ul>";
plt = unescape(plt);
var arr = plt.split('|');
if (plt!= '') {
var newcity=getlastcity();
if (newcity.id != '') subhtml='<li><a href="/'+newcity.ccid+'/'+newcity.id+sec+'/">'+unescape(newcity.name)+'</a></li>';
for (i=0; i < arr.length && i < 5; i++) {
  var ct = arr[i].split(':');
  if (ct[0] != newcity.id) subhtml+='<li><a href="'+"/"+ct[2]+'/'+ct[0]+sec+'/">'+unescape(ct[1])+'</a></li>';
}
if (subhtml != '') subhtml='<ul>'+subhtml+'</ul>';
}
return subhtml;
}
function setlnav(sec) {
if (sec != "") sec="/"+sec;
var lis=document.getElementById('lnav').getElementsByTagName('li');
for (i=0; i<lis.length; i++) {
  var aobj=lis[i].getElementsByTagName('a');
  var p=/\/(\w{2})\/(\w+)\//;
  if (arr=aobj[0].getAttribute("href").match(p)) {
    aobj[0].setAttribute("href", "/"+arr[1]+"/"+arr[2]+sec+"/");
  }
}
}
function gettz() {var tz=getcookie('tz');tz=trim(unescape(tz));if (tz.substr(0,1)=='0'||tz.substr(0,1)=='1') tz='+'+tz;return tz;}
function settz(tz) {setcookie('tz',tz,100)}
function thrownews() {
var lat=document.getElementById('latest');
lat.innerHTML='<h4>LATEST POSTS</h4>';
for (i=0;i<ntitle.length;i++) {
  lat.innerHTML+='<a href="'+nurl[i]+'">'+ntitle[i]+'</a><br>';
}
}
function previewpic(id) {
var pic12=document.getElementById("pic12");
pic12.src='http://www.scripnews.com/scripnews/template/ver1.0/Images/loading.gif';
var picurl=document.getElementById("img"+id).value;
pic12.src=picurl;
}
function delhistory() {
setcookie('plt','',-1);
setcookie('plc','',-1);
location.href='/';
}
function throwcities(id) {
document.getElementById('lastcities').innerHTML=getcities(id);
}
