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_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_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 = new 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);
	var 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);
	}
	var month=parseInt(strMonth);
	var day=parseInt(strDay);
	var 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;
	}
	var cents = Math.floor(( num * 100 + 0.5 ) % 100 );
	num = Math.floor( ( num * 100 + 0.5 ) / 100 ).toString();
	if ( cents < 10 ) {
		cents = "0" + cents;
	}
	for (var 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;
}


 
 
// 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 (var 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 (var 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.getElementById('same_shipping').checked == true) {
	if (document.getElementById('billing_contactname')!=null){document.getElementById('shipping_contactname').value = document.getElementById('billing_contactname').value;}
	if (document.getElementById('billing_address')!=null){	document.getElementById('shipping_address').value = document.getElementById('billing_address').value;}
	if (document.getElementById('billing_city')!=null){document.getElementById('shipping_city').value = document.getElementById('billing_city').value;}
	if (document.getElementById('billing_state')!=null){document.getElementById('shipping_state').value = document.getElementById('billing_state').value;}
	if (document.getElementById('billing_phone')!=null){document.getElementById('shipping_phone').value=document.getElementById('billing_phone').value;}
	//document.getElementById('shipping_zip').value=document.getElementById('billing_zip').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;}
}

}
		


