/*
 +-------------------------------------------------------------------+
 |     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 imgpath = ""; // path to favorite icons
var days = 1000; // days to store cookie
var page = window.location;
 
var hlong = days*24*60*60*1000; 	
var u = new Date(); u.setTime (u.getTime() + hlong);
var e = new Date(); e.setTime (u.getTime());
	
function linkFavorites(n1, n2){
 
if(n2) title = n2;
else title = "ClickHere";
 
   document.write ('<a href="javascript:addFavorites(\''+n1+'\',\''+page+'\');">'+title+'</a>');
}
 
function Favorites(){
  var i = 0;
  while (get('links' + i) != null) {
   document.write ('<li><a href="' + get('urls' + i) + '" target="blank">' + get('links' + i) + '</a></li>&nbsp;<br />' ); i++; 
  }  
  if (i==0) document.write ('<img src="'+imgpath+'/components/nofav.gif" border="0" align="left" hspace="0">&nbsp;<font style="FONT-FAMILY: Verdana; FONT-SIZE: 8pt;"> 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()+";";
}
 
function addFavorites(n1, n2){
  var i = 0;
  var f=false;
  while (get('links' + i) != null) { 
    if (get('links' + i) == n1) f=true;   i++;	
  }    
  if (!f)  set ('links' + i, n1, u);  set ('urls' + i, n2, u);
 
  location.reload();
}
 
 
function clearFavorites() {
var i = 0;
if (window.confirm('Clear Favorites List?')) {
  while (get('links' + i) != null) {
  set('links' + i, '', e); set('urls' + i, '', e); i++; 
  }  
  i++; set('links' + i, '', e); set('urls' + i, '', e); location.reload();
}
}
 
