var strConfirm = "Would you like to add Priority Shipping for $4.05?";
function toPayPal(title,amount,shipping,priority) {
		document.paypal.target = "_blank";
		document.paypal.item_name.value = title;
		document.paypal.amount.value = amount;
		document.paypal.shipping.value = (shipping) ? shipping : "";
		if(priority && confirm(strConfirm)) {
			document.paypal.shipping.value = 4.05;
			document.paypal.item_name.value += " (w/ Priority Shipping)";
		}
		document.paypal.submit();
		return false;
}
function zero(value) {
	if(isNaN(value) || value == "") {
		return 0;
	} else {
		return Number(value);
	}
}
function validate(form) {
 var error = "";
 var email = /^[\w\.=-]+@[\w\.-]+\.[a-zA-Z]{2,4}$/;
 var date = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
 var time = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
 var els = form.elements;
 for (var i=0;i<els.length;i++)
 {
	elRequired = els[i].getAttribute('ss_required'); elPhrase = els[i].getAttribute('ss_phrase');
	elValid = els[i].getAttribute('ss_validation'); elMax = els[i].getAttribute('ss_maxlength');
	elConditional = els[i].getAttribute('ss_conditional');elName = els[i].name; elValue = els[i].value; 
	elType = els[i].type;if(elValue == "  ") { elValue = ""; }
	if (elRequired || (elValid && elValue) || elMax) {
		switch(elValid) {			
			case "email":
			if(!email.test(elValue)) { error += " - " + elPhrase + "\n"; } break;
			
			case "time":
			if(!time.test(elValue)) { error += " - " + elPhrase + " (i.e. 8:00 AM)\n"; } break;
			
			case "select":
			if((els[i].selectedIndex/1) ==0) { error += " - " + elPhrase + " (Please make a choice)\n"; } break;	
			
			case "ssn":
			if(elValue.length != 9 || isNaN(elValue)) { error += " - Social Security No. (No dashes or spaces)\n"; } break;
			
			case "zip":
			if(elValue.length != 5 || isNaN(elValue)) { error += " - Zip Code (5 digits only)\n"; } break;
			
			case "date":
			if(date.test(elValue)) {
				var dArr = elValue.split("/"); var d = new Date(elValue);
				if(!(d.getMonth()+1==dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2])) {
					error += " - " + elPhrase + " (i.e. 1/5/1986)\n";
				}
			} else {
					error += " - " + elPhrase + " (i.e. 1/5/1986)\n";
			}
			break;
			
			case "radio":
			elR = document.elForm[elName].length;
			checked = false;
			for(var y =0; y<elR;y++) {
				if(document.elForm[elName][y].checked) {
					checked = true;
					break;
				}
			}
			if(checked==false) { error += " - " + elPhrase + " (Please make a choice)\n"; }
			break;
			
			case "numeric":
			if(isNaN(elValue.replace(/,/gi,"")) || (elValue == "" && elRequired)) { error += " - " + elPhrase + " (Must be a number)\n"; }
			break;
			
			case "checkbox":
			if(!document.elForm[elName].checked && type==1) { error += " - " + elPhrase + "\n"; }
			break;
			
			case "conditional":
			if(elValue == "" && document.elForm[elConditional].value == "") { error += " - " + elPhrase + "\n"; }
			break;
			
			default:
			if(elType=="textarea") {
				if(elMax && (elValue.length > elMax)) {
						error += " - " + elPhrase + " can be no longer than " + elMax + " characters\n";
				}
				if(elRequired && elValue.length <1) {
					  error += " - " + elPhrase + "\n";
				}
			} else if (elRequired) { 
				if(!elValue) { error += " - " + elPhrase + "\n"; } break;
			}
			break;
		}
	}  
 }
 if(error != "") {
	 error = "The following information is missing and/or invalid:\n\n" + error;
	 alert(error);
	 return false;
 } else {
	 return true;
 }
}
function tab(num,linker) {
	id = linker.id.split('-');
	for(var i=1;i<=num;i++) {
		el = document.getElementById('t-'+i);
		el.className = (i==id[1]) ? "on" : "off";
		document.getElementById('a-'+i).className = "";
	}
	linker.className = "active";
	linker.blur();
	return false;
}

function linkTo(ref,conf,url) {
	if(confirm(conf))
		window.location = url;
	ref.blur();
	return false;
}

var full_size;
function enlarge(pic,title,width,height) {
	if(full_size)
		full_size.close();
	full_size = window.open('','Farolito','dependent=yes, toolbar=no,location=no,scrollbars=no,width='+width+',height='+(height+40));
	full_size.document.open();
	full_size.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + 
		"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
	full_size.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Farolito Music</title>" +
		"</head><body style='margin: 0px; padding: 0px;'><div style='font: 12px Arial, Helvetica, Sans-serif;background:#333;color:#FFF;font-weight:bold;padding:3px 5px;'>" + title + "</div>");
	full_size.document.write("<img src='media/" + pic +"' alt='Farolito Music' />");
	full_size.document.write("<div align='center' style='font: 12px Arial, Helvetica, Sans-serif;'><a href='javascript:window.close();' style='color: #333;'>Close Window</a></div>");
	full_size.document.close();
	full_size.focus();
}