/*
SCRIPT USED BY WHOLE WEB SITE

Modified by  Norbert Fischer, Jan 2003 for Pet Supplies On Line

================================================================
Code by Bill Taylor btaylor@taylormade.com.au

This code may be freely used in full or in part provided this banner is included
     
Code tested with IE3W95 and IE4.5, NS4.6 Macintosh 
	     
================================================================
*/
//Formatting variables
var hover_col = "#EEEEFF";//#DDDDFF
var active_col = "#90EE90";
var inactive_col = "#FFFFFF";
var highlightColor = "#EEEEFF";//background highlight when pressing Add button

/*

TO add an item to the pet supplies menu simply add here in a similar way. The value to 
the left of the comma is the actual file name (case sensitive, without the file extension),
the value to the right of the comma is the page name that appears in the menu */

var prodMenu = new Array
prodMenu[0]="Specials,<font color=\"#FF0000\">Specials</font>"
//prodMenu[1]="Arthritis,Arthritis"
prodMenu[1]="Books,Books"
prodMenu[2]="Dental,Dental"
prodMenu[3]="EarAndEye,Ear and Eye"
prodMenu[4]="Fleas,Flea & Tick"
prodMenu[5]="Harnesses,Harnesses"
prodMenu[6]="Heartworm,Heartworm"
prodMenu[7]="Leashes,Leashes"
prodMenu[8]="NewItems,New Items"
//prodMenu[10]="Supplements,Supplements"
prodMenu[9]="Toys,Toys"
//prodMenu[12]="Treats,Treats"
prodMenu[10]="Worming,Worming"
prodMenu[11]="Others,Miscellaneous"
prodMenu[12]="Cats,Cats only"
prodMenu[13]="Dogs,Dogs only"
prodMenu[14]="ProdIndex,Full Index"

var longestMenuWord = "Miscellaneous"
/*Geoff- when adding a new page category please, if required, change the longestMenuWord
parameter above - this is for formatting of the table above containing the
curve image - to ensure it is aligned properly if a user chooses to view at a larger text size */

var thisPagePathArray = location.pathname.split("/")
var arrayLength = thisPagePathArray.length
var thisPageFileArray = thisPagePathArray[arrayLength-1].split(".")
var thisPage = thisPageFileArray[0]

var ausORint
var ausORintLinkTo
if((location.pathname.indexOf("/aus/") != -1) || (location.pathname.indexOf("\\aus\\") != -1)){
	ausORint = "aus"
	ausORintLinkTo = "int"
	altBanner = "Australia";
}else{
	ausORint = "int"
	ausORintLinkTo = "aus"
	altBanner = "International";
}

var isOldNN = false;
if (parseInt(navigator.appVersion) < 6) {
	if (navigator.appName.indexOf("Netscape") != -1) {
		isOldNN = true
	}
}


function highlightMenu(){
	if (typeof document.getElementById != "undefined"){
		document.getElementById(thisPage).style.backgroundColor="#90EE90"
	}
}

function writeBanner(){
	document.write('<a name="top"></a><table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#90EE90"><tr valign="middle">')
	document.write('<td><img src="../images/interface/psol_'+ ausORint + '.gif" width="300" height="46" alt="Pet Supplies On Line '+ altBanner +' - Banner"></td>')
	document.write('<td align="right" width="215"><b><i><font color="#009999"><img src="../images/interface/pooch.gif" width="62" height="46" align="left" alt="Wise Old Pooch"></font><span class="serving"><font face="Times New Roman, Times, serif" color="#006666">Serving pet-lovers around&nbsp;<br>the&nbsp;world&nbsp;<span id="blink_text">since 1997</span></font></span></i></b></td></tr></table>')
}

function writeTopMenu(){
	document.write('<table width="100%" border="0" cellspacing="0" cellpadding="5" bgcolor="#008080"><tr><td>')
	document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>')
	document.write('<td><div align="left"><font size=1 color="#FFFFFF">Please use our <a href="../' + ausORintLinkTo +'/index.html"><font color="#DDDDFF"><font color="#99FF99">')
	if(ausORint=="aus"){
			document.write('International</font></font></a> site if you live outside Australia</font></div></td>')
	}else{
			document.write('Australian</font></font></a> site if you live in Australia</font></div></td>')
	}
	document.write('<td><div align="right"><font color="#FFFFFF">')
	document.write('<a href="../index.html" class="site_menu"><font color="#FFFFFF" size="1">Home</font></a> ')
	document.write('| <a href="index.html" class="site_menu"><font color="#FFFFFF" size="1">Welcome</font></a> ')
	document.write('| <a href="About.html" class="site_menu"><font color="#FFFFFF" size="1">About</font></a> ')
	document.write('| <a href="terms.html" class="site_menu"><font color="#FFFFFF" size="1">Terms&nbsp;&amp;&nbsp;Cond\'s</font></a> ')
	document.write('| <a href="privacy.html" class="site_menu"><font color="#FFFFFF" size="1">Privacy</font></a> ')
	document.write('| <a href="links.html" class="site_menu"><font color="#FFFFFF" size="1">Links</font></a> ')
	document.write('| <a href="ContactUs.html" class="site_menu"><font color="#FFFFFF" size="1">Contact</font></a></font>&nbsp;</div>')
	document.write('</td></tr></table>')
	document.write('</td></tr></table>')
	if (isOldNN != true){
		document.write('<table width="100%" cellpadding=0 cellspacing=0><tr><td bgcolor="#008080" width=110><table cellpadding=8 cellspacing=0><tr><td><font class="site_menu" color="#008080">'+ longestMenuWord +'</font></td></tr></table></td><td><img src="../images/interface/curve_top_left.gif"></td></tr></table>')
	}
}


function writeMenu(){
	document.writeln('<table width="100" border="1" cellspacing="0" cellpadding="1" bordercolor="#000000"><tr><td bgcolor="#66CCCC">')
	document.writeln('<div align="center"><font face="Arial, Helvetica, sans-serif, Arial Narrow">Order&nbsp;Form</font></div>')
	document.writeln('</td></tr><tr><td title="Use this to view your Current Order" id="Orders" onClick="goToLink(\'Orders\')" onMouseOver="bgStyleChange(this)" onMouseOut="bgStyleRestore(this)" valign="top" bgcolor="#FFFFFF">')
	document.writeln('<div align="center"><a href="Orders.html" class="site_menu"><font color="#000000">View Order</font></a></div></td></tr>')
	if (ausORint=="int"){
		document.write('<tr><td title="Use this Link to Guide you on Prices in Your Currency - opens in a new window so Pop ups MUST be allowed or the window will not open" id="Currency" onMouseOver="bgStyleChange(this)" onMouseOut="bgStyleRestore(this)" valign="top" bgcolor="#FFFFFF"><div align="center"><font size=1><a href="http://www.xe.com/pca/launch.cgi?From=AUD" class="site_menu"><font color="#000000">XE.com Personal Currency Assistant - (opens in a new window)</font></a></font></div></td></tr>')
	}
	document.writeln('</table>');

	document.write('<br><table width="100" border="1" cellspacing="0" cellpadding="1" bordercolor="#000000"><tr><td bgcolor="#66CCCC"><p align="center"><font face="Arial, Helvetica, sans-serif, Arial Narrow">Pet&nbsp;Supplies</font><br></p></td></tr>')
	for (var i=0; i <prodMenu.length; i++){
		var namesReferences = prodMenu[i].split(",")
		var fileName = namesReferences[0]
		var refName = namesReferences[1]
		document.write('<tr><td id="'+fileName+'" onClick="goToLink(\''+fileName+'\')" onMouseOver="bgStyleChange(this)" onMouseOut="bgStyleRestore(this)" bgcolor="#FFFFFF"><div align="center"><a href="'+fileName+'.html" class="site_menu"><font color="#FF0000"><font color="#000000">'+refName+'</font></font></a></div></td></tr>')
	}
	document.writeln('</table></br>')
	if (ausORint=="int"){ 
			document.write('<table width="100" border="1" cellspacing="0" cellpadding="1" bordercolor="#000000"><tr><td id="Question"  onMouseOver="bgStyleChange(this)" onMouseOut="bgStyleRestore(this)" bgcolor="#FFFFFF" align="center"><a href="mailto:questions@psol.com.au?subject=Question for Pet Supplies On Line">Email Us a Question</a></td></tr></table>');
	}else{
			document.write('<table width="100" border="1" cellspacing="0" cellpadding="1" bordercolor="#000000"><tr><td id="Question"  onMouseOver="bgStyleChange(this)" onMouseOut="bgStyleRestore(this)" bgcolor="#FFFFFF" align="center"><a href="mailto:questions@psol.com.au?subject=Question for Pet Supplies On Line Australia">Email Us a Question</a></td></tr></table>');
	}
}

var today = new Date();
year=today.getYear(); 

if (year < 2000){
	year = year + 1900;
}
    
var bottomHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="5" bgcolor="#008080"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="10%" width="2%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td width="96%"><div align="center">&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FFFFFF" size="1">&copy; 1997-'+year+' Pet Supplies On Line, Australia</font></div></td><td width="2%"><div align="right">&nbsp;<a href="#top" class="site_menu"><font color="#FFFFFF" size="1">top&nbsp;^</font></a>&nbsp;</div></td></tr></table></td></tr></table>'

function writeBottom(){
	document.write(bottomHTML)
}

function writeBottomBanner(){
	if(ausORint=="aus"){
		document.write('<table style="border-bottom: 1px #008080 solid" cellpadding="5" cellspacing="0" border="0" bgcolor="#EEEEFF" width="100%">')
		document.write('<tr><td><div align="left"></div></td><td><div align="center"><font size="1"><img src="../images/interface/ausFlag.gif" width="60" height="30" align="middle" alt="Australian Flag">')
		document.write(' &nbsp;&nbsp;You are currently on the Australian site. If you are outside Australia please use our <a href="../int/index.html">International</a> site. &nbsp;&nbsp; ')
		document.write('<img src="../images/interface/ausFlag.gif" width="60" height="30" align="middle" alt="Australian Flag"></font></div></td><td><div align="right"></div></td></tr></table>')
	}
}

function twodp(n) {	//converts to 2 decimal places
   	n=parseFloat(n);
	n+=.005;
    var ns = " "+n;
    ns = ns.substring(1,ns.length);
    var dp = ns.indexOf(".");
   	if (dp < 0) ns = ns+".00";
  	else if (dp == ns.length-2) ns = ns+"0";
   	else if (dp < ns.length-1) ns = ns.substring(0,dp+3);
   	return ns;
}

function threedp(n) {	//converts to 3 decimal places
    n=parseFloat(n)	
	n+=.0005; //round up to three dec places, would now have a dec point unless num ended in .9995
	var ns = " "+n; //convert to string by adding a string
    ns = ns.substring(1,ns.length); //remove the space just assigned
    var dp = ns.indexOf("."); //find position of decimal point
   	if (dp < 0) ns = ns+".000"; // if dec point not found, ie after entering numb ending in 0.9995, add '.000' to number string
  	else if (dp == ns.length-2) ns = ns+"00"; //if dec point is second last character then add '0' to number string
  	else if (dp == ns.length-3) ns = ns+"0"; //if dec point is third last character then add '0' to number string
	else if (dp < ns.length-1) ns = ns.substring(0,dp+4); //if dec point is at any position before last character take only the slice that includes 3 dec places after the dec point
   	return ns;
}

function rCookiesOn() {
	var hascookie = 2;
	if (!document.cookie){
  		cookie_name = "psolOrder";
  		document.cookie=cookie_name+"=; path=/";
  		(!document.cookie)?hascookie = 0:hascookie=1; 
	}
	return hascookie;
}

function CookieWarning() {
  	if (rCookiesOn()==0) {
  		alert("Sorry, you need to enable 'Cookies' on your browser to use this site: Look in Edit menu:preferences (Macintosh or Netscape), Tools menu Internet option (Windows Internet Explorer) on your browser")
 		// var noCookies = window.open("/cookies.html","NoCookies","HEIGHT=600,WIDTH=450,status=0,resizable=1,scrollbars=1,menubar=0");
	}
}

CookieWarning();

function getCookieValue(cookie_name) {
	var cv="";
  	if(document.cookie) {
        index = document.cookie.indexOf(cookie_name+"=");
        if (index != -1) {
           	var namestart = (document.cookie.indexOf("=", index) + 1);
            var nameend = document.cookie.indexOf(";", index);
            if (nameend == -1) {nameend = document.cookie.length;}
            	cv = document.cookie.substring(namestart, nameend); 
          	}
        }
	return cv;
}

function eatCookie(cookie_name) {
	if(document.cookie) {
        index = document.cookie.indexOf(cookie_name);
        if (index != -1) document.cookie=cookie_name+"=; path=/";
    }
}

function insuranceNote() {
	window.open("insurance.html","insurance","HEIGHT=250,WIDTH=500,status=0,resizable=0,scrollbars=0,menubar=0");
}

function rememberOrder() {
	var order= unescape(getCookieValue("psolOrder"));
 	if (order =="undefined") { 
		order = "";
	 	return order;
	}
}

function storeOrder(order) {
 	document.cookie="PalmCurrentProduct="+escape(order)+"; path=/"; 
}

function forgetOrder() {
	eatCookie("psolOrder");
	history.go(0);
}

//called by psolorder.html
function forgetngoback() {
	eatCookie("psolOrder");
	history.go(0);
}

function priceNorder(productPrice) {
	if(isOldNN==false){
		productPrice = productPrice.replace(/\s+/g," ");   //removes spaces inserted into product name for sql-asp sorting founction - cookie later and element name now
		productPrice = productPrice.replace(/[']+/g,""); //removes single quote, double quote will not reach here succesffully inside Js function params string
	}
	p = productPrice.split("$") //p[1] is the price, qty field is named with productPrice
	if (location.pathname.indexOf("Specials") == -1){
		document.write('$'+p[1]+'</td><td align=\'center\' width=\'5%\'><input class=\'alignRight\' type=text size=3 name="'+productPrice+'" value="'+norder(productPrice)+'" maxlength=2 onChange="orderIt(\''+productPrice+'\');"></td><td align=\'center\'><input type=\'button\' class=\'btn\' value=\'Add\' onClick="orderIt(\''+productPrice+'\');addAlert(\''+productPrice+'\')"></td><td align=\'center\'><input type=\'button\' value=\'View\' class=\'btn\' onClick=\'document.location=\"Orders.html\"\'</td>');
	}else{
		document.write('<b><font color=\'#FF0000\'>$'+p[1]+'</font></b></td><td align=\'center\' width=\'5%\'><input class=\'alignRight\' type=text size=3 name="'+productPrice+'" value="'+norder(productPrice)+'" maxlength=2 onChange="orderIt(\''+productPrice+'\');"></td><td align=\'center\'><input type=\'button\' class=\'btn\' value=\'Add\' onClick="orderIt(\''+productPrice+'\');addAlert(\''+productPrice+'\')"></td><td align=\'center\'><input type=\'button\' value=\'View\' class=\'btn\' onClick=\'document.location=\"Orders.html\"\'</td>');
	}
}

function addAlert(productPrice){
	if(isOldNN==false){
	
	var haveAlerted = getCookieValue("haveAlerted")
	var formElementObj = eval("document.forms[0].elements['"+productPrice+"']");
	var qty = formElementObj.value
	var productPriceArray = productPrice.split('$')
	var product = productPriceArray[0]
	var price = productPriceArray[1]
	
	if (haveAlerted=="undefined" || haveAlerted==""){
		document.cookie="haveAlerted=yes"
		formElementObj = eval("document.forms[0].elements['"+productPrice+"']");
		qty = formElementObj.value
		productPriceArray = productPrice.split('$')
		product = productPriceArray[0]
		price = productPriceArray[1]
		
		if(typeof document.getElementById != "undefined" && parseInt(qty) > 0){
			formElementObj.style.backgroundColor=highlightColor
			alert("      "+product+" @ $"+price+" x "+qty+" was added. \n\nClick [View] anytime to View or Finalise your Full Order\n\n        This message will not appear again");
		}else{
			//invalid qty so rewrite cookie as empty
			formElementObj.style.backgroundColor="white"
			document.cookie="haveAlerted=";
			if ((parseInt(qty) == 0) || qty==""){
				alert("A valid Qty was not entered, \n               or\nThis product was removed from Your Order");
			}else{
				alert("Please enter a valid quantity");
			}
		}
	}else{
		if (typeof document.getElementById != "undefined"){
			if ((parseInt(qty) == 0) || qty==""){
				formElementObj.style.backgroundColor="white"
				alert("A valid Qty was not entered, \n               or\nThis product was removed from Your Order");
			}else{
				formElementObj.style.backgroundColor=highlightColor
			}
		}
	}
	}else{
		alert("Product was added, Click [View] button to View or Finalise your Order")
	}
}

function insertWtRnge(min,max,min_lb,max_lb){
		//store all wt range values in the name of input element
		//identify as a wt range type element by prefixing the element name with 'wts' so can chnage all these together
		var element_name = "wts-"+min+"-"+max+"-"+min_lb+"-"+max_lb;
		if(min==0 && max==0 && min_lb==0 && max_lb==0){
			document.write("<input class='noBorder' type='text' size='10' onFocus='this.blur()' name='"+element_name+"' value=''></input>")
		}else{
			document.write("<input class='noBorder' type='text' size='10' onFocus='this.blur()' name='"+element_name+"' value='"+min+" to "+max+" kg'></input>")
		}
}


var lastChecked = "kg";

function changeWt(kgOrlb){
	if(lastChecked == kgOrlb){
		//alert("You have clicked the same weight unit twice");
		return;
	}
	for (var i=0; i<document.forms[0].elements.length; i++){
	var element_name = document.forms[0].elements[i].name;//look at each form element
		if (element_name.indexOf("wts")==0){//if elements name starts with 'wts'
			element_wts_array = element_name.split("-");
			
			var min = element_wts_array[1];
			var max = element_wts_array[2];
			var min_lb = element_wts_array[3];
			var max_lb = element_wts_array[4];
			
			if (kgOrlb=="lb"){
				if(min==0 && max==0 && min_lb==0 && max_lb==0){
					document.forms[0].elements[i].value ="";
				}else{
					document.forms[0].elements[i].value = min_lb+" to "+max_lb+" lb";
				}
			}else{
				if(min==0 && max==0 && min_lb==0 && max_lb==0){
					document.forms[0].elements[i].value ="";
				}else{
					document.forms[0].elements[i].value = min+" to "+max+" kg";
				}
			}
		}
		//record which btn type last checked so as to prevent reclicking taking effect next time- prevents wasted execution
		lastChecked = kgOrlb;
	}
}


function norder(productPrice) {
	sep = "\n";
	fsep = "$";
	cname = "psolOrder";
	order = unescape(getCookieValue(cname)).split(sep);
	var n="";
	for (i=0;i<order.length;i++) {
		if (order[i].indexOf(productPrice)==0)  {
 			fields = order[i].split(fsep);
  			n = fields[6];
  		}
	}
	//document.psol[productPrice].value =n;
	return n;
}

var allProdWt = 0;
var fullcost = 0;

// use this for adjusting the number ordered or ordering a new item or deleting an ordered item

function orderIt(productPrice) {

	newn = parseInt(document.psol[productPrice].value);
	(isNaN(newn)) ? qty=0: qty=newn;
	(qty > 0) ? document.psol[productPrice].value = qty : document.psol[productPrice].value = "";//get qty from field named with this productPrice
	newcookie = "";
	sep = "\n";
	fsep = "$";
	cname = "psolOrder";
	found = -1;
	order = unescape(getCookieValue(cname)).split(sep);
	
	for (i=0;i<order.length;i++) {
		if (order[i].indexOf(productPrice)==0) {
  			found = 0;
 				if (qty > 0) newcookie+=productPrice + fsep + qty + fsep + document.location.pathname + sep;
 				}else{
   				if (order[i].length > 0 && order[i] != "undefined")newcookie += order[i] + sep;
		}
	}
	
	if (found==-1 && qty !=0) newcookie += productPrice + fsep + qty + fsep + document.location.pathname + sep;
	document.cookie=cname+"="+escape(newcookie)+"; path=/";
}
 
function bgStyleChange(td_obj){
	if(typeof td_obj.id != "undefined"){
		if(location.pathname.indexOf(td_obj.id) == -1){//only mouseover if path doesnt contain td ID
			td_obj.style.backgroundColor = hover_col;
			td_obj.style.cursor="hand";
		}else{
			td_obj.style.backgroundColor= active_col;
		}
	}
}

function bgStyleRestore(td_obj){
	if(typeof td_obj.id != "undefined"){
		if(location.pathname.indexOf(td_obj.id) == -1){//only mouseout if path doesnt contain td ID
			td_obj.style.backgroundColor = inactive_col;
			td_obj.style.cursor="default";
		}
	}
}

function goToLink(link_url){
	document.location.href = link_url+".html";
}

function writeStylesheets(){
	if(navigator.appName.indexOf("Explorer") != -1){ 
		document.write("<link rel='stylesheet' href='../css/index.css' type='text/css'>")
	}else{
		document.write("<link rel='stylesheet' href='../css/index_netscape.css' type='text/css'>")
	}
}


