/* Functions */
function sdfetch_object(idname)
{
		if(navigator.userAgent.indexOf("Firefox") != -1){		//only do this if firefox
			return document.all[idname];
		}

		if (document.getElementById)
        {
                return document.getElementById(idname);
        }
        else if (document.all)
        {
                return document.all[idname];
        }
        else if (document.layers)
        {
                return document.layers[idname];
        }
        else
        {
                return null;
        }
}

function makeRequestSend( my_httpRequest, url, parameters, alertFunction ) {
	if(	my_httpRequest != null ){
		delete( my_httpRequest );
	}

	if (window.XMLHttpRequest) { 			// Mozilla, Safari, ...
		my_httpRequest = new XMLHttpRequest();

		if (my_httpRequest.overrideMimeType) {
			my_httpRequest.overrideMimeType('text/xml');
		}

	}  else if (window.ActiveXObject) { 		// IE
		try {
			my_httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				my_httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}

	if (!my_httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	var date = new Date();
	if( parameters == null ){
		url_with_time = url + "?time=" + date.getTime();
	} else { 
		url_with_time = url + parameters + "&time=" + date.getTime();
	}

	my_httpRequest.onreadystatechange = function() { alertFunction(my_httpRequest); };

//THIS IS THE GET METHOD
	my_httpRequest.open('GET', url_with_time, true);
	my_httpRequest.send(null);
	
// THIS IS THE POST METHOD	
//	my_httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//	my_httpRequest.setRequestHeader("Content-length", parameters.length);
//	my_httpRequest.setRequestHeader("Connection", "close");
//	my_httpRequest.open('OST', url_with_time, true);
//	my_httpRequest.send(parameters);


}


function doMessages( httpRequest ){
	if (httpRequest.readyState == 4) { 
		if (httpRequest.status == 200) { 
			var xmldoc = httpRequest.responseXML;							// get the XML doc
			var root_node = xmldoc.getElementsByTagName('Message');			// get the tags named "Message"
			var num_items = root_node.length;								// set the number of items in the root_node

			for( var i=0; i<num_items; i++ ){
				messageText = root_node[i].getElementsByTagName("messageText")[0].firstChild.nodeValue;
				alert( messageText )
			}
			
			root_node = xmldoc.getElementsByTagName('ReturnVal');
			num_items = root_node.length;
			if( num_items > 0 ){
				var retVal = root_node[0].getElementsByTagName("val")[0].firstChild.nodeValue;
				return retVal;
			} else {
				return 0;
			}
			
		} else { 
			alert('There was a problem with the request.'); 
			return 0;
		}
	}
	return 0;
}


function toggleDiv(id, state) 
{ 
	var objStyle = sdfetch_object(id);
	var headerid = id.replace("deal_","deal_header_");
	var objHeader = sdfetch_object(headerid);
	var headerExp = " deal_header_expand";
	
	switch(state)
	{
		case 'c':
			objStyle.style.display = "none";
			objHeader.className = objHeader.className.replace(headerExp,"");
			break;
		case 'e':
			objStyle.style.display = "block";
			if (!objHeader.className.match(headerExp))
				objHeader.className = objHeader.className + headerExp;
			break;
		default:
			if (objStyle.style.display=="block")
			{
				objStyle.style.display = "none";
				objHeader.className = objHeader.className.replace(headerExp,"");
			} else {
				objStyle.style.display = "block";
				if (!objHeader.className.match(headerExp))
					objHeader.className = objHeader.className + headerExp;
			}
			break;
	}
} 

function hideAllDivs( id ){
	var divs = document.getElementsByTagName('div'); 
	for(i=0; i < divs.length; i++){ 
//		if( divs[i].id != id )
			divs[i].style.display = "none";
	}
}

function populateDropdownFromAJAX( dropdownName, httpRequest ){
	var myDrp = sdfetch_object( dropdownName );
	if( myDrp != null ){
		if (httpRequest.readyState == 4) { 
			if (httpRequest.status == 200) {
				var length = myDrp.options.length;
				while( length > 0 ){
					myDrp.remove(0);
					length = myDrp.options.length;
				}

				var xmldoc = httpRequest.responseXML;							// get the XML doc
				var root_node = xmldoc.getElementsByTagName('option');			// get the tags named "option"
				var num_items = root_node.length;								// set the number of items in the root_node
				for( var i=0; i<num_items; i++ ){
					value = root_node[i].getElementsByTagName("value")[0].firstChild.nodeValue;
					string = root_node[i].getElementsByTagName("text")[0].firstChild.nodeValue;
					addOption(myDrp, string, value);
				}
			}
		}

	} else {
		alert( dropdownName + ' is an invalid dropdown name.\nCannot populate dropdown list.' );
	}
}


function addOption(selectbox,text,value ){
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}


function CheckKeyCode(){	//only allows numbers, backspaces, deletes, lefts, rights and tabs
	if( (event.keyCode == 189 || event.keyCode == 109) ||
	(event.keyCode >= 48 && event.keyCode <= 57) || 
	(event.keyCode >= 96 && event.keyCode <= 105) ||
	(event.keyCode == 8) || (event.keyCode == 46) ||
	(event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9) ) {
		return true; }
	else {
		return false;
	}
}

function childClosed(){
	window.location.reload();
}

function validateUserName(fieldname) {
	var errorMsg = "";
	var space  = " ";
	fieldname   = document.thisForm.userName; 
	fieldvalue  = fieldname.value; 
	fieldlength = fieldvalue.length; 

	//It must not contain a space
	if (fieldvalue.indexOf(space) > -1) {
		errorMsg += "\nUsername cannot include a space.\n";
	}     

	//It must start with at least one letter     
	if (!(fieldvalue.match(/^[a-zA-Z]+/))) {
		errorMsg += "\nUsername must start with at least one letter.\n";
	}

	//It must contain at least one special character
	if (fieldvalue.indexOf(/\W+/) > -1) {
		errorMsg += "\nUsername may not include any special characters - #,@,%,!\n";
	}

	//It must be at least 7 characters long.
	if (!(fieldlength >= 7)) {
		 errorMsg += "\Username must be at least 7 characters long.\n";
	}

	//If there is aproblem with the form then display an error
     if (errorMsg != ""){
		errorMsg += alert(errorMsg + "\n");
			return false;
     }

	return true;
}

function validatePwd(fieldname) {
	var errorMsg = "";
	var space  = " ";
	fieldname   = document.thisForm.password1; 
	fieldvalue  = fieldname.value; 
	fieldlength = fieldvalue.length; 
	 
	//It must not contain a space
	if (fieldvalue.indexOf(space) > -1) {
		 errorMsg += "\nPassword cannot include a space.\n";
	}     
	 
	//It must contain at least one number character
	if (!(fieldvalue.match(/\d/))) {
		 errorMsg += "\nPassword must include at least one number.\n";
	}
	//It must start with at least one letter     
	if (!(fieldvalue.match(/^[a-zA-Z]+/))) {
		 errorMsg += "\nPassword must start with at least one letter.\n";
	}
	//It must contain at least one upper case character     
//	if (!(fieldvalue.match(/[A-Z]/))) {
//		 errorMsg += "\nStrong passwords must include at least one uppercase letter.\n";
//	}
	//It must contain at least one lower case character
//	if (!(fieldvalue.match(/[a-z]/))) {
//		 errorMsg += "\nPassword must include one or more lowercase letters.\n";
//	}
	//It must contain at least one special character
//	if (!(fieldvalue.match(/\W+/))) {
//		 errorMsg += "\nPassword must include at least one special character - #,@,%,!\n";
//	}
	//It must be at least 7 characters long.
	if (!(fieldlength >= 7)) {
		 errorMsg += "\nPassword must be at least 7 characters long.\n";
	}
	//If there is aproblem with the form then display an error
     if (errorMsg != ""){
//          msg = "______________________________________________________\n\n";
//          msg += "Please correct the problem(s) with your trial password test it again.\n";
//          msg += "______________________________________________________\n";
//          errorMsg += alert(msg + errorMsg + "\n\n");
		errorMsg += alert(errorMsg + "\n");
//			fieldname.focus();
          return false;
     }
     
     return true;
}


function isTime(txtfld)
{
 var RE10 = /([1-9]|1[0-2]):[0-5]\d$/;
 var RE11 = /([1-9]|1[0-2]):[0-5]\d\spm/;
 var RE12 = /([1-9]|1[0-2]):[0-5]\d\sam/;
 var RE13 = /([1-9]|1[0-2]):[0-5]\dpm/;
 var RE14 = /([1-9]|1[0-2]):[0-5]\dam/;
 var RE15 = /([1-9]|1[0-2]):[0-5]\d\sPM/;
 var RE16 = /([1-9]|1[0-2]):[0-5]\d\sAM/;
 var RE17 = /([1-9]|1[0-2]):[0-5]\dPM/;
 var RE18 = /([1-9]|1[0-2]):[0-5]\dAM/;
 var str=txtfld;

 for (var i = 10; i <= 18; i++) {
  var index=str.search(eval("RE" + i));
  if (index != -1){ // string found
   return true;
  }
   }
 
 alert("Time is not in proper format.  Proper format is 'hh:mm am/pm').");
 
 return(false);
}

var reAlphanumeric = /^[a-zA-Z0-9]+$/
function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    else {
       return reAlphanumeric.test(s)
    }
}
function isChecked(object) {
	if (object.checked) {
		return true;
	}
	else {
		return false;
	}
}


// checks to see if the string is a digit (accepts decimals)
function isNumber( str ){
	foundDot = false;
	for( var i=0; i < str.length; i++ ){
		var ch = str.substring(i, i + 1);
		if( ch < "0" || "9" < ch ){
			if( ch == "." ){
				if( foundDot ){
					return false;
				} else {
					foundDot = true;
				}
			} else {
				return false;
			}
		}
	}
	return true;
}

function isNumber2(txtfld, maxdigits, msg)
{
	var str=txtfld.value;
	for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("\nThe " + msg + " field only accepts digits.\n\r Please re-enter " + msg + ".");
			txtfld.select();
			txtfld.focus();
			return(false);
      }
   }
   if(str.length>maxdigits){
		alert("\nThe " + msg + " field shall have " + maxdigits + " digits only.\n\n Please re-enter " + msg + ".");
		txtfld.select();
		txtfld.focus();
		return(false);
   }
	return(true);
}

function detectBrowser() {
	var browser = navigator.appName;
	var version = parseInt(navigator.appVersion);
	return navigator.appName;
}

function isEmpty(txtFld,msg) {
	var str = txtFld.value;
	if (str == "" || str == "0" || str == " " || str == null) {
		if (msg != "") {	
			alert("\nPlease fill in " + msg + ".\n\nIt is required.")
			txtFld.focus();
		}
		return(true);
	}
	return(false);	
}	

function isEmpty2(txtFld,msg) {
	var str = txtFld.value;
	if (str == "" || str == " " || str == null) {
		if (msg != "") {	
			alert("\nPlease fill in " + msg + ".\n\nIt is required.")
			txtFld.focus();
		}
		return(true);
	}
	return(false);	
}	

function inRange(txtFld,f,t,msg) {
	var str = txtFld.value;
	if (isEmpty(txtFld, "")) return true;

	if ((str < f) || (str > t)) {
		if (msg != "") {	
			alert("\n" + msg + " is Invalid.\n\nPlease correct.")
			txtFld.focus();
			txtFld.select();
		}
		return(false);
	}
	return(true);	
}	
      
function isEmail(txtFld,msg) {
   var str   = txtFld.value;
	if (txtFld.value == "") {
		return(true);
	}

   if (txtFld.value.indexOf ('@',0) == -1 || 
       txtFld.value.indexOf ('.',0) == -1)
      {
      alert("\nThe " + msg + " address entered is not in a proper format. Please re-enter or leave blank." )
      txtFld.select();
      txtFld.focus();
      return(false);
      }
   else
      {
		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch)) && ch != '@' && ch !='.' && ch !='-' && ch!='_') 
				{
				alert("\nPlease use only letters, numbers and @.-_ for " + msg + ".");
				txtFld.select();
				txtFld.focus();
				return(false);
				}
		}	    
		if ( txtFld.value.length < 7 || 
			 txtFld.value.indexOf ('@',0) >= (txtFld.value.indexOf ('.',0) - 1) )
		   {
		   alert("\nThe " + msg + " address entered is not in a proper format. Please re-enter or leave blank." )
		   txtFld.select();
		   txtFld.focus();
		   return(false);
		   }
		return(true);
      }
}


function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 
		
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}



function isDecimal(txtFld,msg)  {
   var str = clean(txtFld.value);
   if (str == "") {
         alert("\nThe " + msg + " field is blank.\n\nPlease enter a decimal number.");
         txtFld.focus();
         return false;
   }
   for (var i = 0; i < str.length; i++) 
      {
      var ch = str.substring(i, i + 1);
      if ((ch < "0" || "9" < ch) && ch != '.') 
         {
         alert("\nThe " + msg + " field accepts only numbers and a decimal point. \n\nPlease re-enter a decimal number.");
         txtFld.select();
         txtFld.focus();
         return false;
         }
      }
   return true;
   }

function isPercent(txtFld,msg)  {
   var str = clean(txtFld.value);
   if (str == "") {
         alert("\nThe " + msg + " field is blank.\n\nPlease enter a percentage.");
         txtFld.focus();
         return false;
   }
   for (var i = 0; i < str.length; i++) 
      {
      var ch = str.substring(i, i + 1);
      if ((ch < "0" || "9" < ch) && ch != '.') 
         {
         alert("\nThe " + msg + " field only accepts percentage figures. \n\nPlease re-enter a percentage.");
         txtFld.select();
         txtFld.focus();
         return false;
         }
      }
   return true;
   }   

function isPhone(txtFld,msg) {
	var str=txtFld.value;
	var newstr="";
	var i;
	var ch;
 
	if (str == "") return true;
	
    for (var i = 0; i < str.length; i++) {
      ch = str.substring(i, i + 1);
      if ((ch < "0" || "9" < ch) && ch != '-' && ch != '(' && ch != ')' && ch != ' ') {
         alert("\nThe " + msg + " field accepts only numbers and the characters () or -. \n\nPlease re-enter a valid phone number.");
         txtFld.select();
         txtFld.focus();
         return false;
         }
      }

	for(i=0;i<str.length;i++){
		ch=str.substring(i,i+1);
		if(! (ch < "0" || ch > "9")) newstr=newstr + ch;
		}
	//if(newstr.length!=10){
	if(newstr.length<10){
         alert("\nThe " + msg + " field is invalid.\n\nPlease enter the number again.");
         txtFld.focus();
         return false;
		}
	//str = "("+newstr.substring(0,3)+") "+newstr.substring(3,6)+"-"+newstr.substring(6,10)
	txtFld.value = str;
	return true;
}

function isCreditCard(txtFld,msg) {
	var str = txtFld.value;
	if (str == "") {
         alert("\nThe " + msg + " field is blank.\n\nPlease enter the Credit Card Number.");
         txtFld.focus();
         return false;
    }
    for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i + 1);
		if (ch < "0" || "9" < ch) {
			alert("\nThe " + msg + " field accepts only digits. \n\nPlease re-enter the Credit Card Number.");
			txtFld.select();
			txtFld.focus();
			return false;
		}
    }
	if (str.length < 13 || str.length > 16) {
		alert("Credit card number must be a string of digits between 13 and 16 characters.  \n\nPlease re-enter the Credit Card Number.")
		txtFld.select();
		txtFld.focus();
		return false;
	}
	if (!isCreditCardValid(str)) {
		alert("Credit card number is Invalid.  \n\nPlease re-enter the Credit Card Number.")
		txtFld.select();
		txtFld.focus();
		return false;
	}
	return true;
}

function isCreditCardValid(st) {
  // Encoding only works on cards with less than 19 digits
  if ((st.length > 19) || (st.length < 13))
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0) 
	    return (true);
  else
		return (false);

}

function isExpMonth(monthFld,yearFld,msg) {
	if(monthFld.options[monthFld.selectedIndex].value=="" || yearFld.options[yearFld.selectedIndex].value=="") {
		alert("\nThe " + msg + " fields need to be entered");
		monthFld.focus();
		return (false);
	}
	var intMM = parseInt(monthFld.options[monthFld.selectedIndex].value);
	var intYYYY = parseInt(yearFld.options[yearFld.selectedIndex].value);
	var dtToday = new Date();
	if(intMM<1 || intMM > 12 || intYYYY < dtToday.getFullYear()) {
		alert("\nThe " + msg + " contains invalid date values.\n\nPlease re-enter the values.");
		monthFld.focus();
		return (false);
	}
	if(intYYYY==dtToday.getFullYear() && (intMM - 1) < dtToday.getMonth()) {
		alert("\nThe " + msg + " contains expired date values.\n\nPlease re-enter the values.");
		monthFld.focus();
		return (false);
	}
	return (true);
}

function isDate(txtFld, msg) {
	var str=txtFld.value
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
	var matchArray = str.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("The Date value in " + msg + " is not in a valid format.")
		txtFld.select();
		txtFld.focus();
		return false;
	}
	var month = matchArray[1]; 
	var day = matchArray[3];
	var year = matchArray[5];
	if (month < 1 || month > 12) { 
		alert("The Month in " + msg + " must be between 1 and 12.");
		txtFld.select();
		txtFld.focus();
		return false;
	}
	if (day < 1 || day > 31) {
		alert("The Day in " + msg + " must be between 1 and 31.");
		txtFld.select();
		txtFld.focus();
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		txtFld.select();
		txtFld.focus();
		return false
	}
	if (month == 2) { 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			txtFld.select();
			txtFld.focus();
			return false;
		}
	}
	return true;
}

function areDatesInOrder(fdate,sdate,fmsg,smsg){
	var fd = new Date(fdate.value);
	var sd = new Date(sdate.value);
	var d,m,y;
	var strf;
	var strs;
	d = fd.getDate();
	m = fd.getMonth();
	y = fd.getFullYear();
	strf = "" + y;
	if(m<10)strf=strf + "0" + m; else strf = strf + m;
	if(d<10)strf=strf + "0" + d; else strf = strf + d;

	d = sd.getDate();
	m = sd.getMonth();
	y = sd.getFullYear();
	strs = "" + y;
	if(m<10)strs=strs + "0" + m; else strs = strs + m;
	if(d<10)strs=strs + "0" + d; else strs = strs + d;
	if(strf > strs){
		alert(fmsg + " is later than " + smsg);
		fdate.select();
		fdate.focus();
		return(false);
	}
	return(true);
}

function isCurrency(txtfld,msg) {
	var strfld = clean(txtfld.value);
	var strlcl = "";
	var ch;
	var bdec = false;
	for (var i = 0; i < strfld.length; i++){
		ch = strfld.substring(i,i+1);
		if(ch>="0" && ch<="9"){ strlcl = strlcl + ch;}
		else if((ch=="." || ch==",") && bdec==false){
				strlcl=strlcl + ch;
				bdec==true;
			}
		else{
			alert(msg + " has invalid characters.  Please re-enter in the correct format.");
			txtfld.select();
			txtfld.focus();
			return(false);
		}
	}
	if(strlcl.indexOf(".")>=0 && strlcl.indexOf(".")<(strlcl.length-1)){
		var strdec = strlcl.substring(strlcl.indexOf(".")+1,strlcl.length);
		if(strdec.length>2){
			alert(msg + " can be up to two decimals only.");
			txtfld.select();
			txtfld.focus();
			return(false);
		}
	}
	return(true);	
}

function replace(s, F, R) {
	var find = 0;
	var start = 0
	while (find != -1) {
		find = s.indexOf(F, start);
		if (find != -1) {
			s = s.substring(0,find) + R + s.substring(find + F.length);
			start = find + R.length;
		}
	}
	return s;
}

function trim(s) {
	return s.replace(/(^\s*)|(\s*$)/g, "");
}

function clean(s) {
	if (!s) return s;
	s = replace(s, '$', '');
	s = replace(s, ',', '');
	s = replace(s, '%', '');	
	return s;
}

function checkempty(elem) {
	if ((elem.value == null) || (elem.value.length<2)) {
		alert('Please enter a value for this field.');
		elem.focus();
		return false;
	}
	return true;
}

function checkamt(elem, dec) {
	if ((elem.value == null) || (elem.value.length==0)) elem.value = 0
	value = parseFloat(clean(elem.value));
	if (isNaN(value)) {
		alert('You have entered an incorrect character in this field. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	elem.value = FmtMoney(value,dec)
	return true
}

function checkrate(elem) {
	if ((elem.value == null) || (elem.value.length==0)) elem.value = "0%";
	value = parseFloat(clean(elem.value));
	if (isNaN(value)) {
		alert('You have entered an incorrect character in this field. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	if ((value<1) || (value>99)) {
		alert('You have exceeded the range for some information on this tab. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	elem.value = FmtRate(value)
	return true
}

function FmtRate(A) {
	N=Math.abs(Math.round(A*1000));
	S=((N<10)?"00":((N<100)?"0":""))+N;
	S=S.substring(0,(S.length-3))+"."+S.substring((S.length-3),S.length)+"%";
	return S;
}

function FmtMoney(A,D) {
	N=Math.abs(Math.round(A*100));
	S=((N<10)?"00":((N<100)?"0":""))+N;
	S=((A<0)?"-":"")+"$"+WGgroup(S.substring(0,(S.length-2))) + 
	      ((D>0)?"."+S.substring((S.length-2),S.length):"");
	return S;
}

function WGgroup(S) {
	return (S.length<4)?S:(WGgroup(S.substring(0,S.length-3))+","+S.substring(S.length-3,S.length));
}

function currentTime() {
	var d = new Date();
	h = d.getHours();
	m = d.getMinutes();
	s = d.getSeconds();
	a = "am";
	if (h == 12) {
		a = "pm";
	}
	else if (h == 0) {
		h = 12;
		a = "am";
	}
	else if (h > 12) {
		a = "pm";
		h = h - 12;
	}
	t = h + ":" + m + ":" + s + " " + a;
	return t;
}

function hideleft() {
	top.window.location.href = replace(replace(window.location.href,"wxplr=1&",""),"&wxplr=1","");
}

function editField( table_cell, the_span, tableName, tableField, tableKey, tableID ){
	var my_td = sdfetch_object( table_cell );

	var original_text = the_span.innerHTML;

	my_td.innerHTML = "<INPUT TYPE=\"text\" id=\"editCell\" class=\"small\" value=\"" + original_text + "\" onBlur=\"doneEdit('"+table_cell+"',this,'"+original_text+"','"+tableName+"','"+tableField+"','"+tableKey+"','"+tableID+"')\">";

	var editCell = sdfetch_object('editCell');
	editCell.select();
	editCell.focus();
}

function doneEdit( table_cell, the_textbox, old_text, tableName, tableField, tableKey, tableID){
	var my_td = sdfetch_object( table_cell );

	var new_text = the_textbox.value;
	if( trim(new_text) == "" ){
		new_text = old_text;
	}

	var widthVariable;
	if( new_text.length == 0 ){
		widthVariable = "style=\"width:20px;\"";
	}
	my_td.innerHTML = "<SPAN " + widthVariable + " onDblClick=\"editField('" + table_cell + "',this,'"+tableName+"','"+tableField+"','"+tableKey+"','"+tableID+"')\">" + new_text + "</SPAN>"

	if( new_text != old_text ){
		new_text = new_text.replace("&","%26");

		var params = "?tableName="+ tableName + "&fieldName="+ tableField + "&tableKey="+ tableKey + "&tableID="+ tableID + "&fieldValue="+ new_text
		updateDatabase( params );
	}
}

function updateDatabase( params ){
	var httpRequest;
	makeRequestSend( httpRequest, 'updateDatabase.asp', params, doMessages )
}
