var xmlHttp;
var div_name_global;
var add_counter=0;
var waittime= 60 * 1000;		/* time between chat refreshes (ms) */
var ori_field_value ="";

function ajax_add_basic(fname,loop_count,div_name)
{		
	if(fname.length <1 )
	{
		alert("Invalid filename: "+new_value);	
		return;
	}
	
	if(div_name.length > 1 )
	{
		div_name_global = div_name;
	}
	
	//reset div content
	document.getElementById(div_name).innerHTML = "";
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
  		return;
  	}   	
	var url=fname;
	url=url+"?sid="+Math.random();		
	url=url+"&loopcount="+loop_count;		
	
	xmlHttp.onreadystatechange=update_status_msg_basic;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
} 

function update_status_msg_basic() 
{ 	 
	if (xmlHttp.readyState==4)
	{
		document.getElementById(div_name_global).innerHTML += xmlHttp.responseText;		
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		// Internet Explorer
	  try
	  {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e)
	  {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
  	}
	return xmlHttp;
}

function isNumber(val)
{
	if (isNaN(parseInt(val)))
	{
		//alert("Invalid Number");			
		return false;
	}
	else
	{
		return true;
	}	
}

function updateDOM(inputField) {
    // if the inputField ID string has been passed in, get the inputField object
    if (typeof inputField == "string") {
        inputField = document.getElementById(inputField);
    }

    if (inputField.type == "select-one") {
        for (var i=0; i<inputField.options.length; i++) {
            if (i == inputField.selectedIndex) {
                inputField.options[inputField.selectedIndex].setAttribute("selected","selected");
            }
        }
    } else if (inputField.type == "text") {
        inputField.setAttribute("value",inputField.value);
    } else if (inputField.type == "textarea") {
        inputField.setAttribute("value",inputField.value);
    } else if ((inputField.type == "checkbox") || (inputField.type == "radio")) {
        if (inputField.checked) {
            inputField.setAttribute("checked","checked");
        } else {
            inputField.removeAttribute("checked");
        }
    }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

