var http = getHTTPObject(); // We create the HTTP Object
var strCurrentTime = new Date()

var ap_instances = new Array();

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
			else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );


function handleHttpResponse() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    results = http.responseText.split(",");
    document.getElementById('city').value = results[0];
    document.getElementById('state').value = results[1];
  }
}

function createXMLHttpRequest() {
  var xmlhttp;
  try {
    xmlhttp= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttp=false;
  }
 }
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  try {
   var xmlhttp = new XMLHttpRequest();
  } catch (e) {
   var xmlhttp=false;
   alert('couldn\'t create xmlhttp object');
  }
 }
 return(xmlhttp);
}



function xmlhttpOpenEX(strIVURL, objIVFunction) 
{
	  var objhttp;
  objhttp = new createXMLHttpRequest();
	objhttp.open("GET",strIVURL,true);
	objhttp.onreadystatechange =  function() {
		if (objhttp.readyState==4) {
			objIVFunction(objhttp.responseText);
		delete objhttp;
		}
	}
	objhttp.send(null);
}

function xmlhttpOpenPOST(strIVURL, strIVParameters, objIVFunction)
{
	var objhttp;
	objhttp = new createXMLHttpRequest();
	objhttp.open("POST",strIVURL,true);
	objhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    objhttp.setRequestHeader("Content-length", strIVParameters.length);
    objhttp.setRequestHeader("Connection", "close");
	objhttp.onreadystatechange =  function() {
		if (objhttp.readyState==4) {
			objIVFunction(objhttp.responseText);
		delete objhttp;
		}
	}

	objhttp.send(strIVParameters)
	
}

function isBlank(strIVValue)
{
	blnRValue = true;
	
	if (strIVValue == "" || strIVValue == undefined)
	 {
		 blnRValue = true;
	 }
	 else
	 {
		 blnRValue = false;
	 }
	
	return blnRValue;
	
}

function isValidEmailAddress (strIVValue) {
    return String(strIVValue).search ('^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$') != -1;
 }

function xmlhttpOpen(strIVURL) 
{
	  var objhttp;
  objhttp = new createXMLHttpRequest();
	objhttp.open("GET",strIVURL,true);
	objhttp.onreadystatechange =  function() {
		if (objhttp.readyState==4) {
		document.getElementById('city').value = 'done';	
		delete objhttp;
		}
	}	
	objhttp.send(null);
}

function updateCityState() {
  var zipValue = document.getElementById("zip").value;
  http.open("GET", url, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
 }

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function delayRedirectURL(strIVURL, intIVInterval)
  { 
  setTimeout("redirectURL('" + strIVURL + "');",intIVInterval); 
  }
   
 function redirectURL(strIVURL)
 {
	 window.location = strIVURL;
 }

function isIE() {
	var useragent = navigator.userAgent;
	var pos = useragent.indexOf('MSIE');
	if (pos > -1) {
		return true;
	} else {
		return false;
	}
}

function RND(tmpl, ns) {
  var fn = function(w, g) {
    g = g.split("|");
    var cnt = ns[g[0]];
    for(var i=1; i < g.length; i++)
      cnt = eval(g[i])(cnt);
    return cnt || w;
  };
  return tmpl.replace(/%(([A-Za-z0-9_|.]*))/g, fn);
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

function checkAll(field,blnValue) 
{
if (field) {
for (i = 0; i < field.length; i++)
        field[i].checked = blnValue ;
        }
}


