/* Copyright 2009 Netrise LLC */

var _responseTimeoutMilis = 300000;
var _et_handshake = '';
var _et_gsid = '';



// start ajax
Ajax.Responders.register({
	onCreate: function(request) {
		request['timeoutId'] = window.setTimeout(
			function() {
			// If we have hit the timeout and the AJAX request is active, abort it and let the user know
			if (callInProgress(request.transport)) {
				request.transport.abort();
				showTimeoutMessage(request);
			}
			},_responseTimeoutMilis // 120 seconds
		);
	},
	onLoading: function(request) {
		showProgressIndicator(request);
	},
	onFailure: function(request) {
		showFailureMessage(request);
	},
	onComplete: function(request) {
		window.clearTimeout(request['timeoutId']);
	},
	onSuccess: function(request) {
		window.clearTimeout(request['timeoutId']);
	}	
});

function et_showTransactionSuccess(msg,time) {
 var msgtime = _success_msg_time;
 if (time != null) {
   msgtime = time;
 }
  var obj = $('transaction_success_div');
	  var x = getScrollPosX() + 200;
      var y = getScrollPosY() + 150;
      var xpos = x +'px';
	   	var ypos = y +'px';
	  	obj.style.top = ypos;
	  	obj.style.left = xpos;
	  	obj.innerHTML = msg;
	  	obj.style.visibility = 'visible';
	  	obj.style.display = 'block';
	  	setTimeout(	function() {
			makeInvisible('transaction_success_div')
			},msgtime
		);  	
}

// ascii decimal 32-126 space-~
function et_replaceSpecialChars(str) {
	var mystr = new String(str);
	/*	*/
	var re;
	re = /\"/g;
	mystr=mystr.replace(re,"&quot;");
	re = /\'/g;
	mystr = mystr.replace(re,"&#039;");
	re = new RegExp("[^\x20-\x7E]","g");  
	mystr = mystr.replace(re," ");
	return mystr;
}



function cleanUpTextString(str) {
  var nstr = str.trim();
  if (nstr.length == 0) {
    return '';
  }
  var rstr = et_replaceSpecialChars(nstr);
  var stripped = rstr.stripScripts();
  return stripped;  
}

// handles 200, 404, etc
function callInProgress (xmlhttp) {
	switch (xmlhttp.readyState) {
		case 1: case 2: case 3:
		return true;
		break;
		// Case 4 and 0
		default:
		return false;
		break;
	}
}


// functions that deal with the ajax request.
// handles timeouts and errors
function showProgressIndicator(request) {
  var divid = request['divid'];
  if (divid != null) {
    if ( request.transport.readyState != 4) {
      showProgress(divid);
    }
  } 
}
function showProgress(divid) {
    var divobj  = $(divid);
    var pstr = '<img src="images/mozilla_blu.gif"><span class="progressIndicator">  Loading results...</span>';
   	divobj.innerHTML = pstr;
   	divobj.style.display = 'block'; 
   	divobj.style.visibility = 'visible';
}


function showTimeoutMessage(request) {
  var divid = request['divid'];
  var msg = 'A problem occurred with communicating with the server. Please try again.';
  //var fid = 'error_msg_anchor';
  var fid = '';
  handleAjaxErrorMessage(msg,fid);
  hideAjaxLoading();
  if (divid != null) {
	var divobj  = $(divid);
	divobj.innerHTML = '';
  }
}

function showFailureMessage(request) {
  var divid = request['divid'];
  var msg = 'A problem occurred with the request.  <br /> Error: ' + request.status + ' -- ' + request.statusText + '<br /> Please try again.';
  var fid = '';
  handleAjaxErrorMessage(msg,fid);
  hideAjaxLoading();
  if (divid != null) {
	var divobj  = $(divid);
	divobj.innerHTML = '';
  }
}

function buildNetriseResponseObjXml(xmlstring) {
  var errdata = '';
  var msgdata = '';
  var txiddata = '';
  var divdata = '';
  var pluckdata = '';
  var qsdata = '';
  var serverproblem = false;
  var robj = new Object();  
  var endstr = '';
  var slen = xmlstring.length;
  if (slen > 20) {
    endstr = xmlstring.substring(slen-21,slen);
    //console.log(endstr);
  }
  if (endstr != '</NetriseWebResponse>') {
   serverproblem = true;
  }
  if (serverproblem) {
    robj['ErrorCode'] = '999';
  	robj['Message'] = xmlstring;
  	robj['Tranx_ID'] = '';
  	robj['Division_ID'] = '';
  	return robj;
  }
  if (window.ActiveXObject)  {
    var xmlobject=new ActiveXObject("Microsoft.XMLDOM");
    xmlobject.async="false";
    xmlobject.loadXML(xmlstring);
  } else {
   var parser=new DOMParser();
   var xmlobject=parser.parseFromString(xmlstring,"application/xml");
  }
  
  var root = xmlobject.getElementsByTagName('NetriseWebResponse')[0];
  try {
  var errnode = root.getElementsByTagName('ErrorCode');
  if (errnode[0].hasChildNodes()) {
	  errdata = errnode[0].firstChild.nodeValue; 
	}
	
	var msgnode = root.getElementsByTagName('Message');
	if (msgnode[0].hasChildNodes()) {
	  msgdata = msgnode[0].firstChild.nodeValue;
  } 
	
	var txidnode = root.getElementsByTagName('Tranx_ID');
	if (txidnode[0].hasChildNodes()) {
	 txiddata = txidnode[0].firstChild.nodeValue;
	}
	
	var divnode = root.getElementsByTagName('Division_ID');
	if (divnode[0].hasChildNodes()) {
	  divdata = divnode[0].firstChild.nodeValue;
	}
   
	var viewnode = root.getElementsByTagName('Views');
	if (viewnode[0].hasChildNodes()) {
	  var gdviewnodes = viewnode[0].getElementsByTagName('NetriseView');
	  for (i=0;i<gdviewnodes.length;i++) {
	   var viewdata = gdviewnodes[i].firstChild.nodeValue;
	   var viewtype = gdviewnodes[i].getAttribute("id");
	   robj[viewtype] = viewdata; //.stripScripts();
	  }
	}
	
  } catch (e) {
   showInDebugArea('bogus xml from server ' + xmlstring);
   errdata = '2';
   msgdata = 'bogus xml';
  }	
  robj['ErrorCode'] = errdata;
  robj['Message'] = msgdata;
  robj['Tranx_ID'] = txiddata;
  robj['Division_ID'] = divdata;
  return robj;
}

function createNetriseObjectFromJSON(jsonstr) {
	 var obj = null;
	 try {
	 	 obj = jsonstr.evalJSON(true); //1.5.1 
	 //  obj = jsonstr.parseJSON(); // 1.5.0
	 } catch (e) {
	 	 obj = null;
	 	 showInDebugArea(jsonstr);
	 }
	 return obj;
}
function masterLookupErrorHandler(crobj,element) {
  hideAjaxLoading();
  var errorcode = crobj['ErrorCode'];
  var msg = crobj['Message'];
  if (errorcode == '3') {
     //showAjaxLogon();
     handleAjaxErrorMessage(msg,element,errorcode);
     return true;
  } else if (errorcode == '2') {
     handleAjaxErrorMessage(msg,element,errorcode);
     return true;
  } else if (errorcode == '1') {
     handleAjaxErrorMessage(msg,element,errorcode);
     return true;
  } else if (errorcode == '99') {
     handleAjaxErrorMessage(msg,element,errorcode);
     setTimeout(function(){handleUserLogsOff()},3000);
     return true;
  } else if (errorcode == '999') {
     alert('Problem with your request.\nPlease try again.\n' + msg);
     return true;
  }
  return false;
}
function handleErrorMessage(msg,fid) {
    var closestr = '<a href="javascript:window.parent.closeErrorMsg(\'' + fid + '\')">';
    closestr += '<img src="ajaxtheme/validate_closex.gif" border="0"></a>';
    var str = '<html><body background="ajaxtheme/val_background.gif" MARGINWIDTH="0" MARGINHEIGHT=0">';
    str += '<table width="100%"><tr>';
    str += '<td width="15%">&nbsp;</td>';
    str += '<td align="center">';
    str += '<span ';
    str += 'style="font-family: verdana; font-size: 8pt; font-weight: bold;';
    str += '">';
    str += 'Validation';
    str += '</span>';
     str += '</td><td width="15%" align="center">';
    str += closestr;
    str += '</td>';
    str += '</tr>';
    str += '<tr><td colspan="3">';
    str += '<div style="';
    str += 'margin-left:8px;margin-right:8px;';
    str += 'text-align:center;font-family: verdana; font-size: 8pt; font-weight: normal;';
    str += 'background-color: #F0F0F0;';
    str += 'padding:5px;';
    str += 'border:1px solid black;';
    str += '">';
    str += msg;
    str += '</div></td></tr></table>';
    str += '</body></html>';
    var iframeWin = window.frames.error_Iframe;
  	iframeWin.document.open();
  	iframeWin.document.write(str);
  	iframeWin.document.close();
    var msgobj = $('error_msg_area_iframe');
    var x = 10;
	var y = 10;
	if (fid.length>0) {
	 var posobj = getAdjustedLinkPositionAry(fid);
      x = posobj[0];
      y = posobj[1];
      if (y<0) y= 10 + getScrollPosY();  // added this on 08/11/08 to fix "please indentify who you are problem if the scroll down
	//  x = getRealLeft(fid);
	//  y = getRealTop(fid);
	}
	var xpos = x +'px';
	var ypos = y +'px';
	msgobj.style.top = ypos;
	msgobj.style.left = xpos;
	msgobj.style.visibility = 'visible';
	msgobj.style.display = 'block';
 }
 function handleErrorMessageOffset(msg,fid,xoff,yoff) {
    var closestr = '<a href="javascript:window.parent.closeErrorMsg(\'' + fid + '\')">';
    closestr += '<img src="ajaxtheme/validate_closex.gif" border="0"></a>';
    var str = '<html><body background="ajaxtheme/val_background.gif" MARGINWIDTH="0" MARGINHEIGHT=0">';
    str += '<table width="100%"><tr>';
    str += '<td width="15%">&nbsp;</td>';
    str += '<td align="center">';
    str += '<span ';
    str += 'style="font-family: verdana; font-size: 8pt; font-weight: bold;';
    str += '">';
    str += 'Validation';
    str += '</span>';
     str += '</td><td width="15%" align="center">';
    str += closestr;
    str += '</td>';
    str += '</tr>';
    str += '<tr><td colspan="3">';
    str += '<div style="';
    str += 'margin-left:8px;margin-right:8px;';
    str += 'text-align:center;font-family: verdana; font-size: 8pt; font-weight: normal;';
    str += 'background-color: #F0F0F0;';
    str += 'padding:5px;';
    str += 'border:1px solid black;';
    str += '">';
    str += msg;
    str += '</div></td></tr></table>';
    str += '</body></html>';
    var iframeWin = window.frames.error_Iframe;
  	iframeWin.document.open();
  	iframeWin.document.write(str);
  	iframeWin.document.close();
    var msgobj = $('error_msg_area_iframe');
    var x = 10;
	var y = 10;
	if (fid.length>0) {
	 var posobj = getAdjustedLinkPositionAry(fid);
      x = posobj[0];
      y = posobj[1];
      if (y<0) y= 10 + getScrollPosY();  // added this on 08/11/08 to fix "please indentify who you are problem if the scroll down
	//  x = getRealLeft(fid);
	//  y = getRealTop(fid);
	}
	var xpos = (x+xoff) +'px';
	var ypos = (y+yoff) +'px';
	msgobj.style.top = ypos;
	msgobj.style.left = xpos;
	msgobj.style.visibility = 'visible';
	msgobj.style.display = 'block';
 }
 
 function handleErrorMessagePosition(msg,fid,x,y) {
    var closestr = '<a href="javascript:window.parent.closeErrorMsg(\'' + fid + '\')">';
    closestr += '<img src="ajaxtheme/validate_closex.gif" border="0"></a>';
    var str = '<html><body background="ajaxtheme/val_background.gif" MARGINWIDTH="0" MARGINHEIGHT=0">';
    str += '<table width="100%" border=0><tr><td width="15%">&nbsp;</td><td align="center">';
    str += '<span style="font-family: verdana; font-size: 8pt; font-weight: bold;';
    str += '">';
    str += 'Validation';
    str += '</span></td><td align="center">';
    str += closestr;
    str += '</td></tr><tr><td colspan="3">';
    str += '<div style="';
    str += 'margin-left:8px;margin-right:8px;';
    str += 'text-align:center;font-family: verdana; font-size: 8pt; font-weight: normal;';
    str += 'background-color: #F0F0F0;';
    str += 'padding:5px;';
    str += 'border:1px solid black;';
    str += '">';
    str += msg;
    str += '</div></td></tr></table>';
    str += '</body></html>';
    var iframeWin = window.frames.error_Iframe;
  	iframeWin.document.open();
  	iframeWin.document.write(str);
  	iframeWin.document.close();
    var msgobj = $('error_msg_area_iframe');
    var xpos = x +'px';
	  var ypos = y +'px';
	  msgobj.style.top = ypos;
	  msgobj.style.left = xpos;
	  msgobj.style.visibility = 'visible';
	  msgobj.style.display = 'block';
 }
 
function closeAjaxErrorMsg() {
 makeInvisible('error_msg_area_iframe');

}
function makeInvisible(divid) {
	var obj = $(divid);
	if (obj != null) {
	  obj.style.visibility = 'hidden';
	  obj.style.display = 'none';
	}
}
function makeVisible(divid) {
	var obj = $(divid);
	if (obj != null) {
	  obj.style.display = 'block';
	  obj.style.visibility = 'visible';
	}
}
function handleAjaxErrorMessage(msg,fid,errorcode) {
    var closestr = '<a href="javascript:parent.closeAjaxErrorMsg()">';
    closestr += '<img src="ajaxtheme/validate_closex.gif" border="0"></a>';
    var bgimage = 'val_background.gif';
    var title = 'Problem';
    if (errorcode == '2') {
      bgimage = 'val_background_red.gif';
      title = 'Request Error';
    } else if (errorcode == '9') {
			 bgimage = 'val_background_red.gif';
       title = 'Corrupt Data';
       msg = 'Please contact the site administrator';
		} 
    var str = '<html>';
    str += '<body background="ajaxtheme/' + bgimage + '" MARGINWIDTH="0" MARGINHEIGHT=0">';
    str += '<table width="100%" border=0><tr><td width="15%">&nbsp;</td><td align="center">';
    str += '<span style="font-family: verdana; font-size: 8pt; font-weight: bold; color:#000000;';
    str += '">' + title ;
    str += '</span></td><td align="center" width="15%">';
    str += closestr;
    str += '</td></tr><tr><td colspan="3">';
    str += '<div style="';
    str += 'margin-left:8px;margin-right:8px;';
    str += 'text-align:center;font-family: verdana; font-size: 8pt; font-weight: normal;';
    str += 'background-color: #F0F0F0;';
    str += 'padding:5px;';
    str += 'border:1px solid black;';
    str += '">';
    str += msg;
    str += '</div></td></tr></table>';
    str += '</body></html>';
    var iframeWin = window.frames.error_Iframe;
  	iframeWin.document.open();
  	iframeWin.document.write(str);
  	iframeWin.document.close();
    var msgobj = $('error_msg_area_iframe');
    var x = 0;
	  var y = 0;
	  if (fid.length>0) {
	     if (fid == '*') {
	       x=0;
	       y=0;
	     } else {
	      var posobj = getAdjustedLinkPositionAry(fid);
          x = posobj[0];
          y = posobj[1];
        //  x = getRealLeft(fid);
	    //  y = getRealTop(fid);
	     }
	  } else {
	    x = getScrollPosX() + 400;
        y = getScrollPosY() + 100;
	  }
	  var xpos = x +'px';
	  var ypos = y +'px';
	  msgobj.style.top = ypos;
	  msgobj.style.left = xpos;
	  msgobj.style.visibility = 'visible';
	  msgobj.style.display = 'block';
  }


function showAjaxLoading(areaid,request) {
//alert("here showAjaxLoading");  // ie fix.  don't put the spinner up if the call is complete. 
// this is becuase crazy ie calls the onLoading method after the onComplete is run when selecting a url the SECOND time.  some sort of caching thing.
    if (request.transport.readyState != 4){
   // alert("here showAjaxLoading 4");
	  	var obj = $('loading_ajax_msg');
	  	var x = 10;
	    var y = 10;
	    if (areaid.length>0) {
	     var posobj = getAdjustedLinkPositionAry(areaid);
          x = posobj[0];
          y = posobj[1];
	     // x = getRealLeft(areaid);
	     // y = getRealTop(areaid);
	    }
	  	var xpos = x +'px';
	   	var ypos = y +'px';
	  	obj.style.top = ypos;
	  	obj.style.left = xpos;
	  	obj.style.visibility = 'visible';
	  	obj.style.display = 'block';
  	 }
  }
  
function hideAjaxLoading() {
	var obj = $('loading_ajax_msg');
	 obj.style.visibility = 'hidden';
	 obj.style.display = 'none';
}

 
function closeErrorMsg(objid) {
 var obj = $('error_msg_area_iframe');
 obj.style.visibility = 'hidden';
 obj.style.display = 'none';
 if (objid != '') {
  var fobj = $(objid);
  Field.activate(objid);
 }
} 
function getScrollPosX() {
  var deltaX =  window.pageXOffset
                || document.documentElement.scrollLeft
                || document.body.scrollLeft
                || 0;
    return deltaX;
}
function getScrollPosY() {
  var deltaY =  window.pageYOffset
                || document.documentElement.scrollTop
                || document.body.scrollTop
                || 0;
  return deltaY;
}
function getRealLeft(el){
    xPos = document.getElementById(el).offsetLeft;
    tempEl = document.getElementById(el).offsetParent;
    while (tempEl != null) {
    xPos += tempEl.offsetLeft;
    tempEl = tempEl.offsetParent;
    }
    return xPos;
 }

 function getRealTop(el){
    yPos = document.getElementById(el).offsetTop;
    tempEl = document.getElementById(el).offsetParent;
    while (tempEl != null) {
    yPos += tempEl.offsetTop;
    tempEl = tempEl.offsetParent;
    }
    return yPos;
}
function getAdjustedLinkPositionAry(elid) {
 var elidobj = $(elid);
 if (elidobj == null) {
   var posobj = new Array();
   posobj.push(140);
   posobj.push(100);
   return posobj;
 }
 var posobj = Element.cumulativeOffset(elidobj);
 //posobj[1] = posobj[1] - getScrollPosY();
 return posobj;
}
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 isValidZipCode(sText){
  if (sText.length != 5) {
   return false;
  }
  var intRe =/\d{5}/;
  return  intRe.test(sText);
}

function isValidCreditCardCode(sText){
  if (sText.length != 3) {
   return false;
  }
  var intRe =/\d{3}/;
  return  intRe.test(sText);
}

// string functions
function StringBuffer() {
   this.buffer = [];
 }

 StringBuffer.prototype.append = function append(string) {
   this.buffer.push(string);
   return this;
 };

 StringBuffer.prototype.toString = function toString() {
   return this.buffer.join("");
 };
 
function LTrim( str ) {
	var re = /\s*((\S+\s*)*)/;
	return str.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( str ) {
	var re = /((\s*\S+)*)\s*/;
	return str.replace(re, "$1");
}

// Removes leading and ending whitespaces
function LRTrim( str ) {
	str = this != window ? this : str;	
	return LTrim(RTrim(str));
}

String.prototype.trim = LRTrim;


function isValidPhoneNumberFormat(ph) {
  if (ph.trim().length == 0) {
    return true;
  }
  if (ph.trim().length != 12) { 
    return false;
  }
  var phoneRe =/\d{3}-\d{3}-\d{4}/;
  return  phoneRe.test(ph);
}


function isValidEmailFormat(addr) {
    var rstr = '';
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
	      rstr = 'email address contains invalid characters';
	      return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
	      rstr = 'email address contains non ascii characters.';
	      return false;
	   }
	}	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   rstr = 'email address must contain an @';
	   return false;
	}
	if (atPos == 0) {
	   rstr = 'email address must not start with @';
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   rstr = 'email address must contain only one @';
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   rstr = 'email address must contain a period in the domain name';
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   rstr = 'period must not immediately follow @ in email address';
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   return 'period must not immediately precede @ in email address';
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   rstr = 'two periods must not be adjacent in email address';
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length<2) {
	  return false;
	 }
	// if (stringContainsNumericChar(suffix)) {
	//  return false;
	// }
  return true;
}

function stringContainsNumericChar(pw) {
  var hasnRe =/\d/;
  var hasnumber = hasnRe.test(pw);
  return hasnumber;
}

// cookie handling 

/**
 * Provides a simple interface for creating, retrieving and clearing cookies.
 */

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
 //    alert('cur group ' + _currentGroupName);
     name = name + _currentGroupName;
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    name = name + _currentGroupName;
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    name = name + _currentGroupName;
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};



// for responses that only look for errors.  when json obj is not needed
function simpleAjaxRequestContainsError(ajaxRequest,button) {
  var results = ajaxRequest.responseText;
  var crobj =  buildNetriseResponseObjXml(results);
	 if (masterLookupErrorHandler(crobj,button)) {
	    return true;
	 }
	 var jsonstr = crobj['JSON'];
	 var jsonobj = createETObjectFromJSON(jsonstr);
	 if (jsonobj == null) {
	 	  handleAjaxErrorMessage('',button,'9');
		  return true;
	 }
  return false;
 }
 
 // **********************
// UTILITIES
// **********************
function formatCurrency(num,showdollar) {
  var dolsign = '';
  if (showdollar) dolsign = '$';
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) {
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	return (((sign)?'':'-') + dolsign + num + '.' + cents);
}

  // library utilities
function makeInvisibleFade(divid) {
	var dd = new Effect.Fade(divid);
}


function makeVisibleEffect(divid,which) {
  if (which == 'APPEAR') {
    var dd = new Effect.Appear(divid);
  }
  if (which == 'BLIND') {
    var dd = new Effect.BlindDown(divid);
  }
  if (which == 'SLIDE') {
    var dd = new Effect.SlideDown(divid);
  }
  if (which == 'GROW') {
    var dd = new Effect.Grow(divid);
  }
}
function clearSelectList(id) {
    var sobj = $(id);
 	 while (sobj.options.length) {
 	     sobj.options[0] = null;
  	}
}
function loadSelectOptionsFromArrays(selectid,nameary,valary) {
  clearSelectList(selectid);
 	var sobj  = $(selectid);
 	for (var i = 0; i < nameary.length; i++) {
 	    var val = valary[i];
 	    var name = nameary[i];
 	    sobj.options[i] = new Option(name,val);
 	}
 }
 function showInDebugArea(str) {
     $('debugarea').innerHTML = str;
 }

