base_url = self.location.toString();
stripped_url = base_url.substr(0,base_url.search(".com")+4);
nons_url = stripped_url.replace("https","http");
withs_url = stripped_url.replace("http:","https:");


var xmlHttp;
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

function xmlHttp_Get(xmlhttp, url) {
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}

function xmlHttp_Post(xmlhttp, url, data) {
	xmlhttp.open('POST', url, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(data);
}

function GetXmlHttpObject(handler) {
	var objXmlHttp = null;
	if (is_ie){
		var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
		try{
			objXmlHttp = new ActiveXObject(strObjName);
			objXmlHttp.onreadystatechange = handler;
		}
		catch(e){
			alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
			return;
		}
	}else if (is_opera){
		alert('Opera detected. The page may not behave as expected.');
		return;
	}else{
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload = handler;
		objXmlHttp.onerror = handler;
	}
	return objXmlHttp;
}

/* error message for the entire example */
function display_message(str, id){
	var obj = document.getElementById(id);
	var strary = str.split("|");
	if(strary[0] == "ERROR"){
		obj.className="txt-red";
	}
	else{
		obj.className="txt-green";
	}
		switch (str) {
		case 'ERROR|USERNAME|1': message="Username Is Not Available"; break;
		case 'USERNAME|1': message="Username is Available";break;
		case 'ERROR|ZIPSTATE|1': message="State does not match Zip!";break;
		case 'ERROR|ZIPSTATE|2': message="Zip must be an integer only!";break;
		case 'ZIPSTATE|1': message="";break;
		default: message="";
	}
	document.getElementById(id).innerHTML=message;
}


/*** Start Username Availability ***/
function retrieveUsernameHandler(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
		var str = xmlHttp.responseText;
		display_message(str, 'username_result');
	}
}

function username_availability(strfnbr){
	var username = document.getElementById("username").value;
	var url = withs_url+"/maxexp/main.pl?pgm=ajax&func=username_availability&username="+username+"&strfnbr="+strfnbr;
	if (username.length >= 1 ){
	xmlHttp = GetXmlHttpObject(retrieveUsernameHandler);
	xmlHttp_Get(xmlHttp, url);
	}
}
/*** END Username Availability ***/


/*** START PASSWORD STRENGTH ***/
function eval_password(){
	var username = document.getElementById('username').value;
	var pwd = document.getElementById('password2').value;
	var result_bar = document.getElementById('pwd-result-bar');
	var result_str = document.getElementById('pwd-result-str');
	var pwd_strength = '';
	var pwd_score = 0;
	var strColor = '';

	document.getElementById('pwd-bar').style.display = "block";
	
	if(pwd.length == 0){
		document.getElementById('pwd-bar').style.display = "none";
	}	
	else if(pwd == username){
		pwd_strength = '<span style=color:red;>Password cannot be the same as the Username</span>';
		strColor = "red";
		pwd_score = 15;
	}
	else if(pwd.match(/\s/)){
		pwd_strength = '<span style=color:red;>Password cannot include space</span>';
		strColor = "red";
		pwd_score = 15;
	}
	else if(pwd.length <= 5){
		pwd_strength = '<span style=color:red;>Too Short</span.';
		strColor = "red";
		pwd_score = 15;
	}
	else{
		pwd_score = ((pwd.length) * 5);
		pwd_score -= get_repeated_char(pwd);
		if(pwd.match(/^[0-9]+$/)) pwd_score -= 10;
		if(pwd.match(/^[A-Za-z]+$/)) pwd_score -= 10;
		if(pwd.match(/[A-Za-z]/)) pwd_score += 10;
		if(pwd.match(/[A-Za-z]/) && pwd.match(/[0-9]/)) pwd_score += 15;
		if(pwd.match(/[!@#$%&*+=-?\|]/) && pwd.match(/[0-9]/)) pwd_score += 15;
		if(pwd.match(/[!@#$%&*+=-?\|]/) && pwd.match(/[A-Za-z]/)) pwd_score += 15;

		if(pwd_score > 100) pwd_score = 100;
		if(pwd_score < 0 ) pwd_score = 0;

		if(pwd_score >= 0 && pwd_score < 34){
			pwd_strength = "<span style=color:red;>Weak</span>";
			strColor = "red"; 
		}
		else if(pwd_score >= 34 && pwd_score < 68){
			pwd_strength = "<span style=color:#ff9900;>Good</span>";
			strColor = "#ff9900";
		}
		else if(pwd_score >= 68 && pwd_score < 80){
			pwd_strength = "<span style=color:#006600;>Strong</span>";
			strColor = "#006600";
		}
		else{
			pwd_strength = "<span style=color:#006600;>Strong</span>";
			strColor = "#006600";
			pwd_score = 100;
		}
	}
	result_bar.style.width=pwd_score+'%';
	result_bar.style.backgroundColor=strColor;
	result_str.innerHTML=pwd_strength;

}

function get_repeated_char(pwd){
	var score = 0;
	var index = -1;
	for(i=0; i<pwd.length; i++){
		for(j=i+1; j<pwd.length; j++){
			if( pwd.charAt(i) == pwd.charAt(j) ){
				index = pwd.indexOf(pwd.charAt(i));
				if(index == i){
					score++;
				}
				else{
					break;
				}
					
			}
		}
	}
	return score;
}
/*** END PASSWORD STRENGTH ***/

/*** START PASSWORD W/O USERNAME STRENGTH ***/
function eval_passwordonly(){
	var pwd = document.getElementById('password2').value;
	var result_bar = document.getElementById('pwd-result-bar');
	var result_str = document.getElementById('pwd-result-str');
	var pwd_strength = '';
	var pwd_score = 0;
	var strColor = '';

	document.getElementById('pwd-bar').style.display = "block";
	
	if(pwd.length == 0){
		document.getElementById('pwd-bar').style.display = "none";
	}	
	else if(pwd.match(/\s/)){
		pwd_strength = '<span style=color:red;>Password cannot include space</span>';
		strColor = "red";
		pwd_score = 15;
	}
	else if(pwd.length <= 5){
		pwd_strength = '<span style=color:red;>Too Short</span.';
		strColor = "red";
		pwd_score = 15;
	}
	else{
		pwd_score = ((pwd.length) * 5);
		pwd_score -= get_repeated_char(pwd);
		if(pwd.match(/^[0-9]+$/)) pwd_score -= 10;
		if(pwd.match(/^[A-Za-z]+$/)) pwd_score -= 10;
		if(pwd.match(/[A-Za-z]/)) pwd_score += 10;
		if(pwd.match(/[A-Za-z]/) && pwd.match(/[0-9]/)) pwd_score += 15;
		if(pwd.match(/[!@#$%&*+=-?\|]/) && pwd.match(/[0-9]/)) pwd_score += 15;
		if(pwd.match(/[!@#$%&*+=-?\|]/) && pwd.match(/[A-Za-z]/)) pwd_score += 15;

		if(pwd_score > 100) pwd_score = 100;
		if(pwd_score < 0 ) pwd_score = 0;

		if(pwd_score >= 0 && pwd_score < 34){
			pwd_strength = "<span style=color:red;>Weak</span>";
			strColor = "red"; 
		}
		else if(pwd_score >= 34 && pwd_score < 68){
			pwd_strength = "<span style=color:#ff9900;>Good</span>";
			strColor = "#ff9900";
		}
		else if(pwd_score >= 68 && pwd_score < 80){
			pwd_strength = "<span style=color:#006600;>Strong</span>";
			strColor = "#006600";
		}
		else{
			pwd_strength = "<span style=color:#006600;>Strong</span>";
			strColor = "#006600";
			pwd_score = 100;
		}
	}
	result_bar.style.width=pwd_score+'%';
	result_bar.style.backgroundColor=strColor;
	result_str.innerHTML=pwd_strength;

}

function get_repeated_char(pwd){
	var score = 0;
	var index = -1;
	for(i=0; i<pwd.length; i++){
		for(j=i+1; j<pwd.length; j++){
			if( pwd.charAt(i) == pwd.charAt(j) ){
				index = pwd.indexOf(pwd.charAt(i));
				if(index == i){
					score++;
				}
				else{
					break;
				}
					
			}
		}
	}
	return score;
}
/*** END PASSWORD W/O USERNAME STRENGTH ***/


/*** START ZIP START VALIDATION ***/

function clear(){
	if (document.getElementById('Other').checked == true || document.getElementById('Canada').checked == true){
		var str = "";
		display_message(str, 'zipstate_result');
	}
}


function retrieveZipStateHandler(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
		var str = xmlHttp.responseText;
		display_message(str, 'zipstate_result');
	}
}

function validation_zip_state(){
	var state = document.getElementById("state").value;
	var zip = document.getElementById('zip').value;
	var url = withs_url+"/maxexp/main.pl?pgm=ajax&func=validation_zip_state&zip="+zip+"&state="+state;
	if (zip.length > 1 && state.length >1){
		xmlHttp = GetXmlHttpObject(retrieveZipStateHandler);
		xmlHttp_Get(xmlHttp, url);
			}
}
/*** END ZIP START VALIDATION ***/


/*** START SHIPPING ZIP START VALIDATION ***/

function clear2(){
	if (document.getElementById('Other2').checked == true || document.getElementById('Canada2').checked == true){
		var str = "";
		display_message(str, 'zipstate_result2');
	}
}


function retrieveZipStateHandler2(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
		var str2 = xmlHttp.responseText;
		display_message(str2, 'zipstate_result2');
	}
}

function validation_zip_state2(){
	var state2 = document.getElementById("ship_state").value;
	var zip2 = document.getElementById('ship_zip').value;
	var url2 = withs_url+"/maxexp/main.pl?pgm=ajax&func=validation_zip_state&zip="+zip2+"&state="+state2;
	if (zip2.length > 1 && state2.length >1){
	xmlHttp = GetXmlHttpObject(retrieveZipStateHandler2);
	xmlHttp_Get(xmlHttp, url2);
	}
}
/*** END SHIPPING ZIP START VALIDATION ***/


function validForm(passForm){
		if (passForm.adfname.value == "") {
			alert ("You must enter your first name.")
			passForm.adfname.focus()
			return false
		}
		if (passForm.adlname.value == "") {
			alert ("You must enter your last name.")
			passForm.adlname.focus()
			return false
		}
		if (passForm.adaddr1.value == "") {
			alert ("You must enter your address.")
			passForm.adaddr1.focus()
			return false
		}
		if (passForm.adcity.value == "") {
			alert ("You must enter your city.")
			passForm.adcity.focus()
			return false
		}
		if (passForm.state.value == "") {
			alert ("You must select a state.")
			passForm.state.focus()
			return false
		}
		if (passForm.adzipc.value == "") {
			alert ("You must enter your zip.")
			passForm.adzipc.focus()
			return false
		}

		if (passForm.adphone.value == "") {
			alert ("You must enter your phone.")
			passForm.adphone.focus()
			return false
		}
		if (passForm.ademail.value == "") {
			alert ("You Must enter your email address.")
			passForm.ademail.focus()
			return false
		}

if (passForm.culogid.value == "") {
				alert ("You Must enter your username.")
				passForm.culogid.focus()
				return false
			}
			var invalid = " "; // Invalid character is a space

			if (document.passForm.culogid.value.indexOf(invalid) > -1) {
				alert("Your username cannot have space.");
				passForm.culogid.focus();
				return false;
			}
			if (passForm.cupswd.value == "") {
				alert ("You must enter a password.")
				passForm.cupswd.focus()
				return false
				}
			if (passForm.cupswd2.value == "") {
				alert ("You must enter your password again to confirm.")
				passForm.cupswd2.focus()
				return false
				}
			if (passForm.cupswd.value.length < 6) {
				alert('Your password must have at least 6 characters.');
				passForm.cupswd.focus()
				 return false
			} 		
			if (passForm.cupswd.value != passForm.cupswd2.value){	
				alert ("Your passwords did not match.")
				passForm.cupswd.focus()
				passForm.cupswd2.focus()
				return false
			}

		if (document.getElementById('ship_same_as_bill').checked == true) {
			document.getElementById('ship_fname').value = passForm.adfname.value;
			document.getElementById('ship_mname').value = passForm.admname.value;
			document.getElementById('ship_lname').value = passForm.adlname.value;
			document.getElementById('ship_add1').value = passForm.adaddr1.value;
			document.getElementById('ship_add2').value = passForm.adaddr2.value;
			document.getElementById('ship_city').value = passForm.adcity.value;
			document.getElementById('ship_zip').value = passForm.adzipc.value;
			document.getElementById('ship_parea').value = passForm.adarea.value;
			document.getElementById('ship_phone').value = passForm.adphone.value;
			document.getElementById('ship_state').value = passForm.state.value;
			document.getElementById('ship_email').value = passForm.ademail.value;
		
	
		}
		else {
			if (passForm.ship_fname.value == "") {
				alert ("You must enter your shipping first name.")
				passForm.ship_fname.focus()
				return false
			}
			if (passForm.ship_lname.value == "") {
				alert ("You must enter your shipping last name.")
				passForm.ship_lname.focus()
				return false
			}
			if (passForm.ship_add1.value == "") {
				alert ("You must enter your shipping address.")
				passForm.ship_add1.focus()
				return false
			}
			if (passForm.ship_city.value == "") {
				alert ("You must enter your shipping city.")
				passForm.ship_city.focus()
				return false
			}
			if (passForm.ship_zip.value == "") {
				alert ("You must enter your shipping zip.")
				passForm.ship_zip.focus()
				return false
			}
			if (passForm.ship_phone.value == "") {
				alert ("You must enter your shipping phone.")
				passForm.ship_phone.focus()
				return false
			}
			if (passForm.ship_email.value == "") {
				alert ("You Must enter your shipping email address.")
				passForm.ship_email.focus()
				return false
			}
			
		
		}
		return true

	}

function ValidPassWord(PassWordform){
	if (PassWordform.password.value == "") {
			alert ("You must enter your current password.")
			PassWordform.password.focus()
			return false
			}
		
		if (PassWordform.password2.value == "") {
			alert ("You must enter your new password.")
			PassWordform.password2.focus()
			return false
			}
		if (PassWordform.password3.value == "") {
			alert ("You must enter your new password again to confirm.")
			PassWordform.password3.focus()
			return false
			}
		if (PassWordform.password2.value.length < 6) {
			alert('Your new password must have at least 6 characters.');
			PassWordform.password2.focus()
			 return false
		} 		
		if (PassWordform.password2.value != PassWordform.password3.value){	
			alert ("Your passwords did not match.")
			PassWordform.password2.focus()
			PassWordform.password3.focus()
			return false
		}
		return true

	}

function ValidUserName(UserNameform){
	if (UserNameform.cusername.value == "") {
			alert ("You must enter your current username.")
			UserNameform.cusername.focus()
			return false
			}
		
		if (UserNameform.cusername2.value == "") {
			alert ("You must enter your new username.")
			UserNameform.cusername2.focus()
			return false
			}
		var invalid = " "; // Invalid character is a space

		if (document.UserNameform.cusername2.value.indexOf(invalid) > -1) {
			alert("Your username cannot have space.");
			UserNameform.cusername2.focus();
			return false;
		}
		if (UserNameform.cusername3.value == "") {
			alert ("You must enter your new username again to confirm.")
			UserNameform.cusername3.focus()
			return false
			}
	
		if (UserNameform.cusername2.value != UserNameform.cusername3.value){	
			alert ("Your usernames did not match.")
			UserNameform.cusername2.focus()
			UserNameform.cusername3.focus()
			return false
		}
		if (UserNameform.password.value == "") {
			alert ("You must enter your password.")
			UserNameform.password.focus()
			return false
			}
		return true
	}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}



