// Self-Power Main JavaScript File ***********************************
// Written by Dale Campbell

function Is_Empty( inputstring ){
	if( inputstring == null || inputstring == "" ){ return true; }
	else { return false; }
}

// IS VALID E-MAIL ADDRESS FUNCTION
// Returns TRUE if Email is valid and FALSE if NOT VALID
function Is_Valid_Email( emailaddy ){
	if( Is_Empty( emailaddy ) ){ return false; }
	var valaddy = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return valaddy.test(emailaddy);
}
// END OF FUNCTION

function Validate_Mailing_List( formdata ){
	if( Is_Empty(formdata.firstname.value) ){
		alert("Missing Required Field. First Name.");
		formdata.firstname.focus();
		formdata.firstname.select();
		return false;
	}
	if( Is_Empty(formdata.lastname.value) ){
		alert("Missing Required Field. Last Name.");
		formdata.lastname.focus();
		formdata.lastname.select();
		return false;
	}
	if( Is_Empty(formdata.email.value) ){
		alert("Missing Required Field. Email address.");
		formdata.email.focus();
		formdata.email.select();
		return false;
	}
	else {
		if( !Is_Valid_Email( formdata.email.value ) ){
			alert("Improper Email address. Please check the address.");
			formdata.email.focus();
			formdata.email.select();
			return false;
		}
	}
	if( Is_Empty(formdata.state.options[formdata.state.selectedIndex].value) ){
		alert("Missing Required Field. State.");
		formdata.state.focus();
		return false;
	}
	return true;
}

function Do_Nothing(){
	;
}

function Create_Product_Window( imgwhichprod, imgheight, imgwidth ){
	var winprop = "width="+ (imgwidth + 60) +",height="+ (imgheight + 60) +"";
	var temptext = "<html><head><title>Self-Power Product Detail</title></head>";
	temptext += "<body bgcolor='#ffffff' text='#000000'>";
	temptext += "<div align='center'><img src='images/" + imgwhichprod + "' alt='Product Detail'";
	temptext += " width='" + imgwidth  + "' height='" + imgheight  + "' border='0' style='border: 1px #000000 none;' /></div>";
	temptext += "</body></html>";
	var ProductWindow = window.open("about:blank", "ProductWindow", winprop);
   ProductWindow.document.write(temptext);
	ProductWindow.window.focus();
}

function Create_MoreImages_Window( whichview, startimg ){
	if( startimg == false ){ startimg = "1"; }
	var fname = "view" + whichview + ".php?cp=" + startimg;
	var ProdViewWindow = window.open(fname, "MoreImagesWindow", "width=450,height=600,resizable=1,status=0");
	ProdViewWindow.window.focus();
}

function Create_Priv_Window(){
	var PrivViewWindow = window.open("privpol.html", "PrivPolicyWindow", "width=450,height=500,scrollbars=1,resizable=0,status=0");
	PrivViewWindow.window.focus();
}

function Create_Ret_Window( whereat ){
	var fname = "retpol.html#" + whereat;
	var PrivRetWindow = window.open(fname, "RetPolicyWindow", "width=550,height=500,scrollbars=1,resizable=0,status=0");
	PrivRetWindow.window.focus();
}
