var timeout;
var speed = 5; 

function updateHomePage1()
{
 	changeOpac(0,'main1');
  	for( i = 100; i >= 0; i-- ) { 
        changeOpac(i,'main4'); 
    } 
    
  	document.getElementById("main1").style.display = "block";
  	document.getElementById("main2").style.display = "none";
  	document.getElementById("main3").style.display = "none";
  	document.getElementById("main4").style.display = "none";
  	//document.getElementById("main5").style.display = "none";
  	document.getElementById("tab1").style.background = "#fff4f4";
  	document.getElementById("tab2").style.background = "#ffffe9";
  	document.getElementById("tab3").style.background = "#ffffe9";
  	document.getElementById("tab4").style.background = "#ffffe9";
  	//document.getElementById("tab5").style.background = "#ffffe9";
  	clearTimeout(timeout);
  	timeout = setTimeout("updateHomePage2()", 8000);
  	
  	for( i = 1; i <= 100; i++ ) { 
        changeOpac(i,'main1'); 
    } 
}

function updateHomePage2()
{
 	changeOpac(0,'main2');
  	for( i = 100; i >= 0; i-- ) { 
        changeOpac(i,'main1'); 
    } 
    
  	document.getElementById("main1").style.display = "none";
  	document.getElementById("main2").style.display = "block";
  	document.getElementById("main3").style.display = "none";
  	document.getElementById("main4").style.display = "none";
  	document.getElementById("tab1").style.background = "#ffffe9";
  	document.getElementById("tab2").style.background = "#fff4f4";
  	document.getElementById("tab3").style.background = "#ffffe9";
  	document.getElementById("tab4").style.background = "#ffffe9";
  	//document.getElementById("tab5").style.background = "#ffffe9";
  	clearTimeout(timeout);
  	timeout = setTimeout("updateHomePage3()", 8000);
  	
  	for( i = 1; i <= 100; i++ ) { 
        changeOpac(i,'main2'); 
    } 
}

function updateHomePage3()
{
 	changeOpac(0,'main3');
  	for( i = 100; i >= 0; i-- ) { 
        changeOpac(i,'main2'); 
    } 
    
  	document.getElementById("main1").style.display = "none";
  	document.getElementById("main2").style.display = "none";
  	document.getElementById("main3").style.display = "block";
  	document.getElementById("main4").style.display = "none";
  	//document.getElementById("main5").style.display = "none";
  	document.getElementById("tab1").style.background = "#ffffe9";
  	document.getElementById("tab2").style.background = "#ffffe9";
  	document.getElementById("tab3").style.background = "#fff4f4";
  	document.getElementById("tab4").style.background = "#ffffe9";
  	//document.getElementById("tab5").style.background = "#ffffe9";
  	clearTimeout(timeout);
  	timeout = setTimeout("updateHomePage4()", 8000);
  	
  	for( i = 1; i <= 100; i++ ) { 
        changeOpac(i,'main3'); 
    } 
}

function updateHomePage4()
{
 	changeOpac(0,'main4');
  	for( i = 100; i >= 0; i-- ) { 
        changeOpac(i,'main3'); 
    } 
    
  	document.getElementById("main1").style.display = "none";
  	document.getElementById("main2").style.display = "none";
  	document.getElementById("main3").style.display = "none";
  	document.getElementById("main4").style.display = "block";
  	//document.getElementById("main5").style.display = "none";
  	document.getElementById("tab1").style.background = "#ffffe9";
  	document.getElementById("tab2").style.background = "#ffffe9";
  	document.getElementById("tab3").style.background = "#ffffe9";
  	document.getElementById("tab4").style.background = "#fff4f4";
  	//document.getElementById("tab5").style.background = "#ffffe9";
  	clearTimeout(timeout);
  	//timeout = setTimeout("updateHomePage5()", 8000);
  	timeout = setTimeout("updateHomePage1()", 8000);
  	
  	for( i = 1; i <= 100; i++ ) { 
        changeOpac(i,'main4'); 
    } 
}

function updateHomePage5()
{
 	changeOpac(0,'main5');
  	for( i = 100; i >= 0; i-- ) { 
        changeOpac(i,'main4'); 
    } 
    
  	document.getElementById("main1").style.display = "none";
  	document.getElementById("main2").style.display = "none";
  	document.getElementById("main3").style.display = "none";
  	document.getElementById("main4").style.display = "none";
  	document.getElementById("main5").style.display = "block";
  	document.getElementById("tab1").style.background = "#ffffe9";
  	document.getElementById("tab2").style.background = "#ffffe9";
  	document.getElementById("tab3").style.background = "#ffffe9";
  	document.getElementById("tab4").style.background = "#ffffe9";
  	document.getElementById("tab5").style.background = "#fff4f4";
  	clearTimeout(timeout);
  	timeout = setTimeout("updateHomePage1()", 8000);
  	
  	for( i = 1; i <= 100; i++ ) { 
        changeOpac(i,'main5'); 
    } 
}

function validateCheckout( form )
{
	var test = true;

	// Test Policies accepted.
	if( form.policies.checked == true ) {
		form.policies.style.backgroundColor = "white";
	} else {
		form.policies.style.backgroundColor = "yellow";
		test = false;
	}

	var i;
	var ctype = "";
	for( i = 0; i < form.ctype.length; i++ ) {
		if( form.ctype[i].checked ) {
			ctype = form.ctype[i].value;
		}
	}

	if( ctype == "usa" ) {

	// Test billing name.
	if( form.c_name.value ) {
		form.c_name.style.backgroundColor = "white";
	} else {
		form.c_name.style.backgroundColor = "yellow";
		test = false;
	}

	// Test billing address line 1.
	if( form.c_address1.value ) {
		form.c_address1.style.backgroundColor = "white";
	} else {
		form.c_address1.style.backgroundColor = "yellow";
		test = false;
	}

	// Test billing city.
	if( form.c_city.value ) {
		form.c_city.style.backgroundColor = "white";
	} else {
		form.c_city.style.backgroundColor = "yellow";
		test = false;
	}

	// Test billing state.
	if( form.c_state.value ) {
		form.c_state.style.background = "white";
	} else {
		form.c_state.style.background = "yellow";
		test = false;
	}
	
	// Test billing zip 1.
	if( isNumber(form.c_zip1.value) && (form.c_zip1.value.length == 5) ) {
		form.c_zip1.style.backgroundColor = "white";
	} else {
		form.c_zip1.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test billing zip 2.
	if( !(form.c_zip2.value) || (isNumber(form.c_zip2.value) && (form.c_zip2.value.length == 4)) ) {
		form.c_zip2.style.backgroundColor = "white";
	} else {
		form.c_zip2.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test billing phone 1.
	if( isNumber(form.c_phone1.value) && (form.c_phone1.value.length == 3) ) {
		form.c_phone1.style.backgroundColor = "white";
	} else {
		form.c_phone1.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test billing phone 2.
	if( isNumber(form.c_phone2.value) && (form.c_phone2.value.length == 3) ) {
		form.c_phone2.style.backgroundColor = "white";
	} else {
		form.c_phone2.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test billing phone 3.
	if( isNumber(form.c_phone3.value) && (form.c_phone3.value.length == 4) ) {
		form.c_phone3.style.backgroundColor = "white";
	} else {
		form.c_phone3.style.backgroundColor = "yellow";
		test = false;
	}

	// Test billing email address.
	if( form.c_email.value ) {
		form.c_email.style.backgroundColor = "white";
	} else {
		form.c_email.style.backgroundColor = "yellow";
		test = false;
	}

	// Test shipping method
	if( form.needed1.value ) {
	 	var today = new Date();
		var needed = new Date(form.needed3.value, (form.needed1.value)-1, form.needed2.value);
		var days = Math.floor(((needed - today) / (60*60*24)) / 1000);
		
		if( (form.ship_method.value == "priority") && (days < 8) ) {
			form.ship_method.style.backgroundColor = "yellow";
			test = false;
		} else {
			form.ship_method.style.backgroundColor = "white";
		}
	}

	}
	/*
	
	// If there is a different shipping address, check those fields.
	if( form.billing_same_shipping.checked == false ) {
	
		// Test shipping name.
		if( form.s_name.value ) {
			form.s_name.style.backgroundColor = "white";
		} else {
			form.s_name.style.backgroundColor = "yellow";
			test = false;
		}

		// Test shipping address line 1.
		if( form.s_address1.value ) {
			form.s_address1.style.backgroundColor = "white";
		} else {
			form.s_address1.style.backgroundColor = "yellow";
			test = false;
		}
	
		// Test shipping city.
		if( form.s_city.value ) {
			form.s_city.style.backgroundColor = "white";
		} else {
			form.s_city.style.backgroundColor = "yellow";
			test = false;
		}
	
		// Test shipping state.
		if( form.s_state.value ) {
			form.s_state.style.background = "white";
		} else {
			form.s_state.style.background = "yellow";
			test = false;
		}
		
		// Test shipping zip 1.
		if( isNumber(form.s_zip1.value) && (form.s_zip1.value.length == 5) ) {
			form.s_zip1.style.backgroundColor = "white";
		} else {
			form.s_zip1.style.backgroundColor = "yellow";
			test = false;
		}
		
		// Test shipping zip 2.
		if( !(form.s_zip2.value) || (isNumber(form.s_zip2.value) && (form.s_zip2.value.length == 4)) ) {
			form.s_zip2.style.backgroundColor = "white";
		} else {
			form.s_zip2.style.backgroundColor = "yellow";
			test = false;
		}
	} else {
		form.s_name.style.backgroundColor = "white";
		form.s_address1.style.backgroundColor = "white";
		form.s_address2.style.backgroundColor = "white";
		form.s_city.style.backgroundColor = "white";
		form.s_state.style.background = "white";
		form.s_zip1.style.backgroundColor = "white";
		form.s_zip2.style.backgroundColor = "white";
	}
	
	// Test payment card holder.
	if( form.cc_name.value ) {
		form.cc_name.style.backgroundColor = "white";
	} else {
		form.cc_name.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test payment card number 1.
	if( isNumber(form.cc_number1.value) && (form.cc_number1.value.length == 4) ) {
		form.cc_number1.style.backgroundColor = "white";
	} else {
		form.cc_number1.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test payment card number 2.
	if( isNumber(form.cc_number2.value) && (form.cc_number2.value.length == 4) ) {
		form.cc_number2.style.backgroundColor = "white";
	} else {
		form.cc_number2.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test payment card number 3.
	if( isNumber(form.cc_number3.value) && (form.cc_number3.value.length == 4) ) {
		form.cc_number3.style.backgroundColor = "white";
	} else {
		form.cc_number3.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test payment card number 4.
	if( isNumber(form.cc_number4.value) && (form.cc_number4.value.length == 4) ) {
		form.cc_number4.style.backgroundColor = "white";
	} else {
		form.cc_number4.style.backgroundColor = "yellow";
		test = false;
	}
	
	// Test payment card expiration date 1.
	if( isNumber(form.cc_exp1.value) && (form.cc_exp1.value.length == 2) ) {
		form.cc_exp1.style.background = "white";
	} else {
		form.cc_exp1.style.background = "yellow";
		test = false;
	}
	
	// Test payment card expiration date 2.
	if( isNumber(form.cc_exp2.value) && (form.cc_exp2.value.length == 4) ) {
		form.cc_exp2.style.background = "white";
	} else {
		form.cc_exp2.style.background = "yellow";
		test = false;
	}
	
	// Make sure the expiration date entered is not expired.
	var d = new Date();
	var curdate = d.getFullYear();
	if( d.getMonth() < 10 ) {
		curdate = curdate + "0" + d.getMonth();
	} else {
		curdate = curdate + "" + d.getMonth();
	}
	if( (form.cc_exp2.value + "" + form.cc_exp1.value) < curdate ) {
		form.cc_exp1.style.background = "yellow";
		form.cc_exp2.style.background = "yellow";
	} else {
		form.cc_exp1.style.background = "white";
		form.cc_exp2.style.background = "white";
	}
	*/
	
	return test;
}

function validateLink( form )
{
	var test = true;

	// Test url.
	if( form.url.value ) {
		form.url.style.backgroundColor = "white";
	} else {
		form.url.style.backgroundColor = "yellow";
		test = false;
	}

	// Test title.
	if( form.title.value ) {
		form.title.style.backgroundColor = "white";
	} else {
		form.title.style.backgroundColor = "yellow";
		test = false;
	}

	// Test description.
	if( form.description.value ) {
		form.description.style.backgroundColor = "white";
	} else {
		form.description.style.backgroundColor = "yellow";
		test = false;
	}

	// Test reciprocal url.
	if( form.reciprocal.value ) {
		form.reciprocal.style.backgroundColor = "white";
	} else {
		form.reciprocal.style.backgroundColor = "yellow";
		test = false;
	}

	// Test contact name.
	if( form.contact.value ) {
		form.contact.style.backgroundColor = "white";
	} else {
		form.contact.style.backgroundColor = "yellow";
		test = false;
	}

	// Test email address.
	if( ((form.email.value).indexOf('@') > -1) && ((form.email.value).indexOf('.') > -1) ) {
		form.email.style.backgroundColor = "white";
	} else {
		form.email.style.backgroundColor = "yellow";
		test = false;
	}

	// Test Category.
	if( form.category.value ) {
		form.category.style.backgroundColor = "white";
	} else {
		form.category.style.backgroundColor = "yellow";
		test = false;
	}

	// Test Security validation code.
	if( form.security.value == "862754" ) {
		form.security.style.backgroundColor = "white";
	} else {
		form.security.style.backgroundColor = "yellow";
		test = false;
	}
	
	return test;
}

function blankLink()
{
	var form = document.exchange;
	form.url.style.backgroundColor = "white";
	form.title.style.backgroundColor = "white";
	form.description.style.backgroundColor = "white";
	form.category.style.backgroundColor = "white";
	form.reciprocal.style.backgroundColor = "white";
	form.contact.style.backgroundColor = "white";
	form.email.style.backgroundColor = "white";
	form.security.style.backgroundColor = "white";
}

function validateSupport( form )
{
	var test = true;

	// Test contact.
	if( form.contact.value ) {
		form.contact.style.backgroundColor = "white";
	} else {
		form.contact.style.backgroundColor = "yellow";
		test = false;
	}

	// Test description.
	if( form.description.value ) {
		form.description.style.backgroundColor = "white";
	} else {
		form.description.style.backgroundColor = "yellow";
		test = false;
	}

	// Test email address.
	if( ((form.email.value).indexOf('@') > -1) && ((form.email.value).indexOf('.') > -1) ) {
		form.email.style.backgroundColor = "white";
	} else {
		form.email.style.backgroundColor = "yellow";
		test = false;
	}
	
	return test;
}

function trim( str )
{
 	while( str.charAt(0) == (" ") ) {  
		str = str.substring(1);
  	}
  	
  	while( str.charAt(str.length-1) == " " ) {  
	   	str = str.substring(0,str.length-1);
  	}
  	
  	return str;
}

function isNumber( stext )
{
	var ValidChars = "0123456789.";
   	var IsNum = true;
   	var Char;

 	for( i = 0; i < stext.length && IsNum == true; i++ ) { 
      	Char = stext.charAt(i); 
      	if( ValidChars.indexOf(Char) == -1 ) {
         	IsNum = false;
        }
    }
    
   	return IsNum;
}

function setCheckoutType( ctype )
{
 	// Billing Information
	var usa = document.getElementById("c_usa");
	var international = document.getElementById("c_international");
	if( ctype == "usa" ) {
		usa.style.display = "block";
		international.style.display = "none";
	} else {
		usa.style.display = "none";
		international.style.display = "block";
	}
	
	// Shipping Information
	usa = document.getElementById("s_usa");
	international = document.getElementById("s_international");
	if( ctype == "usa" ) {
		usa.style.display = "block";
		international.style.display = "none";
	} else {
		usa.style.display = "none";
		international.style.display = "block";
	}
}