
// SHIPPING COUNTRIES INFORMATION
var allowedPCCountries = 'DZ,AS,AD,AR,AM,AU,AT,AZ,A2,BH,BD,BY,BE,BM,BA,BR,BN,BG,CA,IC,CL,CN,KM,CR,HR,CY,CZ,DK,DO,TL,EC,EG,SV,EN,EE,FO,FI,FR,GF,PF,GE,DE,GI,GR,GL,GP,GU,GT,GG,GW,HT,HO,HN,HU,IS,IN,ID,IQ,IL,IT,JP,JE,JO,KZ,KE,KO,KW,KG,LA,LV,LR,LI,LT,LU,MK,MG,M3,MY,MV,MT,MH,MQ,YT,MX,FM,MD,MC,MN,ME,MA,MZ,NL,NC,NZ,NI,NG,NF,NB,MP,NO,OM,PK,PW,PH,PL,PO,PT,PR,RE,RO,RT,RU,SP,SM,SA,SF,RS,SG,SK,SI,ZA,KR,ES,LK,NT,SX,UV,TB,VL,SZ,SE,CH,TA,TW,TJ,TH,TI,TU,TN,TR,TM,UA,GB,US,UY,UZ,VA,VE,VN,VI,WL,YA,ZM,';
var requiredPCCountries = 'DZ,AR,AM,AU,AT,AZ,A2,BD,BY,BE,BA,BR,BN,BG,CA,IC,CN,HR,CY,CZ,DK,EN,EE,FO,FI,FR,GE,DE,GR,GL,GG,HO,HU,IN,ID,IL,IT,JP,JE,KZ,KO,KG,LV,LI,LT,LU,MK,MG,M3,MY,MH,MQ,YT,MX,MN,ME,NL,NZ,NB,NO,PK,PH,PL,PO,PT,PR,RE,RU,SA,SF,RS,SG,SK,SI,ZA,KR,ES,LK,NT,SX,UV,VL,SE,CH,TW,TJ,TH,TU,TR,TM,UA,GB,US,UY,UZ,VA,VN,VI,WL,YA,';
var addressOrderCountries = 'AS,AU,BD,BN,CA,CR,TL,EN,FO,GG,HK,IN,ID,IL,JP,JE,KO,MY,FM,NP,NZ,NB,OM,PW,PO,PR,SF,SG,ZA,KR,SX,UV,VL,TW,TH,TU,GB,US,VI,WL,YA,';
var userCountry = 'US';


function formSubmit(op, id)
{
	var actionStmt = "";
	switch(op)
	{
		case "aits":
			actionStmt = "./shoppingCart/shoppingCart.php?id=" + id + "&add=true&ops=aits&fid=0";
			break;    
		case "aitw":
			actionStmt = "./shoppingCart/wishList.php?id=" + id + "&add=true&ops=aitw&fid=0";
			break;    
	}
	document.productsForm.action = actionStmt;
	document.productsForm.submit();
}

function changePic(imageName, imageSource)
{
	document[imageName].src=imageSource;
}

function transferItem(field)
{
	if(field.checked)
	{
		var answer = confirm("Would like to ADD this item to your Shopping Cart?");
		var id = field.value;
		
		if (answer)
		{
			window.location = "./wishList.php?id=" + id + "&ops=trans";
		}
		else
		{
			field.checked = false;
		}
	}
}

function copyInfo()
{
	if (document.customerInfo.same.checked)
	{
		document.customerInfo.bill_firstname.value = document.customerInfo.ship_firstname.value;
		document.customerInfo.bill_lastname.value = document.customerInfo.ship_lastname.value;
		document.customerInfo.bill_address1.value = document.customerInfo.ship_address1.value;
		document.customerInfo.bill_address2.value = document.customerInfo.ship_address2.value;
		document.customerInfo.bill_city.value = document.customerInfo.ship_city.value;
		document.customerInfo.bill_state_id.value = document.customerInfo.ship_state_id.value;
		document.customerInfo.bill_country_id.value = document.customerInfo.ship_country_id.value;
		document.customerInfo.bill_postal_code.value = document.customerInfo.ship_postal_code.value;
		document.customerInfo.bill_phone.value = document.customerInfo.ship_phone.value;
	}
}

function determineShipping(shippingType)
{
/*
	var shippingCost = 0;
	switch(shippingType.value)
	{
		case "1":
			shippingCost = 10;
			break;    
		case "2":
			shippingCost = 20;
			break;    
		case "3":
			shippingCost = 30;
			break;    
		case "4":
			shippingCost = 40;
			break;    
		default:
			shippingCost = 10;
			break;    
	}	
	
	var orgStringTotal = document.checkout.merchandiseTotal.value;
	var replacedNumNoCommas = orgStringTotal.replace(/\,/g,"");
	var orgFloatTotal = parseFloat(replacedNumNoCommas);
	var newTotal = orgFloatTotal + shippingCost;
	currencyTotal = newTotal.toFixed(2);
	
	document.checkout.x_amount.value = currencyTotal;
	document.getElementById('totalPrice').innerHTML = "$" + currencyTotal;
	*/
}


//
// Each required form field can be checked with JavaScript. Here are 
//    the function names for the different kinds of checks:
//
//       1. WithoutContent() -- check if the text, textarea, password, 
//              or file fields has no content.
//       2. NoneWithContent() -- check if none of the set of text, 
//              textarea, password, or file fields have content. 
//              (Set: More than one with the same field name.)
//
//       3. NoneWithCheck() -- check if none of the set of radio buttons 
//              or checkboxes are checked. (Set: More than one with the 
//              same field name.)
//       4. WithoutCheck() -- check if the single radio button or checkbox 
//              is unchecked.
//
//       5. WithoutSelectionValue() -- check if selected drop-down list or 
//              select box entries have no value.
//
//
// The format for using the above functions is
//             if(       WithoutContent([FORMFIELDVALUE])) [ERRORMESSAGE]
//             if(      NoneWithContent([FORMFIELD])     ) [ERRORMESSAGE]
//             if(        NoneWithCheck([FORMFIELD])     ) [ERRORMESSAGE]
//             if(         WithoutCheck([FORMFIELD])     ) [ERRORMESSAGE]
//             if(WithoutSelectionValue([FORMFIELD])     ) [ERRORMESSAGE]
//
// The if(...) part and the error message part may be on separate lines, like
//             if(WithoutContent([FORMFIELDVALUE]))
//                [ERRORMESSAGE]
//             if(NoneWithContent([FORMFIELD]))
//                [ERRORMESSAGE]
//             if(NoneWithCheck([FORMFIELD]))
//                [ERRORMESSAGE]
//             if(WithoutCheck([FORMFIELD]))
//                [ERRORMESSAGE]
//             if(WithoutSelectionValue([FORMFIELD]))
//                [ERRORMESSAGE]
//
//
//      FORMFIELD -- The format for specifying a "form field" is 
//                         document.[FORMNAME].[FIELDNAME]
// FORMFIELDVALUE -- The format for specifying a "form field value" is 
//                         document.[FORMNAME].[FIELDNAME].value
//   ERRORMESSAGE -- The format for specifying an "error message" is
//                         { errormessage += "\n\n[MESSAGE]"; }
//                   If the message itself contains quotation marks, 
//                      they must be preceded with a back slash. 
//                      Example: \"
//
//
//      FORMNAME -- The name assigned to the form in the <FORM... tag. 
//     FIELDNAME -- The field name being checked.
// 
//
// For use with this JavaScript, the only non-alphanumeric character a 
//    fieldname may have is the underscore. Replace any hyphens, colons, 
//    spaces, or other non-alphanumeric characters in your field names 
//    with an underscore character.
//
//
// Put field checks into the function CheckRequiredFields(), in the order 
//    you want the fields checked.
//

function CheckRequiredFields() 
{			
	var errormessage = new String();

	// CUSTOMER SHIPPING NAME ERROR CHECK
	if( (WithoutContent(document.customerInfo.ship_firstname.value)) || (WithoutContent(document.customerInfo.ship_lastname.value)) )
	{ 
		errormessage += "\n\nPlease provide the first and last name of shipping individual."; 
	}
		
	// SHIPPING ADDRESS ERROR CHECK	
	if(WithoutContent(document.customerInfo.ship_address1.value))
	{ 
		errormessage += "\n\nPlease provide a valid shipping address."; 
	}
	if(WithoutContent(document.customerInfo.ship_city.value))
	{ 
		errormessage += "\n\nPlease provide the shipping city."; 
	}	
	if(WithoutSelectionValue(document.customerInfo.ship_state_id))
	{ 
		errormessage += "\n\nPlease provide the shipping state."; 
	}	
	if(WithoutSelectionValue(document.customerInfo.ship_country_id))
	{ 
		errormessage += "\n\nPlease provide the shipping country."; 
	}	
	if(WithoutContent(document.customerInfo.ship_postal_code.value))
	{ 
		errormessage += "\n\nPlease provide a valid postal code."; 
	}	

	// SHIPPING PHONE ERROR CHECK
	if(WithoutContent(document.customerInfo.ship_phone.value))
	{ 
		errormessage += "\n\nPlease provide a valid phone number."; 
	}	
	
	// CUSTOMER BILLING NAME ERROR CHECK
	if( (WithoutContent(document.customerInfo.bill_firstname.value)) || (WithoutContent(document.customerInfo.bill_lastname.value)) )
	{ 
		errormessage += "\n\nPlease provide the first and last name for the billing individual."; 
	}
		
	// BILLING ADDRESS ERROR CHECK	
	if(WithoutContent(document.customerInfo.bill_address1.value))
	{ 
		errormessage += "\n\nPlease provide a valid billing address."; 
	}
	if(WithoutContent(document.customerInfo.bill_city.value))
	{ 
		errormessage += "\n\nPlease provide the billing city."; 
	}	
	if(WithoutSelectionValue(document.customerInfo.bill_state_id))
	{ 
		errormessage += "\n\nPlease provide the billing state."; 
	}	
	if(WithoutSelectionValue(document.customerInfo.bill_country_id))
	{ 
		errormessage += "\n\nPlease provide the billing country."; 
	}	
	if(WithoutContent(document.customerInfo.bill_postal_code.value))
	{ 
		errormessage += "\n\nPlease provide a valid billing postal code."; 
	}	

	// BILIING EMAIL ERROR CHECK
	if(!isEmail(document.customerInfo.bill_email.value))
	{
		errormessage += "\n\nPlease provide a valid email address.";
	}
	else if ( (document.customerInfo.bill_email.value)!= (document.customerInfo.bill_email_confirm.value) )
	{
		errormessage += "\n\nPlease ensure that the email address and confirmation email address match.";
	}

	// BILLING PHONE ERROR CHECK
	if(WithoutContent(document.customerInfo.bill_phone.value))
	{ 
		errormessage += "\n\nPlease provide a valid billing phone number."; 
	}	
		
	// Put field checks above this point.
	if(errormessage.length > 2) 
	{
		alert('PLEASE COMPLETE THE FOLLOWING:' + errormessage);
		return false;
	}			

	return true; 
}


function CheckCCRequiredFields() 
{			
	var errormessage = new String();

	// CREDIT CARD TYPE ERROR CHECK
	if(WithoutSelectionValue(document.checkout.ccType))
	{ 
		errormessage += "\n\nPlease select the Credit Card Type."; 
	}	
	
	// CREDIT CARD NUMBER ERROR CHECK	
	if(WithoutContent(document.checkout.x_card_num.value))
	{ 
		errormessage += "\n\nPlease provide a valid Credit Card Number."; 
		document.checkout.x_card_num.style.backgroundColor="yellow";
	}
	else
	{
		document.checkout.x_card_num.style.backgroundColor="white";
	}	
	// CREDIT CARD EXPIRATION MONTH ERROR CHECK	
	if(WithoutContent(document.checkout.ccExpMonth.value))
	{ 
		errormessage += "\n\nPlease provide the Credit Card Expiration Month."; 
		document.checkout.ccExpMonth.style.backgroundColor="yellow";
	}
	else
	{
		document.checkout.ccExpMonth.style.backgroundColor="white";
	}	
	// CREDIT CARD EXPIRATION YEAR ERROR CHECK	
	if(WithoutContent(document.checkout.ccExpYear.value))
	{ 
		errormessage += "\n\nPlease provide the Credit Card Expiration Year."; 
		document.checkout.ccExpYear.style.backgroundColor="yellow";
	}
	else
	{
		document.checkout.ccExpYear.style.backgroundColor="white";
	}		
	// CREDIT CARD SECURITY NUMBER ERROR CHECK	
	if(WithoutContent(document.checkout.securityNum.value))
	{ 
		errormessage += "\n\nPlease provide the Credit Card Security Number."; 
		document.checkout.securityNum.style.backgroundColor="yellow";
	}
	else
	{
		document.checkout.securityNum.style.backgroundColor="white";
	}		
	// Put field checks above this point.
	if(errormessage.length > 2) 
	{
		alert('PLEASE COMPLETE THE FOLLOWING:' + errormessage);
		return false;
	}			

	return true; 
}


function CheckShippingRequiredFields() 
{			
	var errormessage = new String();

	// SHIPPING METHOD CHECK	
	if(NoneWithCheck(document.checkout.shippingID))
	{ 
		errormessage += "\n\nPlease provide the Credit Card Security Number."; 
		alert('PLEASE SPECIFY A SHIPPING METHOD');
		return false;
	}			

	return true; 
}

	
function WithoutContent(ss) 
{
	if(ss.length > 0) 
		{ return false; }
	return true;
}

function NoneWithContent(ss) 
{
	for(var i = 0; i < ss.length; i++) 
	{
		if(ss[i].value.length > 0) { return false; }
	}
	return true;
}

function NoneWithCheck(ss) 
{
	for(var i = 0; i < ss.length; i++) 
	{
		if(ss[i].checked) 
			{ return false; }
	}
	return true;
}

function WithoutCheck(ss) 
{
	if(ss.checked) 
		{ return false; }
	return true;
}

function WithoutSelectionValue(ss) 
{
	for(var i = 0; i < ss.length; i++) 
	{
		if(ss[i].selected) 
		{
			if(ss[i].value.length) 
				{ return false; }
		}
	}
	return true;
}

function isEmail(str) 
{
	// are regular expressions supported?
	var supported = 0;

	if (window.RegExp) 
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) 
		supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

function checkemail(str)
{
	//var str=document.mailcheck.emailaddress.value
	 var filter=/^.+@.+\..{2,3}$/;

	if (filter.test(str))
	{
		result = false;
	}
	else 
	{
		result = true;
	}
	return (result);
}
