/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function GetTable(thisTable,divId,memberId,sortField,sortOrder,myFilter,thisType)
{
	if(document.getElementById(divId + "_wait"))
	{document.getElementById(divId + "_wait").style.display = ""}

	var url=parent.location.protocol + "//" + document.domain + "/remote/rem_return_table.asp"
	var myConn = new XHConn()
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.")

	var fnWhenDone = function (oXML) {
		//alert(oXML.responseText)
		//alert(oXML.responseXML.xml)
		response = oXML.responseXML.documentElement
		if(response.getElementsByTagName("buildhtml")[0].firstChild!=null)
			{var thisHTML = response.getElementsByTagName("buildhtml")[0].firstChild.data}
			document.getElementById(divId).innerHTML = thisHTML
		}
	var postString="table=" + thisTable + "&divid=" + divId + "&id=" + memberId + "&sortfield=" + sortField + "&sortorder=" + sortOrder + "&filter=" + myFilter + "&type=" + thisType
	myConn.connect(url, "POST",postString, fnWhenDone)
}

function confirmChoice() {

	var thisUpdate = confirm("Are you sure?")
	return thisUpdate
}


function decodeHex(mytext) {
	var temp=""
	for (i=0; i<mytext.length;i+=2){
	nvv=mytext.charAt(i) + mytext.charAt(i+1);
	dec="%"+nvv;
	temp+=unescape(dec);
	}
	return temp;
	}

function limitText(limitField, limitCount, limitNum) {
	if (document.getElementById(limitField).value.length > limitNum) {
			document.getElementById(limitField).value = document.getElementById(limitField).value.substring(0, limitNum);
	} else {
		document.getElementById(limitCount).value = limitNum - document.getElementById(limitField).value.length;
	}
}

function checkUsername(thisAction,thisType){
	//ajax request to check if username is already registered, and return suggestion?
	thisImg="Checking...&nbsp;&nbsp;<img style='vertical-align:top;' src='skins/comparisonplus/images/images-icons/indicator.gif' border='0'/>"
	document.getElementById("UsernameStatus").innerHTML = thisImg
	document.getElementById("UsernameStatus").style.display=''
	var thisUsername=document.getElementById("Username").value
	var url=parent.location.protocol + "//" + document.domain + "/remote/rem_check_username.asp"
	var myConn = new XHConn()
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.")

	var fnWhenDone = function (oXML) {
		//alert(oXML.responseText)
		response = oXML.responseXML.documentElement
		if(response.getElementsByTagName("message")[0].firstChild!=null)
		{var thisMessage = response.getElementsByTagName("message")[0].firstChild.data}
		document.getElementById("UsernameStatus").innerHTML = thisMessage
		document.getElementById("UsernameStatus").style.display=''
		}
	myConn.connect(url, "POST","type=" + thisType + "&username=" + escape(thisUsername) + "&action=" + thisAction,fnWhenDone)
}

function showMore(textDiv,showDiv) {
	showhide_div(showDiv)
	if(document.all) {
		 if(document.getElementById(textDiv).innerText=="Less..."){
			 document.getElementById(textDiv).innerText="More..."
		 }
		 else {
			 document.getElementById(textDiv).innerText ="Less..."
		 }
	 }
	else {
		if(document.getElementById(textDiv).textContent=="Less..."){
			document.getElementById(textDiv).textContent = "More..."
		}
		else {
			document.getElementById(textDiv).textContent = "Less..."
		}
	}
}

function showMoreHideOriginal(hideDiv,showDiv) {
	showhide_div(hideDiv)
	showhide_div(showDiv)
}

function showhide_div(div_id){
	// show the requested div
	//var lastMenu = GetCookie(div_id);
	if(document.getElementById(div_id))
		{
		if (document.getElementById(div_id).style.display == '')
			{
			document.getElementById(div_id).style.display='none';
			//Effect.SlideUp(div_id)
			if(document.getElementById("img_"+div_id))
				{
				document.getElementById("img_"+div_id).innerHTML = "+ ";
				}
			SetCookie(div_id, 'none');
			}
		else
			{
			if (document.getElementById(div_id).style.display == 'none')
				{
				document.getElementById(div_id).style.display = ''
				//Effect.SlideDown(div_id)

				if(document.getElementById("img_"+div_id))
					{
					document.getElementById(div_id).style.display='';
					document.getElementById("img_"+div_id).innerHTML = "- ";
					}
				SetCookie(div_id, '');
			}
		}
	}
}

function showdiv(div_id){
	if(document.getElementById(div_id))
		{
		document.getElementById(div_id).style.display=""
		}
}

function hidediv(div_id){
	if(document.getElementById(div_id))
		{
		document.getElementById(div_id).style.display="none"
		}
}

function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++)
	  {
	  Char = sText.charAt(i);
	  if (ValidChars.indexOf(Char) == -1)
		 {
		 IsNumber = false;
		 }
	  }
   return IsNumber;
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;

  while (i < clen) {
    var j = i + alen;

   if (document.cookie.substring(i, j) == arg)
       return getCookieVal (j);

      i = document.cookie.indexOf(" ", i) + 1;

 if (i == 0) break;

}

return null;

}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();

}


function amt(){
  var count = GetCookie('count');

  if(count == null) {
    SetCookie('count','1');
    return 1;
} else {
   var newcount = parseInt(count) + 1;
   DeleteCookie('count');
   SetCookie('count',newcount,exp);
return count

}

}

function getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
     endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
  var count = GetCookie('count');
  if (count == null) {
    count=1;
    SetCookie('count', count, exp);
    window.open(page, "", windowprops);
  } else {
    count++;
    SetCookie('count', count, exp);
  }

}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function checkDate(strDate,strFormat){
    if(strDate.length>0){
    	var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;

        var match=strDate.match(dateregex);
        if (match){
        	switch (strFormat) {
				case 'MDY':
					var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
					if (tmpdate.getDate()==parseInt(match[2],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10)){
						return true;
					}
					break;
				case 'DMY':
					var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
					if (tmpdate.getDate()==parseInt(match[1],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[2],10)){
						return true;
					}
					break;
				default:
					return false;
			}
    	}
    	alert('no match on ' + strDate + '\n' + match[1]);
        return false;
    }
    else{
        return true;
    }
}

// replaces broken images with a placeholder
function replaceBrokenImage(thisID) {
	document.getElementById(thisID).src = 'global/no_image.gif'
	document.getElementById(thisID).alt = 'No image available';
}


<!--

//Generic Drag Script- © Dynamic Drive (www.dynamicdrive.com)
//For full source code and terms of usage,
//visit http://www.dynamicdrive.com

var ie=document.all
var ns6=document.getElementById&&!document.all

var dragapproved=false
var z,x,y

function move(e){
	if (dragapproved){
	z.style.left=ns6? temp1+e.clientX-x: temp1+event.clientX-x
	z.style.top=ns6? temp2+e.clientY-y : temp2+event.clientY-y
	return false
	}
}

function drags(e){
	if (!ie&&!ns6)
	return
	var firedobj=ns6? e.target : event.srcElement
	var topelement=ns6? "HTML" : "HTML"

	while (firedobj.tagName!=topelement&&firedobj.className!="drag"){
	firedobj=ns6? firedobj.parentNode : firedobj.parentElement
	}

	if (firedobj.className=="drag"){
		dragapproved=true
		z=firedobj
		temp1=parseInt(z.style.left+0)
		temp2=parseInt(z.style.top+0)
		x=ns6? e.clientX: event.clientX
		y=ns6? e.clientY: event.clientY
		document.onmousemove=move
		return false
	}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")
//-->

