// JAVASCRIPT FOR SITE


function letternumber(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 // window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
 return myHeight;
}

function numbersonly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers only
else if ((("0123456789-").indexOf(keychar) > -1))
   return true;
else
   return false;
}


function lettersonly(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz").indexOf(keychar) > -1))
   return true;
else
   return false;
}


addary = new Array();           //red
addary[0] = new Array(0,1,0);   //red green
addary[1] = new Array(-1,0,0);  //green
addary[2] = new Array(0,0,1);   //green blue
addary[3] = new Array(0,-1,0);  //blue
addary[4] = new Array(1,0,0);   //red blue
addary[5] = new Array(0,0,-1);  //red
addary[6] = new Array(255,1,1);
clrary = new Array(360);
for(i = 0; i < 6; i++)
for(j = 0; j < 60; j++) {
clrary[60 * i + j] = new Array(3);
for(k = 0; k < 3; k++) {
clrary[60 * i + j][k] = addary[6][k];
addary[6][k] += (addary[i][k] * 4);
   }
}



function capture() {
if(document.layers) {
layobj = document.layers['wheel'];
layobj.document.captureEvents(Event.MOUSEMOVE);
layobj.document.onmousemove = moved;
}
else {
layobj = document.all["wheel"];
layobj.onmousemove = moved;
   }
}



function moved(e) {
y = 4 * ((document.layers)?e.layerX:event.offsetX);
x = 4 * ((document.layers)?e.layerY:event.offsetY);
sx = x - 512;
sy = y - 512;
qx = (sx < 0)?0:1;
qy = (sy < 0)?0:1;
q = 2 * qy + qx;
quad = new Array(-180,360,180,0);
xa = Math.abs(sx);
ya = Math.abs(sy);
d = ya * 45 / xa;
if(ya > xa) d = 90 - (xa * 45 / ya);
deg = Math.floor(Math.abs(quad[q] - d));
n = 0;
sx = Math.abs(x - 512);
sy = Math.abs(y - 512);
r = Math.sqrt((sx * sx) + (sy * sy));
if(x == 512 & y == 512) {
c = "000000";
}
else {
for(i = 0; i < 3; i++) {
r2 = clrary[deg][i] * r / 256;
if(r > 256) r2 += Math.floor(r - 256);
if(r2 > 255) r2 = 255;
n = 256 * n + Math.floor(r2);
}
c = n.toString(16);
while(c.length < 6) c = "0" + c;
}
if(document.layers) {
document.layers["wheel"].document.f.t.value = "#" + c;
document.layers["wheel"].bgColor = "#" + c;
}
else {
document.all["wheel"].document.f.t.value = "#" + c;
document.all["wheel"].style.backgroundColor = "#" + c;
}
return false;
}


function img_act(imgName) 
  {
    imgOn = eval(imgName + "On.src");
    document [imgName].src = imgOn;
  }
  
function img_inact(imgName) 
  {
    imgOff = eval(imgName + "Off.src");
    document [imgName].src = imgOff;
  }

function popUp1(url) 
  { 
    open(url,"","height=300,width=400,scrollbars=no; window.focus()"); 
  }

function popUp2(url) 
  { 
    open(url,"","height=450,width=550,scrollbars=no; window.focus()"); 
  }

function popUp3(url) 
  { 
    open(url,"","height=460,width=500,scrollbars=1; window.focus()"); 
  }

function popUp4(url) 
  { 
    open(url,"","height=500,width=500,scrollbars=auto; window.focus()"); 
  }

function popUp5(url) 
  { 
    open(url,"","height=630,width=500,scrollbars=no; window.focus()"); 
  }

function popUp6(url) 
  { 
    open(url,"","height=100,width=300,scrollbars=no; window.focus()"); 
  }

function popUp7(url) 
  { 
    open(url,"","height=550,width=625,scrollbars=auto; window.focus()"); 
  }

function popUp8(url) 
  { 
    open(url,"","height=600,width=610,scrollbars=auto; window.focus()"); 
  }

function popUp10(url) 
  { 
    open(url,"","height=500,width=450,scrollbars=1; window.focus()"); 
  }

function popUp11(url) 
  { 
    open(url,"","height=500,width=450,scrollbars=1; window.focus()"); 
  }

function makevisible(cur,which)
  {
    if (which==0)
      cur.filters.alpha.opacity=80
    else
      cur.filters.alpha.opacity=60
  }

function openWin( windowURL, windowName, windowFeatures )
  {
    return window.open( windowURL, windowName, windowFeatures ) ;
  }

function borderit(which,color)
  {
    //if IE 4+ or NS 6+
    if (document.all||document.getElementById)
      {
        which.style.borderColor=color
      }
  }
  
function validateString(field, msg, min, max) { 
if (!min) { min = 1 } 
if (!max) { max = 65535 } 

if (!field.value || field.value.length < min ||  
field.value.max > max) { 
alert(msg); 
field.focus(); 
field.select(); 
return false; 
} 

return true; 
}

function validateNumber(field, msg, min, max) { 
if (!min) { min = 0 } 
if (!max) { max = 255 } 

if ( (parseInt(field.value) != field.value) ||  
       field.value.length < min || field.value.length > max) { 
alert(msg); 
field.focus(); 
field.select(); 
return false; 
} 

return true; 
}


function isEmail(who) {
	function isEmpty(who) {
		var testArr=who.split("");
		if(testArr.length==0)
			return true;
		var toggle=0;
		for(var i=0; i<testArr.length; i++) {
			if(testArr[i]==" ") {
				toggle=1;
				break;
			}
		}
		if(toggle)
			return true;
		return false;
	}

	function isValid(who) {
		var invalidChars=new Array("~","!","@","#","$","%","^","&","*","(",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<",">","?");
		var testArr=who.split("");
		for(var i=0; i<testArr.length; i++) {
			for(var j=0; j<invalidChars.length; j++) {
				if(testArr[i]==invalidChars[j]) {
					return false;
				}
			}
		}
		return true;
	}

	function isfl(who) {
		var invalidChars=new Array("-","_",".");
		var testArr=who.split("");
		which=0;
		for(var i=0; i<2; i++) {
			for(var j=0; j<invalidChars.length; j++) {
				if(testArr[which]==invalidChars[j]) {
					return false;
				}
			}
			which=testArr.length-1;
		}
		return true;
	}

	function isDomain(who) {
		var invalidChars=new Array("-","_",".");
		var testArr=who.split("");
		if(testArr.length<2||testArr.length>4) {
			return false;
		}
		for(var i=0; i<testArr.length; i++) {
			for(var j=0; j<invalidChars.length; j++) {
				if(testArr[i]==invalidChars[j]) {
					return false;
				}
			}
		}
		return true;
	}


	var testArr=who.split("@");
	if(testArr.length<=1||testArr.length>2) {
		return false;
	}
	else {
		if(isValid(testArr[0])&&isfl(testArr[0])&&isValid(testArr[1])) {
			if(!isEmpty(testArr[testArr.length-1])&&!isEmpty(testArr[0])) {
				var testArr2=testArr[testArr.length-1].split(".");
				if(testArr2.length>=2) {
					var toggle=1;
					for(var i=0; i<testArr2.length; i++) {
						if(isEmpty(testArr2[i])||!isfl(testArr2[i])) {
							toggle=0;
							break;
						}
					}
					if(toggle&&isDomain(testArr2[testArr2.length-1]))
						return true;
					return false;
				}
				return false;
			}
		}
	}
}


function validateEmail(who, msg) 
{
  var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
  //return(email.test(who));
 
  if(!email.test(who))
   {	  
     alert(msg); 
     field.focus(); 
     field.select(); 
     return false; 
   }
}






function validateNewCust(cust_f_name, cust_l_name, cust_bd_month, cust_bd_day, cust_bd_year, cust_email, cust_confirm_email, cust_phone_1, cust_phone_2, cust_phone_3, cust_add_1, cust_city, cust_state, cust_zip, cust_country, cust_pw, cust_confirm_pw)
{

	if(document.getElementById(cust_f_name).value == ""){
		alert('Please enter a first name and try again.');
		document.getElementById(cust_f_name).focus();
		return false;
	}
	if(document.getElementById(cust_l_name).value == ""){
		alert('Please enter a last name and try again.');
		document.getElementById(cust_l_name).focus();
		return false;
	}
	if(document.getElementById(cust_bd_month).value == ""){
		alert('Please enter birth month and try again.');
		document.getElementById(cust_bd_month).focus();
		return false;
	}
	if(document.getElementById(cust_bd_day).value == ""){
		alert('Please enter birth day and try again.');
		document.getElementById(cust_bd_day).focus();
		return false;
	}
	if(document.getElementById(cust_bd_year).value == ""){
		alert('Please enter birth year and try again.');
		document.getElementById(cust_bd_year).focus();
		return false;
	}

	if (document.getElementById(cust_email).value.length > 0)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(document.getElementById(cust_email).value))
		{
			//valid email
		}
		else
		{
				alert('The Email Address You Entered Is Invalid. Please Try Again!');
				document.getElementById(cust_email).focus();
				return false;
		}
	}else
	{
		alert('Please enter a valid email address');
		document.getElementById(cust_email).focus();
		return false;
	}

	if (document.getElementById(cust_confirm_email).value.length > 0)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(document.getElementById(cust_email).value))
		{
			//valid email
		}
		else
		{
				alert('The Email Address You Entered Is Invalid. Please Try Again!');
				document.getElementById(cust_email).focus();
				return false;
		}
	}else
	{
		alert('Please enter a valid email address');
		document.getElementById(cust_confirm_email).focus();
		return false;
	}

	if(document.getElementById(cust_email).value != document.getElementById(cust_confirm_email).value){
		alert('Your email fields do NOT match! Please double check and try again.');
		document.getElementById(cust_email).focus();
		return false;
	}

	if(document.getElementById(cust_phone_1).value == ""){
		alert('Please enter phone number and try again.');
		document.getElementById(cust_phone_1).focus();
		return false;
	}
	if(document.getElementById(cust_phone_2).value == ""){
		alert('Please enter phone number and try again.');
		document.getElementById(cust_phone_2).focus();
		return false;
	}
	if(document.getElementById(cust_phone_3).value == ""){
		alert('Please enter phone number and try again.');
		document.getElementById(cust_phone_3).focus();
		return false;
	}
	if(document.getElementById(cust_add_1).value == ""){
		alert('Please enter a street address and try again.');
		document.getElementById(cust_add_1).focus();
		return false;
	}
	if(document.getElementById(cust_city).value == ""){
		alert('Please enter a city and try again.');
		document.getElementById(cust_city).focus();
		return false;
	}
	if(document.getElementById(cust_state).value == ""){
		alert('Please select a state and try again.');
		document.getElementById(cust_state).focus();
		return false;
	}
	if(document.getElementById(cust_zip).value == ""){
		alert('Please enter a zip or postal code and try again.');
		document.getElementById(cust_zip).focus();
		return false;
	}
	if(document.getElementById(cust_country).value == ""){
		alert('Please select a country and try again.');
		document.getElementById(cust_country).focus();
		return false;
	}
	if(document.getElementById(cust_pw).value == ""){
		alert('Please enter a password and try again.');
		document.getElementById(cust_pw).focus();
		return false;
	}
	if(document.getElementById(cust_confirm_pw).value == ""){
		alert('Please confirm your password and try again.');
		document.getElementById(cust_confirm_pw).focus();
		return false;
	}
	if(document.getElementById(cust_pw).value != document.getElementById(cust_confirm_pw).value){
		alert('Your password fields do NOT match! Please double check and try again.');
		document.getElementById(cust_pw).focus();
		return false;
	}


}


function validateEditCust(cust_f_name, cust_l_name, cust_email, cust_confirm_email, cust_phone_1, cust_phone_2, cust_phone_3, cust_add_1, cust_city, cust_state, cust_zip, cust_country, cust_pw, cust_confirm_pw)
{

	if(document.getElementById(cust_f_name).value == ""){
		alert('Please enter a first name and try again.');
		document.getElementById(cust_f_name).focus();
		return false;
	}
	if(document.getElementById(cust_l_name).value == ""){
		alert('Please enter a last name and try again.');
		document.getElementById(cust_l_name).focus();
		return false;
	}
	if (document.getElementById(cust_email).value.length > 0)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(document.getElementById(cust_email).value))
		{
			//valid email
		}
		else
		{
				alert('The Email Address You Entered Is Invalid. Please Try Again!');
				document.getElementById(cust_email).focus();
				return false;
		}
	}else
	{
		alert('Please enter a valid email address');
		document.getElementById(cust_email).focus();
		return false;
	}

	if (document.getElementById(cust_confirm_email).value.length > 0)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(document.getElementById(cust_email).value))
		{
			//valid email
		}
		else
		{
				alert('The Email Address You Entered Is Invalid. Please Try Again!');
				document.getElementById(cust_email).focus();
				return false;
		}
	}else
	{
		alert('Please enter a valid email address');
		document.getElementById(cust_confirm_email).focus();
		return false;
	}

	if(document.getElementById(cust_email).value != document.getElementById(cust_confirm_email).value){
		alert('Your email fields do NOT match! Please double check and try again.');
		document.getElementById(cust_email).focus();
		return false;
	}

	if(document.getElementById(cust_phone_1).value == ""){
		alert('Please enter phone number and try again.');
		document.getElementById(cust_phone_1).focus();
		return false;
	}
	if(document.getElementById(cust_phone_2).value == ""){
		alert('Please enter phone number and try again.');
		document.getElementById(cust_phone_2).focus();
		return false;
	}
	if(document.getElementById(cust_phone_3).value == ""){
		alert('Please enter phone number and try again.');
		document.getElementById(cust_phone_3).focus();
		return false;
	}
	if(document.getElementById(cust_add_1).value == ""){
		alert('Please enter a street address and try again.');
		document.getElementById(cust_add_1).focus();
		return false;
	}
	if(document.getElementById(cust_city).value == ""){
		alert('Please enter a city and try again.');
		document.getElementById(cust_city).focus();
		return false;
	}
	if(document.getElementById(cust_state).value == ""){
		alert('Please select a state and try again.');
		document.getElementById(cust_state).focus();
		return false;
	}
	if(document.getElementById(cust_zip).value == ""){
		alert('Please enter a zip or postal code and try again.');
		document.getElementById(cust_zip).focus();
		return false;
	}
	if(document.getElementById(cust_country).value == ""){
		alert('Please select a country and try again.');
		document.getElementById(cust_country).focus();
		return false;
	}
	if(document.getElementById(cust_pw).value == ""){
		alert('Please enter a password and try again.');
		document.getElementById(cust_pw).focus();
		return false;
	}
	if(document.getElementById(cust_confirm_pw).value == ""){
		alert('Please confirm your password and try again.');
		document.getElementById(cust_confirm_pw).focus();
		return false;
	}
	if(document.getElementById(cust_pw).value != document.getElementById(cust_confirm_pw).value){
		alert('Your password fields do NOT match! Please double check and try again.');
		document.getElementById(cust_pw).focus();
		return false;
	}


}



function validateCheckout(billing_f_name, billing_l_name, billing_phone, billing_email, billing_add_1, billing_city, billing_state, billing_zip, billing_country, billing_card_holder, billing_card_number, billing_card_cvv2, billing_exp_month, billing_exp_year, ubill, shipping_f_name, shipping_l_name, shipping_add_1, shipping_city, shipping_state, shipping_city, shipping_zip, shipping_country, shipping_method)
{

	if(document.getElementById(billing_f_name).value == ""){
		alert('Please enter a billing first name and try again.');
		document.getElementById(billing_f_name).focus();
		return false;
	}
	if(document.getElementById(billing_l_name).value == ""){
		alert('Please enter a billing last name and try again.');
		document.getElementById(billing_l_name).focus();
		return false;
	}
	if(document.getElementById(billing_card_holder).value == ""){
		alert('Please enter the name as it appears on your credit card and try again.');
		document.getElementById(billing_card_holder).focus();
		return false;
	}
	if(document.getElementById(billing_card_number).value == ""){
		alert('Please enter your credit card number and try again.');
		document.getElementById(billing_card_number).focus();
		return false;
	}
	if(document.getElementById(billing_card_cvv2).value == ""){
		alert('Please enter your credit card CVV2 number or security number and try again.');
		document.getElementById(billing_card_cvv2).focus();
		return false;
	}
	if(document.getElementById(billing_exp_month).value == ""){
		alert('Please select a card expiration month and try again.');
		document.getElementById(billing_exp_month).focus();
		return false;
	}
	if(document.getElementById(billing_exp_year).value == ""){
		alert('Please select a card expiration year and try again.');
		document.getElementById(billing_exp_year).focus();
		return false;
	}
	if(document.getElementById(billing_phone).value == ""){
		alert('Please enter a billing phone number and try again.');
		document.getElementById(billing_phone).focus();
		return false;
	}
	if(document.getElementById(billing_add_1).value == ""){
		alert('Please enter a billing street address and try again.');
		document.getElementById(billing_add_1).focus();
		return false;
	}
	if(document.getElementById(billing_city).value == ""){
		alert('Please enter a billing city and try again.');
		document.getElementById(billing_city).focus();
		return false;
	}
	if(document.getElementById(billing_state).value == ""){
		alert('Please enter a billing state and try again.');
		document.getElementById(billing_state).focus();
		return false;
	}
	if(document.getElementById(billing_zip).value == ""){
		alert('Please enter a billing zip or postal code and try again.');
		document.getElementById(billing_zip).focus();
		return false;
	}
	if(document.getElementById(billing_country).value == ""){
		alert('Please select a billing country and try again.');
		document.getElementById(billing_country).focus();
		return false;
	}
	if(document.getElementById(shipping_f_name).value == ""){
		alert('Please enter a shipping first name and try again.');
		document.getElementById(shipping_f_name).focus();
		return false;
	}
	if(document.getElementById(shipping_l_name).value == ""){
		alert('Please enter a shipping last name and try again.');
		document.getElementById(shipping_l_name).focus();
		return false;
	}
	if(document.getElementById(shipping_add_1).value == ""){
		alert(document.getElementById(shipping_add_1).value);
		document.getElementById(shipping_add_1).focus();
		return false;
	}
	if(document.getElementById(shipping_city).value == ""){
		alert('Please enter a shipping city and try again.');
		document.getElementById(shipping_city).focus();
		return false;
	}
	if(document.getElementById(shipping_state).value == ""){
		alert('Please select a shipping state and try again.');
		document.getElementById(shipping_state).focus();
		return false;
	}
	if(document.getElementById(shipping_zip).value == ""){
		alert('Please enter a shipping zip or postal code and try again.');
		document.getElementById(shipping_zip).focus();
		return false;
	}
	if(document.getElementById(shipping_country).value == ""){
		alert('Please select a shipping country and try again.');
		document.getElementById(shipping_country).focus();
		return false;
	}
	if(document.getElementById(shipping_method).value == ""){
		alert('Please select a shipping method and try again.');
		document.getElementById(shipping_method).focus();
		return false;
	}
	if (document.getElementById(billing_email).value.length > 0)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(document.getElementById(billing_email).value))
		{
			//valid email
		}
		else
		{
				alert('The Email Address You Entered Is Invalid. Please Try Again!');
				document.getElementById(billing_email).focus();
				return false;
		}
	}else
	{
		alert('Please enter a valid email address');
		document.getElementById(billing_email).focus();
		return false;
	}





}
