var onloadHandlers = [];
window.onload = function(){
	for(var i=0;i<onloadHandlers.length;i++){
		eval(onloadHandlers[i]);
	}
}

function seokill(){
	document.getElementById('developed-by').className = 'developed-by-seo';
}

onloadHandlers[onloadHandlers.length] = 'seokill()';

function brandSearchValidate(){
	var myForm=document.getElementById('drop-brand');
	if(myForm.value==""){
		alert('select a brand');
		myForm.focus();
		return false;
	}
}
/**************************Checkout*****************************/

function autoComplete(){
var myForm = document.getElementById('checkout-form');
if(myForm.same_address.checked){
	myForm.shipping_first_name.value=myForm.customer_first_name.value;
	myForm.shipping_last_name.value=myForm.customer_last_name.value;
	myForm.shipping_address.value=myForm.customer_address.value;
	myForm.shipping_city.value=myForm.customer_city.value;
	myForm.shipping_province.value=myForm.customer_province.value;
	myForm.shipping_country[myForm.customer_country.selectedIndex].selected=true;
	myForm.shipping_pcode.value=myForm.customer_pcode.value;
}else{
	myForm.shipping_first_name.value="";
	myForm.shipping_last_name.value="";
	myForm.shipping_address.value="";
	myForm.shipping_city.value="";
	myForm.shipping_province.value="";
	//myForm.shipping_country.value="";
	myForm.shipping_pcode.value="";
}
}
function showWrap(){
	var myObject=document.getElementById("gift-wrap");
	var myForm=document.getElementById('checkout-form');
	myObject.style.display = (myForm.gift_wrap.checked) ? 'block' : 'none';
}

function validEmail(email) {
	invalidChars = " /:,";

	if (email == "") {						
		return false;
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)			
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) {	
		return false;
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					
		return false;
	}
	if (periodPos+3 > email.length)	{		
		return false;
	}
	return true;
}

function validateCheckout(){
var myForm = document.getElementById('checkout-form');
for (i=0; i<myForm.length; i++) {
	if (myForm.elements[i].type == 'text'){
		if(myForm.elements[i].name!='shipping_to'){
			if(myForm.elements[i].name!='shipping_from'){
				if(myForm.elements[i].name!='promo_code'){
			  		if (myForm.elements[i].value == ""){
			  			myForm.elements[i].focus();
			  			alert("form is incomplete");
			  			return false;
					}
					if(myForm.elements[i].name=='email'){
						if (!validEmail(myForm.elements[i].value)) {
							alert("invalid email address")
							myForm.email.focus();
							return false;
						}
					}
				}
			}
		}
 	}
}
if(myForm.shipping_country.value=="United States"){
	if (myForm.shipping_method[0].checked || myForm.shipping_method[1].checked){
		alert("invalid Shipping Method to United Stated selected");
		return false;
	}
}
if(myForm.shipping_country.value=="Canada"){
	if (myForm.shipping_method[2].checked || myForm.shipping_method[3].checked){
		alert("invalid Shipping Method to Canada selected");
		return false;
	}
}
if (myForm.gift_wrap.checked){
	if (myForm.shipping_to.value==""){
		alert("form is incomplete");
		myForm.shipping_to.focus();
		return false;
	}
	if (myForm.shipping_from.value==""){
		alert("form is incomplete");
		myForm.shipping_from.focus();
		return false;
	}
}
	return true;
}

function txtCount(field,countTracker,maxValue) {
  if (field.value.length>maxValue){
    field.value=field.value.substring(0,maxValue);
    alert('Greeting can only be 200 characters in length.');
    return false;
  }else{countTracker.value=maxValue-field.value.length;}
}

function clearText(me){
	if(me.value=="Please type greeting here."){
		me.value="";
	}
}



/***********************SUMMARY****************************/

function validateSummary(){
    myForm = document.getElementById('info');
    var cc_num = myForm.cc_num.value;
	var cc_name = myForm.cc_name.value;
	var cc_type = myForm.cc_type.value;
	if (cc_type=="Credit Card"){
        alert("select credit card type");
        return false;
    }
    if (cc_num==""){
        alert("enter a credit card number");
        return false;
    }
    if (cc_num.indexOf(" ")>=0){
        alert("no spaces in credit card number");
        return false;
    }
	if (cc_name==""){
        alert("enter name on credit card");
        return false;
    }
    if (cc_name==" "){
        alert("enter name on credit card");
        return false;
    }	
}