// JavaScript Document

function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}


function clearinput(input,val) {
	if (input.value == val) {
		input.value = '';
	}
}

function resetinput (input,val) {
	if (input.value == '') {
		input.value = val;
	}
}

function formval() {
	var err = 0;
	var err_msg = '';
	if (document.validation.first_name.value == 'First Name\*' || document.validation.first_name.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your first name';
	}
	if (document.validation.last_name.value == 'Last Name\*' || document.validation.last_name.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your last name';
	}
	if (document.validation.company.value == 'Organization') {
		document.validation.company.value = '';
	}
	if (document.validation.address.value == 'Address Line 1\*' || document.validation.address.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter the first line of your address';
	}
	if (document.validation.address2.value == 'Address Line 2') {
		document.validation.address2.value = '';
	}
	if (document.validation.city.value == 'City\*' || document.validation.city.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your city';
	}
	if (document.validation.province.value == 'State/Province\*' || document.validation.province.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your state/province';
	}
	if (document.validation.postal_code.value == 'zip/postal code\*' || document.validation.postal_code.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your Zip/Postal Code';
	}
	if (document.validation.country.value == 'Country\*' || document.validation.country.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your country';
	}
	if (document.validation.email.value == 'Email Address\*' || document.validation.email.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your email address';
	}
	if (document.validation.phone.value == 'Phone\*' || document.validation.phone.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your phone number';
	}
	if (document.validation.password.value == 'Create Password\*   (6-16 characters)' || document.validation.password.value == '' || document.validation.password.value.length < 6 || document.validation.password.value.length > 16) {
		err = 1;
		err_msg = err_msg + '\nPlease enter a valid password';
	}
	if (document.validation.passcheck.value == 'Confirm Password\*' || document.validation.passcheck.value == '' || document.validation.password.value != document.validation.passcheck.value) {
		err = 1;
		err_msg = err_msg + '\nPlease confirm your password';
	}
	if (err == 1) {
		alert(err_msg);
		if (document.validation.company.value == '') {
			document.validation.company.value = 'Organization';
		}
		if (document.validation.address2.value == '') {
			document.validation.address2.value = 'Address Line 2';
		}		return false;
	} else {
		return true;
	}
}

function formval2() {
	var err = 0;
	var err_msg = '';
	if (document.validation2.account_type.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease select your membership option';
	}
	if (document.validation2.pay_method.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease select your method of payment';
	}
	if ( document.validation2.card_number.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your credit card number';
	}
	if (document.validation2.cc_cvv.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your CVC number';
	}
	if (document.validation2.name_on_card.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter the name on your credit card';
	}
	if (document.validation2.expire_month.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your card expiry month';
	}
	if (document.validation2.expire_year.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your card expiry year';
	}
	if (err == 1) {
		alert(err_msg);
		return false;
	} else {
		return true;
	}
}

function toggleShipping() {
	var chkbox = document.getElementById('shippingtoggle');
	if (chkbox.checked == true) {
		document.getElementById('shipping').style.display = 'none';	
	} else {
		document.getElementById('shipping').style.display = 'block';
	}
}

function checkoutformval() {
	var err = 0;
	var err_msg = '';
	if (document.checkoutform.firstname.value == 'First Name\*' || document.checkoutform.firstname.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your first name';
	}
	if (document.checkoutform.lastname.value == 'Last Name\*' || document.checkoutform.lastname.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your last name';
	}
	if (document.checkoutform.company.value == 'Organization') {
		document.checkoutform.company.value = '';
	}
	if (document.checkoutform.address1.value == 'Address Line 1\*' || document.checkoutform.address1.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter the first line of your address';
	}
	if (document.checkoutform.address2.value == 'Address Line 2') {
		document.checkoutform.address2.value = '';
	}
	if (document.checkoutform.city.value == 'City\*' || document.checkoutform.city.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your city';
	}
	if (document.checkoutform.astate.value == 'State/Province\*' || document.checkoutform.astate.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your state/province';
	}
	if (document.checkoutform.zip.value == 'Zip/Postal Code\*' || document.checkoutform.zip.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your Zip/Postal Code';
	}
	if (document.checkoutform.country.value == 'Country\*' || document.checkoutform.country.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your country';
	}
	if (document.checkoutform.email.value == 'Email Address\*' || document.checkoutform.email.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your email address';
	}
	if (document.checkoutform.phone.value == 'Phone\*' || document.checkoutform.phone.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your phone number';
	}
	if (isdefined(document.checkoutform.ship_same_address) && document.checkoutform.ship_same_address.checked == false) {
		if (isdefined(document.checkoutform.shipfirstname) && document.checkoutform.shipfirstname.value == 'Shipping First Name\*' || document.checkoutform.shipfirstname.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter your shipping first name';
		}
		if (isdefined(document.checkoutform.shiplastname) && document.checkoutform.shiplastname.value == 'Shipping Last Name\*' || document.checkoutform.shiplastname.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter your shipping last name';
		}
		if (isdefined(document.checkoutform.shipcompany) && document.checkoutform.shipcompany.value == 'Shipping Organization') {
			document.checkoutform.shipcompany.value = '';
		}
		if (isdefined(document.checkoutform.shipaddress1) && document.checkoutform.shipaddress1.value == 'Shipping Address Line 1\*' || document.checkoutform.shipaddress1.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter the first line of your shipping address';
		}
		if (isdefined(document.checkoutform.shipaddress2) && document.checkoutform.shipaddress2.value == 'Shipping Address Line 2') {
			document.checkoutform.shipaddress2.value = '';
		}
		if (isdefined(document.checkoutform.shipcity) && document.checkoutform.shipcity.value == 'Ship City\*' || document.checkoutform.shipcity.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter your shipping city';
		}
		if (isdefined(document.checkoutform.shipastate) && document.checkoutform.shipastate.value == 'Shipping State/Province\*' || document.checkoutform.shipastate.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter your shipping state/province';
		}
		if (isdefined(document.checkoutform.shipzip) && document.checkoutform.shipzip.value == 'Shipping Zip/Postal Code\*' || document.checkoutform.shipzip.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter your Zip/Postal Code';
		}
		if (isdefined(document.checkoutform.shipcountry) && document.checkoutform.shipcountry.value == 'Shipping Country\*' || document.checkoutform.shipcountry.value == '') {
			err = 1;
			err_msg = err_msg + '\nPlease enter your shipping country';
		}
	}
	if (document.checkoutform.ShipRateCode.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease select a shipping method';
	}
	if (document.checkoutform.paymethod.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease select your method of payment';
	}
	if ( document.checkoutform.cardnumber.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your credit card number';
	}
	if (document.checkoutform.cc_cvv.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your CVC number';
	}
	if (document.checkoutform.nameoncard.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter the name on your credit card';
	}
	if (document.checkoutform.expiremonth.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your card expiry month';
	}
	if (document.checkoutform.expireyear.value == '') {
		err = 1;
		err_msg = err_msg + '\nPlease enter your card expiry year';
	}
	if (err == 1) {
		if (isdefined(document.checkoutform.company) && document.checkoutform.company.value == '') {
			document.checkoutform.company.value = 'Organization';
		}
		if (isdefined(document.checkoutform.address2) && document.checkoutform.address2.value == '') {
			document.checkoutform.address2.value = 'Address Line 2';
		}
		if (isdefined(document.checkoutform.shipcompany) && document.checkoutform.shipcompany.value == '') {
			document.checkoutform.shipcompany.value = 'Shipping Organization';
		}
		if (isdefined(document.checkoutform.shipaddress2) && document.checkoutform.shipaddress2.value == '') {
			document.checkoutform.shipaddress2.value = 'Shipping Address Line 2';
		}
		alert(err_msg);
		return false;
	} else {
		return true;
	}
}

function showsmresource(id) {
	for (i=1; i<4; i++) {
		var hideid = 'sm'+i;
		document.getElementById(hideid).style.display = 'none';
		var hidelink = 'smlink'+i;
		document.getElementById(hidelink).className = "";
	}
	var showid = 'sm'+id;
	document.getElementById(showid).style.display = 'block';
	var showlink = 'smlink'+id;
	document.getElementById(showlink).className = "selected";
}

function showsuggestions() {
	var suggestionbox = document.getElementById('suggestionbox');
	suggestionbox.style.display = 'block';	
}