leftpos =0
if(screen) {
leftpos = screen.width
}
rightpos=0
if (screen) {
rightpos = screen.height
}

function isEmpty(formfield) {
for(var i = 0; i < formfield.length; i++) {
		var c = formfield.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
} 

function ValidEmail(Str)
{
	var invalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var valid = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;

	return (!invalid.test(Str) && valid.test(Str))
}


function openpanel(theURL,winName,features) 
{
window.open(theURL,winName,features);
}

function cancel() {
    if (confirm("Are you sure you wish to cancel your registration?\n\nOK to cancel your registration and return to the start page.\nCancel to return to your registration.")){
		  location = "start.asp"
    }
}

// Ajax Zipcode lookup
function updateCityState() {
var url = "getcitystate.asp?param="; 

	    var zipValue = document.getElementById('Zipcode').value;
		var loader = new net.ContentLoader(url+zipValue,handleHttpResponse);

}

function handleHttpResponse() {
var results = new Array();

	if (this.req.responseText.indexOf('invalid') == -1) {

      // Split the comma delimited response into an array
		results = this.req.responseText.split(",");

		document.getElementById('City').value = results[0];
		document.getElementById('State').value = results[1];
		document.getElementById('Country').value = results[2];
		     
	}
}

function ZipCodeLookup(){

	if (document.Form1.Zipcode) var querystr = "?" + "idbszip=" + document.Form1.Zipcode.value;
	
	
	// Process ZipCode lookup
	if (window.showModalDialog)
  {
    retval = showModalDialog("ZipCodeLookup.asp" + querystr,"","dialogWidth:20;dialogHeight:10;center:1;status=1");
  }
  else
  {
    winModalWindow = window.open ("ZipCodeLookUp.asp" + querystr,"","modal=yes,dependent=yes,width=20,height=10");
  }

	
	// Fill in form fields with returned values IE
	if (navigator.appName == 'Netscape') {
	}
	else{
	if(retval[1] != ''){
		if(document.Form1.City) 	document.Form1.City.value = retval[1];
		if(document.Form1.State) 	document.Form1.State.value = retval[2];
		if(document.Form1.Country)  document.Form1.Country.value = retval[3];
	}
	}
	
}

var msg = '';
var winModalWindow;
function PromoCodeValidate() {
  if (document.Form1.Promo1) var querystr = "?promo1=" + escape(document.Form1.Promo1.value) + '&o=' + document.Form1.ordernumber.value;
	
  // Process Promo
  if (window.showModalDialog)
  {
	msg = showModalDialog("PromoValidation.asp" + querystr,"","dialogWidth:20;dialogHeight:10;center:1;status=1");
  }
  else
  {
    winModalWindow = window.open("PromoValidation.asp" + querystr,"","modal=yes,dependent=yes,width=20,height=10");
	alert('Your information is now being validated.');
	//Safari has trouble closing the pop-up, so...
	if (!winModalWindow.closed) {
		if (window.focus) {
			winModalWindow.focus();
		}
		winModalWindow.close();
	}
  }
}


function IsNum(ValueIn) {
   ValidFlag = true
   if (ValueIn == "") {
      ValidFlag = false
   }
   for (i=0; i<ValueIn.length; i++) {
      if (ValueIn.charAt(i) < "0") {
          ValidFlag = false
      }
      if (ValueIn.charAt(i) > "9") {
          ValidFlag = false
      }
   }
   return ValidFlag
}


function ZipCodeLookupAjax(){
	var retval;
	var querystr;
	var strResponse;
	//var resp = "test";
	
	if (document.Form1.Zipcode) {
	 	querystr = "ZipCodeLookup.php?" + "ajax=true&idbszip=" + document.Form1.Zipcode.value;
	}
	
	if(document.Form1.Zipcode.value != '') {
		loadXMLDoc(querystr, "zip");
	}
}

function PromoCodeValidateAjax(){
	var querystr;
	//var resp = "test";
	
	if (document.Form1.Promo1) {
	 	querystr = "PromoValidation.asp?ajax=true&promo1=" + escape(document.Form1.Promo1.value) + '&o=' + document.Form1.ordernumber.value;
	}
	
	if(document.Form1.Promo1.value != '') {
		loadXMLDoc(querystr, "promo");
	}
}


var xmlhttp;
var resp;

//

function loadXMLDoc(url, type)
{
xmlhttp=null
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	  {
	  	xmlhttp=new XMLHttpRequest()
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  }
	if (xmlhttp!=null)
	  {
	  	if(type == "zip") { //allow for this to be used with other functions
	 		xmlhttp.onreadystatechange=zip_state_Change
			xmlhttp.open("GET",url,true)
	  		xmlhttp.send(null)
	 	} else if(type == "promo") {
			xmlhttp.open("GET",url,false)
	  		xmlhttp.send(null)
			msg = xmlhttp.responseText;
		}
	  }
	else
	  {
	  	if(type == "zip") { 
			ZipCodeLookup();
		} else if(type == "promo") {
			PromoCodeValidate();
		}
	  }
}


function stripHtml(strHTML) {
// Replace all newLines with .$!$. string
strOutput = strHTML.replace(/\n/g, ".$!$.")
// Replace all <script>s with an empty string
aScript=strOutput.split(/\/script>/i);
for(i=0;i<aScript.length;i++){
aScript[i]=aScript[i].replace(/\<script.+/i,"");
}
strOutput=aScript.join('');
// Replace all HTML tag matches with the empty string
strOutput = strOutput.replace(/\<[^\>]+\>/g, "")
// Remove empty lines
strOutput = strOutput.replace(/\.\$\!\$\.\r\s*/g,"")
// Replace all .$!$. with the empty string
strOutput = strOutput.replace(/\.\$\!\$\./g,"")
// Remove empty lines
strOutput = strOutput.replace(/\r\ \r/g,"")
return strOutput;
}  



function zip_state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
    	resp =  xmlhttp.responseText;
    	retval = resp.split("|");
		
		if(retval[0] != '') {
	
			if(document.Form1.City) 	document.Form1.City.value = stripHtml(retval[0]);
			if(document.Form1.State) 	document.Form1.State.value = stripHtml(retval[1]);
			if(document.Form1.Country)  document.Form1.Country.value = stripHtml(retval[2]);
		
		}
    	
    }
    
  else
    {
    	resp =  "";
    }
  }
}
