// HELPER METHODS

String.prototype.trim = function()
{
    return( this.replace(new RegExp("^([\\s]+)|([\\s]+)$", "gm"), "") );
}

function RefreshBanner(l,s) {
	var f = document.getElementById(l)
	var rsrc = f.src
	f.src="about:blank"
	f.src=rsrc
	
	setTimeout("RefreshBanner('"+l+"','" + s + "')",s*1000) 
}

function RefreshBanner2(l,s,n) {
	var f = document.getElementById(l)
	var rsrc = f.src
	f.src="about:blank"
	f.src=rsrc
	
	n = n - 1
	if (n > 0) {
		setTimeout("RefreshBanner2('"+l+"','" + s + "','" + n + "')",s*1000) 
	}
}

function addNode(parent, tag, id, css, text, name)
{
    var child = null;
    id = id == undefined ? "" : id;
    css = css == undefined ? "" : css;
    text = text == undefined ? "" : text; 
    
    // TAG
    if (tag.length > 0)
    {
        child = document.createElement('input');
        switch (tag)
        {
            case "textbox":
                child.setAttribute ("type", "text");
                break;
            case "button":                
                child.setAttribute("type", "button");
                break; 
            case "checkbox":                
                child.setAttribute("type", "checkbox");
                break;
            case "radio":
				try
				{
					var e = "<input type='radio' name='" + name + "' />";
					child = document.createElement(e);
				}
				catch(err)
				{
					child = document.createElement("input");
					child.setAttribute("type", "radio");
					child.setAttribute("name",name);
				}
                 break;
            case "file":
            case "document":
                var src = document.location.hostname == "localhost" ? "/homefreednn" : ""; 
                src += "/desktopmodules/homefree/ajaxfileinput.aspx?axn=" + tag + '&css=' + css;
                css = ""; // css is passed to iframe, the frame itself uses default class fileChooser 
                child = document.createElement('iframe');
                child.setAttribute('src', src);
                child.setAttribute('allowTransparency', true);
                child.setAttribute('tabindex','-1')
                child.setAttribute('height', '23');
                child.setAttribute('frameBorder', 'no');
                child.setAttribute ('border', '0');
                child.setAttribute('marginWidth', '0');
                child.setAttribute('marginHeight', '0');
                child.setAttribute ('leftMargin', '0');
                child.setAttribute('topMargin', '0');
                child.setAttribute('scrolling', 'no'); 
                child.style.backgroundColor   = 'Transparent';
                child.className = 'fileChooser';
                break;
            default:
                child = document.createElement(tag);
                break;
        }   
    }          
    // TEXT
    if (text.length > 0)
    {
        if (child == null)
            child = parent;
        switch (child.tagName)
        {
			case "OPTION":
				child.appendChild(document.createTextNode(text));
				break;
			case "INPUT":
				child.value = text;
				break;
			default:
				child.innerHTML = text;
				break;
		}
    }
    // ID 
    if (id.length > 0)
    {
        child.id = id;
        child.name = id;
    }
    // CSS
    if (css.length > 0)
        child.className = css;
    
    parent.appendChild(child);
    return child;
} 

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function pop (url, name, w , h, scroll) {
var top, left;
top = screen.availHeight/2 - h/2;
left = screen.availWidth/2 - w/2;
window.open(url,name,"width="+ w +",height=" + h + ",top="+top+",left="+left+",toolbar=no,location=no,directories=no,status=no,scrollbars=" + scroll + ",resizable=no,menubar=no,screenX=200,screenY=200");
}

function getHttpRequestObj() {
var req = false;
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} 
catch(e) {
req = false;
}
} 
else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} 
catch(e) {
req = false;
}
}
}

return req;
}	
		
var click = false;
		
function cpress (e) {
click = true;
}

function uload() {
//return;
if (!click) {
var url = '/close.asp'
http = getHttpRequestObj();
//http.onreadystatechange = handleHttpResponse;
http.open('GET', url, true);
http.send(null);		
}
}
		
document.onclick = cpress;

