// JavaScript Document

function swap(pic, color, zoom, att) { //swap(img, name)
	//alert(zoom)
	document.getElementById("preview").src=pic;
	document.getElementById("color").innerHTML=color;
	document.getElementById("attn").innerHTML=att;
	temp="javascript: MM_openBrWindow('pop_zoom.asp?p="+zoom+"','','scrollbars=no,resizable=no,width=600,height=300');";
	document.getElementById("zoom").href=temp;
	document.getElementById("zoom2").href=temp;
	//document.form.codecolo.selectedIndex = col2;
	
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function OnChange(pg, codeprod, codesize, codecolo)
{
	//codeprod
	var codeprod = codeprod.value;
	//size
	var SelValue = codesize.value;
	sizestr = "&codesize="+SelValue;

	//color
	var myindex2  = codecolo.selectedIndex
	var SelValue2 = codecolo.options[myindex2].value
	colostr = "&codecolo="+ SelValue2;
	
	//lens
	//var myindex3  = codelens.selectedIndex
	//var SelValue3 = codelens.options[myindex3].value
	//lensstr = "&codelens="+ SelValue3;
	
	if(pg.value == "sun"){
		baseURL = "products_detail_sun.asp?codeprod=";	
	}else if(pg.value == "f8"){
		baseURL = "products_detail_f8.asp?codeprod=";
	}else{
		baseURL = "products_detail_rec.asp?codeprod=";
	}
	
	
	top.location.href = baseURL+codeprod+sizestr+colostr;
	
	return true;
	
}

function OnChange2(pg, codeprod, codesize, codecolo, codelens)
{
	//codeprod
	var codeprod = codeprod.value;
	//size
	var SelValue = codesize.value;
	sizestr = "&codesize="+SelValue;

	//color
	var myindex2  = codecolo.selectedIndex
	var SelValue2 = codecolo.options[myindex2].value
	colostr = "&codecolo="+ SelValue2;
	
	//lens
	var myindex3  = codelens.selectedIndex
	var SelValue3 = codelens.options[myindex3].value
	lensstr = "&codelens="+ SelValue3;
	
	if(pg.value == "sun"){
		baseURL = "products_detail_sun.asp?codeprod=";	
	}
	
	
	top.location.href = baseURL+codeprod+sizestr+colostr+lensstr;
	
	return true;
	
}

//news_5_4.asp, dealersignin_10.asp, dealersignin_4_guarantees.asp
//resetting form
function resetForm(){
	document.form.reset();
}

//contact.asp, dealersignin_12.asp
function resetForm1(){
	document.form1.reset();
}

function resetForm2(){
	document.form2.reset();
}

function checkForm1(){
	if(document.form1.namecont.value == ""){
		alert("Please enter your name.");	
		document.form1.namecont.focus();
		return false;
	}
	if(document.form1.telecont.value == ""){
		alert("Please enter your telephone number.");	
		document.form1.telecont.focus();
		return false;
	}
	if(document.form1.mailcont.value == ""){
		alert("Please enter your Email address.");	
		document.form1.mailcont.focus();
		return false;
	}else{
		var theEmail = document.form1.mailcont.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			document.form1.mailcont.focus();
			return false;
		}	
	}
}

function checkForm2(){
	if(document.form2.namecont.value == ""){
		alert("Please enter your name.");	
		document.form2.namecont.focus();
		return false;
	}
	if(document.form2.telecont.value == ""){
		alert("Please enter your telephone number.");	
		document.form2.telecont.focus();
		return false;
	}
	if(document.form2.mailcont.value == ""){
		alert("Please enter your Email address.");	
		document.form2.mailcont.focus();
		return false;
	}else{
		var theEmail = document.form2.mailcont.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			document.form2.mailcont.focus();
			return false;
		}	
	}
}

//distribution.asp
function checkFormDist(){
	if(document.form.namedist.value == ""){
		alert("Please enter your name.");	
		document.form.namedist.focus();
		return false;
	}
	if(document.form.teledist.value == ""){
		alert("Please enter your telephone number.");	
		document.form.teledist.focus();
		return false;
	}
	if(document.form.maildist.value == ""){
		alert("Please enter your Email address.");	
		document.form.maildist.focus();
		return false;
	}else{
		var theEmail = document.form.maildist.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			document.form.maildist.focus();
			return false;
		}	
	}
}

//dealersignin_13.asp
function checkPW(){
	if(document.form3.passreta.value ==""){
		alert("Please enter your new password.");	
		document.form3.passreta.focus();
		return false;
	}
	if(document.form3.passreta.value.length < 6){
		alert("New password has to be no less than 6 characters long.");	
		document.form.passreta.focus();
		return fals3e;
	}
	
	if(document.form3.passreta2.value.length < 6){
		alert("New password has to be no less than 6 characters long.");	
		document.form3.passreta2.focus();
		return false;
	}
	if(document.form3.passreta.value != document.form3.passreta2.value){
		alert("Passwords that you entered do not match. Please confirm your new password by entering the exact same password as above.");	
		document.form3.passreta2.value = "";
		document.form3.passreta2.focus();
		return false;
	}
	
}

function checkAcct(){
	pref = document.form2
	if(pref.str1reta.value == ""){
		alert("Please enter the Address line 1.");	
		pref.str1reta.focus();
		return false;
	}
	if(pref.cityreta.value == ""){
		alert("Please enter the City.");	
		pref.cityreta.focus();
		return false;
	}
	if(pref.zippreta.value.length < 5){
		alert("Please enter your 5 digit zip code.");
		pref.zippreta.focus();
		return false;
	}
	if(pref.tel1reta.value.length < 3){
		alert("Please enter 3 digit area code of your telephone number.");	
		pref.tel1reta.focus();
		return false;
	}
	if(pref.tel2reta.value.length < 7){
		alert("Please enter 7 digit telephone number.");	
		pref.tel2reta.focus();
		return false;
	}
	if(pref.mailreta.value == ""){
		alert("Please enter your Email address.");	
		pref.mailreta.focus();
		return false;
	}else{
		var theEmail = pref.mailreta.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			pref.mailreta.focus();
			return false;
		}	
	}
}

//dealersignin_4_rx.asp
function checkRXForm(){
	pref = document.form;
	if(pref.acctreta.value ==""){
		alert("Please enter your Account number.");	
		pref.acctreta.focus();
		return false;
	}
	if(pref.namereta.value ==""){
		alert("Please enter your Account name.");	
		pref.namereta.focus();
		return false;
	}
	if(pref.odplreta.value ==""){
		alert("Please enter your name.");	
		pref.odplreta.focus();
		return false;
	}
	if(pref.teleform.value ==""){
		alert("Please enter your telephone number.");	
		pref.teleform.focus();
		return false;
	}
	if(pref.r_spform.value ==""){
		alert("Please enter the right Sphere.");	
		pref.r_spform.focus();
		return false;
	}
	if(pref.l_spform.value ==""){
		alert("Please enter the left Sphere.");	
		pref.l_spform.focus();
		return false;
	}
	if(pref.r_diform.value ==""){
		alert("Please enter the right distance.");	
		pref.r_diform.focus();
		return false;
	}
	if(pref.l_diform.value ==""){
		alert("Please enter the left distance.");	
		pref.l_diform.focus();
		return false;
	}
	if(pref.fnamform.value==""){
		alert("Please enter the style name of frame.");
		pref.fnamform.focus();
		return false;
	}
	if(pref.fcolform.value==""){
		alert("Please enter the name of color.");
		pref.fcolform.focus();
		return false;
	}
	if(pref.fsizform.value ==""){
		alert("Please enter the size of the frame.");
		pref.fsizform.focus();
		return false;
	}
}

//about_5.asp
function checkJob(){
	pref = document.form
	if(pref.namejobs.value ==""){
		alert("Please enter your name.");	
		pref.namejobs.focus();
		return false;
	}
	if(pref.telejobs.value ==""){
		alert("Please enter your phone number.");	
		pref.telejobs.focus();
		return false;
	}
	if(pref.mailjobs.value == ""){
		alert("Please enter your Email address.");	
		pref.mailjobs.focus();
		return false;
	}else{
		var theEmail = pref.mailjobs.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			pref.mailjobs.focus();
			return false;
		}	
	}
	if(pref.posijobs.value ==""){
		alert("Please enter the position you are applying for.");	
		pref.posijobs.focus();
		return false;
	}
	
}

//dealersignin_3.asp
function checkPrev(){
	pref = document.form
	if(pref.offiprev.value ==""){
		alert("Please enter your office name.");
		pref.offiprev.focus();
		return false;
	}
	if(pref.nameprev.value ==""){
		alert("Please enter your name.");
		pref.nameprev.focus();
		return false;
	}
	if(pref.titlprev.value ==""){
		alert("Please enter your title.");
		pref.titlprev.focus();
		return false;
	}
	if(pref.profprev.value ==""){
		alert("Please select your profession.");
		pref.profprev.focus();
		return false;
	}
	if(pref.str1prev.value ==""){
		alert("Please enter the street address.");
		pref.str1prev.focus();
		return false;
	}
	if(pref.cityprev.value ==""){
		alert("Please enter city.");
		pref.cityprev.focus();
		return false;
	}
	if(pref.ctryprev.value == "United States" && pref.stteprev.value ==""){
		alert("Please select the state.");
		pref.stteprev.focus();
		return false;
	}
	if(pref.zippprev.value.length <5){
		alert("Please enter your zip code.");
		pref.zippprev.focus();
		return false;
	}	
	if(pref.teleprev.value.length < 10){
		alert("Please enter your 10 digit telephone number.");
		pref.teleprev.focus();
		return false;
	}
	if(pref.mailprev.value == ""){
		alert("Please enter your Email address.");	
		pref.mailprev.focus();
		return false;
	}else{
		var theEmail = pref.mailprev.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			pref.mailprev.focus();
			return false;
		}	
	}
}

function checkSignup(){
	if(document.form.mailnwsl.value ==""){
		alert("Please enter your Email address.");	
		document.form.mailnwsl.focus();
		return false;
	}else{
		var theEmail = document.form.mailnwsl.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			document.form.mailnwsl.focus();
			return false;
		}	
	}
		
}

function checkTestimonial(){
	pref = document.form;
	if(pref.nametest.value ==""){
		alert("Please enter your name.");
		pref.nametest.focus();
		return false;
	}
	if(pref.mailtest.value ==""){
		alert("Please enter your Email address.");	
		pref.mailtest.focus();
		return false;
	}else{
		var theEmail = pref.mailtest.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			pref.mailtest.focus();
			return false;
		}	
	}
	if(pref.texttest.value==""){
		alert("Please enter your testimonial.");
		pref.texttest.focus();
		return false;
	}
	submitonce(pref);
}

function submitonce(theform){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				//disable em
				tempobj.disabled=true
		}
	}
}

function checkSearch(){
	if(document.formF.textsear.value == ""){
		alert("Please enter the search criteria.")	
		document.formF.textsear.focus();
		return false;
	}
}

function checkShip(){
	pref = document.form;
	if(pref.x_ship_to_first_name.value== ""){
		alert("Please enter First name.");	
		pref.x_ship_to_first_name.focus();
		return false;
	}
	if(pref.x_ship_to_last_name.value== ""){
		alert("Please enter Last name.");	
		pref.x_ship_to_last_name.focus();
		return false;
	}
	if(pref.x_ship_to_address.value== ""){
		alert("Please enter Street address.");	
		pref.x_ship_to_address.focus();
		return false;
	}
	if(pref.x_ship_to_city.value== ""){
		alert("Please enter City.");	
		pref.x_ship_to_city.focus();
		return false;
	}
	if(pref.x_ship_to_state.value== ""){
		alert("Please enter State.");	
		pref.x_ship_to_state.focus();
		return false;
	}
	if(pref.x_ship_to_zip.value == ""){
		alert("Please enter Zip Code.");	
		pref.x_ship_to_zip.focus();
		return false;
	}else if(pref.x_ship_to_zip.value.length < 5){
		alert("Zip code format is invalid.");	
		pref.x_ship_to_zip.focus();
		return false;
	}
	
}

function checkPay(){
	pref = document.form;
	if(pref.x_first_name.value== ""){
		alert("Please enter First name.");	
		pref.x_first_name.focus();
		return false;
	}
	if(pref.x_last_name.value== ""){
		alert("Please enter Last name.");	
		pref.x_last_name.focus();
		return false;
	}
	if(pref.x_address.value== ""){
		alert("Please enter Street address.");	
		pref.x_address.focus();
		return false;
	}
	if(pref.x_city.value== ""){
		alert("Please enter City.");	
		pref.x_city.focus();
		return false;
	}
	if(pref.x_state.value== ""){
		alert("Please enter State.");	
		pref.x_state.focus();
		return false;
	}
	if(pref.x_zip.value == ""){
		alert("Please enter Zip Code.");	
		pref.x_zip.focus();
		return false;
	}else if(pref.x_zip.value.length < 5){
		alert("Zip code format is invalid.");	
		pref.x_zip.focus();
		return false;
	}
	if(pref.x_phone.value ==""){
		alert("Please enter Phone number.");	
		pref.x_phone.focus();
		return false;
	}else if(pref.x_phone.value.length < 10){
		alert("Phone number format is invalid.");	
		pref.x_phone.focus();
		return false;
	}
	if(pref.x_email.value ==""){
		alert("Please enter Email address.");	
		pref.x_email.focus();
		return false;
	}else{
		var theEmail = pref.x_email.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			pref.x_email.focus();
			return false;
		}	
	}
	/*card infor*/
	if(pref.card_co.value== ""){
		alert("Please select Credit Card Type.");	
		pref.card_co.focus();
		return false;
	}
	if(pref.x_card_num.value== ""){
		alert("Please enter Credit Card Number.");	
		pref.card_co.focus();
		return false;
	}else if(pref.x_card_num.value.length < 13){
		alert("Credit Card Number format is invalid.");	
		pref.x_card_num.focus();
		return false;
	}
	if(pref.exp_mo.value ==""){
		alert("Please select Month of Expiration.");	
		pref.exp_mo.focus();
		return false;
	}
	if(pref.exp_yr.value ==""){
		alert("Please select Year of Expiration.");	
		pref.exp_yr.focus();
		return false;
	}
	if(pref.exp_yr.value ==""){
		alert("Please select Year of Expiration.");	
		pref.exp_yr.focus();
		return false;
	}
	if(pref.x_card_code.value==""){
		alert("Please enter the Card Identification Number.");	
		pref.x_card_code.focus();
		return false;
	}
}

function checkAcc(){
	var txt;
	
	if(document.form.accefile.value =="C"){
		txt = " the color ";	
	}else if(document.form.accefile.value =="S"){
		txt = " the size ";
	}else{
		txt = " the color and size ";
	}
	//alert(txt);
	if(document.form.optnitem.value ==""){
		alert("Please type"+ String(txt) + "desired before adding to cart.");
		document.form.optnitem.focus();
		return false;
	}
}

//review form
function checkReviewform(){
	pref = document.form
	if(pref.namerevi.value ==""){
		alert("Please enter your name.");	
		pref.namerevi.focus();
		return false;
	}
	if(pref.telerevi.value ==""){
		alert("Please enter your phone number.");	
		pref.telerevi.focus();
		return false;
	}
	if(pref.mailrevi.value == ""){
		alert("Please enter your Email address.");	
		pref.mailrevi.focus();
		return false;
	}else{
		var theEmail = pref.mailrevi.value;
		var atLoc = theEmail.indexOf("@", 1);
		var dotLoc = theEmail.indexOf(".", atLoc+2);
		var len = theEmail.length;
		if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
			
		}
		else{
			alert("Please enter your e-mail address properly.");
			pref.mailrevi.focus();
			return false;
		}	
	}
	if(pref.commrevi.value ==""){
		alert("Please enter your comment.");	
		pref.commrevi.focus();
		return false;
	}
	
}
