//Global variables used as delimeters - new version
delimitem = "ÿ";
delimoption = "þ";

//Cookie functions
function getCookie(name){
	var cookiename = name + "=";
	var doccookie = document.cookie;
	if (doccookie.length > 0) {
		start = doccookie.indexOf(cookiename);
		if (start != -1) {
			start += cookiename.length;
			end = doccookie.indexOf(";", start);
			if (end == -1) end = doccookie.length;
			return unescape(doccookie.substring(start, end));
		}
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + ((path == null) ? "" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) + ((secure == null) ? "" : "; secure");
}

function delCookie (name) {
	var delDate=new Date("January 1, 1999 23:30:00");
	setCookie(name,null,delDate);
}

//Seperate strings
function separatedata(datain,delimin){
	var i=0;
	var xarray=new Array(datain);
	var j=0;

	for(i=0;i<datain.length;i++)
	{
	   var tempstring=datain.substring(i,datain.length);
	   var x=tempstring.indexOf(delimin);
	   if(x>0)
	   {
	   	var k=x+i;
	  	 xarray[j++]=datain.substring(i,k);
	  	 i+=x
	   }
	   else
	   {
	   	xarray[j++]=tempstring;
	   	i=datain.length
	   }
	}

	return xarray;
}

function showcart (page) {
  window.open(page,"Cart","toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=500");
}

function checkout (page) {
	if (document.title=='Cart')
	{
		window.open(  "https://www.murphywhips.com/" + page, "Checkout","toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400"); 
//		window.open(  "https://ssl17.pair.com/murphywh/" + page, "Checkout","toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400");
		window.close();
	}
	else
	{
		window.open(  "https://www.murphywhips.com/" + page, "Checkout","toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400"); 
//		location.href= "https://ssl17.pair.com/murphywh/" + page;
	}
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function changeSelect(thisform) {
var y = document.forms[thisform].Size.selectedIndex;
	document.forms[thisform].Price.selectedIndex = y;
	document.forms[thisform].Code.selectedIndex = y;
	document.forms[thisform].Size.selectedIndex = y;
	document.forms[thisform].Weight.selectedIndex = y;
}
function changeSelect1(thisform) {
var y = document.forms[thisform].Price.selectedIndex;
	document.forms[thisform].Price.selectedIndex = y;
	document.forms[thisform].Code.selectedIndex = y;
	document.forms[thisform].Size.selectedIndex = y;
	document.forms[thisform].Weight.selectedIndex = y;
}
function changeSelect2(thisform) {
var y = document.forms[thisform].Code.selectedIndex;
	document.forms[thisform].Price.selectedIndex = y;
	document.forms[thisform].Code.selectedIndex = y;
	document.forms[thisform].Size.selectedIndex = y;
	document.forms[thisform].Weight.selectedIndex = y;
}
function changeSelect3(thisform) {
var y = document.forms[thisform].Weight.selectedIndex;
	document.forms[thisform].Price.selectedIndex = y;
	document.forms[thisform].Code.selectedIndex = y;
	document.forms[thisform].Size.selectedIndex = y;
	document.forms[thisform].Weight.selectedIndex = y;
}
