
// *********************************
function unSecure() {		
// *********************************
	var locn = window.location.href;
	
	if (locn.substring(0,8) == 'https://') {
		window.location.href = 'http://' + locn.substring(8, locn.length);
	}
  }

// *********************************
function secure() {		
// *********************************
	var locn = window.location.href;
	
	if (locn.substring(0,7) == 'http://') {
		window.location.href = 'https://' + locn.substring(7, locn.length);
	}
  }



// *********************************
function getCode(sourceField) {		
// *********************************
	var codeValue;
  var formID;

  formID = document.forms.length - 1;

  codeValue = '';
  if (document.forms[formID].elements[sourceField].value.indexOf("-") > 0) 
  {
  	codeValue = document.forms[formID].elements[sourceField].value.split("-");
  	codeValue = codeValue[0];
  }

  return codeValue;
}

// *********************************
function forgotPW() {		
// *********************************
    var userName = $("#UserName").val();
    var URL = '/ForgotPassword.asp?P=ForgotPassword';
    if (userName != '') {
        URL += '&UserName=' + userName;
    }
	window.location = URL;
  }

// *********************************
function enableOtherTextField(sourceField, targetField) {		
// *********************************
	var codeValue;
  var leftCode;
  var formID;

  formID = document.forms.length - 1;
  
  codeValue = getCode(sourceField);
  leftCode = codeValue.substr(0, 3);
  leftCode = leftCode.toUpperCase();
  
  if ((leftCode == 'OTH') || (codeValue == '999')) 
    return;
  else {
    document.forms[formID].elements[targetField].value = '';
    document.forms[formID].elements[targetField].blur();
  }
}


// *********************************
function window_onbeforeunload() 
// *********************************
{
  if (field_exists('showexitwarning')){
	  if (document.forms[0].elements['showexitwarning'].value == "yes")    
      event.returnValue = "If you leave now, the changes will not be saved.";

    document.forms[0].elements['showexitwarning'].value = "no";
  }
}


// *********************************
function field_exists(fieldName) 
// *********************************
{
  var i, j;
  
	for (j=0; j <= document.forms.length - 1; j++)
	{
	  for (i=0; i < document.forms[j].length; i++)
	  {
	    if (document.forms[j].elements[i].name == fieldName)
	      return true;
	  }
	}
	
	return false;
}


// *********************************
function aLink(URL, newWindow, top, left, width, height) {
// *********************************
	// called by Site Editor and Dynamic Content anchors
	
	var sFeatures, newWin;
	
	if (width == 0) { width = 570; }
	if (height == 0) { height = 440; }

	sFeatures = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes";
		
	//alert(URL+"\n"+sFeatures);	
	if (newWindow) {
		newWin = window.open(URL, "NewPopupWindow", sFeatures, false);
	} else {
		window.location.href = URL;
	}
}


// *********************************
function isIE4() {
// *********************************
	var userAgent

	userAgent = navigator.userAgent;
	if (userAgent != "" ) {
		if (userAgent.indexOf("MSIE") != -1) {
			//It's a Microsoft browser
		    var startPt = userAgent.indexOf("MSIE") + 5;
		    var endPt = userAgent.indexOf(";", startPt);
		    var version = userAgent.substr(startPt, endPt-startPt);
		    if (version >= 4)
				return true;
		}
	}
	return false;
}


// *********************************
function mac() {
// *********************************
	if (navigator.platform == "Win32") {
		document.all("macSpace").style.display= "none";
	}
}


// *********************************
function OpenWindowOld(URL){
// *********************************
	/*
	var str = URL.substr(1,7);
	
	if (URL.substr(1,7) != 'http://'){
		URL = 'http://' + URL
	}
	*/


	newwin=window.open("","Information","top=0,left=0,width=570,height=440,menubar=no,toolbar=yes,scrollbars=yes,resizable=yes",false)
	newwin.location.href = URL;
        setTimeout('newwin.focus();',250); 
}


// *********************************
function OpenWindow(URL, W, H, MB, TB, SB, R){
// *********************************
	/*
	var str = URL.substr(1,7);
	
	if (URL.substr(1,7) != 'http://'){
		URL = 'http://' + URL
	}
	*/

	
	if (OpenWindow.arguments.length == 1)
		newwin=window.open("","Information","top=0,left=0,width=570,height=440,menubar=no,toolbar=yes,scrollbars=yes,resizable=yes",false)
	else		
		newwin = window.open("","Information","top=0,left=0,width=" + W + ",height=" + H + ",menubar=" + MB + ",toolbar=" + TB + ",scrollbars=" + SB + ",resizable=" + R,false);

newwin.location.href = URL;
        setTimeout('newwin.focus();',250);
	//return newwin;
}


// *********************************
function OpenWindow2(URL, ID){
// *********************************
	newwin=window.open("","PasteWindow","top=0,left=0,width=570,height=440,menubar=no,toolbar=yes,scrollbars=yes,resizable=yes",false)

	if (ID == ''){
		newwin.location.href = "Process.asp?P=" + URL
	}
	else {
		newwin.location.href = "Process.asp?P=" + URL + "&E=" + ID
	}

    setTimeout('newwin.focus();',250); // Blows up IE4
}


// *********************************
function enterKey(event, srcName, fName) {		
// *********************************
	if (event.keyCode == 13) {
		sendPage(srcName, fName);
		event.cancelBubble = true;
	}
}
		

// *********************************
function sendPage(srcName, fName){
// *********************************
	var frm;
	if (fName == null || fName == ""){
		frm = $('form');
		if (frm.length > 1) {frm = frm[0];}
	} else {
		frm = $('form[name=' + fName + ']');
	}
	$('input[name=SubmitAction]').val(srcName);
	frm.submit();
	return false;
}


// *********************************
function sendPageOld(fName){
// *********************************
	if (fName == null){
		var value = event.srcElement.name;
		var actn  = document.forms(0).action;

		if (actn.indexOf(value) == -1){
			if (actn.indexOf("?") == -1) {
			actn+= "?";
			} else {
			actn+= String.fromCharCode(38);
			}
			actn+= value + '=1';
		}

		document.forms(0).action = actn;
		document.forms(0).submit();
		event.returnValue = false;
	} else {
		var value = event.srcElement.name;
		var actn  = document.forms(fName).action;

		if (actn.indexOf(value) == -1){
			if (actn.indexOf("?") == -1) {
			actn+= "?";
			} else {
			actn+= String.fromCharCode(38);
			}
			actn+= value + '=1';
		}

		document.forms(fName).action = actn;
		document.forms(fName).submit();
		event.returnValue = false;
	}
}


// *********************************
function Send(value, frm){
// *********************************
	var actn = document.forms(frm).action;
					
	if (actn.indexOf(value) == -1){
		actn+= String.fromCharCode(38) + value + '=1'
	}

	document.forms(frm).action = actn;
	document.forms(frm).submit();
	return;
}


// *********************************
function setUTCOffset(){	
// *********************************
	var d = new Date();
	var s = document.cookie;
	var t = "UTCOFFSET=";
	t=t+String(d.getTimezoneOffset());
	var c = t + ";path=/;";
		
	if( s.indexOf("UTCOFFSET",0) == -1 )
	{
		document.cookie = c;
	}else
	{
		if( s.indexOf(t,0) == -1 )
		{
			document.cookie = c;
			window.location.reload(1);
		}
	}
}
window.onLoad = setUTCOffset();

// Factory Pattern for XMLHTTP Request
// A slightly different implentation that returns an error instead of null for failure

function FactoryXMLHttpRequest(){
	if (window.XMLHttpRequest){return new XMLHttpRequest();}
	if(window.ActiveXObject){
		var msxmls=new Array('Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
		for(var i=0;i<msxmls.length;i++){
			try{
				return new ActiveXObject(msxmls[i]);
				}catch (e){
			}
		}
	}
	//throw new Error('Could not instantiate XMLHttpRequest');
	return null;
}

// Here is a class that will allow multiple async calls simultaneously, each with its own event handler
// use an anonymous function assignment to readystatechange states (or delegate a static function)
// override the 'complete' function (or any of the functions) with the new function to implement
// note the signature of the 'complete' function 
// (and all of the functions-- delegates must have the same signature as the function you are overriding)

function Asynchronous(){this._xmlhttp=new FactoryXMLHttpRequest();}

function Asynchronous_call(url, post, body, forceRefresh){

	var instance=this;
	
	if(!post){
	    this._xmlhttp.open('GET',url,true);
	}else{
	    this._xmlhttp.open('POST',url,true);
	}
	
	if(forceRefresh){
	    this._xmlhttp.setRequestHeader("If-Modified-Since", new Date(0));
	}
	
	// anonymous function references 'this' and stays bound to this instance while 'this' remains an object
	this._xmlhttp.onreadystatechange=function(){
		switch(instance._xmlhttp.readyState){
		case 1: instance.loading();break;
		case 2: instance.loaded();break;
		case 3: instance.interactive();break;
		case 4: instance.complete(instance._xmlhttp.status,instance._xmlhttp.statusText,instance._xmlhttp.responseText, instance._xmlhttp.responseXML);break;
		}
	}
	
	if(!post){
	    this._xmlhttp.send(null);
	}else{
	    this._xmlhttp.setRequestHeader("hasXML", "TRUE");
	    this._xmlhttp.send(body);
	}
	
}

function Asynchronous_loading(){}
function Asynchronous_loaded(){}
function Asynchronous_interactive(){}
function Asynchronous_complete(status, statusText, responseText, responseXML){}
//usage: 
//	var ax=new Asynchronous; 
//	ax.complete=function(status, statusText, responseText, responseXML){alert(responseText);}
//	ax.call(url);

Asynchronous.prototype.loading=Asynchronous_loading;
Asynchronous.prototype.loaded=Asynchronous_loaded;
Asynchronous.prototype.interactive=Asynchronous_interactive;
Asynchronous.prototype.complete=Asynchronous_complete;
Asynchronous.prototype.call=Asynchronous_call;



