// this does several things:
//1: reads the "books" cookie if already exists
//2: adds the title of this page to the "books" cookie if user presses "request more info" (calls function:process)
//3: opens a popup to arrange sending this page URL to a third party if user presses "forward to a friend" (calls function:submittopopup)
//4: prints the page if user presses "print" (calls function:printpage)
//5: if user presses "go to parent website" it gets complicated.  The page will normally have been opened as a popup from the parent website so just needs closing, parent page will still be open...
//[cont...] If the page has been opened by the recipient of a "forward to a friend" mail then we want to open parent home page in a new browser.

var desc = document.title;
var books_cookie= "";
books_cookie = getcookie('books');
var crumbs = books_cookie.split("###");
		
function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function getexpirydate( nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setcookie(name,value,duration){
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration)+";PATH=\/;DOMAIN=.hawkridge.co.uk";
	document.cookie=cookiestring;
}	

function process(desc){
	var cookie_content = books_cookie + "###" + desc ;
	setcookie('books',cookie_content,1);
	window.location="http://www.hawkridge.co.uk/document_request.php";
}

function submittopopup(name) {
	url="http://www.wardcnc.com/mailpage1.php?page_name=" + document.location.href + "&page_title=" + document.title;;
	newwin=window.open(url,'newwin','width=400,height=400,resizable=yes,scrollbars=yes');
}

function gotoMain() {

	newwin=window.open('./','newwin1','toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,outerHeight=' + screen.availHeight + ',outerWidth=' + screen.availWidth);
	window.setTimeout(window.close, 1500 );
	}

function closeWindow() {
    self.close();
}

function checkparent() {
    if (window.opener && !window.opener.closed)
    self.close();
    else {
        gotoMain();
    }
}
function sendit() {
	window.setTimeout(window.close, 3500 );
	document.form2.submit(); 
}

function refreshcookie() {
var cookiestringout=""; 
for (var count = 0; count < document.form2.tick.length; count++) {
if (!document.form2.tick[count].checked) {

	cookiestringout= cookiestringout+ "###" + crumbs[count+1];
}
}
setcookie('books',cookiestringout,1);
window.location="http://www.hawkridge.co.uk/document_request.php";
}
function expirecookie(name){
	setcookie(name,'',-1);
}
	
function droplist() {
	expirecookie('books');
}

function hidediv(pass) {
   var l_item = document.getElementById (pass);

   if ( l_item == null )
   {
      alert ('Sorry.. there are problems with runing JavaScript.');
      return;
   }else{
      l_item.style.display = 'none';
	}
 
}

function showdiv(pass) {
   var l_item = document.getElementById (pass);

   if ( l_item == null )
   {
      alert ('Sorry.. there are problems with runing JavaScript.\n'+pass);
      return;
   }else{
      l_item.style.display = 'block';
    }
}