/* launch popups -- press articles, policies, store listings */
function popWin(url,name,w,h) {
	var win = open(url,name,'width='+w+',height='+h+',scrollbars=yes,resizable=no');
	win.focus();
}

//------------------------------------------------------------------//
// CATALOG PRODUCT PAGES //
//------------------------------------------------------------------//
function thumbCall(name)
{
	swapShirt(name);
	colorMenu(name);
}

function menuCall()
{
	var theSelectedIndex	= document.myOrder.color.selectedIndex;
	var theSelectOptions	= document.myOrder.color.options;
	var theColorName		= theSelectOptions[theSelectedIndex].value;
	swapShirt(theColorName);
}

var myT1 = new Array('Black','White','Brown','Green','Magenta','Watermelon','Pink','Red','Logo','Phrase','Hello','Organic','Something','Star','Heart','Fabulous','Hugs','Heart','Birthday','Custom');
function swapShirt(name)
{
  for(i = 0; i < myT1.length; i++)
  {
		if ( document.getElementById(myT1[i]) )
		{
			if (name == myT1[i])
			{
				document.getElementById(myT1[i]).style.display = 'block';
			}
			else
			{
				document.getElementById(myT1[i]).style.display = 'none';
			}
  		}
}  
return false;
}

//CHANGE THE MENU ITEM, WHEN A NEW COLOR THUMB IS SELECTED //
function colorMenu(theColorName)
{
	// Loop through all items in the menu, then set select if it matches theColorName //
	var colorSelect = document.myOrder.color; 
	for ( var i=0; i<colorSelect.options.length; i++ )
	{
		if( colorSelect.options[i].value == theColorName )
		{
			colorSelect.options[i].selected = true;
			break;
		}
	} 
}	

function validateShirtSize()
{
	var theSelectedIndex = document.myOrder.size.selectedIndex;
	var theSelectOptions = document.myOrder.size.options;
	var theShirtSize = theSelectOptions[theSelectedIndex].value;

	if ( (theShirtSize == "") || (theShirtSize=="-----") )
	{	
		alert('Please enter the SHIRT SIZE for the item you wish to order');
		return false;
	}
	else
	{	
		return true;
	}
}

function validateShirtQuantity()
{
	var quantity = document.myOrder.quantity.value;
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	if ( (quantity == "") || (quantity == "0" ) )
	{
			alert('You must order at least 1 shirt in order to proceed.');
			IsNumber = false;	
	}		
	else
	{
		for (i = 0; i < quantity.length && IsNumber == true; i++) 
		{ 
			Char = quantity.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				alert('You must enter a Quantity for the shirts you wish to order.  Please remove any spaces, commas, or other non-numeric characters.');
				IsNumber = false;
			}
		}
	}

	if (IsNumber == false)
	{
		return false;
	}	
	else
	{
		return true;
	}
}

// Called from onSubmit //
function validate() 
{
	return validateShirtSize() && validateShirtQuantity();
}


//------------------------------------------------------------------//
// SHOP MAIN PAGE //
//------------------------------------------------------------------//

var objNames			= new Array('','cneck_emb','cneck', 'vneck','kids','bcancer','vneck_tank','sneck_tank','cneck_ls');
var imgHost			= '';
var imgBase			= 'http://www.be-tees.com/images/2005/shop/thumbs/';

var tmbOn				= new Array();
var tmbOff				= new Array();

var txtOn				= new Array();
var txtOff				= new Array();

var lastCurrent		= "";

// PRE-LOAD SHOP MAIN IMAGES //
function ploadShopM()
{
	for (i = 1; i < objNames.length + 1; i++)
	{
		var imgDir				= imgHost + imgBase;

		myTmbOn				= imgDir + objNames[i] + '_on.jpg';
		tmbOn[i] 				= myTmbOn;
		var ploadTmbOn		= new Image();
	    ploadTmbOn.src		= myTmbOn;

		myTmbOff				= imgDir + objNames[i] + '_off.jpg';
		tmbOff[i] 				= myTmbOff;
		var ploadTmbOff		= new Image();
	    ploadTmbOff.src		= myTmbOff;

		myTxtOn				= imgDir + objNames[i] + '_txt_on.gif';
		txtOn[i]					= myTxtOn;
		var ploadTxtOn		= new Image();
	    ploadTxtOn.src		= myTxtOn;

		myTxtOff				= imgDir + objNames[i] + '_txt_off.gif';
		txtOff[i]					= myTxtOff;
		var ploadTxtOff		= new Image();
		ploadTxtOff.src		= myTxtOff;
	}
}

// CHANGE "ON" SHOP MAIN IMAGES //
function over(imgIndex) 
{
	if (lastCurrent) { off(lastCurrent); }
	var tmbName		= objNames[imgIndex];
	var tmbObj		= document[tmbName];		
	tmbObj.src 		= tmbOn[imgIndex];   		// REPLACE THUMB

	var txtName		= objNames[imgIndex] + '_txt';
	var txtObj			= document[txtName];		
	txtObj.src 			= txtOn[imgIndex];   		// REPLACE TEXT

	lastCurrent			= imgIndex;
}

// CHANGE "OFF" SHOP MAIN IMAGES //
function off(imgIndex) 
{
	var tmbName		= objNames[imgIndex];
	var tmbObj		= document[tmbName];		
	tmbObj.src 		= tmbOff[imgIndex];   		// REPLACE THUMB

	var txtName		= objNames[imgIndex] + '_txt';
	var txtObj			= document[txtName];		
	txtObj.src 			= txtOff[imgIndex];   		// REPLACE TEXT
}

// VALIDATE SHIPPING TYPE - UPS, ETC //

function validateShipType()
{
    if ( ( document.shipType.shipping_method[0].checked == false )
    && ( document.shipType.shipping_method[1].checked == false ) 
    && ( document.shipType.shipping_method[2].checked == false ) )
    {
        alert ( "Please select a SHIPPING method"); 
        return false;
    }
	else
	{
		return true;
	}
}

// FORM VALIDATE BILLING / SHIPPING INFO //
function validateFormText(alertName, elementName) 
{
	if (elementName.value.length <= 0)
	{
		alert("Please make sure you enter a valid " + alertName);
		return false;
	}
	else 
	{
		return true;
	}
}

// Validate Email Address //
function validateFormEmail(elementName)
{
	var AtSym		= elementName.value.indexOf('@')
	var Period		= elementName.value.lastIndexOf('.')
	var Space		= elementName.value.indexOf(' ')
	var Length		= elementName.value.length - 1   // Array is from 0 to length-1

	if ((AtSym < 1)||(Period <= AtSym+1)||(Period == Length )||(Space  != -1))                    			
	{
		alert("Please make sure you enter a valid E-MAIL ADDRESS");
		elementName.focus();
		return false;
	}
  	else
	{
		return true;
	}
}

// Validate Phone Numbers //
function validatePhone() 
{
	if (document.deliveryInfo.phone1.value.length < 3) 
	{
		alert("Please make sure you enter the Area Code for your phone number.");
		return false;
	}
	else if ( (document.deliveryInfo.phone2.value.length < 3) || (document.deliveryInfo.phone3.value.length < 4) )
	{
		alert("Remember to enter your 7 digit phone number.");
		return false;
	}
	else 
	{
		return true;
	}
}



// Validate the Dates Requested for Reservation //
function validateState()
{
	if ((document.deliveryInfo.bill_state.options[0].selected))
	{
		alert("Please make sure you enter the BILLING STATE you would like your order billed to.");
		return false;
	}
	else
	{
		return true;
	}
}

function validateShipState()
{
	if ((document.deliveryInfo.ship_state.options[0].selected))
	{
		alert("Please make sure you enter the SHIPPING STATE you would like your order shipped to.");
		return false;
	}
	else
	{
		return true;
	}
}

// Called from onSubmit //
function validateBilling() 
{
	if (document.deliveryInfo.sameasbilling.checked)
	{
		return validateFormText('FIRST NAME', document.deliveryInfo.fname) &&		
		validateFormText('LAST NAME', document.deliveryInfo.lname) &&	
		validateFormEmail(document.deliveryInfo.email) &&
		validatePhone() &&
		validateFormText('BILLING ADDRESS 1', document.deliveryInfo.bill_address1) &&	
		validateFormText('BILLING CITY', document.deliveryInfo.bill_city) &&	
		validateFormText('BILLING ZIP CODE', document.deliveryInfo.bill_zip) &&
		validateState(); 	
	}
	else
	{
		return validateFormText('FIRST NAME', document.deliveryInfo.fname) &&		
		validateFormText('LAST NAME', document.deliveryInfo.lname) &&	
		validateFormEmail(document.deliveryInfo.email) &&
		validatePhone() &&
		validateFormText('BILLING ADDRESS 1', document.deliveryInfo.bill_address1) &&	
		validateFormText('BILLING CITY', document.deliveryInfo.bill_city) &&	
		validateFormText('BILLING ZIP CODE', document.deliveryInfo.bill_zip) &&
		validateState() && 	
		validateFormText('SHIPPING ADDRESS 1', document.deliveryInfo.ship_address1) &&
		validateFormText('SHIPPING CITY', document.deliveryInfo.ship_city) &&	
		validateFormText('SHIPPING ZIP CODE', document.deliveryInfo.ship_zip) &&
		validateShipState(); 	
	}
}


function validateCreditType()
{
	var theSelectedIndex = document.myOrder.ccardType.selectedIndex;
	var theSelectOptions = document.myOrder.ccardType.options;
	var theCardType = theSelectOptions[theSelectedIndex].value;

	if ( (theCardType == "") || (theCardType=="-----") )
	{	
		alert('Please enter the CARD TYPE you will be using.');
		return false;
	}
	else
	{	
		return true;
	}
}

function validateCreditMonth()
{
	var theSelectedIndex = document.myOrder.ccardMonth.selectedIndex;
	var theSelectOptions = document.myOrder.ccardMonth.options;
	var theCardMonth = theSelectOptions[theSelectedIndex].value;

	if ( (theCardMonth == "") || (theCardMonth =="-----") )
	{	
		alert('Please enter the MONTH your card expires.');
		return false;
	}
	else
	{	
		return true;
	}
}

function validateCreditYear()
{
	var theSelectedIndex = document.myOrder.ccardYear.selectedIndex;
	var theSelectOptions = document.myOrder.ccardYear.options;
	var theCardYear = theSelectOptions[theSelectedIndex].value;

	if ( (theCardYear == "") || (theCardYear=="-----") )
	{	
		alert('Please enter the YEAR your card expires.');
		return false;
	}
	else
	{	
		return true;
	}
}

function validateCardInfo() 
{
		return validateCreditType() &&		
		validateFormText('CREDIT CARD NUMBER', document.myOrder.ccardNumber) &&
		validateFormText('CREDIT CARD CODE', document.myOrder.ccardCode) &&
		validateCreditMonth() && 
		validateCreditYear();
}	