var netscape= (document.layers) ? true : false;
var ie= (document.all) ? true : false;
var dom= (document.getElementById && !document.all) ? true : false;

// Get object
function getElement(id)
{
	if(netscape) {
		path=document.layers[id];
	} else if(ie) {
		path=document.all[id];
	} else {
		path=document.getElementById(id);
	}
	return path;
}
// Open popups
function openPop(url,w,h) {
	var thisPage;
	thisPage = window.open(url, 'myWin', 'toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,width='+w+',height='+h)
	thisPage.focus();
}

// Trims whitespace
function trim(string) {
	return string.replace(/^\s*|\s*$/g, '');
}

// Converts a string to lowercase
function lcase(string) {
	return string.toLowerCase();
}

// Converts a string to uppercase
function ucase(string) {
	return string.toUpperCase();
}	

// Check that an email address is valid based on RFC 821
function isValidEmail(email) {
	var re  = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return re.test(email);
}
// Validates phone number
function isValidPhone(string){
	var re  = /^\(?[1-9]\d{2}\)?[- ]?\d{3}[- ]\d{4}$/;
	return re.test(string);
}
// Validates if a string is numeric
function isNumeric(string) {
	if(!isNaN(string)) {
		return true;
	} else {
		return false;
	}		 
}

function clear(id)
{
	var obj = document.getElementById(id);
	while(obj.childNodes.length > 0)
	{
		obj.removeChild(obj.childNodes[0]);
	}
}
function updateOptions(reqId, id, node)
{
	clear(id);
	var obj = document.getElementById(id);
	var results = xmlHttp[reqId].responseXML.getElementsByTagName(node);
	var option = null;		
	
	if(results.length==0)
	{
		alert('No data is available.');
	} else {			
		for(var i=0; i < results.length; i++)
		{
			option= document.createElement('option');
			option.appendChild(document.createTextNode(results[i].firstChild.nodeValue));
			option.setAttribute("value", results[i].attributes.getNamedItem("id").value); 
			obj.appendChild(option);
		}	
	}
}
function getFieldLength(instanceName)
{
	// Get the editor instance that we want to interact with.
	var oEditor=FCKeditorAPI.GetInstance(instanceName);
	// Get the Editor Area DOM (Document object).
	var oDOM=oEditor.EditorDocument;
	var iLength=0;
	// The are two diffent ways to get the text (without HTML markups).
	// It is browser specific.
	if (document.all) 
	{
		// If Internet Explorer
		iLength = oDOM.body.innerText.length;
	} else { 
		// If Gecko
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body );
		iLength = r.toString().length;
	}
	return iLength;
}