function popupWindow(url){
	newwindow=window.open(url,'privacyWindow','height=420,width=620,resizable=no,scrollbars=yes,toolbar=no,status=no');
}

function formCheck(theForm){
	theForm = document.forms[0];
	var errstr = '';
		if(Trim(theForm.fname.value) == ""){
			errstr += "You need to enter your first name.\n";
		}
		if(Trim(theForm.lname.value) == ""){
			errstr += "You need to enter your last name.\n";
		}
		if(Trim(theForm.address1.value) == ""){
			errstr += "You need to enter your address.\n";
		}
		if(Trim(theForm.city.value) == ""){
			errstr += "You need to enter your city name.\n";
		}
		if(theForm.state.selectedIndex == 0){
			errstr += "You need to select your state.\n";
		}
	theForm.zip.value = Trim(theForm.zip.value);
		if(Trim(theForm.zip.value) == ""){
			errstr += "You need to enter your zip/postal code.\n";
		}else{
			var valid = 0;
			if(/^\d{5}$/.test(theForm.zip.value)){
				valid = 1;
			}else if(/^[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]s?\d[A-Za-z]\d$/.test(theForm.zip.value)){
				valid = 1; 
			}else{
				errstr += "Your zip/postal code is invalid.\n";
			}
		}
	rad = 1;
	for(i = 0; i < theForm.school.length; i++){
		if (theForm.school[i].checked){
			rad = 0;
		}
	}
	if(rad == 1){
		errstr += "Are you interested in Online or campus-based learning?\n";
	}
	if(errstr != ""){
		alert(errstr);
	} else {
	document.getElementById('form1').submit();
	}
}

function Trim(strValue){
	return LTrim(RTrim(strValue));
}
function LTrim(strValue){
	var LTRIMrgExp = /^\s */;
	return strValue.replace(LTRIMrgExp, "");
}
function RTrim(strValue){
	var RTRIMrgExp = /\s *$/;
	return strValue.replace(RTRIMrgExp, "");
}
function focusOnFirstName() {
	document.forms[0].fname.focus();
}

function getHttpRequestObj() {
  var req = false;
  if(window.XMLHttpRequest) {
      try {
         req = new XMLHttpRequest();
      } 
      catch(e) {
         req = false;
      }
  } else if(window.ActiveXObject) {
      try {
         req = new ActiveXObject("Msxml2.XMLHTTP");
      } 
      catch(e) {
         try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
         } 
         catch(e) {
            req = false;
         }
      }
  }
  return req;
}


function handleHttpResponse() {
   
   var state_select = document.forms[0].state;
   var city_text = document.forms[0].city;
   var country_select = document.forms[0].country; 
 
   if(http.readyState == 4){
      var data = parseResponseText(http.responseText);
      if(data) {
         city_text.value = data[0];
         if(state_select) {
            for(var i = 0; i < state_select.options.length; i++) {
               if(state_select.options[i].value.indexOf(data[1]) != -1){
                  state_select.options[i].selected = true;
               }
            }
         }
        if(country_select) {
            for(var i = 0; i < country_select.options.length; i++) {
               if(country_select.options[i].value.indexOf(data[2]) != -1){
                  country_select.options[i].selected = true;
               }
            }
         }

      }
      else {
         // no zip info found - clear state/city elements
         //do nothing
         //state_select.options[0].selected = true;
         //city_text.value = "";
      }
   }
}

function lookupZip(zip) {  
	var zipNumCount = document.getElementById('zip').value;
		if (zipNumCount.length >= 5) {
			document.getElementById('ff4b').style.display='block'; 
	} 

    var url;
    if (document.domain == 'dev.clk4.com') {
        url = 'http://dev.clk4.com/egomez/TEST_CSS/ziplookup.cgi?zipcode=' + zip;
    }
    else {
        url = 'http://www.clk4.com/UPJ_10188/ziplookup.cgi?zipcode=' + zip;
    }

   http = getHttpRequestObj();
   http.onreadystatechange = handleHttpResponse;
   http.open('GET', '/adcd/ajax/proxy?q='+escape(url), true);
   http.send(null);
}

function parseResponseText(str) {
  if(str.indexOf('NOT FOUND') != -1) {
      return null;
  }  
  var parsed = Array();
  parsed = str.split('|');
  return parsed;
}

