/********************
COMMON FUNCTIONS
********************/

/*******************************************************************************
Image Rollovers
*******************************************************************************/
function movepic(img_name,img_src) {document[img_name].src=img_src;}
image1 = new Image(); image1.src = "image1.gif"; image2 = new Image(); image2.src = "image2.gif";
/*******************************************************************************
Selecting which info to show
*******************************************************************************/
function moreInfo(sel)
{
	var d=document, dv;
	if(d.getElementById)
	{
		for(var ii=0; ii<sel.options.length; ii++)
		{
			dv=d.getElementById(sel.options[ii].value);
			if(dv)
			dv.style.display=sel.options[ii].selected?"block":"none";
		}
	}
}
/*******************************************************************************
Hide/show on click
*******************************************************************************/
function expandcollapse (id)
{ 
	which = document.getElementById(id); 
	if (which.className=="hidden") {which.className="shown";}
	else {which.className="hidden";} 
} 
/*******************************************************************************
Strip whitespace from the beginning and end of a string
*******************************************************************************/
function trim(str) {return str.replace(/^\s+|\s+$/g,'');}
/*******************************************************************************
Make sure that textBox only contain number
*******************************************************************************/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value))
	{textBox.value = textBox.value.substring(0, textBox.value.length - 1)}
}
/*******************************************************************************
Opening picture window
*******************************************************************************/
function picWin(URL)
{
	aWindow = window.open(URL, "composerwindow", "toolbar=no, height=850, status=no, scrollbars=yes, resize=yes, menubar=no, left=0, top=0");
}
/*******************************************************************************
Live preview of text area.
Created by: Jonathan Lau; Web Site: http://lauweijie7715.excell.org
*******************************************************************************/
function livePreviewAdd()
{
	document.getElementById("preview").innerHTML = document.frmAdd.mtxContent.value
	setTimeout("livePreviewAdd()",80);
}
function livePreviewModify()
{
	document.getElementById("preview").innerHTML = document.frmModify.mtxContent.value
	setTimeout("livePreviewModify()",80);
}
/********************************************************************************
Calculate Cup Size
********************************************************************************/
function cupSize()
{
	var cup = '';
	var diff = 0;
	var bust = document.frmCup.bust.value;
	var under = document.frmCup.under.value;
	diff = (bust / 1) - (under / 1) - (3 / 1);
	if(diff <= 1) cup = 'A Cup';
	if(diff == 2) cup = 'B Cup';
	if(diff == 3) cup = 'C Cup';
	if(diff == 4) cup = 'D Cup';
	if(diff >= 5) cup = 'DD/F Cup';
	document.frmCup.result.value = cup;
}
/******************************************************************************
SET SHIPPING SAME AS PAYMENT INFO
******************************************************************************/
function setPaymentInfo(isChecked)
{
	with (window.document.frmPayShip)
	{
		if (isChecked)
		{
			txtShippingFirstName.value  = txtPaymentFirstName.value;
			txtShippingLastName.value   = txtPaymentLastName.value;
			txtShippingAddress1.value   = txtPaymentAddress1.value;
			txtShippingAddress2.value   = txtPaymentAddress2.value;
			txtShippingPhone.value      = txtPaymentPhone.value;
			txtShippingState.value      = txtPaymentState.value;			
			txtShippingCity.value       = txtPaymentCity.value;
			txtShippingPostalCode.value = txtPaymentPostalCode.value;
			cboShippingCountry.value    = cboPaymentCountry.value;

			txtShippingFirstName.readOnly  = true;
			txtShippingLastName.readOnly   = true;
			txtShippingAddress1.readOnly   = true;
			txtShippingAddress2.readOnly   = true;
			txtShippingPhone.readOnly      = true;
			txtShippingState.readOnly      = true;			
			txtShippingCity.readOnly       = true;
			txtShippingPostalCode.readOnly = true;			
			cboShippingCountry.readOnly    = true;			
		}
		else
		{
			txtShippingFirstName.readOnly  = false;
			txtShippingLastName.readOnly   = false;
			txtShippingAddress1.readOnly   = false;
			txtShippingAddress2.readOnly   = false;
			txtShippingPhone.readOnly      = false;
			txtShippingState.readOnly      = false;			
			txtShippingCity.readOnly       = false;
			txtShippingPostalCode.readOnly = false;			
			cboShippingCountry.readOnly    = false;			
		}
	}
}
/******************************************************************************
BLOCK ENTER TO SUBMIT A FORM - USED FOR ULTIMATE VALIDATOR FORMS ONLY
******************************************************************************/
function blockEnter(evt)
{
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode :
((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13)
	{
		return false;
	}
	else
	{
		return true;
	}
}
/******************************************************************************
<<<<<<<<<<<<<<<<<<<<<<<<< ULTIMATE VALIDATOR >>>>>>>>>>>>>>>>>>>>>>
 Orignal Ultimate Validator: http://www.squidfingers.com
 Added Live Validation: http://www.codylindley.com
 Added Drop-Down Form Fields and CC Validation: http://habibihon.com
 CC Validation Adapted From: http://javascript.internet.com/forms/val-credit-card.html
    & http://javascript.internet.com/forms/credit-card-number-validation.html
******************************************************************************/
//MINI VALIDATE FUNCTIONS
function isEmpty(str)							// is empty
{return (str == null) || (str.length == 0);}
function isEmail(str)							// is valid email
{
	if(isEmpty(str)) return false;
	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
	return re.test(str);
}
function isAlpha(str)							// only contains A-Z or a-z
{
	var re = /[^a-zA-Z ]/g
	if (re.test(str)) return false;
	return true;
}
function isNumeric(str)							// only contains 0-9
{
	var re = /[\D]/g
	if (re.test(str)) return false;
	return true;
}
function isAlphaNumeric(str)						// only has A-Z, a-z or 0-9
{
	var re = /[^a-zA-Z0-9 ]/g
	if (re.test(str)) return false;
	return true;
}
function isLength(str, len)						// string's length is "len"
{return str.length == len;}
function isLengthBetween(str, min, max)				// string's length between "min" and "max"
{return (str.length >= min)&&(str.length <= max);}
function isPhoneNumber(str)						// US phone: (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
{
	var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
	return re.test(str);
}
function isDate(str)							// date: mm dd yyyy, mm/dd/yyyy, mm.dd.yyyy, mm-dd-yyyy
{
	var re = /^(\d{1,2})[\s\.\/-](\d{1,2})[\s\.\/-](\d{4})$/
	if (!re.test(str)) return false;
	var result = str.match(re);
	var m = parseInt(result[1]);
	var d = parseInt(result[2]);
	var y = parseInt(result[3]);
	if(m < 1 || m > 12 || y < 1900 || y > 2100) return false;
	if(m == 2){
		var days = ((y % 4) == 0) ? 29 : 28;
	}else if(m == 4 || m == 6 || m == 9 || m == 11){
		var days = 30;
	}else{
		var days = 31;
	}
	return (d >= 1 && d <= days);
}
function isMatch(str1, str2)						// "str1" is the same as the "str2"
{return str1 == str2;}
function isCreditCard(str)
{
	var lenStr = str.length;
	var intStr = parseInt(str);
	var iTotal = 0;						// integer total set at zero
	var temp;							// temp var for parsing string
	var calc;							// used for calc of each digit

	if (!isNumeric(str)) {return false;}
	else if (!isLengthBetween(str, 13, 19)) {return false;}
	else
	{
		for(var i=lenStr;i>0;i--)
		{							// LOOP through the digits of the card
			calc = parseInt(intStr) % 10;		// right most digit
			calc = parseInt(calc);			// assure it is an integer
			iTotal += calc;				// running total of card # thru loop - Do Nothing to first digit
			i--;						// decrement the count - move to the next digit in the card
			intStr = intStr / 10;			// subtracts right most digit from txtN
			calc = parseInt(intStr) % 10;		// NEXT right most digit
			calc = calc *2;				// multiply the digit by two
			// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7, I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      		switch(calc)
			{
				case 10: calc = 1; break;	//5*2=10 & 1+0 = 1
				case 12: calc = 3; break;	//6*2=12 & 1+2 = 3
				case 14: calc = 5; break;	//7*2=14 & 1+4 = 5
				case 16: calc = 7; break;	//8*2=16 & 1+6 = 7
				case 18: calc = 9; break;	//9*2=18 & 1+8 = 9
				default: calc = calc;		//4*2= 8 &   8 = 8  -same for all lower numbers
			}                                               
			intStr = intStr / 10;			// subtracts right most digit from ccNum
			iTotal += calc;				// running total of card # as we loop
		}							// END OF LOOP
		if ((iTotal%10)==0) {return true;}
		else {return false;}
	}
}
function isExpDate(str1, str2)
{
	var lenStr2 = str2.length;
	if(!isNumeric(str1) || !isNumeric(str2)) {return false;}
	else if (str1 <= 12 && (lenStr2 == 2 || lenStr2 == 4))
	{
		today = new Date();
		expiry = new Date(str2, str1);
		if (today.getTime() < expiry.getTime()) {return true;}
		else {return false;}
	}
	else {return false;}
}
function isType(str1, str2)
{
	var cardpatterns = {
      	'visa'       : /^(4\d{12})|(4\d{15})$/,
      	'mastercard' : /^5[1-5]\d{14}$/,
      	'discover'   : /^6011\d{12}$/,
		'amex'       : /^3[47]\d{13}$/,
		'diners'     : /^(30[0-5]\d{11})|(3[68]\d{12})$/
	};

	for (var typeForCC in cardpatterns)
	{
		for (var pattern in cardpatterns)
		{
			if (cardpatterns[pattern].test(str1))
			{
				if (pattern == str2) {return true;}
				else {return false;}
			}
		}
	}
}
//PRECHECK FUNCTIONS
function valPayShip()
{
	f = null;
	f = document.frmPayShip;
	f.txtDanceName.isAlphaNumeric = true;
	f.txtPassword1.isLengthBetween = [4,255];
	f.txtPassword2.isMatch = f.txtPassword1.value;
	f.txtEmail.isEmail = true;
	f.txtDomain.optional = true;
//	f.chkSame.optional = true;
	f.txtPaymentFirstName.isAlpha = true;
	f.txtShippingFirstName.optional = true;
	f.txtPaymentLastName.isAlpha = true;
	f.txtShippingLastName.optional = true;
	f.txtPaymentPhone.isEmpty = true;
	f.txtShippingPhone.optional = true;
	f.txtPaymentAddress1.isEmpty = true;
	f.txtShippingAddress1.optional = true;
	f.txtPaymentAddress2.optional = true;
	f.txtShippingAddress2.optional = true;
	f.txtPaymentCity.isAlpha = true;
	f.txtShippingCity.optional = true;
	f.txtPaymentState.isAlpha = true;
	f.txtShippingState.optional = true;
	f.txtPaymentPostalCode.isAlphaNumeric = true;
	f.txtShippingPostalCode.optional = true;
//	f.rdoGoto.optional = true;
//	f.txtGoto.optional = true;

	//deal with radio and check buttons must be set according to page specifics
	var preCheck = true;

	return validateForm(f,preCheck,'valPayShip');
}
function valCheckout()
{
	f = null;
	f = document.frmCheckout;
	f.txtDanceName.isAlphaNumeric = true;
	f.txtPassword1.isLengthBetween = [4,255];
	f.txtPassword2.isMatch = f.txtPassword1.value;
	f.txtEmail.isEmail = true;
	f.txtDomain.optional = true;
//	f.chkSame.optional = true;
	f.txtPaymentFirstName.isAlpha = true;
	f.txtShippingFirstName.optional = true;
	f.txtPaymentLastName.isAlpha = true;
	f.txtShippingLastName.optional = true;
	f.txtPaymentPhone.isEmpty = true;
	f.txtShippingPhone.optional = true;
	f.txtPaymentAddress1.isEmpty = true;
	f.txtShippingAddress1.optional = true;
	f.txtPaymentAddress2.optional = true;
	f.txtShippingAddress2.optional = true;
	f.txtPaymentCity.isAlpha = true;
	f.txtShippingCity.optional = true;
	f.txtPaymentState.isAlpha = true;
	f.txtShippingState.optional = true;
	f.txtPaymentPostalCode.isAlphaNumeric = true;
	f.txtShippingPostalCode.optional = true;
	f.txtCc.optional = true;
	f.cboType.optional = true;
	f.rdoCode.optional = true;
	f.txtCode.optional = true;
	f.txtMonth.optional = true;
	f.txtYear.optional = true;

	//deal with radio and check buttons must be set according to page specifics
	var preCheck = true;

	var method = f.cboPayment.selectedIndex;
	if (method == 3)
	{
		var type = f.cboType.value;
		cc = document.getElementById('txtCc').value;
		code = document.getElementById('txtCode').value;
		var lenCode = code.length;
		month = document.getElementById('txtMonth').value;
		year = document.getElementById('txtYear').value;

		//validate credit card
		if (isEmpty(cc))
		{
			document.getElementById('txtCcLm').style.display = 'block';
			document.getElementById('txtCcL').className = 'errorLabel';
			document.getElementById('txtCcLm').innerHTML = 'Required Entry';
			preCheck = false;
		}
		else if (!isCreditCard(cc))
		{
			document.getElementById('txtCcLm').style.display = 'block';
			document.getElementById('txtCcL').className = 'errorLabel';
			document.getElementById('txtCcLm').innerHTML = 'Invalid Credit Card Number';
			preCheck = false;
		}
		else
		{
			document.getElementById('txtCcLm').style.display = 'none';
			document.getElementById('txtCcL').className = 'fixedLabel';
			document.getElementById('txtCcLm').innerHTML = '';
		}
		//validate type
		if (type == 'noselection')
		{
			document.getElementById('cboTypeLm').style.display = 'block';
			document.getElementById('cboTypeL').className = 'errorLabel';
			document.getElementById('cboTypeLm').innerHTML = 'Required Entry';
			preCheck = false;
		}
		else if (isCreditCard(cc))
		{
			if (!isType(cc, type))
			{
				document.getElementById('cboTypeLm').style.display = 'block';
				document.getElementById('cboTypeL').className = 'errorLabel';
				document.getElementById('cboTypeLm').innerHTML = 'Invalid Card Type';
				preCheck = false;
			}
			else
			{
				document.getElementById('cboTypeLm').style.display = 'none';
				document.getElementById('cboTypeL').className = 'fixedLabel';
				document.getElementById('cboTypeLm').innerHTML = '';
			}
		}
		else
		{
			document.getElementById('cboTypeLm').style.display = 'none';
			document.getElementById('cboTypeL').className = 'fixedLabel';
			document.getElementById('cboTypeLm').innerHTML = '';
		}
		//validate code
		if (!f.rdoCode[0].checked && !f.rdoCode[1].checked)
		{
			document.getElementById('rdoCodeLm').style.display = 'block';
			document.getElementById('rdoCodeL').className = 'errorLabel';
			document.getElementById('rdoCodeLm').innerHTML = 'Required Selection';
			preCheck = false;
		}
		else
		{
			if (f.rdoCode[1].checked)
			{
				if (isEmpty(code))
				{
					document.getElementById('rdoCodeLm').style.display = 'block';
					document.getElementById('rdoCodeL').className = 'errorLabel';
					document.getElementById('rdoCodeLm').innerHTML = 'Required Entry';
					preCheck = false;
				}
				else
				{
					document.getElementById('rdoCodeLm').style.display = 'none';
					document.getElementById('rdoCodeL').className = 'fixedLabel';
					document.getElementById('rdoCodeLm').innerHTML = '';
				}
			}
			else
			{
				document.getElementById('rdoCodeLm').style.display = 'none';
				document.getElementById('rdoCodeL').className = 'fixedLabel';
				document.getElementById('rdoCodeLm').innerHTML = '';
			}
		}
		//validate expiration date
		if (!isExpDate(month, year))
		{
			document.getElementById('txtMonthLm').style.display = 'block';
			document.getElementById('txtMonthL').className = 'errorLabel';
			document.getElementById('txtMonthLm').innerHTML = 'Invalid Expiration Date';
			preCheck = false;
		}
		else
		{
			document.getElementById('txtMonthLm').style.display = 'none';
			document.getElementById('txtMonthL').className = 'fixedLabel';
			document.getElementById('txtMonthLm').innerHTML = '';
		}
	}	

	return validateForm(f,preCheck,'valCheckout');
}
function valGifts()
{
	f = null;
	f = document.frmGifts;
	f.txtAmount.isNumeric = true;
	f.txtTo.isAlpha = true;
	f.mtxDescription.optional = true;
	f.txtEmail.isEmail = true;
	f.txtPaymentFirstName.isAlpha = true;
	f.txtPaymentLastName.isAlpha = true;
	f.txtPaymentPhone.isEmpty = true;
	f.txtPaymentAddress1.isEmpty = true;
	f.txtPaymentAddress2.optional = true;
	f.txtPaymentCity.isAlpha = true;
	f.txtPaymentState.isAlpha = true;
	f.txtPaymentPostalCode.isAlphaNumeric = true;
	f.txtCc.optional = true;
	f.cboType.optional = true;
	f.rdoCode.optional = true;
	f.txtCode.optional = true;
	f.txtMonth.optional = true;
	f.txtYear.optional = true;

	//deal with radio and check buttons must be set according to page specifics
	var preCheck = true;

	var method = f.cboPayment.selectedIndex;
	if (method == 2)
	{
		var type = f.cboType.value;
		cc = document.getElementById('txtCc').value;
		code = document.getElementById('txtCode').value;
		var lenCode = code.length;
		month = document.getElementById('txtMonth').value;
		year = document.getElementById('txtYear').value;

		//validate credit card
		if (isEmpty(cc))
		{
			document.getElementById('txtCcLm').style.display = 'block';
			document.getElementById('txtCcL').className = 'errorLabel';
			document.getElementById('txtCcLm').innerHTML = 'Required Entry';
			preCheck = false;
		}
		else if (!isCreditCard(cc))
		{
			document.getElementById('txtCcLm').style.display = 'block';
			document.getElementById('txtCcL').className = 'errorLabel';
			document.getElementById('txtCcLm').innerHTML = 'Invalid Credit Card Number';
			preCheck = false;
		}
		else
		{
			document.getElementById('txtCcLm').style.display = 'none';
			document.getElementById('txtCcL').className = 'fixedLabel';
			document.getElementById('txtCcLm').innerHTML = '';
		}
		//validate type
		if (type == 'noselection')
		{
			document.getElementById('cboTypeLm').style.display = 'block';
			document.getElementById('cboTypeL').className = 'errorLabel';
			document.getElementById('cboTypeLm').innerHTML = 'Required Entry';
			preCheck = false;
		}
		else if (isCreditCard(cc))
		{
			if (!isType(cc, type))
			{
				document.getElementById('cboTypeLm').style.display = 'block';
				document.getElementById('cboTypeL').className = 'errorLabel';
				document.getElementById('cboTypeLm').innerHTML = 'Invalid Card Type';
				preCheck = false;
			}
			else
			{
				document.getElementById('cboTypeLm').style.display = 'none';
				document.getElementById('cboTypeL').className = 'fixedLabel';
				document.getElementById('cboTypeLm').innerHTML = '';
			}
		}
		else
		{
			document.getElementById('cboTypeLm').style.display = 'none';
			document.getElementById('cboTypeL').className = 'fixedLabel';
			document.getElementById('cboTypeLm').innerHTML = '';
		}
		//validate code
		if (!f.rdoCode[0].checked && !f.rdoCode[1].checked)
		{
			document.getElementById('rdoCodeLm').style.display = 'block';
			document.getElementById('rdoCodeL').className = 'errorLabel';
			document.getElementById('rdoCodeLm').innerHTML = 'Required Selection';
			preCheck = false;
		}
		else
		{
			if (f.rdoCode[1].checked)
			{
				if (isEmpty(code))
				{
					document.getElementById('rdoCodeLm').style.display = 'block';
					document.getElementById('rdoCodeL').className = 'errorLabel';
					document.getElementById('rdoCodeLm').innerHTML = 'Required Entry';
					preCheck = false;
				}
				else
				{
					document.getElementById('rdoCodeLm').style.display = 'none';
					document.getElementById('rdoCodeL').className = 'fixedLabel';
					document.getElementById('rdoCodeLm').innerHTML = '';
				}
			}
			else
			{
				document.getElementById('rdoCodeLm').style.display = 'none';
				document.getElementById('rdoCodeL').className = 'fixedLabel';
				document.getElementById('rdoCodeLm').innerHTML = '';
			}
		}
		//validate expiration date
		if (!isExpDate(month, year))
		{
			document.getElementById('txtMonthLm').style.display = 'block';
			document.getElementById('txtMonthL').className = 'errorLabel';
			document.getElementById('txtMonthLm').innerHTML = 'Invalid Expiration Date';
			preCheck = false;
		}
		else
		{
			document.getElementById('txtMonthLm').style.display = 'none';
			document.getElementById('txtMonthL').className = 'fixedLabel';
			document.getElementById('txtMonthLm').innerHTML = '';
		}
	}	
	return validateForm(f,preCheck,'valGifts');
}
// FINAL FORM VALIDATION
function validateForm(f,preCheck,theformfunction)
{
	var valid = true;
	var i,e,t,v,g,b,spantxt,spanid,spanelement,hiddenspan,revalidate,errorwarning;
	errorwarning = document.getElementById('errorwarning');
	
	for(i=0; i < f.elements.length; i++)
	{
		e = f.elements[i];
			
		//add event & functions to form elements based on the formfucntion string
		if (theformfunction == 'valPayShip') revalidate = function(){valPayShip()};
		if (theformfunction == 'valCheckout') revalidate = function(){valCheckout()};
		if (theformfunction == 'valGifts') revalidate = function(){valGifts()};
		if (e.type == 'text' || e.type == 'password' || e.type == 'textarea'){e.onblur = revalidate};
		//if (e.nodeName.toLowerCase() == "select"){e.onchange = revalidate};
		if (e.type == 'radio' || e.type == 'checkbox'){e.onclick = revalidate};
		if(e.optional) continue;
		
		t = e.type;
		v = e.value;
		
		g = e.id + "L";
		if(document.getElementById(g)) b = document.getElementById(g);
		
		spanid = e.id + "m";
		spanelement = document.createElement('span');
		spanelement.id = spanid;
		spanelement.className = "errortxt"
		if (!document.getElementById(spanid)) e.parentNode.appendChild(spanelement);
		hiddenspan = document.getElementById(spanid);
		
		if (t == 'text' || t == 'password' || t == 'textarea')
		{
			if(isEmpty(v))
			{
				valid = false;
				b.className = "errorLabel";
				hiddenspan.style.display = 'block';
				hiddenspan.innerHTML = 'Required Information';
				continue;
			}
			else
			{
				hiddenspan.style.display = 'none';
				hiddenspan.innerHTML = '';
				b.className = "fixedLabel"
			}
			//if(v == e.defaultValue)
			//{
			//	valid = false;
			//	hiddenspan.style.display = 'block';
			//	hiddenspan.innerHTML = 'Replace Default Text';
			//	b.className = "errorLabel";
			//	continue;
			//}
			//else
			//{
			//	hiddenspan.style.display = 'none';
			//	hiddenspan.innerHTML = '';
			//	b.className = "fixedLabel"
			//}
			if(e.isAlpha)
			{
				if(!isAlpha(v))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Only Letters Allowed';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isNumeric)
			{
				if(!isNumeric(v))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Only Numbers Allowed';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isAlphaNumeric)
			{
				if(!isAlphaNumeric(v))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Only Letters & Numbers Allowed';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isEmail)
			{
				if(!isEmail(v))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Invalid Email Format';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isLength != null)
			{
				var len = e.isLength;
				if(!isLength(v,len))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Invalid Amount Characters';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isLengthBetween != null)
			{
				var min = e.isLengthBetween[0];
				var max = e.isLengthBetween[1];
				if(!isLengthBetween(v,min,max))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Invalid Amount Characters';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isPhoneNumber)
			{
				if(!isPhoneNumber(v))
				{
				 	valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Invalid Phone Format';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isDate)
			{
				if(!isDate(v))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Invalid Date Format';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
			if(e.isMatch != null)
			{
				if(!isMatch(v, e.isMatch))
				{
					valid = false;
					b.className = "errorLabel";
					hiddenspan.style.display = 'block';
					hiddenspan.innerHTML = 'Entered Values Do Not Match';
					continue;
				}
				else
				{
					hiddenspan.style.display = 'none';
					hiddenspan.innerHTML = '';
					b.className = "fixedLabel"
				}
			}
		}
		if(t.indexOf('select') != -1)
		{
			if(e.options[e.selectedIndex].value == 'noselection')
			{
				valid = false;
				b.className = "errorLabel";
				hiddenspan.style.display = 'block';
				hiddenspan.innerHTML = 'Required Information';
				continue;
			}
			else
			{
				hiddenspan.style.display = 'none';
				hiddenspan.innerHTML = '';
				b.className = "fixedLabel"
			}
		}
		if(t == 'file')
		{
			if(isEmpty(v))
			{
				valid = false;
				b.className = "errorLabel";
				hiddenspan.style.display = 'block';
				hiddenspan.innerHTML = 'Required Information';
				continue;
			}
			else
			{
				hiddenspan.style.display = 'none';
				hiddenspan.innerHTML = '';
				b.className = "fixedLabel"
			}
		}
		
		
	}
	if(preCheck == false){valid = false};
	if(preCheck == false || valid == false)
	{
		errorwarning.style.display = 'block';
		(window.location.hash == '#errorwarning') ? null : window.location.hash = 'errorwarning';
	}
	else
	{
		errorwarning.style.display = 'none';
	}

	return valid;
}
/* All elements are assumed required and will only be validated for an empty value or defaultValue unless specified by the following properties.
isEmail = true;          // valid email address
isAlpha = true;          // A-Z a-z characters only
isNumeric = true;        // 0-9 characters only
isAlphaNumeric = true;   // A-Z a-z 0-9 characters only
isLength = number;       // must be exact length
isLengthBetween = array; // [lowNumber, highNumber] must be between lowNumber and highNumber
isPhoneNumber = true;    // valid US phone number. See "isPhoneNumber()" comments for the formatting rules
isDate = true;           // valid date. See "isDate()" comments for the formatting rules
isMatch = string;        // must match string
isCreditCard = true;     // must be valid CC number
isType = true;           // must be valid credit card type
isExpDate = true;        // must be valid expiration date
optional = true;         // element will not be validated
*/
/******************************************************************************
DELETE FUNCTIONS
******************************************************************************/
function deleteCategory(categoryId)
{
	if (confirm('Deleting this will move all products in it to the Admin cateogry. Delete this category anyway?'))
	{window.location.href = 'process.php?action=delete&categoryId=' + categoryId;}
}
function deleteOrder(cartId)
{
	if (confirm('Do you want to delete this order?'))
	{window.location.href = 'process.php?action=delete&cartId=' + cartId;}
}
function deleteLayaway(orderId)
{
	if (confirm('Do you want to delete this order?'))
	{window.location.href = 'process.php?action=delete&orderId=' + orderId;}
}
function deleteProduct(productId)
{
	if (confirm('Delete this product?'))
	{window.location.href = 'process.php?action=delete&productId=' + productId;}
}
function deleteUser(userId)
{
	if (confirm('Delete this user?'))
	{window.location.href = 'process.php?action=delete&userId=' + userId;}
}
function deleteLog(logId)
{
	if (confirm('Delete this log item?'))
	{window.location.href = 'process.php?action=delete&logId=' + logId;}
}
function deleteClient(clientId)
{
	if (confirm('Delete this client?'))
	{window.location.href = 'process.php?action=delete&clientId=' + clientId;}
}
function deleteLink(linkId)
{
	if (confirm('Delete this link?'))
	{window.location.href = 'process.php?action=delete&linkId=' + linkId;}
}
function deleteTestimonial(testimonialId)
{
	if (confirm('Delete this testimonial?'))
	{window.location.href = 'process.php?action=delete&testimonialId=' + testimonialId;}
}
function deleteDiscount(discountId)
{
	if (confirm('Delete this discount?'))
	{window.location.href = 'process.php?action=delete&discountId=' + discountId;}
}
function deleteLogItem(logId)
{
	if (confirm('Delete this log item?'))
	{window.location.href = 'process.php?action=delete&logId=' + logId;}
}
function deleteSale(saleId)
{
	if (confirm('Delete this sale?'))
	{window.location.href = 'process.php?action=delete&saleId=' + saleId;}
}
function deleteSaleProducts(saleId)
{
	if (confirm('Delete this sale?'))
	{window.location.href = 'process.php?action=delete&return=products&saleId=' + saleId;}
}
function deleteShipment(shipmentId)
{
	if (confirm('Delete this shipment?'))
	{window.location.href = 'process.php?action=delete&shipmentId=' + shipmentId;}
}
function deleteListItem(productId)
{
	if (confirm('Delete this item from your wishlist?'))
	{window.location.href = 'process.php?action=delete&productId=' + productId;}
}
function deleteCartItem(productId)
{
	if (confirm('Delete this item from your shopping cart?'))
	{window.location.href = 'process.php?action=delete&productId=' + productId;}
}
function removeDiscount()
{
	if (confirm('Remove this discount from the shopping cart?'))
	{window.location.href = 'process.php?action=remove';}
}
