// JavaScript Document

// Functions for order/index.php
function charCount(field1, field2, field3) {
  	field2.value = field1.value.length;

}
function leftOverValues()
{
	add_phrase="false"
	quantity="false"
	phrase1_name=""
	phrase2_name=""
	
	element_count=document.forms[0].elements.length
	for (i=0;i<element_count;i++)
	{
		box = document.forms[0].elements[i]
		if (box.value.length>0)
		{
			if(box.name=="form_phrase")
			{
				add_phrase="true"
				phrase2_name=box.value
			}
			else if(box.name=="form_phrase2")
			{
					phrase2_name="Side 1: "+phrase2_name+"\n"+"Side 2: "+box.value
			}
			else if(box.name=="charCnt" || box.name=="charCnt2" || box.name=="form_artwork" || box.name=="form_notes" || box.name=="form_promo" || box.name=="current_phrase" )
			{
				test="true"
			}
			else
			{
				quantity="true"
			}
		}
	}
	if(quantity=="true" && add_phrase=="true")
	{
		var name=confirm("There are bands that have not been added to your cart. \n"+phrase2_name+"\n Please click \"OK\" to add them to your cart or click \"CANCEL\" to continue to check out.\n Clicking \"OK\" will redirect you back to this page where you must click on \"CHECK OUT\" again.")
		if (name==true)
		{
		document.form1.submit()
		return false
		}
		else
		{
		return true
		}
	}
	else
	{
		return true
	}
}

Event.observe(window,'load',init);
function init() {	
	if($('form1')) {	
		Event.observe('form1','submit',validateForm);
	}
}

function validateForm(event) {
	var pg = $F('form_product_grp');
	if(pg == 5) {
		var colors = $F('form_multi_option');
		if(colors == '') {
			alert("You need to choose how many colors for your multi-colored band.");
			$('form_multi_option').style.border = '2px solid red';
			$('form_multi_option').focus();
			Event.stop(event);
		}
	}
}

function showOptions() {
	var prod = $F('form_product_grp');
	if(prod == 5 || prod == 6 || prod == 7) {
		$('div_multi_option').style.display = 'block';
		$('div_silk_option').style.display = 'none';
	}else if(prod == 10 || prod == 15 || prod == 16 || prod == 17) {
		$('div_silk_option').style.display = 'block';
		$('div_multi_option').style.display = 'none';
	}else{
		$('div_silk_option').style.display = 'none';
		$('div_multi_option').style.display = 'none';
	}
}

function art() {
	var objArt = $('form_artwork');
	
	if(objArt.checked) {
		Effect.BlindDown('div_art',{duration:.5});
		//$('div_art').style.display = 'block';
		$('form_notes').value = 'Artwork to be e-mailed.';
	}else{
		Effect.BlindUp('div_art',{duration:.5});
		//$('div_art').style.display = 'none';
		$('form_notes').value = '';
	}
}

function popPhrase(intPhrase,style) {
	if(intPhrase == 1) {	
		var objPhrase = $('phrase');
		var divRealPhrase = $('real_phrase1');
		var divCrestPhrase = $('crest_phrase1');
		var divLogoPhrase = $('logo_phrase1');
	}else{
		var objPhrase = $('phrase2');
		var divRealPhrase = $('real_phrase2');
		var divCrestPhrase = $('crest_phrase2');
		var divLogoPhrase = $('logo_phrase2');
	}
	
	if(style == 'crest') {
		Element.hide(divRealPhrase);
		Element.hide(divLogoPhrase);
		Element.show(divCrestPhrase);
		objPhrase.value = $F('grk_crest');
	}else if(style == 'logo') {
		Element.show(divLogoPhrase);
		Element.hide(divCrestPhrase);
		Element.hide(divRealPhrase);
		objPhrase.value = $F('grk_logo');
	}else if(style == 'letters') {
		Element.show(divRealPhrase);
		Element.hide(divCrestPhrase);
		Element.hide(divLogoPhrase);
		objPhrase.value = $F('grk_letters');
	}else if(style == 'custom') {
		Element.show(divRealPhrase);
		Element.hide(divCrestPhrase);
		Element.hide(divLogoPhrase);
		objPhrase.value = '';
	}
	
	if($('form_artwork')) {
		updateNotes();
	}
}

function updateNotes() {
	var objPhrase2 = $('phrase2');
	var style = $('ph1_grk').value;
	var style2 = $('ph2_grk').value;
	var objNotes = $('form_artwork');
	var notes = '';
	
	var isPhrase2 = false;
	if(objPhrase2.value != '') {
		isPhrase2 = true;
	}
	
	if(style != 'custom' && style != 'letters') {
		notes = 'Phrase 1 - ' + $F('grk_' + style + '_file');
	}
	
	if(isPhrase2) {
		if(style2 != 'custom' && style2 != 'letters') {
			if(style != 'custom' && style != 'letters') {
				notes = notes + ' and Phrase 2 - ' + $F('grk_' + style2 + '_file');
			}else{
				notes = 'Phrase 2 - ' + $F('grk_' + style2 + '_file');
			}
		}
	}
	
	$('form_notes').value = notes;
}