
function show($obid){ // show info popup for discount

document.getElementById($obid).style.visibility='visible';
document.getElementById($obid).style.display='block';
document.getElementById($obid).style.cursor='pointer';
}
function hide($obid){ // show info popup for discount

document.getElementById($obid).style.visibility='hidden';
document.getElementById($obid).style.display='none';
}



function validatePSCode(theform,codes){
//alert(codes);
	d=theform.presale.value;
	
	//alert(hex_md5(d.toUpperCase()));
	
	//temp=md5(d.toUpperCase());
	
	//alert(codes.toString().indexOf(hex_md5(d.toUpperCase())));
	
	if(d != "" && d !=" " && codes.toString().indexOf(hex_md5(d.toUpperCase()))!= -1){
		 return true;
	}//b64_md5(d
	alert('Please Enter A Valid Pre Sale Code');
	theform.presale.focus();
	return false;
	
}


function validDelivery(){
	theform=document.getElementById('OrderForm1');
	ok=true;
	if(theform.delivery.value == ""){

			alert("Delivery Method Required");

			theform.delivery.focus();
	ok=false;
			return false

	}
	if(theform.agree.checked == ""){

			alert("You must agree to the Terms and Conditions");

			theform.agree.focus();
ok=false;
			return false

	}
	
	
	//confirm any coupon codes that may be entered
	if(theform.orderCouponCodes){
	if(!CouponCodeisValid(theform.orderCouponCodes.value,theform)){
		//
			alert("The Coupon Codes Entered Are Not Valid");

			theform.orderCouponCodes.focus();
ok=false;
			return false;
	}
	}
	if(ok){
	return true;
	}
}

function CouponCodeisValid(enteredCodes,theform){
	//check to see if the entered coupon code is valid
	if(codeStarted && enteredCodes != ''  ){
		//compare to hashed data
		attemptcodes=intoArray(enteredCodes);
clearedCodes="";
//alert(attemptcodes);

for(x=0; x < attemptcodes.length;x++){
//alert(x);
d=attemptcodes[x];
	if(codeStarted && d != "" && d !=" " && codes.indexOf(hex_md5(d.toUpperCase()))!= -1){
		
		//this code matches
		clearedCodes=clearedCodes + d.toUpperCase()+',';
	}//b64_md5(d
}


	if(clearedCodes ==''){
		//alert('Please Enter A Valid Coupon Code');
		theform.orderCouponCodes.focus();
		return false;
	}else{
		//some code passes so refresh
		theform.orderCouponCodes.value=clearedCodes;
		
		return true;
	}

		
		
	}else{
		if(enteredCodes == '' || enteredCodes.substring(0,5) == 'Enter'){
			theform.orderCouponCodes.value='';
			return true;
		
		}else{
			
		}
	}
	
}

function validPurchaseForm(theform){
	ok=true;
		if(theform.fnm.value == ""){

			alert("First Name Required");

			theform.fnm.focus();
ok=false;
			return false

		}

		if(theform.lnm.value == ""){

			alert("Last Name Required");

			theform.lnm.focus();
ok=false;
			return false

		}
		if(theform.phn.value == ""){

			alert("Phone Number Required");

			theform.phn.focus();
ok=false;
			return false

		}
		if(theform.adr.value == ""){

			alert("Billing Address Required");

			theform.adr.focus();
ok=false;
			return false

		}

		if(theform.cty.value == ""){

			alert("City Required");

			theform.cty.focus();
ok=false;
			return false

		}

		if(theform.ste.value == ""){

			alert("State Required");

			theform.ste.focus();
ok=false;
			return false

		}

		if(theform.zip.value == ""){

			alert("Zip Required");

			theform.zip.focus();
ok=false;
			return false

		}
		if(theform.eml.value == ""){

			alert("E-Mail Required");

			theform.eml.focus();
ok=false;
			return false

		}
		if(theform.crd.value == ""){

			alert("Payment Method Required");

			theform.crd.focus();
ok=false;
			return false

		}
		if(theform.num.value == ""){

			alert("Credit Card Number Required");

			theform.num.focus();
ok=false;
			return false

		}
		if(theform.cdn.value == ""){

			alert("CID Card Number Required");

			theform.cdn.focus();
ok=false;
			return false

		}
		if(theform.mth.value == ""){

			alert("Expiration Date Month Required");

			theform.mth.focus();
ok=false;
			return false

		}
		if(theform.yer.value == ""){

			alert("Expiration Date Year Required");

			theform.yer.focus();
ok=false;
			return false;

		}
		if(theform.orderCouponCodes){
		if(!CouponCodeisValid(theform.orderCouponCodes.value,theform)){
		//
			alert("The Coupon Codes Entered Are Not Valid");

			theform.orderCouponCodes.focus();
ok=false;
			return false;
						
	}
		}
			if(ok){
		return true;
			}
}






function validForm(){

		if(document.forms[0].elements[0].value == ""){

			alert("First Name Required");

			document.forms[0].elements[0].focus();

			return false

		}

		if(document.forms[0].elements[1].value == ""){

			alert("Last Name Required");

			document.forms[0].elements[1].focus();

			return false

		}
		if(document.forms[0].elements[2].value == ""){

			alert("Home Phone Number Required");

			document.forms[0].elements[2].focus();

			return false

		}
		if(document.forms[0].elements[4].value == ""){

			alert("Billing Address Required");

			document.forms[0].elements[4].focus();

			return false

		}

		if(document.forms[0].elements[5].value == ""){

			alert("City Required");

			document.forms[0].elements[5].focus();

			return false

		}

		if(document.forms[0].elements[6].value == ""){

			alert("State Required");

			document.forms[0].elements[6].focus();

			return false

		}

		if(document.forms[0].elements[7].value == ""){

			alert("Zip Required");

			document.forms[0].elements[7].focus();

			return false

		}
		if(document.forms[0].elements[8].value == ""){

			alert("E-Mail Required");

			document.forms[0].elements[8].focus();

			return false

		}
		if(document.forms[0].elements[9].value == ""){

			alert("Delivery Method Required");

			document.forms[0].elements[9].focus();

			return false

		}
		if(document.forms[0].elements[10].value == ""){

			alert("Payment Method Required");

			document.forms[0].elements[10].focus();

			return false

		}
		if(document.forms[0].elements[11].value == ""){

			alert("Credit Card Number Required");

			document.forms[0].elements[11].focus();

			return false

		}
		if(document.forms[0].elements[11].value == ""){

			alert("Credit Card Number Required");

			document.forms[0].elements[11].focus();

			return false

		}
		if(document.forms[0].elements[12].value == ""){

			alert("CID# Required");

			document.forms[0].elements[12].focus();

			return false

		}
		if(document.forms[0].elements[13].value == ""){

			alert("Expiration Date Month Required");

			document.forms[0].elements[13].focus();

			return false

		}
		if(document.forms[0].elements[14].value == ""){

			alert("Expiration Date Year Required");

			document.forms[0].elements[14].focus();

			return false

		}
		return true

	}
// Load HREF Function
//==========================================================================//
function load_href(href,value){
	new_loc = href+value;
	window.location.href = new_loc;
}

function intoArray(str){
	//break a string into parts for comparision 
	//two break options are ,(comma) and return newline
	returnArray=new Array(1);
	
	if(str.indexOf(',') == -1){
		// split on newline
		if(str.indexOf('\n') != -1){
			returnArray = str.split('\n');
		}else{
			returnArray[0]=str;	
		}
	}else{
		//split on comma,	
		str=str.replace('\n',',');
		returnArray = str.split(',');
	}
	
	return returnArray;

	
}
