
	function form_submit_standard(action)
	{
		switch(action)
		{
			case 'reset':
				if(confirm('All fields will be cleared!!\nAre you sure you want to reset the form?'))
					return (true);
				break;
			default:
				return (true);
		}
		return (false);
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	var preloaded = new Array(8);
	
	function load_images(imagearray)
	{
		for( i=0; i<imagearray.length; i++ )
		{
			preloaded[i] = new Image()
			preloaded[i].src = imagearray[i]
		}
	}
	
	var images = new Array(8);
	
	images[0] = 'zpimages/awbg.png';
	images[1] = 'zpimages/awtl.png';
	images[2] = 'zpimages/awtr.png';
	images[3] = 'zpimages/awbl.png';
	images[4] = 'zpimages/awbr.png';
	images[5] = 'zpimages/loader.gif';
	images[6] = 'zpimages/transbg.png';
	images[7] = 'zpimages/close.png';

	load_images(images);
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function centre_it(c)
{
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if(window.pageYOffset) ScrollTop = window.pageYOffset;
		else ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	var W = xWindow();
	c.style.left = (W.Width - c.clientWidth) / 2;
	c.style.top = ScrollTop + (W.Height - c.clientHeight) / 2;
}

function xWindow()
{
	var O = new Object;
	if(parseInt(navigator.appVersion) > 3)
	{
		if(navigator.appName == "Netscape")
		{
			O.Width = window.innerWidth;
			O.Height = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft") != -1)
		{
			O.Width = document.body.offsetWidth;
			O.Height = document.body.offsetHeight;
		}
	}
	return (O);
}

function getQueryString(formname)
{
    var form = document.forms[formname];
	var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + name + "="
            + safeString(value);
            // + value;
            // + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }
	
	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "IMAGE"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}

function safeString(s)
{
	s = s.replace(/\&/g, "%26");
    s = s.replace(/\+/g, "%2B");
	return (s);
}

function popup(strURL, container, query, destroy) {
	if(destroy !== false)
		popup_create(container);
	xmlhttpPost(strURL, container, query);
}

function request(strURL, container, query) {
	xmlhttpPost(strURL, container, query);
}

function xmlhttpPost(strURL, container, query) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(container, self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(query);
	return (false);
}

function getquerystring() {
    var form     = document.forms['f1'];
    var word = form.word.value;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(container, str){
    document.getElementById(container).innerHTML = str;
	centre_it(document.getElementById(container));
}
var popup_layer = null;
var popup_container = null;
function popup_create(container_id)
{
	popup_layer = document.createElement("DIV");
	popup_layer.setAttribute("id", "layer");
	// popup_layer.innerHTML = '';
	popup_layer.style.height = document.body.scrollHeight
	document.body.appendChild(popup_layer);
	
	if(popup_container != null)
		document.body.removeChild(popup_container);
	popup_container = document.createElement("DIV");
	popup_container.setAttribute("id", container_id);
	popup_container.innerHTML = '<img src="zpimages/loader.gif" align="center" />';
	document.body.appendChild(popup_container);
	centre_it(popup_container);
}

function popup_close(do_confirm)
{
	if((do_confirm !== true) || (confirm('Are you sure you want to close?')))
	{
		if(popup_container != null) {
			document.body.removeChild(popup_container);
			popup_container = null;
		}
		if(popup_layer != null) {
			document.body.removeChild(popup_layer);
			popup_layer = null;
		}
	}
	return (false);
}

function display_tribute(tribute_id)
{
	popup('scripts/load_tribute.php', 'popup', 'tribute_id=' + tribute_id, true);
	return (false);
}

function get_hits(container, ct, ni)
{
	request('scripts/agent_hits.php', container, 'ct=' + ct + '&ni=' + ni);
	return (false);
}

function form_load(auth_code, url)
{
	popup('scripts/form_loader.php', 'popup', 'auth_code=' + auth_code + '&url=' + url, true);
	return (false);
}

function form_submit(form, auth_code)
{
	var query_string = getQueryString(form);
	popup('scripts/form_loader.php', 'popup', query_string + '&auth_code=' + auth_code, false);
	return (false);
}

function form_reset(auth_code)
{
	if(confirm('All data will be lost!\nAre you sure you want to reset the form?'))
		popup('scripts/form_loader.php', 'popup', 'auth_code=' + auth_code, false);
	return (false);
}

function display_audioplayer(id, m)
{
	document.write('<div class="ap">');
	document.write('<table cellspacing="0" cellpadding="0" border="0" align="center"><tr>');
	document.write('<td class="aplogo"><a target="_blank" href="http://www.lankasri.fm/" title="Lankasri FM"><img src="http://www.lankasrinotice.com/photos/others/others/lankasrifm01.jpg" /></a></td>');
	document.write('<td class="applayer" id="'+id+'">not supported</td>');
	document.write('</tr></table>');
	document.write('Broadcasted by <a target="_blank" href="http://www.lankasri.fm/">Lankasri FM</a></div>');
	var so = new SWFObject("playerSingle.swf", "mymovie", "192", "67", "0", "#FFFFFF");
	so.addVariable("autoPlay", "no");
	so.addVariable("soundPath", m);
	so.write(id);
}
