<!--


// Add left trim, right trim, and trim functions
if (!String.prototype.lTrim) {
    String.prototype.lTrim = function() { return this.replace(/^\s*/, ''); }
}
if (!String.prototype.rTrim) {
    String.prototype.rTrim = function() { return this.replace(/\s*$/, ''); }
}
if (!String.prototype.trim) {
    String.prototype.trim = function() { return this.lTrim().rTrim(); }
}

// This will remove all whitespace from a string
if (!String.prototype.removeAllWhitespace) {
    String.prototype.removeAllWhitespace = function() { return this.replace(/\s+/g, ''); }
}

function switchMenu(obj) {
	var el = document.getElementById(obj);
	if (el.style.display == "") {
		el.style.display = 'block';
	}
	else if ( el.style.display == 'none' ) {
		el.style.display = 'block';
	}
	else {
		el.style.display = 'none';
	}
}

function openMenu(obj) {
	var el = document.getElementById(obj);
	el.style.display = 'block';
}

function closeMenu(obj) {
	var el = document.getElementById(obj);
	el.style.display = 'none';
}


function checkFormElement(obj) {
	var el = document.getElementById(obj);
	el.checked = true;
}

function unCheckFormElement(obj) {
	var el = document.getElementById(obj);
	el.checked = false;
}



var total_scripts = 0;

function tally(q) {
	total_scripts += (q.checked?-1:1);
	if (total_scripts < 0) total_scripts = 0;
	calculateSummary();
}

function calculateSummary() {
	
	total = 0;
	final_output = '';
	
	frm = document.quoteForm;
	sub = document.submitForm;
	
	var text = frm.text.value;
	w = text;
	
	words = 0;
	
	if (preloaded_base_price != -1) {
		
		total = preloaded_base_price;
		words = -1;
		
	}
	else {
		
		if (w.length > 0) {
		
				
			//Word breaks
			w = w.replace(/-/g," ");
			w = w.replace(/:/g," ");
			w = w.replace(/\s/g," ");
			w = w.replace(/\"/g," ");
			w = w.replace(/,/g," ");
			w = w.replace(/\./g," ");
			
			//Reduce spaces
			oldlength = w.length;
			while (true) {
				w = w.replace(/\s\s/g," ");
				if (oldlength == w.length) break;
				oldlength = w.length;
			}
			
			tokenized = w.trim().split(" ");
			
			words = tokenized.length;
			
		}
		
		if (words == 0) total = 0;
		else if (words == 1) total = 20;
		else if ( (words > 1) && (words <= 5) ) total = 24;
		else total = 24 + ( (words-5) * 3);
		
		document.getElementById("wordcount").innerHTML = "~" + words + " words. ($" + total + ")";
		
	}
	
	if (words > 0) document.getElementById("wordcount").style.display = "block";
	else document.getElementById("wordcount").style.display = "none";
	
	if (words == -1) {
	
		//Submission
		sub.words.value 		 = text;
		sub.words_quantity.value = -1;
		sub.words_cost.value	 = total;
		
		//Summary
		final_output += '<div class="textPreview">&quot;' + text + '&quot;</div>';
		final_output += '<div class="summaryTitle">Base Cost:</div><div class="summaryValue">$' + total + '</div>';
	
	}
	else if (total > 0) {
		
		//Submission
		sub.words.value 		 = text;
		sub.words_quantity.value = words;
		sub.words_cost.value	 = total;
		
		//Summary
		final_output += '<div class="textPreview">&quot;' + text + '&quot;</div>';
		final_output += '<div class="summaryTitle">Base Translation Cost:</div><div class="summaryValue">$' + total + '</div>';
		
	}
	else {
	
		//Submission
		sub.words.value 		 = "Nothing specified.";
		sub.words_quantity.value = "0";
		sub.words_cost.value	 = "0";
	}
	
	//Scripts
	var scriptNames = Array();
	
	for (var i=0; i<frm.scripts.length; i++) {
		if (frm.scripts[i].checked == true) scriptNames[scriptNames.length] = frm.scripts[i].value;
	}
	
	var additional_scripts = scriptNames.length-1;
	if (additional_scripts < 0) additional_scripts = 0;
	
	scriptsEach = 5;
	scriptsCost = (additional_scripts) * scriptsEach;
	
	if (scriptNames.length > 0) {
		
		//Submission
		sub.scripts.value 		   = scriptNames.join(", ");
		sub.scripts_quantity.value = additional_scripts;
		sub.scripts_cost.value	   = scriptsEach;
		
		//Summary
		total += scriptsCost;
		final_output += '<div class="summaryTitle">Scripts: <small><em>(' + scriptNames.join(", ") + ')</em></small></div><div class="summaryValue">$' + scriptsCost + '</div>';
	}
	else {
		
		//Submission
		sub.scripts.value 		   = "None specified.";
		sub.scripts_quantity.value = "0";
		sub.scripts_cost.value	   = scriptsEach;
		
	}
	
	//Tattoo Stencil
	var stencil = "false";
	
	for (var i=0; i<frm.stencil.length; i++) {
		if (frm.stencil[i].checked == true) stencil = frm.stencil[i].value;
	}
	
	if (stencil == "digital") {
		
		stencilCost = 25;
		
		//Submission
		sub.stencil.value 		   = "digital";
		sub.stencil_cost.value	   = stencilCost;
		
		//Summary
		total += stencilCost;
		final_output += '<div class="summaryTitle">Digital Tattoo Stencil: Standard</div><div class="summaryValue">$' + stencilCost + '</div>';
	}
	else if (stencil == "custom") {
		
		//Submission
		stencilCost = 100;
		
		//Submission
		sub.stencil.value 		   = "custom";
		sub.stencil_cost.value	   = stencilCost;
		
		//Summary
		total += stencilCost;
		final_output += '<div class="summaryTitle">Digital Tattoo Stencil: Custom</div><div class="summaryValue">$' + stencilCost + '</div>';
	}
	else {
		
		//Submission
		sub.stencil.value 		   = "none";
		sub.stencil_cost.value	   = "0";
		
	}
	
	//Rush Ordering
	var rush = "false";
	
	for (var i=0; i<frm.rush.length; i++) {
		if (frm.rush[i].checked == true) rush = frm.rush[i].value;
	}
	
	if (rush == "week") {
		
		rushCost = 25;
		
		//Submission
		sub.rush.value 		   = "week";
		sub.rush_cost.value	   = rushCost;
		
		//Summary
		total += rushCost;
		final_output += '<div class="summaryTitle">Rush Order: <small><em>(same week)</em></small></div><div class="summaryValue">$' + rushCost + '<br/></div>';
	}
	else if (rush == "day") {
	
		rushCost = 50;
		
		//Submission
		sub.rush.value 		   = "day";
		sub.rush_cost.value	   = rushCost;
		
		//Summary
		total += rushCost;
		final_output += '<div class="summaryTitle">Rush Order: <small><em>(same day)</em></small></div><div class="summaryValue">$' + rushCost + '</div>';
	}
	else {
	
		//Submission
		sub.rush.value 		   = "none";
		sub.rush_cost.value	   = "0";
	
	}
	
	//Audio Recording
	var audio = "false";
	
	for (var i=0; i<frm.audio.length; i++) {
		if (frm.audio[i].checked == true) audio = frm.audio[i].value;
	}
	
	if (audio == "true") {
	
		audioCost = 15;
		
		//Submission
		sub.audio.value 		   = "true";
		sub.audio_cost.value	   = audioCost;
		
		//Summary
		total += audioCost;
		final_output += '<div class="summaryTitle">Audio Recording:</div><div class="summaryValue">$' + audioCost + '</div>';
	}
	else {
	
		//Submission
		sub.audio.value 		   = "none";
		sub.audio_cost.value	   = "0";
		
	}
	
	//Proofreading
	var proof = "false";
	
	for (var i=0; i<frm.proof.length; i++) {
		if (frm.proof[i].checked == true) proof = frm.proof[i].value;
	}
	
	if (proof == "true") {
		
		proofCost = 20;
		
		//Submission
		sub.proof.value 		   = "true";
		sub.proof_cost.value	   = proofCost;
	
		//Summary
		total += proofCost;
		final_output += '<div class="summaryTitle">Additional Proofreading:</div><div class="summaryValue">$' + proofCost + '</div>';
	}
	else {
		
		//Submission
		sub.proof.value 		   = "none";
		sub.proof_cost.value	   = "0";
		
	}
	
	
	//Framed Art
	var frame = "false";
	var frame_type = "false";
	
	for (var i=0; i<frm.frame.length; i++) {
		if (frm.frame[i].checked == true) frame = Number(frm.frame[i].value);
	}
	for (var i=0; i<frm.frame_type.length; i++) {
		if (frm.frame_type[i].checked == true) frame_type = frm.frame_type[i].value;
	}
	
	if (frame_type == "print" || frame_type == "calligraphy") {
		
		//Submission
		sub.frame.value 		   = frame_type;
		sub.frame_cost.value	   = Number(frame);
		
		//Summary
		total += Number(frame);
		final_output += '<div class="summaryTitle">Framed Artwork: <small><em>(' + frame_type + ')</em></small></div><div class="summaryValue">$' + frame + '<br/></div>';
	}
	else {
	
		//Submission
		sub.frame.value 		   = "none";
		sub.frame_cost.value	   = "0";
	
	}
	
	
	//Final Touches
	if (final_output.length > 0) {	
		final_output += '<div class="summaryTitle quoteTotal"><strong>Quote Total:</strong></div><div class="summaryValue quoteTotal"><strong>$' + total + '</strong></div>';
	}
	else {
		final_output = "<strong>Nothing calculated yet.</strong>";
	}
	
	//Submission
	sub.total.value	   = total;
	
	document.getElementById("itemizedQuote").innerHTML = final_output;
	
}

function submitQuote() {
	
	frm = document.quoteForm;
	sub = document.submitForm;
	
	//Check The Form... Hehe... Long check...
	
	//Check if there actually is something to translate.
	if (sub.words_quantity.value == 0) {
		alert("You must specify what you would like translated at the very top of this quote page for us to do anything.");
		return false;
	}
	
	//Check if the Customer Information has been initiated.
	if (!sub.returning_customer.checked && !sub.new_customer.checked) {
		alert("You must fill out your Customer Information by choosing whether you are a new customer or a returning one.");
		return false;
	}
	
	//Check New Customer Info
	if (sub.new_customer.checked) {
		
		//Email Fields
		if (sub.customer_email.value.length == 0) {
			alert("You must provide a valid email address.");
			return false;
		}
		if (sub.customer_email.value != sub.customer_email_2.value) {
			alert("Your email address fields do not match.");
			return false;
		}
		
		//Password Fields
		if (sub.customer_password.value.length <= 4) {
			alert("Your password must be at least 4 characters long.");
			return false;
		}
		if (sub.customer_password.value != sub.customer_password_2.value) {
			alert("Your password fields do not match.");
			return false;
		}
		
		//Name
		if (sub.customer_name_first.value.length == 0) {
			alert("You must provide us with your first name.");
			return false;
		}
		if (sub.customer_name_last.value.length == 0) {
			alert("You must provide us with your last name.");
			return false;
		}
		
		//Address
		if ( (sub.customer_address.value.length 
				+ sub.customer_address_2.value.length
				+ sub.customer_address_3.value.length) == 0) {
			alert("You must provide us with your street address.");
			return false;
		}
		if (sub.customer_city.value.length == 0) {
			alert("You must provide us with your city name.");
			return false;
		}
		if (sub.customer_state.value.length == 0) {
			alert("You must provide us with your state or provence.");
			return false;
		}
		if (sub.customer_zip.value.length == 0) {
			alert("You must provide us with your postal code.");
			return false;
		}
		if (sub.customer_country.value.length == 0) {
			alert("You must provide us with your country's name.");
			return false;
		}
		if (sub.customer_phone.value.length == 0) {
			alert("You must provide us with a phone number where we can contact you in case problems arise.");
			return false;
		}
		
	}
	
	//Returning Customer
	if (sub.returning_customer.checked) {
	
		if (sub.login_email.value.length == 0) {
			alert("Your login email is blank.");
			return false;
		}
		if (sub.login_password.value.length == 0) {
			alert("Your login password is blank.");
			return false;
		}
	
	}
	
	//Check Terms of Service
	if (document.getElementById("i_accept").checked != true) {
		alert("You must accept the Terms of Service and understand the Privacy Policy before submitting an order.");
		return false;
	}

	switchMenu("submitButtonDiv");
	switchMenu("submitQuoteAndRedirect");
	document.submitForm.submit();
	return true;
	
}

function submitPayPal() {

	sub = document.theForm;
	sub.submit();
	return true;

}


-->