function confirmdelete()
{
	if (confirm("Are you sure you want to delete this?") == true) {
		return true;
	} else {
		return false;
	}
}

function xyz(c,a,b,s) {
	var s = (s == null) ? true : s;
	var o = '';
	var m = '';
	var m2 = ':otliam';
	for (i = 0; i <= b.length; i++) {
    	o = b.charAt (i) + o;
	}
	b = o;
	for (i = 0; i <= m2.length; i++) {
    	m = m2.charAt (i) + m;
	}
	if (!s) {m = '';}
	return m + a + unescape('%'+'4'+'0') + b + '.' + c;
}


function two_dp(num)
{
  num = parseFloat(num);
  return(Math.round(num*100)/100);
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

function validate(field,val,type)
{
	if (type == 'email') {
		//return (val.indexOf(".") > 2) && (val.indexOf("@") > 0);
	} else if (type == 'url') {
		//val.replace("http://","");
	} else if (type == 'integer') {
		var regex = new RegExp ('[^0-9\.]', 'gi') ; //regexp for numeric input and fullstop only
		var newval=parseFloat(val.replace(regex, ""));
		if (newval != val) {alert('Only numeric input is allowed in this field');}
		if (isNaN(newval)) {field.value = '';} else {field.value = newval;}
		
		//document.forms[theform].elements['fm_cost_'+i].value
 	}
}

/*--------------[showhide]--------------*/
function showhide(region)
{
    if (document.getElementById)
    {   
        if (document.getElementById(region).style.display == 'none') {
        	document.getElementById(region).style.display = 'block';
        } else {
        	document.getElementById(region).style.display = 'none';
        }
	} else {
        alert('Sorry, your browser doesn\'t support this');
    }
}

/*--------------[showhide]--------------*/
function showregion(region)
{
    if (document.getElementById)
    {   
       	document.getElementById(region).style.display = 'block';
	} else {
        alert('Sorry, your browser doesn\'t support this');
    }
}

/*--------------[showhide]--------------*/
function hideregion(region)
{
    if (document.getElementById)
    {   
       	document.getElementById(region).style.display = 'none';
	} else {
        alert('Sorry, your browser doesn\'t support this');
    }
}



/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function ajaxsitesearch (keywords) {
	xajax_quicksearch(keywords,getCookie('username'),getCookie('code'));
	clearInterval(x);
}

/*--------------[shownode]--------------*/
function shownode(treename,node)
{
	var cookiecontents = getCookie(treename+'tree');
	if (isNull(cookiecontents)) {var cookiecontents = '';}
	var cookiearr = cookiecontents.split('.');
	var i = cookiearr.length;
	var controllerhtml = document.getElementById('controller'+node).innerHTML;
	if (document.getElementById)
    {
    	//show the node
		document.getElementById('node'+node).style.display = 'block';
		//Change the controller
		controllerhtml = controllerhtml.replace("+","-");
		controllerhtml = controllerhtml.replace("plus.","minus.");
		controllerhtml = controllerhtml.replace("closed.","open.");
		document.getElementById('controller'+node).innerHTML = controllerhtml;
        //first, clear any existing occurances
		for (var n=0; n<cookiearr.length; n++) {
			if (cookiearr[n] == node) {cookiearr[n] = ''}
		}
		cookiearr[i] = node;
		cookiecontents = cookiearr.join(".");
	}
	setCookie(treename+'tree',cookiecontents,'', '/');
}

/*--------------[hidenode]--------------*/
function hidenode(treename,node)
{
	var cookiecontents = getCookie(treename+'tree');
	if (isNull(cookiecontents)) {var cookiecontents = '';}
	var cookiearr = cookiecontents.split('.');
	var i = cookiearr.length;
	var controllerhtml = document.getElementById('controller'+node).innerHTML;
	if (document.getElementById)
    {
    	//hide the node
		document.getElementById('node'+node).style.display = 'none';
       	//Change the controller
		
		controllerhtml = controllerhtml.replace("-","+");
		controllerhtml = controllerhtml.replace("minus.","plus.");
		controllerhtml = controllerhtml.replace("open.","closed.");
		document.getElementById('controller'+node).innerHTML = controllerhtml;
		for (var n=0; n<cookiearr.length; n++) {
			if (cookiearr[n] == node) {cookiearr[n] = ''}
		}
	   
		cookiecontents = cookiearr.join(".");
       	//cookiecontents = cookiecontents.replace(node,'');
       	//cookiecontents = cookiecontents.replace('..','.');
	} else {
        alert('Sorry, your browser doesn\'t support this');
    }
	setCookie(treename+'tree',cookiecontents,'', '/');
}

/*--------------[showhidenode]--------------*/
function showhidenode(treename,node)
{
	//alert(node);
	if ( (document.getElementById('node'+node).style.display == 'none') || (document.getElementById('node'+node).style.display == '') ) {
		shownode(treename,node);
	} else {
		hidenode(treename,node);
	}       
}

/*--------------[showthesenodes]--------------*/
function showthesenodes(treename,nodes)
{
	var showarr = nodes.split('.');
	var cookiecontents = getCookie(treename+'tree');
	if (isNull(cookiecontents)) {var cookiecontents = '';}
	var cookiearr = cookiecontents.split('.');
	var shortlength = showarr.length - 1;
	
	//hide everything
	for (var n=0; n<cookiearr.length; n++) {
		if ((cookiearr[n] != '') && (cookiearr[n] != showarr[shortlength])) {hidenode(treename,cookiearr[n]);}
	}
	//Show specified nodes
	for (var n=0; n<shortlength; n++) {
		if (showarr[n] != '') {shownode(treename,showarr[n]);}
	}
	//Show / Hide last element
	if (showarr[shortlength] != '') {showhidenode(treename,showarr[shortlength]);}
}

/*--------------[loadtree]--------------*/
function loadtree(treename)
{
	var cookiecontents = getCookie(treename+'tree');
	if (isNull(cookiecontents)) {var cookiecontents = '';}
	var cookiearr = cookiecontents.split('.');
	//alert(cookiecontents);
	for (var n=0; n<cookiearr.length; n++) {
		if (cookiearr[n] != '') {shownode(treename,cookiearr[n]);}
	}
}


/*--------------[this is used for FCK - need to add this somewhere tidy]--------------*/
function OpenFile( fileUrl )
{
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function launchxinha(varname) {
    popup1 = open("xinhaeditor.php?varname="+varname,"popup_1","scrollbars=yes,width=800,height=600,resizable=yes")
}

function launchbbeditor(varname) {
    popup1 = open("bb-editor.php?varname="+varname,"popup_1","scrollbars=yes,width=800,height=600,resizable=yes")
}

