function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}

function checkUserName(aTextField)
{
	//contains illegal characters checking
	
	//var illegalChars;
	//illegalChars=/\W/;
	// allow only letters, numbers, and underscores
	//if (illegalChars.test(aTextField)){ return false;} 
	//else {return true;}

	//The user name only characters, number, dash or space
	var entry=aTextField.toUpperCase();	//in case of lowercase characters
	for (i=0; i<entry.length;i++)
	{
		if("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -.".indexOf(entry.charAt(i))<0) {return false;}
	}
	return true;

}

function checkPassword(aTextField) {
	//contains illegal characters checking

	var illegalChars;
	illegalChars=/[\W_]/; // allow only letters and numbers
	if (illegalChars.test(aTextField)){alert("Password only allows letters, numbers");return false;}
	else
		return true;
}

function checkCouponCode(aTextField) {
	//contains illegal characters checking

	var illegalChars;
	illegalChars=/[\W_]/; // allow only letters and numbers
	if (illegalChars.test(aTextField)){alert("The Coupon code only allows letters, numbers");return false;}
	else
		return true;
}

//***
function checkEmail(emailStr)
{
	//check email
	if (emailStr=="" || emailStr=="enter email address"){
		alert("Please enter information before you sign up.");
		return false;
		}
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)")
		return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
	    alert("The username doesn't seem to be valid.")
		return false;
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("Destination IP address is invalid!")
				return false;
		    }
	    }
		document.email_form.email.focus()
		return false;
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.")
		return false;
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
		alert("The address must end in a three-letter domain, or two letter country.")
		return false;
	}

	if (len<2) {
		var errStr="This address is missing a hostname!"
		alert(errStr)
		return false;
	}
	return true;
}

function isNumber(aTextField)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < aTextField.length && IsNumber == true; i++) 
      { 
      Char = aTextField.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

//***
function isEmpty(aTextField)
{
	var str;
	str = aTextField.replace(/\s/g, "");
	if ((str.length==0) || (str==null)) {return true;}
	else
	return false;
}

function checkPhone(aTextField)
{
	var stripped = aTextField.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {alert("The phone number contains illegal characters.");return false;}
	if (!(stripped.length == 10)) {alert("The phone number is the wrong length."+"\n"+"Make sure you included an area code."); return false;}
	return "("+stripped.substr(0,3)+") "+stripped.substr(3,3)+"-"+stripped.substr(6,4);
}
function checkFax(aTextField)
{
	var stripped = aTextField.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {alert("The Fax number contains illegal characters.");return false;}
	if (!(stripped.length == 10)) {alert("The Fax number is the incorrect length."+"\n"+"Make sure you included an area code."); return false;}
	return "("+stripped.substr(0,3)+") "+stripped.substr(3,3)+"-"+stripped.substr(6,4);
}

function isPostCode(aTextField)
{
	// CANADIAN CODES ONLY
	var blnError=false;
	var strlen=aTextField.length;
	if (strlen!=6){alert("Postal code must be exactly six characters.");return false;}
	var entry=aTextField.toUpperCase();	//in case of lowercase characters
	if("ABCEGHJKLMNPRSTVXY".indexOf(entry.charAt(0))<0) {alert("Please input valid Postal Code.");return false;}
	if("0123456789".indexOf(entry.charAt(1))<0) {alert("Please input valid Postal Code.");return false;}
	if("ABCDEFGHJKLMNPQRSTUVWXYZ".indexOf(entry.charAt(2))<0) {alert("Please input valid Postal Code.");return false;}
	if("0123456789".indexOf(entry.charAt(3))<0) {alert("Please input valid Postal Code.");return false;}
	if("ABCDEFGHJKLMNPQRSTUVWXYZ".indexOf(entry.charAt(4))<0) {alert("Please input valid Postal Code.");return false;}
	if("0123456789".indexOf(entry.charAt(5))<0) {alert("Please input valid Postal Code.");return false;}
	return true;
}

function isZip(aTextField) 
{
 
     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 
     if (!reZip.test(aTextField)) {
          alert("Zip Code Is Not Valid");
          return false;
     }
 
	return true;
}

function AllTrim(aTextField)
{
	return aTextField.replace(/^\s+|\s+$/g, '');
}

function LTrim(aTextField)
{
	return str.replace(/^\s+/, '');
}

function RTrim(aTextField)
{
	return str.replace(/\s+$/, '');
}

function isCity(aTextField)
{
	//The city only characters, number, or space
	var entry=aTextField.toUpperCase();	//in case of lowercase characters
	for (i=0; i<entry.length;i++)
	{
		if("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".indexOf(entry.charAt(i))<0) {return false;}
	}
	return true;
}

function GetPhoneAreaCode(aTextField)
{
	var stripped = aTextField.replace(/[\(\)\.\-\ ]/g, '');
	if (!isNumber(stripped)){return false;}
	var strLength=stripped.length;
	var ii=0;
	var blnFind0=false;
	for (i=0; i<strLength;i++)
	{
		if (stripped.substr(i,1)=="0"){ii=i; blnFind0=true;}
		else 
			break;
	}
	if (blnFind0){ii+=1;strLength=strLength-ii;stripped=stripped.substr(ii,strLength)}
	if (stripped.length<3){return false;}
	return stripped;
} 
function GetPhoneNumber(aTextField)
{
	var stripped = aTextField.replace(/[\(\)\.\-\ ]/g, '');
	if (!isNumber(stripped)){return false;}
	var strLength=stripped.length;
	var ii=0;
	var blnFind0=false;
	for (i=0; i<strLength;i++)
	{
		if (stripped.substr(i,1)=="0"){ii=i; blnFind0=true;}
		else 
			break;
	}
	if (blnFind0){ii+=1;strLength=strLength-ii;stripped=stripped.substr(ii,strLength)}
	if (stripped.length<7){return false;}
	if (stripped.length>7){return false;}
	return stripped;
}

function show_logout(strPageName)
{
	if (window.location.host.search("www.")<0) {document.location.href="https://www."+window.location.host+window.location.pathname;}
	var strSecurePath2="http://www.portableacstore.com/";
	var strSecurePath1="https://www.portableacstore.com/";
	//var strSecurePath1="";

	var objXMLHttp = new ActiveXObject("MSXML2.XMLHTTP");
	
	var objLocation=location.href;
	objLocation = objLocation.replace(strPageName, "include_file/html_pages_runSS.asp")

	//alert(objLocation)

	if (objLocation==strSecurePath2&&strSecurePath1!=""){objLocation=objLocation+"include_file/html_pages_runSS.asp";}
	objXMLHttp.open("POST",objLocation, false);
	objXMLHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=ISO-LATIN-7');
	
	
	//send information to test1
	objXMLHttp.send(strPageName)
	
	//get information from test1
	var strReturn = objXMLHttp.responseText
	if (strReturn.substr(0,1)=="0" && strSecurePath1!=""){document.location.href=strSecurePath1+strPageName}
} 

