
// Take user here after session timed out
timedouturl = "./index.php?timeout=1";
var newWin = null;
var version4 = false
if(navigator.appVersion.charAt(0) == "4") version4 = true

function validate_email(emailStr) {
	var msg = "";
	
	/* The following variable tells the rest of the function whether or not
	to verify that the e-mail address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the e-mail address.
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied e-mail address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
  
	if (matchArray != null) {
		if(matchArray[1])
			var user=matchArray[1];
		if(matchArray[2])
			var domain=matchArray[2];

		// Start by checking that only basic ASCII characters are in the strings (0-127).
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				msg += "Ths username contains invalid characters.";
  		}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				msg += "Ths domain name contains invalid characters.";
   		}
		}

		// See if "user" is valid

		if (user.match(userPat)==null) {

			// user is not valid

			msg += "The username doesn't seem to be valid.";
		}

		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */

		var IPArray=domain.match(ipDomainPat);
		
		if (IPArray!=null) {

			// this is an IP address

			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					msg += "Destination IP address is invalid!";
   			}
			}
		}

		// Domain is symbolic name.  Check if it's valid.

		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				msg += "The domain name does not seem to be valid.";
   		}
		}

		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding
		the domain or country. */

		if (checkTLD && domArr[domArr.length-1].length!=2 &&
			domArr[domArr.length-1].search(knownDomsPat)==-1) {
			msg += "The e-mail address must end in a well-known domain or two letter " + "country.";
		}

		// Make sure there's a host name preceding the domain.
	
		if (len<2) {
			msg += "This e-mail address is missing a hostname!";
		}
	}
	else
		msg += "E-mail address seems incorrect check for @";

	return msg;
}
 
function isblank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f) {
    var msg;
    var str;
    var empty_fields = "";
    var errors = "";

		var radio_rcnt 	= 0;
		var radio_fcnt 	= 0;
		var radio_rad 	= "";
		var radio_ltype = "";
	
		var chk_rcnt 	= 0;
		var chk_fcnt 	= 0;
		var chk_rad 	= "";
		var chk_ltype = "";
   	
   	// Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
    	var e = f.elements[i];
				
      if (((e.type == "text") 
      	|| (e.type == "select-one") 
       	|| (e.type == "select-multiple") 
       	|| (e.type == "textarea") 
       	|| (e.type == "password") 
       	|| (e.type == "radio") 
       	|| (e.type == "file") 
       	|| (e.type == "checkbox")) && !e.optional) {
          
        if(radio_rad != e.name && e.type == "radio") {
					if(radio_rcnt == radio_fcnt && radio_fcnt > 0 && radio_ltype=="radio") {
						empty_fields += "\n          " + radio_rad;
						radio_ltype="";
					}
					radio_rad		=e.name;
					radio_ltype	="radio";
					radio_fcnt	=0;
					radio_rcnt	=0;
				}
          	
        if(chk_rad != e.name && e.type == "checkbox") {
					if(chk_rcnt == chk_fcnt && chk_fcnt > 0 && chk_ltype=="checkbox") {
						empty_fields += "\n          " + chk_rad;
						chk_ltype="";
					}
					chk_rad		=e.name;
					chk_ltype	="checkbox";
					chk_fcnt	=0;
					chk_rcnt	=0;
				}
				
        // Check for email field
        var temp = e.name.split('_');
				for (k=0; k < temp.length; k++)
					if(temp[k]=="email")
      			errors += validate_email(e.value);
				if (e.type == "select-one" || e.type == "select-multiple") {
					var n;
					var sel=0;
					for (n = 0; n < e.options.length; n++) {
						if (e.options[n].selected && e.value != null && e.value != "") {
							sel=1;
							break;
						}
					}
					if(sel==0)
						empty_fields += "\n          " + e.name;
					continue;
  			}
	
				if(e.type == "radio") {
					if(!e.checked)
						radio_rcnt++;
					radio_fcnt++;
				}
				if(e.type == "checkbox") {
					if(!e.checked)
						chk_rcnt++;
					chk_fcnt++;
				}

				if (e.value == null || e.value == "" || isblank(e.value)) {
       	 	empty_fields += "\n          " + e.name;
         	continue;
       	}
        	
    	 	// Now check for fields that are supposed to be numeric.
        if (e.numeric || (e.min != null) || (e.max != null)) {
         	var v = parseFloat(e.value);
 	       	if (isNaN(v) ||
   	        ((e.min != null) && (v < e.min)) ||
     	      ((e.max != null) && (v > e.max))) {
       	    errors += "- The field " + e.name + " must be a number";
         	  if (e.min != null)
           	   errors += " that is greater than or equal to " + e.min;
            if (e.max != null && e.min != null)
           	  errors += " and less than " + e.max;
            else if (e.max != null)
              errors += " that is less than or equal to " + e.max;
 	          errors += ".\n";
   				}
     		}
   		}
 		}
 		if(radio_rcnt == radio_fcnt && radio_fcnt > 0 && radio_ltype=="radio")
			empty_fields += "\n          " + radio_rad;
		if(chk_rcnt == chk_fcnt && chk_fcnt > 0 && chk_ltype=="checkbox")
			empty_fields += "\n          " + chk_rad;
				
    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg += "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

function Minutes(data) {
	for (var i = 0; i < data.length; i++)
	if (data.substring(i, i + 1) == ":")
		break;
	return (data.substring(0, i));
}
function Seconds(data) {
	for (var i = 0; i < data.length; i++)
	if (data.substring(i, i + 1) == ":")
		break;
	return (data.substring(i + 1, data.length));
}
function Display(day, hour, min, sec) {
	//alert("DAY "+day+" HR "+hour+" MIN "+min+" Sec "+sec);
	var disp;
	disp="Bidding ends in ";
	if(day > 0)
		disp += day + " days " + hour + " hrs ";
	else {
		if (hour > 0)
			disp += hour + " hrs ";
	}
	if (min <= 9) 
		disp += " 0";
	else 
		disp += " ";
	disp += min + " mins ";
	if (sec <= 9) disp += "0" + sec + " secs";
	else disp += sec + " secs"; 
	return (disp);
	//alert("DISP "+disp);
}
function xpire(shour, smin, ssec) {
	//alert(" HR "+shour+" MIN "+smin+" Sec "+ssec);
	var disp;
	disp="Session will time out in ";
	if (shour > 0)
		disp += shour + " hrs ";
	if (smin <= 9) 
		disp += " 0";
	else 
		disp += " ";
	disp += smin + " mins ";
	if (ssec <= 9) disp += "0" + ssec + " secs";
	else disp += ssec + " secs"; 
	return (disp);
	//alert("DISP "+disp);
}
function Down() { 
	sec--;    
	ssec--;  
	if (sec == -1) { sec = 59; min--; }
	if (min == -1) { min = 59; hour--; }
	if (hour == -1) { hour = 23; day--; }
	if (ssec == -1) { ssec = 59; smin--; }
	if (smin == -1) { smin = 59; shour--; }
	document.timerform.clock.value = Display(day, hour, min, sec);
	document.timerform.xpire.value = xpire(shour, smin, ssec);
	window.status = xpire(shour, smin, ssec);
	if (smin == 0 && ssec == 0) {
		alert("Your session has timed out.");
		window.location.href = timedouturl;
	}
	else down = setTimeout("Down()", 1000);
}
function timeIt() {
	min = parseInt((1 * Minutes(document.timerform.clock.value)) / 60);
	sec = (1 * Minutes(document.timerform.clock.value)) % 60;	
	smin = Seconds(document.timerform.clock.value);
	day=0;
	hour=0;
	shour=0;
	ssec=0;
	if(min >= 1440) {
		day=parseInt(min/1440);
		min= min % 1440;
	}
	if(min >= 60) {
		hour=parseInt(min/60);
		min= min % 60;
	}
	if(smin >= 60) {
		shour=parseInt(smin/60);
		smin= smin % 60;
	}
	Down();
}
function OpenPriceWindow(url) { 
  var newWin = window.open(url,'MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=445,height=465,left=150,top=50'); 
} 
function popWin(){ 
     window.open("http://www.ibabrokers.com/popWin.html","Popup","width=450,height=400,toolbars=no,menubar=no,status=yes,scrollbars=no,resizable=no,left=150,top=50");
} 
function validate(field,theValue) {
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (theValue.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "no") {
    msg = "Invalid entry!  Only ";
	msg += theValue;
	msg += " characters are accepted!";
    alert(msg);
    field.focus();
  }
}

var x;
var w;
var h;
var newWin = null;
function openWindow(hiddenWindow, WindowName) {
	w=Math.round(WindowName/1000);
	h=((WindowName/1000)-(Math.round(WindowName/1000))) * 1000;
	if(h < 0)
		h=h*-1;
	if (!newWin || newWin.closed){
		if (WindowName == "login"){
			newWin = window.open(hiddenWindow, WindowName, "width=650,height=600,toolbar=no,menubar=no,status=no,scrollbars=yes,resize=yes");
		}else{
			newWin = window.open(hiddenWindow, WindowName, "width=650,height=600,toolbar=no,menubar=no,status=no,scrollbars=yes,resize=yes");
		}
	}else{
		newWin.location.href = hiddenWindow;
		newWin.focus();
	}
}
function newWindow(hiddenWindow, WindowName) {
	if (!newWin || newWin.closed){
		if (WindowName == "login"){
			newWin = window.open(hiddenWindow, WindowName, "width=700,height=450,toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
		}else{
			newWin = window.open(hiddenWindow, WindowName, "width=700,height=450,toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
		}
	}else{
		newWin.location.href = hiddenWindow;
		newWin.focus();
	}
}

function fullWindow(hiddenWindow, WindowName,theWidth,theHeight) {
	if (!newWin || newWin.closed){
		if (WindowName == "login"){
			newWin = window.open(hiddenWindow, WindowName, "width=800,height=600,toolbars=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
		}else{
			newWin = window.open(hiddenWindow, WindowName, "width=800,height=600,toolbars=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes");
		}
	}else{
		newWin.location.href = hiddenWindow;
		newWin.focus();
	}
}
function linkSelect(form) {
  window.parent.location = form.link.options[form.link.selectedIndex].value
}

function PrintPage() {
	if (navigator.appName.indexOf("Microsoft")>=0 && navigator.appVersion.substring(22,23) == 4 || navigator.platform.substring(0,3) == "Mac") {
		alert("Your current browser does not support this button.  Please choose File/Print from your browser's menu.");
	} 
	else {
		window.print();
	}
}
function password(form) {
  if(form.password1.value != form.password2.value) {  
    alert("Two passwords not equal please renter!");
    form.password1.focus();
    form.password1.select();	
  }	
}

function SetPhoto(val,fld) {
	dml=document.childForm;
	len = dml.elements.length;
	var i=0;
	var total=0;
	for( i=0 ; i<len ; i++) {
		if (dml.elements[i].name==fld) {
			dml.elements[i].checked=val;
		}
	}
}

function getDirections(address,city,state,zip) {
	var toAdd = prompt("From Street Address (No City/State):","");
	if ((toAdd == "") || (toAdd == null)) { return false }
	var toCity = prompt("From City (No State):","");
	if ((toCity == "") || (toCity == null)) { return false }
	var toState = prompt("From State (2 letter abbrev.):","CT");
	if ((toState == "") || (toState == null)) { return false }
	var escapedURL = "";

	myUrl = "http://www.mapquest.com/directions/main.adp?go=1&do=nw&ct=NA&1y=US&1a="
	myUrl += toAdd
	myUrl += "&1c="
	myUrl += toCity
	myUrl += "&1s="
	myUrl += toState
	myUrl += "&1z="
	myUrl += "&2y=US&2a="
	myUrl += address
	myUrl += "&2c="
	myUrl += city
	myUrl += "&2s="
	myUrl += state
	myUrl += "&2z="
	myUrl += zip

  for (var i=0, output='', space=" "; i<myUrl.length; i++)
  	if (space.indexOf(myUrl.charAt(i)) != -1) {
    	escapedURL += "+" 
    } 
    else {
      escapedURL += myUrl.charAt(i)
    }
		window.open(escapedURL,'','toolbar=yes,menubar=yes,resizable=yes,scrollbars=yes')
}

function autotab(object1, object2, objectsize) {
if (object1.value.length == objectsize)
    object2.focus()
}

// Function used to disable right click
var message="";
///////////////////////////////////
function clickIE() {
	if (document.all) {(message);return false;}
}
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {(message);return false;}}
}

function showElement(strID) {
	try { document.getElementById(strID).style.display = ""; } catch(ex) {}
}
function hideElement(strID) {
	try { document.getElementById(strID).style.display = "none"; } catch(ex) {}
}


function setStateProvince(sel) {
	if (sel =="US") {
		ShiftTo('subdiv2');
	} 
	else if (sel=="CA") {
		alert ("CA");
		ShiftTo('subdiv3');
	} 
	else {
		ShiftTo('subdiv1');
	}
}


function setDepartment(sel) {
	var str = 'subdiv' + sel;
	ShiftTo(str);
}

function ShiftTo(DivID,ct){
	var found = 0;
	var str = (ct > 0) ? "Maindiv"+ct : "Maindiv";
	Base=document.getElementById(str);
	Sub=Base.getElementsByTagName('div');
	for (x=0;x<Sub.length;x++){
		//if (Sub[x].id==DivID && Sub[x].parentNode==Base){
		if (Sub[x].id==DivID){
			Sub[x].style.display="block";
			found = 1;
		}
		else{
			Sub[x].style.display="none";
		}
	}
	if(found == 0)
		document.getElementById("other").style.display="block";
}

function ShiftToBusiness(DivID){
	var found = 0;
	Base=document.getElementById('Maindiv');
	Sub=Base.getElementsByTagName('div');
	for (x=0;x<Sub.length;x++){
		if (Sub[x].id==DivID){
			Sub[x].style.display="block";
			found = 1;
		}
		else{
			Sub[x].style.display="none";
		}
	}
	if(found == 0)
		document.getElementById("business_other").style.display="block";
}

function whatService(strID) {
	if( document.getElementById("service_organization").checked == true) {
		try { document.getElementById("organization").style.display = ""; } catch(ex) {}


		try { document.getElementById("personal").style.display = "none"; } catch(ex) {}

	}
	
	else if( document.getElementById("service_business").checked == true)  {
		try { document.getElementById("business").style.display = ""; } catch(ex) {}


		try { document.getElementById("organization").style.display = "none"; } catch(ex) {}

	}	
	
	else if( document.getElementById("service_personal").checked == true)  {
		try { document.getElementById("business").style.display = ""; } catch(ex) {}


		try { document.getElementById("organization").style.display = "none"; } catch(ex) {}

	}	
}

function hideElement(strID) {
	try { document.getElementById(strID).style.display = "none"; } catch(ex) {}
}

function chooseCountry(state){
	var fields = state.split("|");
	
	if(fields[1]) {
		document.getElementById('txtCountry').value=fields[1];
		document.getElementById('state').value=fields[0];
	}
	else {
		document.getElementById('txtCountry').value='';
		document.getElementById('txtState').value='';
	}
}

function CloseAll(DivID,sh){
	Base=document.getElementById('Maindiv');
	Sub=Base.getElementsByTagName('div');
	for (x=0;x<Sub.length;x++){
		var s = Sub[x].id;
		if(s.substr(0,6) == "detdiv") {
			if(sh == 'h') {
				Sub[x].style.display="none";
				document.getElementById("showme").style.display = "";
				document.getElementById("hideme").style.display = "none";
			}
			else {
				document.getElementById("hideme").style.display = "";
				document.getElementById("showme").style.display = "none";
				Sub[x].style.display="block";
			}
		}
	}
}

function updateuser(xtype,xid,xname,lid,phone,email_address,xdescription,xphoto,xdp) {
	document.getElementById("edit_dep").style.display = "";
	document.getElementById("m_name").value = xname;
	document.getElementById("m_id").value = xid;
	document.getElementById("xm_id").value = xdp;
	document.getElementById("ml_id").value = lid;
	document.getElementById("m_phone").value = phone;
	document.getElementById("m_email_address").value = email_address;
	document.getElementById("m_description").value = xdescription;
	document.getElementById("xtype").value = xtype;
	
}

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function xchangeClass() {
	document.getElementById("idElement").setAttribute("class", "myClass");
}

function changeClass(oldClass1,newClass1,oldClass2,newClass2){
	 xdiv1 = document.getElementsByTagName(oldClass1);
		document.getElementById("theContent").className = newClass1;
		 
	 xdiv2 = document.getElementsByTagName(oldClass2);
	 document.getElementById("theSub").className = newClass2;
}

/* AJAX MAIN FUNCTIONS */
function makeactive(tab,num_tabs,page) { 
 		for (var i = 1; i <= num_tabs; i++) {
 			var tabs = "tab"+i;
 			document.getElementById(tabs).className = "";
 		}
		document.getElementById("tab"+tab).className = "active"; 
		callAHAH('media_content.php?content= '+tab+'&page_type= '+page, 'content', 'getting content for tab '+tab+'. Wait...', 'Error'); 
}

 function makeactive_profile(tab,num_tabs,page) { 
 		for (var i = 1; i <= num_tabs; i++) {
 			var tabs = "tab"+i;
 			document.getElementById(tabs).className = "";
 		}
		document.getElementById("tab"+tab).className = "active"; 
		callAHAH('media_content.php?content= '+tab+'&page_type= '+page, 'profile', 'getting content for tab '+tab+'. Wait...', 'Error'); 
}

function xmlhttpPost(strURL,fn,pageElement) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {	// Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
    self.xmlHttpReq.onreadystatechange = function() {
    	if (self.xmlHttpReq.readyState == 4) {
      		updatepage(self.xmlHttpReq.responseText,pageElement);
      	}
    }
    self.xmlHttpReq.send(getquerystring(fn));
}

function xmlhttpPostPlus(strURL,fn,pageElement,deleteRecord) {
	if(document.forms['second_form'].photo_file.value != ''){
		document.forms['theform'].photo.value = document.forms['second_form'].photo.value;
	}
	document.forms['second_form'].submit();//submit a separate form with nothing but a file upload in it
	
	var xmlHttpReq = false;
	var self = this;
	if (window.XMLHttpRequest) {	// Mozilla/Safari
		self.xmlHttpReq = new XMLHttpRequest();
	}
  else if (window.ActiveXObject) { // IE
    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }
  self.xmlHttpReq.open('POST', strURL, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
  self.xmlHttpReq.onreadystatechange = function() {
  if (self.xmlHttpReq.readyState == 4)
   	updatepage(self.xmlHttpReq.responseText,pageElement);
  }
  self.xmlHttpReq.send(getquerystring(fn,deleteRecord));
}

function xmlhttpPost_profile(strURL,fn) {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {	// Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
    	if (self.xmlHttpReq.readyState == 4)
      		updateprofile(self.xmlHttpReq.responseText);
    }
    self.xmlHttpReq.send(getquerystring(fn));
}

function getquerystring(fn,deleteRecord) {
	var f     = document.forms[fn];
  	var qstr = "theStr =";
  	var ename = '';
  	
	//submitValues = new Array();
  	
  	for(var i = 0; i < f.length; i++) {
   		var e = f.elements[i];
   		//alert("type "+e.type+"name "+e.name+" Val "+e.value);
   		if ((e.type == "text") 
     		|| (e.type == "select-one") 
     		|| (e.type == "select-multiple") 
     		|| (e.type == "textarea") 
     		|| (e.type == "password") 
     		|| (e.type == "radio") 
     		|| (e.type == "file") 
     		|| (e.type == "checkbox")
     		|| (e.type == "hidden")) {
			
     		if(e.type == "checkbox" || e.type == "select-multiple") {
     			if(e.type == "checkbox") {	
     				if(e.checked) {
     					if(ename != e.name) {
     						qstr += '|' + e.name + '^' + escape(e.value);
     						ename = e.name;
     						//submitValues[]	= e.name + '^' + escape(e.value);
     					}
     					else
     						qstr += '^' + escape(e.value);
     				}		
     			}
     			else {
     				for (n = 0; n < e.options.length; n++) {
						if (e.options[n].selected && e.value != null && e.value != "") {
							qstr += '|' + e.name[n] + '^' + escape(e.options[n].value);
							//submitValues[]	= e.name[n] + '^' + escape(e.options[n].value);
						}
					}
     			}
     		}
     		else if(e.type == "radio") {
   				if(e.checked) {
   					qstr += '|' + e.name + '^' + escape(e.value);
   					//submitValues[]	= e.name + '^' + escape(e.value);
   				}
    		}
    		else {
    			qstr += '|' + e.name + '^' + escape(e.value);
    			//submitValues[]	= e.name + '^' + escape(e.value);
    		}
    	}
	}
	if(deleteRecord == "1") {
		qstr += '|delete=1';
		//submitValues[]	= 'delete=1';
	}
	//var arv = submitValues.toString();
  return qstr;
}

function updatepage(str,pageElement){
    document.getElementById(pageElement).innerHTML = str;
}

function updateprofile(str){
    document.getElementById("profile").innerHTML = str;
}

function replaceString(objectString, searchString, replaceString){
	return objectString.split(searchString).join(replaceString);
}

//evalAHAH Added 3/26/08 msh for use in modifying forms & such, for which innerHTML doesn't work
//(with innerHTML the form elements displayed are modified but the document object is not)
function evalAHAH(url, pageElement, callMessage, errorMessage) {
  try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
  } 
  catch(e) {
  	try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
    } 
    catch (e) {
    	try {
      	req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
      } 
      catch (E) {
      	req = false;
      } 
    } 
	}
  req.onreadystatechange = function() {evalResponse(pageElement, errorMessage);};
  req.open("GET",url,true);
  req.send(null);
}

function evalResponse(pageElement, errorMessage){
//script named by URL must return javascript code to be eval'd
	var output = '';
	if(req.readyState == 4) {
		if(req.status == 200) {
			output = req.responseText;
			eval (output);
		} 
		else {
			document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
		}
	}
}

function showAHAH(url, pageElement, callMessage, errorMessage) {
	document.getElementById(pageElement).innerHTML = callMessage;
  try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
  } 
  catch(e) {
  	try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
    } 
    catch (e) {
    	try {
      	req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
      } 
      catch (E) {
      	req = false;
      } 
    } 
	}
  req.onreadystatechange = function() {showresponseAHAH(pageElement, errorMessage);};
  req.open("GET",url,true);
  req.send(null);
}

function showresponseAHAH(pageElement, errorMessage) {
	var output = '';
  if(req.readyState == 4) {
  	if(req.status == 200) {
    	output = req.responseText;
      document.getElementById(pageElement).innerHTML = output;
    } 
    else {
    	document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
    }
	}
}


/* OTHER AJAX FUNCTIONS */
function callAHAH(url, pageElement, callMessage, errorMessage) {
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responseAHAH(pageElement, errorMessage);};
     req.open("GET",url,true);
     req.send(null);
	}
	function responseAHAH(pageElement, errorMessage) {
   	var output = '';
   	if(req.readyState == 4) {
      if(req.status == 200) {
        output = req.responseText;
        document.getElementById(pageElement).innerHTML = output;
      } 
      else {
         document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
      }
		}
  }
  
/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid) {
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	page_request.onreadystatechange=function() {
		loadpage(page_request, containerid)
	}
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
	else
		document.getElementById(containerid).innerHTML="<img src='/images/ajax_spinner.gif'>"
}

function loadobjs() {
	if (!document.getElementById)
		return
	for (i=0; i<arguments.length; i++) {
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1) { //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1) { //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1) { //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!="") {
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

/***Combo Menu Load Ajax snippet**/
function ajaxcombo(selectobjID, loadarea){
	var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
	if (selectobj!="" && selectobj.options[selectobj.selectedIndex].value!="")
		ajaxpage(selectobj.options[selectobj.selectedIndex].value, loadarea)
}


function showPhoto(photoPath) {
	var hideLink = "<a onClick='hidePhoto(\""+photoPath+"\")'>[ Hide Photo ]</a>";
	document.getElementById('photo_box').innerHTML=hideLink+'<br><img src="'+photoPath+'">';
}

function hidePhoto(photoPath) {
		var showLink = "<a onClick=\"showPhoto('"+photoPath+"')\">Show Photo</a>";
		document.getElementById('photo_box').innerHTML=showLink;
}

function showVideo(videoPath) {
	var videoPathEscaped=replaceString(videoPath, "\"", "\\\"")
	var hideLink = "<a onClick='hideVideo(\""+videoPathEscaped+"\")'>[ Hide Video Window ]</a>";
	document.getElementById('video_box').innerHTML=hideLink+'<br>'+ videoPath;
}

function hideVideo(videoPath) {
		var videoPathEscaped=replaceString(videoPath, "\"", "\\\"")
		var showLink = "<a onClick='showVideo(\""+videoPathEscaped+"\")'>Show Video Window</a>";
		document.getElementById('video_box').innerHTML=showLink;
}

/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

