//Filename: nd-secure.js
//Purpose: Manipulates the order information to produce the final cost/weight/etc.

//Global Information
var ndCart = "p-3381";		//The cart id for No-Dog.com.
var ndProducts = 9;		//Number of products on offer

//Define Arrays to store the products
//Note: While they are defined, a product does NOT need to use all these fields.
//      Only the ones that are relevant to that product.
var ndName = new Array(ndProducts);
var ndPrice = new Array(ndProducts);
var ndQuantity = new Array(ndProducts);
var ndColor = new Array(ndProducts);
var ndFont = new Array(ndProducts);
var ndFontStyle = new Array(ndProducts);
var ndWeight = new Array(ndProducts);

function getPrice(x) {
	// returns the amount in the .99 format 
	var amount;
	
	amount = ndPrice[x];
	amount -= 0;
    	amount = (Math.round(amount*100))/100;
    	return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}


//No-Dog Offset Level
ndName[1] = "nodog";			//ID of Product
ndQuantity[1] = 1;			//Quantity purchased (default)
ndColor[1] = "gold, silver, red, blue, green, purple, black, assorted";
ndFont[1] = "Roman 3L, Americana BT, Century Gothic, Continuum, Lucida Handwriting";
ndFontStyle[1] = "Small Caps, All Caps, No Caps, Normal";
ndWeight[1] = 0.08;
ndPrice[1] = 15;

//No-Dog Level Functions
function checkURL() {
	if (document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text != "No Logo") {
		document.getElementById("sides1").style.visibility = 'hidden';
		document.getElementById("sides2").style.visibility = 'hidden';
		
	} else {
		document.getElementById("sides1").style.visibility = 'visible';
		document.getElementById("sides2").style.visibility = 'visible';
	}
	
	if (document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text == "Here is a link to it") {
		document.getElementById("ndURL").style.visibility = 'visible';
		document.nd_level.ndHTTP.value = 'http://';
	} else {
		document.getElementById("ndURL").style.visibility = 'hidden';
	}
}

function ndEngraved() {
	var a = 0;
	//Count the engravings
	if (document.nd_level.ndTop.value != "") {
		a += 1;
	}
	if (document.nd_level.ndBottom.value != "") {
		a += 1;
	}
	if (document.getElementById("sides1").style.visibility != "hidden") {
		if (document.nd_level.ndSide1.value != "") {
			a += 1;
		}
		if (document.nd_level.ndSide2.value != "") {
			a += 1;
		}
	}
	if (document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text != "No Logo") {
		a += 1;
	}
	return a;
}
function nCart(x) {
	var lFinal;
	var z = 0;
	var lTemp;
	
	ndQuantity[x] = document.nd_level.ndQuant[document.nd_level.ndQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "No-Dog Offset Level";
	
	lFinal += "<br><br>Color: " + document.nd_level.ndColor[document.nd_level.ndColor.selectedIndex].text;
	
	if (document.nd_level.ndTop.value != "") {
		lTemp = document.nd_level.ndTop.value
		lTemp = replace(lTemp,"<","&lt;");
		lTemp = replace(lTemp,">","&gt;");
		lFinal += "<br>Top Leg: " + lTemp;
	}
	if (document.nd_level.ndBottom.value != "") {
		lTemp = document.nd_level.ndBottom.value
		lTemp = replace(lTemp,"<","&lt;");
		lTemp = replace(lTemp,">","&gt;");
		lFinal += "<br>Bottom Leg: " + lTemp;
	}
	if (document.getElementById("sides1").style.visibility != "hidden") {
		if (document.nd_level.ndSide1.value != "") {
			lTemp = document.nd_level.ndSide1.value
			lTemp = replace(lTemp,"<","&lt;");
			lTemp = replace(lTemp,">","&gt;");
			lFinal += "<br>Side Line #1: " + lTemp;
		}
		if (document.nd_level.ndSide2.value != "") {
			lTemp = document.nd_level.ndSide2.value
			lTemp = replace(lTemp,"<","&lt;");
			lTemp = replace(lTemp,">","&gt;");
			lFinal += "<br>Side Line #2: " + lTemp;
		}
	}
	z = ndEngraved();
	if (z > 0) {
		if (z == 1 && document.getElementById("sides1").style.visibility == "hidden")  {
			
		} else {
			lFinal += "<br>Font: " + document.nd_level.ndFont[document.nd_level.ndFont.selectedIndex].text;
			lFinal += "<br>Font: " + document.nd_level.ndFontStyle[document.nd_level.ndFontStyle.selectedIndex].text;
		}
		//Logo will have a one time charge IF they don't have it.
		if (document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text != "No Logo") {
			if (document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text != "You already have it") {
				document.nd_level.item_logo.value = "p-3381^logo^One time logo charge.";
				lFinal += "<br>Logo Type: " +document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text;
				document.nd_level.item_logo.value += "<br>Logo Type: " +document.nd_level.ndLogo[document.nd_level.ndLogo.selectedIndex].text;
				document.nd_level.item_logo.value += "^10^1";
			}
			
		}
		if (document.getElementById("ndURL").style.visibility == "visible") {
			lFinal += "<br>Logo URL: " +  document.nd_level.ndHTTP.value;
		}
		lFinal += "<br>Engrave Cost: $" + z;
		document.nd_level.op1.value = " - " + z;
	}
	//Add engravement cost
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "op1^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	lFinal = replace(lFinal,"'","&rsquo;");
	document.nd_level.item.value = lFinal;

}

//No Dog 6inch Level
ndName[2] = "6inch";
ndQuantity[2] = 1;			//Quantity purchased (default)
ndColor[2] = "red, blue, assorted";
ndFont[2] = "Roman 3L, Americana BT, Century Gothic, Continuum, Lucida Handwriting";
ndFontStyle[2] = "Small Caps, All Caps, No Caps, Normal";
ndWeight[2] = 0.325;
ndPrice[2] = 31.5;

//No Dog 6inch Level Functions
function siCheckAngle() {
	var z = 0;
	for (var i=1;i<6;i++) {
		if (eval('document.si_level.sideg'+i+'.checked')) {
			z += 1;		
		}
	}		
	if (z != 3) {
		alert("Please select 3 angles for your Six Inch Level");
		return false;	
	}
}
function siEngraved() {
	var a = 0;
	//Count the engravings
	for (var i=1;i<11;i++) {
		if (eval('document.si_level.siSide'+i+'.value') != "") {
			a += 1;
		}
	}
	return a;
}
function siCart(x) {
	var lFinal;
	var z = 0;
	var lTemp;
	
	ndQuantity[x] = document.si_level.siQuant[document.si_level.siQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "No-Dog Six Inch Level";
	
	lFinal += "<br><br>Color: " + document.si_level.siColor[document.si_level.siColor.selectedIndex].text;

	//Angles
	lFinal += "<br>Angle Set: ";
	for (var i=1;i<6;i++) {
		if (eval('document.si_level.sideg'+i+'.checked')) {
			lFinal += eval('document.si_level.sideg'+i+'.value') + " ";
		}
	}
	//Engravings (eep!)
	for (var i=1;i<11;i++) {
		if (eval('document.si_level.siSide'+i+'.value') != "") {
			lTemp = eval('document.si_level.siSide'+i+'.value')
			lTemp = replace(lTemp,"<","&lt;");
			lTemp = replace(lTemp,">","&gt;");
			lFinal += "<br>Line #"+i+": " + lTemp;
		}
	}
	
	z = siEngraved();
	if (z > 0) {
		lFinal += "<br>Font: " + document.si_level.siFont[document.si_level.siFont.selectedIndex].text;
		lFinal += "<br>Font: " + document.si_level.siFontStyle[document.si_level.siFontStyle.selectedIndex].text;
		lFinal += "<br>Engrave Cost: $" + z;
		document.si_level.op1.value = " - " + z;
	}
	//Add engravement cost
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "op1^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	lFinal = replace(lFinal,"'","&rsquo;");
	document.si_level.item.value = lFinal;
	//alert(lFinal);
}

//No-Dog Angle Finder
ndName[8] = "af";			//ID of Product
ndQuantity[8] = 1;			//Quantity purchased (default)
ndFont[8] = "Roman 3L, Americana BT, Century Gothic, Continuum, Lucida Handwriting";
ndFontStyle[8] = "Small Caps, All Caps, No Caps, Normal";
ndWeight[8] = 0.27;
ndPrice[8] = 30;

//No-Dog Angle Finder Functions
function checkURL() {
	if (document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text != "No Logo") {
		document.getElementById("af1").style.visibility = 'hidden';
		document.getElementById("af2").style.visibility = 'hidden';
		
	} else {
		document.getElementById("af1").style.visibility = 'visible';
		document.getElementById("af2").style.visibility = 'visible';
	}
	
	if (document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text == "Here is a link to it") {
		document.getElementById("afURL").style.visibility = 'visible';
		document.af_level.afHTTP.value = 'http://';
	} else {
		document.getElementById("afURL").style.visibility = 'hidden';
	}
}

function afEngraved() {
	var a = 0;
	//Count the engravings
	if (document.af_level.afSide3.value != "") {
		a += 1;
	}
	if (document.af_level.afSide4.value != "") {
		a += 1;
	}
	if (document.getElementById("af1").style.visibility != "hidden") {
		if (document.af_level.afSide1.value != "") {
			a += 1;
		}
		if (document.af_level.afSide2.value != "") {
			a += 1;
		}
	}
	if (document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text != "No Logo") {
		a += 1;
	}
	return a;
}
function afCart(x) {
	var lFinal;
	var z = 0;
	var lTemp;
	
	ndQuantity[x] = document.af_level.afQuant[document.af_level.afQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "No-Dog Angle Finder";
	

	if (document.getElementById("af1").style.visibility != "hidden") {
		if (document.af_level.afSide1.value != "") {
			lTemp = document.af_level.afSide1.value
			lTemp = replace(lTemp,"<","&lt;");
			lTemp = replace(lTemp,">","&gt;");
			lFinal += "<br>Left Side Line #1: " + lTemp;
		}
		if (document.af_level.afSide2.value != "") {
			lTemp = document.af_level.afSide2.value
			lTemp = replace(lTemp,"<","&lt;");
			lTemp = replace(lTemp,">","&gt;");
			lFinal += "<br>Left Side Line #2: " + lTemp;
		}
	}


	if (document.af_level.afSide3.value != "") {
		lTemp = document.af_level.afSide3.value
		lTemp = replace(lTemp,"<","&lt;");
		lTemp = replace(lTemp,">","&gt;");
		lFinal += "<br>Right Side Line #1: " + lTemp;
	}
	if (document.af_level.afSide4.value != "") {
		lTemp = document.af_level.afSide4.value
		lTemp = replace(lTemp,"<","&lt;");
		lTemp = replace(lTemp,">","&gt;");
		lFinal += "<br>Right Side Line #2: " + lTemp;
	}

	z = afEngraved();
	if (z > 0) {
		if (z == 1 && document.getElementById("af1").style.visibility == "hidden")  {
			
		} else {
			lFinal += "<br>Font: " + document.af_level.afFont[document.af_level.afFont.selectedIndex].text;
			lFinal += "<br>Font: " + document.af_level.afFontStyle[document.af_level.afFontStyle.selectedIndex].text;
		}
		//Logo will have a one time charge IF they don't have it.
		if (document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text != "No Logo") {
			if (document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text != "You already have it") {
				document.af_level.item_logo.value = "p-3381^logo2^One time logo charge.";
				lFinal += "<br>Logo Type: " +document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text;
				document.af_level.item_logo.value += "<br>Logo Type: " +document.af_level.afLogo[document.af_level.afLogo.selectedIndex].text;
				document.af_level.item_logo.value += "^10^1";
			}
			
		}
		if (document.getElementById("afURL").style.visibility == "visible") {
			lFinal += "<br>Logo URL: " +  document.af_level.afHTTP.value;
		}
		lFinal += "<br>Engrave Cost: $" + z;
		document.af_level.op1.value = " - " + z;
	}
	//Add engravement cost
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "op1^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	lFinal = replace(lFinal,"'","&rsquo;");
	document.af_level.item.value = lFinal;

}

//No Dog Adaptor
ndName[3] = "adapt";
ndQuantity[3] = 1;			//Quantity purchased (default)
ndWeight[3] = 0.09375;
ndPrice[3] = 8.5;

//No Dog Adaptor Functions
function saCart(x) {
	var lFinal;
	var z = 0;
	ndQuantity[x] = document.sa_level.saQuant[document.sa_level.saQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "No-Dog Adaptor";
	//Add engravement cost
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	document.sa_level.item.value = lFinal;
	//alert(lFinal);
}

//T-Shirt
ndName[5] = "tee";
ndQuantity[5] = 1;			//Quantity purchased (default)
ndWeight[5] =0.5;
ndPrice[5] = 12.50;

//T-Shirt Functions
function tsCart(x) {
	var lFinal;
	var z = 0;
	ndQuantity[x] = document.ts_level.tsQuant[document.ts_level.tsQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "T-Shirt";
	lFinal += "<br>" + document.ts_level.tsSize[document.ts_level.tsSize.selectedIndex].text;
	
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	document.ts_level.item.value = lFinal;
	//alert(lFinal);
}

//Caps
ndName[6] = "cap";
ndQuantity[6] = 1;			//Quantity purchased (default)
ndWeight[6] = 0.1875;
ndPrice[6] = 14;

//Caps Functions
function bcCart(x) {
	var lFinal;
	var z = 0;
	ndQuantity[x] = document.bc_level.bcQuant[document.bc_level.bcQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "Cap";
	//Add engravement cost
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	document.bc_level.item.value = lFinal;
	//alert(lFinal);
}


//Pouch
ndName[7] = "pouch";
ndQuantity[7] = 1;			//Quantity purchased (default)
ndWeight[7] =0.1;
ndPrice[7] = 4.00;

//Pouch Functions
function dpCart(x) {
	var lFinal;
	var z = 0;
	ndQuantity[x] = document.dp_level.dpQuant[document.dp_level.dpQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "Denim Pouch";
	lFinal += "<br>" + document.dp_level.dpSize[document.dp_level.dpSize.selectedIndex].text;
	
	lFinal += "<br><br>^"
	//Add Cost
	lFinal += ndPrice[x] + "^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += "^^^" + ndWeight[x] + "^"
	document.dp_level.item.value = lFinal;
	//alert(lFinal);
}


//Wallet Card
ndName[9] = "card";
ndQuantity[9] = 1;			//Quantity purchased (default)
ndWeight[9] = 0.0;
ndPrice[9] = 0.5;

//Wallet Card Functions
function wcCart(x) {
	var lFinal;
	var z = 0;
	ndQuantity[x] = document.wc_level.wcQuant[document.wc_level.wcQuant.selectedIndex].text;
	//Add Cart ID
	lFinal = ndCart + "^";
	//Add ID Code
	lFinal += ndName[x] + "^";
	//Add Details
	lFinal += "Wallet Card";
	lFinal += "^"
	//Add Cost
	lFinal += ndPrice[x] + "^";
	//Add Quantity
	lFinal += ndQuantity[x] + "^";
	//Add weight
	lFinal += ndWeight[x] + "0.0"
	document.wc_level.item.value = lFinal;
	//alert(lFinal);
}

