function set_cookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}



function get_cookie ( cookie_name )
{
     var cookie_string = document.cookie ;
    if (cookie_string.length != 0) {
        var cookie_value = cookie_string.match (
                        '(^|;)[\s]*' +
                        cookie_name +
                        '=([^;]*)' );
      if (cookie_value==null){ 
		return undefined;
      }else{
        return unescape ( cookie_value[2] ) ;
        }
    }
    return '' ;
}


//Clippings Stuffz

function addClipping(sTitle	, sURL){
var hashClippings = new Hashtable(get_cookie("myClippings"));
hashClippings.put(sTitle,sURL);

set_cookie("myClippings",hashClippings, 7);
alert("Tour added.");
}

function getClippingsCount(){
	var hashClippings = new Hashtable(get_cookie("myClippings"));
	return hashClippings.size();
}

function printClippings(target, iCount, toElement, bListOnly){
var hashClippings = new Hashtable(get_cookie("myClippings"));

	if (iCount!= hashClippings.size){

		hashClippings.moveFirst();
		var i = 0;
		var sBody ="";
		while (hashClippings.next()){ //While we have more elements
			//print the key and the value
			//document.write("<a href='" + hashClippings.getValue() + "' target="+ target +">" + hashClippings.getKey() + "</a>&nbsp;&nbsp;<a href='#' onclick='removeClippingsIndex("+ i +")'>remove</a> <br>");
			
			/*
			if (bListOnly) {
					sBody = sBody + "<a href='" + hashClippings.getValue() + "' target="+ target +">" + hashClippings.getKey() + "</a><br>";				
				}
			else
				{
					sBody = sBody + "<Div style='width:30px;float:left; margin:5px;' align=left><input type='checkbox' value='1' name='chkLink" + i + "'></div><Div style='width:470px;float:left;' align=left><Textarea name='txtLink" + i + "' style='display:none;'><a href='" + hashClippings.getValue() + "' target="+ target +">" + hashClippings.getKey() + "</a></Textarea><a href='#' owc:control='command' owc:command=\"GoToPage\" owc:commandparams=\"" + DPCCODE_GetPageNumber(hashClippings.getValue()) + "\">" + hashClippings.getKey() + "</a></div><div align=right style='float:right;'><input type='button' value='Remove' onclick='removeClippingsIndex("+ i +")'></div><br><br>";
				}
			*/
			if (bListOnly) {
					sBody = sBody+ "<a href='" + hashClippings.getValue() + "' target="+ target +">" + hashClippings.getKey() + "</a><br>";				
				}
			else
				{
					sBody = sBody+ "<Div style='width:30px;float:left; margin:5px;' align=left><input type='checkbox' value='1' name='chkLink" + i + "'></div><Div style='width:470px;float:left;' align=left><Textarea name='txtLink" + i + "' style='display:none;'><a href=\'" + hashClippings.getValue() + "\' target="+ target +">" + hashClippings.getKey() + "</a></Textarea><a href='" + hashClippings.getValue() + "' target="+ target +">" + hashClippings.getKey() + "</a></div><div align=right style='float:right;'><input type='button' value='Remove' onclick='removeClippingsIndex("+ i +")'></div><br><br>";
				}
			i++;
	
		}
		
		if (bListOnly) {
			document.getElementById(toElement).innerText =sBody;
			}
		else {	
			document.getElementById(toElement).innerHTML =sBody;
		}
		return i;
		
	}
	else {return iCount}
	
	
}

function DPCCODE_GetPageNumber(sUrl) {
	var istart = sUrl.indexOf("&pageno=") +8;

	var iend = sUrl.indexOf("&", istart);

	return sUrl.substring(istart, iend);
}



function removeClippingsIndex(Index){
	var hashClippings = new Hashtable(get_cookie("myClippings"));
	hashClippings.removeindex(Index);
	set_cookie("myClippings",hashClippings, 7);
}


function removeClippings(sTitle){
	var hashClippings = new Hashtable(get_cookie("myClippings"));
	hashClippings.remove(sTitle);
	set_cookie("myClippings",hashClippings, 7);
}

function emptyClippings(){
	set_cookie("myClippings","");
}




