function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function CheckEmail(strEmail) {
	var i;
	var getChar;


	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )
		return false;
	

		getChar = 0;
	for (i = 0 ; i < strEmail.length ; i++ ) {
		if (strEmail.charAt(i)=='@'){
			getChar++;
		}
	}	    

	if ( getChar != 1 )
		return false;

	var email1;
	var email2;
	var temail;
	
	temail = strEmail.split('@')
	email1 = temail[0].replace(/\s/g, "");
	email2 = temail[1].replace(/\s/g, "");	
	
	var cemail;
	cemail = strEmail;
	cemail = cemail.replace(/\@/g, "");	
	cemail = cemail.replace(/\./g, "");	
	
	if (cemail.length == 0)
		return false;
	
	var allow;
	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
	for(i = 0 ; i < cemail.length; i++ )
		if (allow.indexOf(cemail.charAt(i)) < 0 )
			return false;

	if (Left(email1, 1) == '.')
		return false;

	
	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)
		return false;

	if (email2.indexOf("..") >= 0 )
		return false;

	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')
		return false;

	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')
		return false;
	
	return true;
}	

function Left( sourceStr, charIdx ) {
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(0, charIdx);
}

function Right( sourceStr, charIdx ) {	
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);
}


//check join.php
function check_info(e)
{
	var msg;
	var textAll = "Please check your Information.";
	var textfn="";
	var textln="";
	var textem="";
	var textpw="";
	var textst="";
	var textssn="";
	var textein="";
	var textph="";
	var textfs="";
	var fg=1;
	var vg=1;

	if (e.food_selection.value == 0) { textfs = "Please pick your food selection from step 2.\n";}
	if ((e.first_name.value == null) || (e.first_name.value == "") || isblank(e.first_name.value)) { textfn = "First Name is Required.\n";}	
	if ((e.last_name.value == null) || (e.last_name.value == "") || isblank(e.last_name.value)) { textln = "Last Name is Required.\n";}
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
		}
	if ((e.password.value == null) || (e.password.value == "") || isblank(e.password.value)) { textpw = "Password is Required.\n"; vg=0;}
	if (vg) {
	 if (e.password.value != e.c_password.value) { textpw = "Passowrd does not match.\n"; }
	}
	if ((e.site.value == null) || (e.site.value == "") || isblank(e.site.value)) { textst = "City is Required.\n";}
	if ((e.ein.value == "") && (e.ssn.value == "")) 
	{
		textssn = "Either SSN# or EIN# is required.\n";
	}
	if ((e.phone.value == null) || (e.phone.value == "") || isblank(e.phone.value)) { textph = "Home Phone is Required.\n";}
	
	
	if (e.food_selection.style) e.food_selection.style.backgroundColor = textfs != "" ? '#FFCC66':'#FFFFFF';
	if (e.first_name.style) e.first_name.style.backgroundColor = textfn != "" ? '#FFCC66':'#FFFFFF';
	if (e.last_name.style) e.last_name.style.backgroundColor = textln != "" ? '#FFCC66':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textem != "" ? '#FFCC66':'#FFFFFF';
	if (e.password.style) e.password.style.backgroundColor = textpw != "" ? '#FFCC66':'#FFFFFF';
	if (e.c_password.style) e.c_password.style.backgroundColor = textpw != "" ? '#FFCC66':'#FFFFFF';
	if (e.site.style) e.site.style.backgroundColor = textst != "" ? '#FFCC66':'#FFFFFF';
	if (e.ssn.style) e.ssn.style.backgroundColor = textssn != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.phone.style) e.phone.style.backgroundColor = textph != "" ? '#FFCC66':'#FFFFFF';
	
	if ((textfs == "") && (textfn == "") && (textln == "") && (textem == "") && (textpw == "") && (textst == "") && (textssn == "") && (textph == "")) { e.submit(); return true;}
	
	if (textfs && textfn && textln && textem && textpw && textst && textssn && textph) {
		msg = textAll;
	} else {
		msg = textfs + textfn + textln + textem + textpw + textst + textssn  + textph;
	}		
	alert(msg);
	return false;
}

function check_join(e){
	var msg;
	var textAll = "Please check your Information.";
	var textba1="";
	var textbc="";
	var textbs="";
	var textbz="";

	var textsa1="";
	var textsc="";
	var textss="";
	var textsz="";
	
	var textcn="";
	var textct="";
	var textcc="";
	var textce="";
	var textcv="";
	
	if ((e.bill_address1.value == null) || (e.bill_address1.value == "") || isblank(e.bill_address1.value)) { textba1 = "Billing Address 1 is Required.\n";}
	if ((e.bill_city.value == null) || (e.bill_city.value == "") || isblank(e.bill_city.value)) { textbc = "Billing City is Required.\n";}
	if ((e.bill_state.value == null) || (e.bill_state.value == "") || isblank(e.bill_state.value)) { textbs = "Billing State is Required.\n";}
	if ((e.bill_zip.value == null) || (e.bill_zip.value == "") || isblank(e.bill_zip.value)) { textbz = "Billing ZIP is Required.\n";}

	if ((e.ship_address1.value == null) || (e.ship_address1.value == "") || isblank(e.ship_address1.value)) { textsa1 = "Shipping Address 1 is Required.\n";}
	if ((e.ship_city.value == null) || (e.ship_city.value == "") || isblank(e.ship_city.value)) { textsc = "Shipping City is Required.\n";}
	if ((e.ship_state.value == null) || (e.ship_state.value == "") || isblank(e.ship_state.value)) { textss = "Shipping State is Required.\n";}
	if ((e.ship_zip.value == null) || (e.ship_zip.value == "") || isblank(e.ship_zip.value)) { textsz = "Shipping ZIP is Required.\n";}

	if ((e.card_name.value == null) || (e.card_name.value == "") || isblank(e.card_name.value)) { textcn = "Card Name is Required.\n";}
	if ((e.card_type.value == null) || (e.card_type.value == "") || isblank(e.card_type.value)) { textct = "Card Type is Required.\n";}
	if ((e.card_number.value == null) || (e.card_number.value == "") || isblank(e.card_number.value)) { textcc = "Card Number is Required.\n";}
	if ((e.card_cvv.value == null) || (e.card_cvv.value == "") || isblank(e.card_cvv.value)) { textcv = "CVV is Required.\n";}
	
	if (e.bill_address1.style) e.bill_address1.style.backgroundColor = textba1 != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.bill_city.style) e.bill_city.style.backgroundColor = textbc != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.bill_state.style) e.bill_state.style.backgroundColor = textbs != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.bill_zip.style) e.bill_zip.style.backgroundColor = textbz != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.ship_address1.style) e.ship_address1.style.backgroundColor = textsa1 != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.ship_city.style) e.ship_city.style.backgroundColor = textsc != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.ship_state.style) e.ship_state.style.backgroundColor = textss != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.ship_zip.style) e.ship_zip.style.backgroundColor = textsz != "" ? '#FFCC66':'#FFFFFF'; 

	if (e.card_name.style) e.card_name.style.backgroundColor = textcn != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.card_type.style) e.card_type.style.backgroundColor = textct != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.card_number.style) e.card_number.style.backgroundColor = textcc != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.card_cvv.style) e.card_cvv.style.backgroundColor = textcv != "" ? '#FFCC66':'#FFFFFF'; 

	if ((textba1 == "") && (textbc == "") && (textbs == "") && (textbz == "") && (textsa1 == "") && (textsc == "") && (textss == "") && (textsz == "") && (textcn == "") && (textct == "") && (textcc == "") && (textcv == "")) { e.submit(); return true;}
	
	if (textba1 && textbc && textbs && textbz && textsa1 && textsc && textss && textsz && textcn && textct && textcc && textcv) {
		msg = textAll;
	} else {
		msg = textba1 + textbc + textbs + textbz + textsa1 + textsc + textss + textsz + textcn + textct + textcc + textcv;
	}		
	alert(msg);
	return false;

}


function check_num(e){
var txt="Quantity ";
  if (!checkData(e.value)) {
    e.style.backgroundColor = '#FFCC66';
	e.value=""; 
    txt = txt+" should be number!";
	alert(txt);
	return false;
  }
  e.style.backgroundColor = '#FFFFFF';
  return true;
}

function checkData(str)
{
    for( var i=0; i < str.length; i++) {
        var ch = str.substring( i, i+1 );
        if(ch < "0" || ch > "9") 
            return false;              
    }    
    return true;
}

function checkQuantity(){
	var quantity = document.addtocart.quantity.value;
	if(quantity>0){
		return true;
	}
	
	return false;
}

function check_shipping_address(e)
{
	var msg;
	var textAll = "Please check your Personal Information.";
	var textfn="";
	var textln="";
	var textem="";
	var textad="";
	var textct="";
	var textsp="";
	var textzp="";
	var fg = 1;
	
	if ((e.shipping_firstname.value == null) || (e.shipping_firstname.value == "") || isblank(e.shipping_firstname.value)) { textfn = "First Name is Required.\n";}	
	if ((e.shipping_lastname.value == null) || (e.shipping_lastname.value == "") || isblank(e.shipping_lastname.value)) { textln = "Last Name is Required.\n";}
	if ((e.shipping_email.value == null) || (e.shipping_email.value == "") || isblank(e.shipping_email.value)) { textem = "E-mail Address is Required.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.shipping_email.value)) { textem = "An Error occurred. Please enter a correct email address. \n";} 
		}
	if ((e.shipping_address1.value == null) || (e.shipping_address1.value == "") || isblank(e.shipping_address1.value)) {textad = "Address is Required.\n";}
	if ((e.shipping_city.value == null) || (e.shipping_city.value == "") || isblank(e.shipping_city.value)) { textct = "City is Required.\n";}
	if ((e.shipping_state.value == null) || (e.shipping_state.value == "") || isblank(e.shipping_state.value)) { textsp = "State is Required.\n";}
	if ((e.shipping_zip.value == null) || (e.shipping_zip.value == "") || isblank(e.shipping_zip.value)) { textzp = "ZIP or Post Code is Required.\n";}
	
	if (e.shipping_firstname.style) e.shipping_firstname.style.backgroundColor = textfn != "" ? '#FFCC66':'#FFFFFF';
	if (e.shipping_lastname.style) e.shipping_lastname.style.backgroundColor = textln != "" ? '#FFCC66':'#FFFFFF';
	if (e.shipping_email.style) e.shipping_email.style.backgroundColor = textem != "" ? '#FFCC66':'#FFFFFF';
	if (e.shipping_address1.style) e.shipping_address1.style.backgroundColor = textad != "" ? '#FFCC66':'#FFFFFF';
	if (e.shipping_city.style) e.shipping_city.style.backgroundColor = textct != "" ? '#FFCC66':'#FFFFFF';
	if (e.shipping_state.style) e.shipping_state.style.backgroundColor = textsp != "" ? '#FFCC66':'#FFFFFF';
	if (e.shipping_zip.style) e.shipping_zip.style.backgroundColor = textzp != "" ? '#FFCC66':'#FFFFFF';
	
	if ((textfn == "") && (textln == "") && (textem == "") && (textad == "") && (textct == "") && (textsp == "") && (textzp == "")) { e.submit(); return true;}
	
	if (textfn && textln && textem && textad && textct && textsp && textzp) {
		msg = textAll;
	} else {
		msg = textfn + textln + textem + textad + textct  + textsp + textzp;
	}		
	alert(msg);
	return false;
}

function check_billing_address(e)
{
	var msg;
	var textAll = "Please check your Personal Information.";
	var textad="";
	var textcy="";
	var textsp="";
	var textzp="";
	var textcn="";
	var textct="";
	var textcc="";
	var textcv="";
	
	if ((e.billing_address1.value == null) || (e.billing_address1.value == "") || isblank(e.billing_address1.value)) {textad = "Address is Required.\n";}
	if ((e.billing_city.value == null) || (e.billing_city.value == "") || isblank(e.billing_city.value)) { textcy = "City is Required.\n";}
	if ((e.billing_state.value == null) || (e.billing_state.value == "") || isblank(e.billing_state.value)) { textsp = "State is Required.\n";}
	if ((e.billing_zip.value == null) || (e.billing_zip.value == "") || isblank(e.billing_zip.value)) { textzp = "ZIP or Post Code is Required.\n";}
	if ((e.cc_name.value == null) || (e.cc_name.value == "") || isblank(e.cc_name.value)) { textcn = "Card Name is Required.\n";}
	if ((e.cc_type.value == null) || (e.cc_type.value == "") || isblank(e.cc_type.value)) { textct = "Card Type is Required.\n";}
	if ((e.cc_number.value == null) || (e.cc_number.value == "") || isblank(e.cc_number.value)) { textcc = "Card Number is Required.\n";}
	if ((e.cc_code.value == null) || (e.cc_code.value == "") || isblank(e.cc_code.value)) { textcv = "Verification Code is Required.\n";}
	
	if (e.billing_address1.style) e.billing_address1.style.backgroundColor = textad != "" ? '#FFCC66':'#FFFFFF';
	if (e.billing_city.style) e.billing_city.style.backgroundColor = textcy != "" ? '#FFCC66':'#FFFFFF';
	if (e.billing_state.style) e.billing_state.style.backgroundColor = textsp != "" ? '#FFCC66':'#FFFFFF';
	if (e.billing_zip.style) e.billing_zip.style.backgroundColor = textzp != "" ? '#FFCC66':'#FFFFFF';
	if (e.cc_name.style) e.cc_name.style.backgroundColor = textcn != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.cc_type.style) e.cc_type.style.backgroundColor = textct != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.cc_number.style) e.cc_number.style.backgroundColor = textcc != "" ? '#FFCC66':'#FFFFFF'; 
	if (e.cc_code.style) e.cc_code.style.backgroundColor = textcv != "" ? '#FFCC66':'#FFFFFF'; 
	
	if ((textad == "") && (textcy == "") && (textsp == "") && (textzp == "") && (textcn == "") && (textct == "") && (textcc == "") && (textcv == "")) { e.submit(); return true;}
	
	if (textad && textcy && textsp && textzp && textcn && textct && textcc && textcv) {
		msg = textAll;
	} else {
		msg = textad + textcy  + textsp + textzp + textcn + textct + textcc + textcv;
	}		
	alert(msg);
	return false;
}
