/*
 +-------------------------------------------------------------------+
 |     Favorite Links   (v1.0)     Copyright www.YugDesign.com       |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 +-------------------------------------------------------------------+
 +-------------------------------------------------------------------+
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 | Feel free to modify this script as you wish. I'd appreciate that  |
 | you keep link back to my site. I know most of you won't. But it   |
 | is part of the terms of use. So, please keep it.                  |
 +-------------------------------------------------------------------+
*/
var days = 365; // days to store cookie
var page = window.location;
var maxitem = 5; //max items to store
var maxs = (maxitem - 1);
var hlong = days*24*60*60*1000;
var favpath ="/";
var u = new Date(); u.setTime (u.getTime() + hlong);
var e = new Date(); e.setTime (u.getTime());


function Favorites(listid) {
  var i = 0;
  var outlist="";
  var outlist1="";
  while ( i<=maxs ) {
	if (get('links' + i) != null && get('links' + i) !="" ) {
	outlist1 =  "&#187;&nbsp;<a href=" + get('urls' + i) + ">" + get('links' + i) + "</a>&nbsp;<a title=\"Delete this Link\" href=javascript:delFavorites("+get('dels'+i)+")>[x]</a><br />" ;
	outlist += outlist1;
	} else {
	outlist1 =  "" ;
	outlist += outlist1;
	}
	i++;
  }
    var favhere=document.getElementById(listid); //Check the FavList Box exist on  currently page or not.
	if (favhere!="null" && outlist !="") {
		document.getElementById(listid).innerHTML = outlist ;
	} else {
	document.getElementById(listid).innerHTML = "&#187;&nbsp;No Favorites Found";
  }
}

function get (n1) {
var cn = n1 + "="; var cl = document.cookie.length; var b = 0;
  while (b < cl) {
  var v = b + cn.length;
  if (document.cookie.substring(b, v) == cn) {
    var vd = document.cookie.indexOf (";", v); if (vd == -1) vd = cl; return unescape(document.cookie.substring(v, vd));
  }
  b = document.cookie.indexOf(" ", b) + 1;
  if (b == 0) break;
  }
return null;
}

function set (n1, n2, n3) {
if (!n3) n3 = new Date();
document.cookie=n1+"="+escape (n2)+"; expires="+n3.toGMTString()+"; path="+favpath;
}

function addFavorites(n1, n2){
if (window.confirm('Add to Your Favorites List?')) {
  var i = 0;
  var dels= 0;
  var f=false;
  while (get('links' + i) != null && get('links' + i) !="" ) {
    if (get('links' + i) == n1) f=true; dels= i;  i++;
  }
  if ( i > maxs) {
	alert('Sorry,But List Full.');
  } else {
  if (!f) set ('links' + i, n1, u);  set ('urls' + i, n2, u); set ('dels'+i, i, u);
    Favorites('favlist');
  }
}
}

function delFavorites(n1) {
 set('links' + n1, '', e); set('urls' + n1, '', e); set('dels' + n1, '', e); Favorites('favlist');
}

function clearFavorites() {
var i = 0;
if (window.confirm('Clear Favorites List?')) {
  while ( i <= maxs) {
  set('links' + i, '', e); set('urls' + i, '', e); set('dels' + i, '', e); i++;
  }
  Favorites('favlist');
}
}