//code for swapping images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	var win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}


// code for declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=2006;
var maxYear=2020;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The event date format should be mm/dd/yyyy.")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month for your event date.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day for your event date.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+" for your event date.")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		//return false
	}
return true
}

function formatCurrency( num ){
	var isNegative = false;
	num = num.toString().replace(/\\$|\\,/g,'');
	if( isNaN( num )){
		num = "0";
	}
	if( num < 0 ){
		num = Math.abs( num );
		isNegative = true;
	}
	cents = Math.floor(( num * 100 + 0.5 ) % 100 );
	num = Math.floor( ( num * 100 + 0.5 ) / 100 ).toString();
	if ( cents < 10 ){
		cents = "0" + cents;
	}
	for ( i = 0; i < Math.floor( ( num.length - ( 1 + i ) ) / 3 ); i++){
		num = num.substring( 0 ,num.length - ( 4 * i + 3 ) ) + ',' + num.substring( num.length - ( 4 * i + 3 ) );
	}
	var result = '$' + num + '.' + cents;
	if ( isNegative ){
		result = "-" + result;
	}
	return result;
}


// checkout form
function checkForm(cc_numb){
		if (document.checkOut.billing_name.value == ""){
			alert("Please enter a contact name.");
			document.checkOut.billing_name.focus();
			return false;
		}
		if (document.checkOut.billing_phone.value == ""){
			alert("Please enter a phone number.");
			document.checkOut.billing_phone.focus();
			return false;
		}
		if (document.checkOut.billing_email.value == ""){
			alert("Please enter an email address.");
			document.checkOut.billing_email.focus();
			return false;
		}
		if (document.checkOut.billing_address.value == ""){
			alert("Please enter an address.");
			document.checkOut.billing_address.focus();
			return false;
		}
		if (document.checkOut.billing_city.value == ""){
			alert("Please enter a city.");
			document.checkOut.billing_city.focus();
			return false;
		}
		if (document.checkOut.billing_state.value == ""){
			alert("Please enter a state.");
			document.checkOut.billing_state.focus();
			return false;
		}
		if (document.checkOut.billing_zip.value == ""){
			alert("Please enter a zip code.");
			document.checkOut.billing_zip.focus();
			return false;
		}
		if (document.checkOut.shipping_name.value == ""){
			alert("Please enter a shipping name.");
			document.checkOut.shipping_name.focus();
			return false;
		}
		if (document.checkOut.shipping_phone.value == ""){
			alert("Please enter a shipping phone number.");
			document.checkOut.shipping_phone.focus();
			return false;
		}
		if (document.checkOut.shipping_address.value == ""){
			alert("Please enter a shipping address.");
			document.checkOut.shipping_address.focus();
			return false;
		}
		if (document.checkOut.shipping_city.value == ""){
			alert("Please enter a shipping city.");
			document.checkOut.shipping_city.focus();
			return false;
		}
		if (document.checkOut.shipping_state.value == ""){
			alert("Please enter a shipping state.");
			document.checkOut.shipping_state.focus();
			return false;
		}
		if (document.checkOut.shipping_zip.value == ""){
			alert("Please enter a shipping zip.");
			document.checkOut.shipping_zip.focus();
			return false;
		}
		if (document.checkOut.cc_name.value == ""){
			alert("Please enter the name on the credit card.");
			document.checkOut.cc_name.focus();
			return false;
		}

/*
var valid = "0123456789"  // Valid digits in a credit card number
var len = cc_numb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = cc_numb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  //alert("Not a Number");
  bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
if(!bResult){
  alert("This is NOT a valid Credit Card Number!");
  return bResult; // Return the results
}
  */
		 if (document.checkOut.cc_numb.value == ""){
			alert("Please enter a credit card number.");
			document.checkOut.cc_numb.focus();
			return false;
		}
		if (document.checkOut.cc_type.value == ""){
			alert("Please choose a credit card type.");
			document.checkOut.cc_type.focus();
			return false;
		}
		if (document.checkOut.exp_date.value == ""){
			alert("Please enter a credit card expiration date.");
			document.checkOut.exp_date.focus();
			return false;
		}
		if (document.checkOut.cc_cvv.value == ""){
			alert("Please enter a credit card CVV number.");
			document.checkOut.cc_cvv.focus();
			return false;
		}
    return true;
 }
 
 
// show hide content on the fly
function logoplacement1(obj) {
	if (document.productForm.logo_placement_1.checked == true) {
		expandcontent(obj,'logo_placement_1_content');
		}
	else {
		contractcontent(obj,'logo_placement_1_content');
	}
}
function logoplacement2(obj) {
	if (document.productForm.logo_placement_2.checked == true) {
		expandcontent(obj,'logo_placement_2_content');
	}
	else {
		contractcontent(obj,'logo_placement_2_content');
	}
}
function logoplacement3(obj) {
	if (document.productForm.logo_placement_3.checked == true) {
		expandcontent(obj,'logo_placement_3_content');
	}
	else {
		contractcontent(obj,'logo_placement_3_content');
	}
}
function logoplacement4(obj) {
	if (document.productForm.logo_placement_4.checked == true) {
		expandcontent(obj,'logo_placement_4_content');
	}
	else {
		contractcontent(obj,'logo_placement_4_content');
	}
}

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='' //HTML for expand symbol.


if (document.getElementById){
	document.write('<style type="text/css">')
	document.write('.switchcontent{display:block;}')
	document.write('</style>')
}

function getElementbyClass(rootobj, classname){
	var temparray=new Array()
	var inc=0
	var rootlength=rootobj.length
	for (i=0; i<rootlength; i++){
		if (rootobj[i].className==classname)
			temparray[inc++]=rootobj[i]
		}
	return temparray
}

function sweeptoggle(ec){
	var thestate=(ec=="expand")? "block" : "none"
	var inc=0
	while (ccollect[inc]){
		ccollect[inc].style.display=thestate
		inc++
	}
	revivestatus()
}

function contractcontent(omit){
	var inc=0
	while (ccollect[inc]){
	if (ccollect[inc].id!=omit)
		ccollect[inc].style.display="none"
		inc++
	}
}

function expandcontent(curobj, cid){
	var spantags=curobj.getElementsByTagName("SPAN")
	var showstateobj=getElementbyClass(spantags, "showstate")
	if (ccollect.length>0){
		if (collapseprevious=="yes")
			contractcontent(cid)
			document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
		if (showstateobj.length>0){ //if "showstate" span exists in header
		if (collapseprevious=="no")
			showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
		else
			revivestatus()
		}
	}
}

function revivecontent(){
	contractcontent("omitnothing")
	selectedItem=getselectedItem()
	selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++)
	document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
	var inc=0
	while (statecollect[inc]){
		if (ccollect[inc].style.display=="block")
			statecollect[inc].innerHTML=contractsymbol
		else
			statecollect[inc].innerHTML=expandsymbol
			inc++
	}
}

function get_cookie(Name) { 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
		if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function getselectedItem(){
	if (get_cookie(window.location.pathname) != ""){
		selectedItem=get_cookie(window.location.pathname)
		return selectedItem
	}
	else
		return ""
}

function saveswitchstate(){
	var inc=0, selectedItem=""
	while (ccollect[inc]){
		if (ccollect[inc].style.display=="block")
			selectedItem+=ccollect[inc].id+"|"
			inc++
		}
		document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
	uniqueidn=window.location.pathname+"firsttimeload"
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	ccollect=getElementbyClass(alltags, "switchcontent")
	statecollect=getElementbyClass(alltags, "showstate")
	if (enablepersist=="on" && ccollect.length>0){
		document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
		firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
		if (!firsttimeload)
			revivecontent()
		}
		if (ccollect.length>0 && statecollect.length>0)
			revivestatus()
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
	window.attachEvent("onload", do_onload)
else if (document.getElementById)
	window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
	window.onunload=saveswitchstate


function auto_fill () {
	if (document.checkOut.same_shipping.checked == true) {
	document.checkOut.shipping_name.value = document.checkOut.billing_name.value;
	document.checkOut.shipping_address.value = document.checkOut.billing_address.value;
	document.checkOut.shipping_city.value = document.checkOut.billing_city.value;
	document.checkOut.shipping_state.value = document.checkOut.billing_state.value;
	//document.checkOut.shipping_zip.value = document.checkOut.billing_zip.value;
	document.checkOut.shipping_phone.value = document.checkOut.billing_phone.value;
	}
	else {
	document.checkOut.shipping_name.value = '';
	document.checkOut.shipping_company.value = '';
	document.checkOut.shipping_address.value = '';
	document.checkOut.shipping_city.value = '';
	document.checkOut.shipping_state.value = '';
	//document.checkOut.shipping_zip.value = '';
	document.checkOut.shipping_phone.value = '';
	}
}

function EnsureDelete(text) {
	var answer = confirm (text)
		if (answer) {
			return true;
		}
		else {
			return false;
		}
}
function changeFont(font,textarea)
{
document.getElementById(textarea).style.fontFamily=document.getElementById(font).value
}

function changeStyle(textarea,styles)
{
	//Sets the styles back to normal
	document.getElementById(textarea).style.fontStyle='normal'
	document.getElementById(textarea).style.fontWeight='normal'
	
	//if set to bold, then bolds it
	if (document.getElementById(styles).value == 'bold') {
		document.getElementById(textarea).style.fontWeight='bold'
		}
	//if set to italic, then italicises it
	else if (document.getElementById(styles).value == 'italic'){
		document.getElementById(textarea).style.fontStyle='italic'
		}
	else if (document.getElementById(styles).value == 'both'){
		document.getElementById(textarea).style.fontWeight='bold'
		document.getElementById(textarea).style.fontStyle='italic'
		}
}

function changeSize(textarea,sizes)
{
		if (document.getElementById(sizes).value == '12') {
		document.getElementById(textarea).style.fontSize='12px'
		}
	//if set to italic, then italicises it
	else if (document.getElementById(sizes).value == '16'){
		document.getElementById(textarea).style.fontSize='16px'
		}
	else if (document.getElementById(sizes).value == '20'){
		document.getElementById(textarea).style.fontSize='20px'
		}
	else if (document.getElementById(sizes).value == '24'){
	document.getElementById(textarea).style.fontSize='24px'
	}
	else if (document.getElementById(sizes).value == '28'){
	document.getElementById(textarea).style.fontSize='28px'
	}
}

function specifyRow(row,height){
        var x=document.getElementById('texttable').rows
		var newheight = height * 4
        x[row].height=newheight
    }
	
	
function NoEmptyNumber(input){
if(input.value<1){input.value = "0";}
if (input.value >=0 || input.value!=undefined || input.value!="" ||input.value!="NaN"){
var myinput=parseInt(input.value,'10');//base 10
if(myinput>0){input.value=myinput;}
}

}

