

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/



var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        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;
    }
}

//End Base64



// Start Ajax functions
window.urlData=Array();


var xmlHttp = createXMLHttpRequest();

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

var onLoadContentOverlibFunction=function(){
    if (xmlHttp.readyState == 4) {  changeOverlibContent(xmlHttp.responseText); }
    };





function loadOverlibContent(url, f){

  // Open a connection to the server
  xmlHttp.open("GET", url, true);

  if (!f) {
      f=onLoadContentOverlibFunction;
  }
  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = f;

  // Send the request
  xmlHttp.send(null);
}


function handleAJAXCallStateChange(){
    if (xmlHttp.readyState == 4) {  
        alert("I am a dummy function [handleAJAXCallStateChange].\nYou must override me.\n\nBy the way the ready state is " + xmlHttp.readyState); 
    }
}

function doAJAXPostCall(url, params, f){
    //You have to either pass your function or override the handleAJAXCallStateChange

  // Open a connection to the server
  xmlHttp.open("POST", url, true);

  if (!f) {
      f=handleAJAXCallStateChange;
  }
  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = f;
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");

  xmlHttp.send(params);
}

function doAJAXGetCall(url, f){
    //You have to either pass your function or override the handleAJAXCallStateChange

  // Open a connection to the server
  xmlHttp.open("GET", url, true);

  if (!f) {
      f=handleAJAXCallStateChange;
  }
  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = f;

  xmlHttp.send(null);
}



function changeOverlibContent(str){
    showOverlib(str);
    return false;


}


function showOverlib(data,caption){

        if (!caption) {
            if (window.overlibCaption){
                caption=window.overlibCaption;
            } else {
                caption="&nbsp;";
            }
        }
        if (!window.overLibX) {
            window.overLibX=cursor.x;
        }
        if (!window.overLibY) {
            window.overLibY=cursor.y;
        }


        return overlib(data, 
                       CAPTION, caption,
                       FIXX, window.overLibX,
                       FIXY, window.overLibY,


                       STICKY, 
                       FGCOLOR , '#bce0ec', 
                       BGCOLOR, '#153A46', 
                       CAPCOLOR  , '#ffffff',
                       CLOSETEXT, '<img src=/images/close.gif border=0>',
                       CLOSECLICK);
}

// -- end ajax functions




function xoopsGetElementById(id){
	if (document.getElementById) {
		return (document.getElementById(id));
	} else if (document.all) {
		return (document.all[id]);
	} else {
		if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) {
			return (document.layers[id]);
		}
	}
}

function xoopsSetElementProp(name, prop, val) {
	var elt=xoopsGetElementById(name);
	if (elt) elt[prop]=val;
}

function xoopsSetElementStyle(name, prop, val) {
	var elt=xoopsGetElementById(name);
	if (elt && elt.style) elt.style[prop]=val;
}


function getFormDataAsQueryString(fname){
    var frm=document.forms[fname];
    var text="";

    var els = frm.elements; 

    for(i=0; i<els.length; i++){ 
        _value=null;

        switch(els[i].type){
            case "select-one" :
                _value=els[i].options[els[i].selectedIndex].value;

            break;

            case "text":
                _value=els[i].value;
            break;

            case "hidden":
                _value=els[i].value;
            break;

            case "password":
                _value=els[i].value;
            break;
        }
        if (_value) {
            text+=els[i].name+"="+_value+"&"
        }
    }
        return text;

}
function xoopsGetFormElement(fname, ctlname) {
	var frm=document.forms[fname];
	return frm?frm.elements[ctlname]:null;
}

function justReturn() {
	return;
}

function open_xoops_fields_window(url){
    params="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
    return openWithSelfMain(url, "fieldsManagement", 800, 600, params);
}


function openWithSelfMain(url,name,width,height,params) {
    if (!params) {
       params="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
    }
    var options = "width=" + width + ",height=" + height + "," + params;

	new_window = window.open(url, name, options);
	window.self.name = "main";
	new_window.focus();
}

function setElementBackgroundColor(id, color){
	xoopsGetElementById(id).style.backgroundColor = "#" + color;
}

function setElementColor(id, color){
	xoopsGetElementById(id).style.color = "#" + color;
}

function setElementFont(id, font){
	xoopsGetElementById(id).style.fontFamily = font;
}

function setElementSize(id, size){
	xoopsGetElementById(id).style.fontSize = size;
}

function changeDisplay(id){
	var elestyle = xoopsGetElementById(id).style;
	if (elestyle.display == "") {
		elestyle.display = "none";
	} else {
		elestyle.display = "block";
	}
}

function setVisible(id){
	xoopsGetElementById(id).style.visibility = "visible";
}

function setHidden(id){
	xoopsGetElementById(id).style.visibility = "hidden";
}

function toggleVisibility(id){
	if (xoopsGetElementById(id).style.visibility == "hidden"){
		setVisible(id);
	} else {
		setHidden(id);
	}

}

function setLayerDisplay(id, display){
    if (!display) {
        display="inline";
    }
    thisLayer=document.getElementById(id);
    thisLayer.style.display=display
}

function showHide(id){
	thisLayer=document.getElementById(id);

	if (thisLayer.style.display=="block") {
		thisLayer.style.display="none"
	} else {
		thisLayer.style.display="block"
	}
}

function showHideInline(id){
	thisLayer=document.getElementById(id);

	if (thisLayer.style.display=="inline") {
		thisLayer.style.display="none"
	} else {
		thisLayer.style.display="inline"
	}
}

function resizeTextBox(e, d, n){
    element=document.getElementById(e);
        
        if (d=="height"){
            currHeight=parseInt(element.style.height);
            newHeight=currHeight+n;
            if (newHeight>0) {
                element.style.height=newHeight+"px";
            }
        }
        
    if (d=="width"){
        currWidth=parseInt(element.style.width);
        newWidth=currWidth+n;
        if (newWidth>0) {
            element.style.width=newWidth+"px";
        }
    }

}


function resizeSelectBox(e, n, d){
	element=xoopsGetElementById(e);
    if (!d) {
        d="height";
    }
    if (d=="height"){
    	currHeight=parseInt(element.style.height);
    	newHeight=currHeight+n;
    	if (newHeight>0) {
    		element.style.height=newHeight+"px";
    	}
    }

    if (d=="width"){
        currWidth=parseInt(element.style.width);
        newWidth=currWidth+n;

        if (newWidth>0) {
            element.style.width=newWidth+"px";
        }
    }

}


function makeBold(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.fontWeight != "bold" && eleStyle.fontWeight != "700") {
		eleStyle.fontWeight = "bold";
	} else {
		eleStyle.fontWeight = "normal";
	}
}

function makeItalic(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.fontStyle != "italic") {
		eleStyle.fontStyle = "italic";
	} else {
		eleStyle.fontStyle = "normal";
	}
}

function makeUnderline(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.textDecoration != "underline") {
		eleStyle.textDecoration = "underline";
	} else {
		eleStyle.textDecoration = "none";
	}
}

function makeLineThrough(id){
	var eleStyle = xoopsGetElementById(id).style;
	if (eleStyle.textDecoration != "line-through") {
		eleStyle.textDecoration = "line-through";
	} else {
		eleStyle.textDecoration = "none";
	}
}

function appendSelectOption(selectMenuId, optionName, optionValue){
	var selectMenu = xoopsGetElementById(selectMenuId);
	var newoption = new Option(optionName, optionValue);
	selectMenu.options[selectMenu.length] = newoption;
	selectMenu.options[selectMenu.length].selected = true;
}

function disableElement(target){
	var targetDom = xoopsGetElementById(target);
	if (targetDom.disabled != true) {
		targetDom.disabled = true;
	} else {
		targetDom.disabled = false;
	}
}
function xoopsCheckAll(formname, switchid) {
	var ele = document.forms[formname].elements;
	var switch_cbox = xoopsGetElementById(switchid);
	for (var i = 0; i < ele.length; i++) {
		var e = ele[i];
		if ( (e.name != switch_cbox.name) && (e.type == 'checkbox') ) {
			e.checked = switch_cbox.checked;
		}
	}
}

function xoopsCheckGroup(formname, switchid, groupid) {
	var ele = document.forms[formname].elements;
	var switch_cbox = xoopsGetElementById(switchid);
	for (var i = 0; i < ele.length; i++) {
		var e = ele[i];
		if ( (e.type == 'checkbox') && (e.id == groupid) ) {
			e.checked = switch_cbox.checked;
			e.click(); e.click();  // Click to activate subgroups
			// Twice so we don't reverse effect
		}
	}
}

function xoopsCheckAllElements(elementIds, switchId) {
	var switch_cbox = xoopsGetElementById(switchId);
	for (var i = 0; i < elementIds.length; i++) {
		var e = xoopsGetElementById(elementIds[i]);
		if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
			e.checked = switch_cbox.checked;
		}
	}
}

function xoopsSavePosition(id)
{
	var textareaDom = xoopsGetElementById(id);
	if (textareaDom.createTextRange) {
		textareaDom.caretPos = document.selection.createRange().duplicate();
	}
}

function xoopsInsertText(domobj, text)
{
	if (domobj.createTextRange && domobj.caretPos){
		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1)
		== ' ' ? text + ' ' : text;
	} else if (domobj.getSelection && domobj.caretPos){
		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charat(caretPos.text.length - 1)
		== ' ' ? text + ' ' : text;
	} else {
		domobj.value = domobj.value + text;
	}
}

function xoopsCodeSmilie(id, smilieCode) {
	var revisedMessage;
	var textareaDom = xoopsGetElementById(id);
	xoopsInsertText(textareaDom, smilieCode);
	textareaDom.focus();
	return;
}

function showImgSelected(imgId, selectId, imgDir, extra, xoopsUrl) {
	if (xoopsUrl == null) {
		xoopsUrl = "index.html";
	}
	imgDom = xoopsGetElementById(imgId);
	selectDom = xoopsGetElementById(selectId);
	imgDom.src = xoopsUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
}

function xoopsCodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
	if (enterUrlPhrase == null) {
		enterUrlPhrase = "Enter the URL of the link you want to add:";
	}
	var text = prompt(enterUrlPhrase, "");
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		if (enterWebsitePhrase == null) {
			enterWebsitePhrase = "Enter the web site title:";
		}
		var text2 = prompt(enterWebsitePhrase, "");
		if ( text2 != null ) {
			if ( text2 == "" ) {
				var result = "[url=" + text + "]" + text + "[/url]";
			} else {
				var pos = text2.indexOf(unescape('%00'));
				if(0 < pos){
					text2 = text2.substr(0,pos);
				}
				var result = "[url=" + text + "]" + text2 + "[/url]";
			}
			xoopsInsertText(domobj, result);
		}
	}
	domobj.focus();
}

function xoopsCodeImg(id, enterImgUrlPhrase, enterImgPosPhrase, imgPosRorLPhrase, errorImgPosPhrase){
	if (enterImgUrlPhrase == null) {
		enterImgUrlPhrase = "Enter the URL of the image you want to add:";
	}
	var text = prompt(enterImgUrlPhrase, "");
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		if (enterImgPosPhrase == null) {
			enterImgPosPhrase = "Now, enter the position of the image.";
		}
		if (imgPosRorLPhrase == null) {
			imgPosRorLPhrase = "'R' or 'r' for right, 'L' or 'l' for left, or leave it blank.";
		}
		if (errorImgPosPhrase == null) {
			errorImgPosPhrase = "ERROR! Enter the position of the image:";
		}
		var text2 = prompt(enterImgPosPhrase + "\n" + imgPosRorLPhrase, "");
		while ( ( text2 != "" ) && ( text2 != "r" ) && ( text2 != "R" ) && ( text2 != "l" ) && ( text2 != "L" ) && ( text2 != null ) ) {
			text2 = prompt(errorImgPosPhrase + "\n" + imgPosRorLPhrase,"");
		}
		if ( text2 == "l" || text2 == "L" ) {
			text2 = " align=left";
		} else if ( text2 == "r" || text2 == "R" ) {
			text2 = " align=right";
		} else {
			text2 = "";
		}
		var result = "[img" + text2 + "]" + text + "[/img]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeEmail(id, enterEmailPhrase){
	if (enterEmailPhrase == null) {
		enterEmailPhrase = "Enter the email address you want to add:";
	}
	var text = prompt(enterEmailPhrase, "");
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[email]" + text + "[/email]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeQuote(id, enterQuotePhrase){
	if (enterQuotePhrase == null) {
		enterQuotePhrase = "Enter the text that you want to be quoted:";
	}
	var text = prompt(enterQuotePhrase, "");
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var pos = text.indexOf(unescape('%00'));
		if(0 < pos){
			text = text.substr(0,pos);
		}
		var result = "[quote]" + text + "[/quote]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeCode(id, enterCodePhrase){
	if (enterCodePhrase == null) {
		enterCodePhrase = "Enter the codes that you want to add.";
	}
	var text = prompt(enterCodePhrase, "");
	var domobj = xoopsGetElementById(id);
	if ( text != null && text != "" ) {
		var result = "[code]" + text + "[/code]";
		xoopsInsertText(domobj, result);
	}
	domobj.focus();
}

function xoopsCodeText(id, hiddentext, enterTextboxPhrase){
	var textareaDom = xoopsGetElementById(id);
	var textDom = xoopsGetElementById(id + "Addtext");
	var fontDom = xoopsGetElementById(id + "Font");
	var colorDom = xoopsGetElementById(id + "Color");
	var sizeDom = xoopsGetElementById(id + "Size");
	var xoopsHiddenTextDomStyle = xoopsGetElementById(hiddentext).style;
	var textDomValue = textDom.value;
	var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;
	var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;
	var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
	if ( textDomValue == "" ) {
		if (enterTextboxPhrase == null) {
			enterTextboxPhrase = "Please input text into the textbox.";
		}
		alert(enterTextboxPhrase);
		textDom.focus();
	} else {
		if ( fontDomValue != "FONT") {
			textDomValue = "[font=" + fontDomValue + "]" + textDomValue + "[/font]";
			fontDom.options[0].selected = true;
		}
		if ( colorDomValue != "COLOR") {
			textDomValue = "[color=" + colorDomValue + "]" + textDomValue + "[/color]";
			colorDom.options[0].selected = true;
		}
		if ( sizeDomValue != "SIZE") {
			textDomValue = "[size=" + sizeDomValue + "]" + textDomValue + "[/size]";
			sizeDom.options[0].selected = true;
		}
		if (xoopsHiddenTextDomStyle.fontWeight == "bold" || xoopsHiddenTextDomStyle.fontWeight == "700") {
			textDomValue = "[b]" + textDomValue + "[/b]";
			xoopsHiddenTextDomStyle.fontWeight = "normal";
		}
		if (xoopsHiddenTextDomStyle.fontStyle == "italic") {
			textDomValue = "[i]" + textDomValue + "[/i]";
			xoopsHiddenTextDomStyle.fontStyle = "normal";
		}
		if (xoopsHiddenTextDomStyle.textDecoration == "underline") {
			textDomValue = "[u]" + textDomValue + "[/u]";
			xoopsHiddenTextDomStyle.textDecoration = "none";
		}
		if (xoopsHiddenTextDomStyle.textDecoration == "line-through") {
			textDomValue = "[d]" + textDomValue + "[/d]";
			xoopsHiddenTextDomStyle.textDecoration = "none";
		}
		xoopsInsertText(textareaDom, textDomValue);
		textDom.value = "";
		xoopsHiddenTextDomStyle.color = "#000000";
		xoopsHiddenTextDomStyle.fontFamily = "";
		xoopsHiddenTextDomStyle.fontSize = "12px";
		xoopsHiddenTextDomStyle.visibility = "hidden";
		textareaDom.focus();
	}
}

function IsNumeric(strString){
	//  check for valid numeric strings (integer)

	var strValidChars = "0123456789";
	var strChar;
	var isNum = true;

	if (strString.length == 0){
		return false;
	}

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && isNum == true; i++){
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
			isNum = false;
		}
	}
	return isNum;
}

function    xoopsValidateFCK(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
    var oEditor = FCKeditorAPI.GetInstance(textareaId) ;
    var editorcontent = oEditor.GetHTML();

    var subjectDom = xoopsGetElementById(subjectId);
    var submitDom = xoopsGetElementById(submitId);

    if (editorcontent == "" || subjectDom.value == "") {
        if (plzCompletePhrase == null) {
            plzCompletePhrase = "Please complete the subject and message fields.";
        }
        alert(plzCompletePhrase);
        return false;
    }

}

function xoopsValidate(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
	var maxchars = 65535;
	var subjectDom = xoopsGetElementById(subjectId);
	var textareaDom = xoopsGetElementById(textareaId);
	var submitDom = xoopsGetElementById(submitId);
	if (textareaDom.value == "" || subjectDom.value == "") {
		if (plzCompletePhrase == null) {
			plzCompletePhrase = "Please complete the subject and message fields.";
		}
		alert(plzCompletePhrase);
		return false;
	}
	if (maxchars != 0) {
		if (textareaDom.value.length > maxchars) {
			if (msgTooLongPhrase == null) {
				msgTooLongPhrase = "Your message is too long.";
			}
			if (allowedCharPhrase == null) {
				allowedCharPhrase = "Allowed max chars length: ";
			}
			if (currCharPhrase == null) {
				currCharPhrase = "Current chars length: ";
			}
			alert(msgTooLongPhrase + "\n\n" + allowedCharPhrase + maxchars + "\n" + currCharPhrase + textareaDom.value.length + "");
			textareaDom.focus();
			return false;
		} else {
			submitDom.disabled = true;
			return true;
		}
	} else {
		submitDom.disabled = true;
		return true;
	}
}



function printURL(){

    if (window.printLayout) {
        printLayout=window.printLayout;
    } else {
        printLayout="print";
    }
    if (window.printAuto) {
        printAuto=window.printAuto;
    } else {
        printAuto="0";
    }



    var pathname=self.location.pathname;
	var query=self.location.search;

	//  direct call for SEF startpage url (ie: http://{hostname}/)
	if (pathname == '/' && query == '') {
		return pathname+"index.php?layout="+printLayout+"&autoprint="+printAuto;
	}

	var parameters=new Array();
	var params =new Array();
	var seenLayout=false;
    var seenPrintAuto=false;


	query = query.substr(1, query.length - 1);
	query = query.replace(/%26/,'&');
	params= query.split('&');

	for (i = 0; i < params.length; i++){
		if (params[i] != '') {
			parameters[i]=params[i].split('=');

			if (parameters[i][0]=="layout"){
				seenLayout=true;
				parameters[i][1]=printLayout;
			}
            if (parameters[i][0]=="autoprint"){
                seenPrintAutot=true;
                parameters[i][1]=printAuto;
            }

        }
	}
	if (!seenLayout){
		parameters.push(new Array("layout", printLayout));
	}
    if (!seenPrintAuto){
        parameters.push(new Array("autoprint", printAuto));
    }
	params=new Array();
	for (i = 0; i < parameters.length; i++){
		params[i]=parameters[i][0]+"="+parameters[i][1];
	}
	query=params.join('&');
	if (pathname.match(/^\/\d+$/)){
	pathname +='index.html';
}

return pathname + "?" + query;
}

function replaceParamFromLocation(param2replace, replacement_value){
	// replaces value of a parameter from the URL

	var pathname=self.location.pathname;
	var query=self.location.search;

	var parameters=new Array();
	var params =new Array();
	var seenLayout=false;
    var seenParam2replace=false;

	query = query.substr(1, query.length - 1);
	query = query.replace(/%26/,'&');
	params= query.split('&');

	for (i = 0; i < params.length; i++){
		parameters[i]=params[i].split('=');
	}


	params=new Array();
	for (i = 0; i < parameters.length; i++){
		if (parameters[i][0]==param2replace) {
            seenParam2replace=true;
			parameters[i][1]=replacement_value;
		}
        if (parameters[i][0] && parameters[i][1]) {
            params[i]=parameters[i][0]+"="+parameters[i][1];
        }
	}

    if (!seenParam2replace) {
        params[i]=param2replace+"="+replacement_value;

    }
	query=params.join('&');

	return pathname + "?" + query;

}

function getParamFromLocation(param2get){
	// get value of a parameter from the URL

	var query=self.location.search;

	var parameters=new Array();
	var params =new Array();
	var seenLayout=false;


	query = query.substr(1, query.length - 1);
	query = query.replace(/%26/,'&');
	params= query.split('&');

	for (i = 0; i < params.length; i++){
		parameters[i]=params[i].split('=');
	}


	params=new Array();
	for (i = 0; i < parameters.length; i++){
		if (parameters[i][0]==param2get) {
			return parameters[i][1];
		}

	}

	// parameter not found
	return false;

}

function openPrintWindow(){
	oNewWindow = window.open(printURL(), "_blank");
}


function gotoWsContentPage(pageId){

	var pathname=self.location.pathname;

	// Handle first page
	var gotoUrl=false;

	if (pathname=="index.html" ) {
		gotoUrl="/content/0/"+pageId+"/";
		//alert("First Page!\nGotoURL is "+gotoUrl);

	} else {
		path_tokens=pathname.split('index.html');
		if (typeof(path_tokens)=="object") {
			if (path_tokens[1]) {
				//alert(path_tokens[1]);
				if (path_tokens[1].match(/^\d\d*$/)) {
					gotoUrl="/content/"+path_tokens[1]+"/"+pageId+"/";
					//alert("This is a location id\nGotoURL is "+gotoUrl);
				} else if (path_tokens[1].match(/^content*$/)) {
					gotoUrl="/content/"+path_tokens[2]+"/"+pageId+"/";
					//alert("This is content\nGotURL is "+gotoUrl);
				} else if (path_tokens[1].match(/^modules*$/) && path_tokens[2].match(/^wsContent*$/)) {
					gotoUrl=replaceParamFromLocation("page", pageId);
					//alert("Module/wsContent.\nGotoURL is " + gotoUrl);
				}
			}
		}
	}

	if (!gotoUrl) {
		gotoUrl="/content/0/"+pageId+"/";
	}
	if (gotoUrl) {
		self.location=gotoUrl;
	}
	return false;






}


function switchLanguage(lang_code){
    gotoUrl=replaceParamFromLocation("wslanguage", lang_code);
    if (gotoUrl) {
        self.location=gotoUrl;
    }

}

function downloadFile(fileId) {
	var location_id = getParamFromLocation('location_id') || 0 ;
	var page_id = getParamFromLocation('page');
	var hostname = self.location.host;

	var path_upload = 'modules/uploadmanager11/admin/index24ae.html?action=file_download&amp;file_id='+fileId;
	var href_file = 'http://'+hostname+path_upload+'&location_id='+location_id;

	window.open(href_file);
	//self.location.href =  href_file;
	//return false;
}



function scrollToTop(){
	window.scroll(0,0);
}


//window.onload=scrollToTop;
//window.attachEvent("onload", scrollToTop);



function argObject(name,value) {
	this.name=name;
	this.value=value;

}


function remoteCall (url,args){
	var n = args[0];
	var head = document.getElementsByTagName('head').item(0);

	var old  = document.getElementById(n.value);
	if (old) {
		head.removeChild(old);
	}

	script = document.createElement('script');

	script.type = 'text/javascript';
	script.defer = true;

	script.id = n.value; // Just call it somehow....
	var text="?";
	for(var i=0;i<args.length;++i){
		text=text + args[i].name + "=" + args[i].value + "&";
	}
	//alert(url+text);
	script.src = url+text;
	void(head.appendChild(script));

}


function showHideHelpText(id){
	showHide(id);

}

/*********************************************************************************
dw_cookies.js - cookie functions for www.dyn-web.com
Recycled from various sources
**********************************************************************************/

// Modified from Bill Dortch's Cookie Functions (hidaho.com)
// (found in JavaScript Bible)
function setCookie(name,value,days,path,domain,secure) {
	var expires, date;
	if (typeof days == "number") {
		date = new Date();
		date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
	}
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

// Modified from Jesse Chisholm or Scott Andrew Lepera ?
// (found at both www.dansteinman.com/dynapi/ and www.scottandrew.com/junkyard/js/)
function getCookie(name) {
	var nameq = name + "=";
	var c_ar = document.cookie.split(';');
	for (var i=0; i<c_ar.length; i++) {
		var c = c_ar[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
	}
	return null;
}

// from Bill Dortch's Cookie Functions (hidaho.com)
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 confirm2go(msg, url){
    if (confirm(msg)) {
        location.href=url;
    }
}

var cursor = {x:0, y:0};


function prepare_deferred_redirection(href, target) {
	window.deferred_redirection_parameters = { 'href': href, 'target':target};
}

function process_deferred_redirection() {
	var href = window.deferred_redirection_parameters.href;
	var target = window.deferred_redirection_parameters.target;
	
	handle_link(href, target);
}


function handle_link(href, target) {
	if (href.toLowerCase().indexOf("javascript:")==0) {              // Java script presents
		eval(href.substring(11,href.length));
	} else {
		if (!target || target=="_self") {
			location.href = href;
		} else {
                window.open (href, target);
		}
	}
}



function requestAttachFile(id,lang) {
	
	var input = document.getElementById(id);
	if (!input) {
		return false;
	}
	var w = window.open('http://cmsftp.worldsoft-cms.info:81/index.php?lang='+lang+'&rid='+encodeURIComponent(id)+'&red='+encodeURIComponent(window.location.protocol+'//'+window.location.host+'/uploadcallback.php'),'','width=400,height=100,status=no,resizable=no,location=no,menubar=no');
}

function processAttachmentFile(id, attachment) {
	var response = document.getElementById(id);
	if	(!response) {
		return false;
	}
	var display = document.getElementById('display'+id);
	if (!display) {
		return false;
	}
	
	
	response.value= attachment.uri;
	
	var suffix = response.value.slice(-3).toLowerCase();
	if (suffix == 'gif' || suffix == 'jpg' || suffix == 'bmp' || suffix == 'png' ) {
		var preview_image_src = response.value.replace(/^update:\/mounts\/cms-nas\/ecms\/(.*)\.([a-zA-Z]{3})$/,'http://images.worldsoft-cms.info/$1.resize_to.80x0.$2');
		var img = document.createElement('img');
		display.innerHTML = '<img src="'+preview_image_src+'" alt="'+attachment.display_name+'" > '+attachment.display_name+'&nbsp;';
	} else {
		display.innerHTML = attachment.display_name+'&nbsp;';
	}
	

	if (matches = id.match(/^(.*)_multi_([0-9]+)$/)) {
		var fct = 'handler_'+matches[1].replace(/[\[\]]/g,"_");
		var cmd = fct+"('"+id+"')";
		eval(cmd);
	} else {
		var delete_btn_id = 'deletebutton'+id;
		var delete_btn = document.getElementById(delete_btn_id);
		if (delete_btn) {
			delete_btn.style.display='inline';
		}
	}

	
	
    if (window.direct_execute_after_processing_attachment) {
        form_id=window.direct_execute_after_processing_attachment;
        form=document.getElementById(form_id);
        form.submit();
    }

}


function resizeIFrame(frame){
  //find the height of the internal page
  var the_height=frame.contentWindow.
    document.body.scrollHeight;

  var the_width=frame.contentWindow.
    document.body.scrollWidth;

  //change the height of the iframe
  frame.height=the_height+10;

  //change the width of the iframe
  frame.width=the_width+100;
}



function getDeleteLabel() {
	return "Delete";
}
	
function addOption(parentNode, eleName, widget, size, maxlength){
	
	var countId = eleName + "_counter";
	
	var lastId = parseInt(document.getElementById(countId).value);
	
	var nextId = lastId + 1;
	var item = document.createElement("tr");
	var td1 = document.createElement("td");
	var td2 = document.createElement("td");
	item.appendChild(td1);
	item.appendChild(td2);
	item.id = nextId;
	item.className = 'odd';
	parentNode.parentNode.insertBefore(item,parentNode);
	
	var s1 = "<input class='text' name='" + eleName +"["+nextId+"]' id='" + eleName +"["+nextId+"]' size='"+size+"' maxlength='"+maxlength+"' value='' type='"+widget+"'>";
	
	var s2 = "<input class='button' src='http://images.worldsoft-cms.info/data/icons/aa-Vista-e/PNG/16X16/bt_delete.png' name='delopt["+ eleName +"["+nextId+"]' id='delopt["+ eleName +"["+nextId+"]' value='"+getDeleteLabel()+"' type='image' onclick='delOption(this.parentNode,\""+eleName+"\",0);' >";
	
	td1.innerHTML = s1;
	td2.innerHTML = s2;
	document.getElementById(countId).value++;
}

function delOption(parentNode,eleName,next){
	var countId = eleName + "_counter";
	var count = document.getElementById(countId).value;

	if(count == 1){
		return;
	}
	
	parentNode.parentNode.parentNode.removeChild(parentNode.parentNode);
	
	
	document.getElementById(countId).value--;
	/*
	if(next > 0){
		var item = document.createElement("input");
		item.type = "hidden";
		item.name = eleName + "[delete_values]["+next+"]";
		item.value = next;
		document.objects_form.appendChild(item);
	}
	*/
	
}

function changeStyle(o,c){
	o.className = c;
}

function openWSMediaStreamer(url, width, height) {
    params="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no";
    return openWithSelfMain(url,"wsMediaStreamer",width,height, params);

}

function openWSVideoStreamer(flv, width, height, videotype, autostart) {
    if (!flv) {
        return;
    }
    if (!width) {
        width=400;
    }
    if (!height) {
        height=300;
    }

    if (!videotype) {
        videotype="file";
    }


    windowWidth=width;
    windowHeight=height+20;

    if (videotype=="yt") {
        _url="modules/wsVideoStreamer/player/indexdffe.html?yt="+flv;
    } else {
        _url="modules/wsVideoStreamer/player/index92bd.html?file="+flv;
    }

	_url+="&autostart="+autostart;


    if (width) {
        _url+="&width="+width;
    }
    if (height) {
        _url+="&height="+height;
    }

    params="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no";
    return openWithSelfMain(_url,"wsVideoStreamer",windowWidth,windowHeight, params);
}


function openIRCChatWindow(width, height) {
    if (!width) {
        width=640;
    }
    if (!height) {
        height=480;
    }

    if (!window.uid) {
        return;
    }
    if (!window._domain_id) {
        return;
    }

    if (!window.chatName) {
        return;
    }

    windowWidth=width;
    windowHeight=height;

    //_url="http://217.196.177.143:2001/chat.html?nickname=" +  window.chatName + "&channel=" + window._domain;
    _url="http://chatserver.worldsoft-cms.info:2001/chat.html?key=u"+window.uid+"d"+window._domain_id;
    


    if (width) {
        _url+="&width="+width;
    }
    if (height) {
        _url+="&height="+height;
    }

    return openWithSelfMain(_url,"ircChatWindow",windowWidth,windowHeight, "status=no,location=no");
}


function checkout(id,qty){
    lyr=xoopsGetElementById("checkout_"+id);
    _url="checkoutcad7.html?article_id="+id+"&quantity="+qty;
    //self.location="/checkout.php?article_id="+id+"&quantity="+qty;
    lyr.innerHTML="<br><iframe height=400 width=100%  src='"+_url+"'></iframe>";;
    //self.location="/checkout.php?article_id="+id+"&quantity="+qty;
}

function normalizeDomain(domain){
    value = domain.toLowerCase();
    value=value.replace(/\s/g, '');
    value=value.replace(/^http:\/\//, '');
    value=value.replace(/^https:\/\//, '');
    value=value.replace(/^www\./, '');
    value=value.replace(/\/.*/, '');
    value=value.replace(/:.*/, '');
    return value;
}



function scriptLoader() {};

scriptLoader.loaded = {};

scriptLoader.loadOnce = function(script) {
	if (!scriptLoader.loaded[script]) {
		loadScript(script);
		scriptLoader.loaded[script]=true;
	} 
}

