
var xmlHttp

function GetXmlHttpObject()
{ 
  var objXMLHttp=null;

  if (window.XMLHttpRequest)
  {
	objXMLHttp=new XMLHttpRequest();
  }
	else if (window.ActiveXObject)
  {
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  return objXMLHttp;
}

function showData(location, procName, parameters)
{
  if (procName=="")
  {
	  return;
  }

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
	alert ("Browser does not support HTTP Request");
	return;
  } 

  url=location+"/httprequest.adp"
  //url="http://news.channel.office.aol.com/httprequest.adp"
  url = url + "?_pn=" + procName;

  if (parameters!="")
  {
	  url = url + "&_pa=" + parameters;
  }

  //url = url + new Date().getTime();

  xmlHttp.onreadystatechange=displayData;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function displayData() 
{ 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  { 
    document.getElementById("CTM80476.0").innerHTML=xmlHttp.responseText;
  } 
}

 function state(obj)
 {
     for (i = 1; i < obj.length; i++)
        if (obj[i].selected == true)
           eval(obj[i].value);
}

function validateForm (formName) {

    var formControl = 'document.'+formName;

    //check zipCode
    if (formName == 'zipCodeForm') {
        var zipCode = trimAll(eval(formControl)._z.value);
        if (validateZipCode(zipCode) == false) {
            alert('Not a valid Postal Code.');
            eval(formControl)._z.focus();
            return false;
        }
    }

    //check state
    if (formName == 'stateForm') {
        var state = trimAll(eval(formControl)._s.value);
        if (validateZipCode(state) == false) {
            alert('Not a valid State.');
            eval(formControl)._s.focus();
            return false;
        }
    }

    if (formName == 'addForm') {
        var address = trimAll(eval(formControl)._a.value);
        if (address == "") {
            alert('Address cannot be empty.');
            eval(formControl)._a.focus();
            return false;
        }
    }

    return true;
}

function trimAll(strValue) {
    var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

    //check for leading & trailing spaces
    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(strValue)) {
        //remove leading and trailing whitespace characters
        strValue = strValue.replace(objRegExp, '$2');
    }
    return strValue;
}

function validateZipCode(strValue) {
  var objRegExp  = /^\d{5}$/;
  return objRegExp.test(strValue);
}

function validateState(strValue) {
  var objRegExp  = /^\s{2}$/;
  return objRegExp.test(strValue);
}

function adRefresh() {
	var adSpots = '0';
	try {
	if (pgAdSpots != null && pgAdSpots != 'undefined' && pgAdSpots != '') {
			adSpots = pgAdSpots;
	}
	} catch(e) {
			adSpots = '0';
	}
	try {
		top.ch_refresher.refresh_ads_by_spot(adSpots);
	} catch(e) { }
	return true;
}


function refreshWindow (cntrlType) {
    var parentUrl = 'http://'+window.opener.location.hostname;

    if (cntrlType == 1) {
       parentUrl += window.opener.location.pathname;
    } else {
        parentUrl += '/elections/state';
    }
    window.opener.location.href = parentUrl;
    window.close();
}

function popup_window(url,width,height){
	var features="status=0,menubar=0,location=0,toolbar=0";
	if (!isNaN(parseInt(width))){features+=",width="+width;}
	if (!isNaN(parseInt(height))){features+=",height="+height;}

	if (typeof(window.screenLeft)!="undefined"){
		features+=",left="+window.screenLeft;
		features+=",left="+Math.round(window.screenLeft+((document.body.clientWidth/2)-(width/2)));
	}else if (typeof(window.screenX)!="undefined"){
		features+=",left="+Math.round(window.screenX+((window.outerWidth/2)-(width/2)));
	}

	if (typeof(window.screenTop)!="undefined"){
		features+=",top="+window.screenTop;
		features+=",top="+Math.round(window.screenTop+150);
	}else if (typeof(window.screenY)!="undefined"){
		features+=",top="+Math.round(window.screenY+((window.outerHeight-window.innerHeight)+150));
	}
	var popupWin=window.open(url,"popupWin",features);

	if (popupWin.focus){popupWin.focus();}
}
