function setTab(formName, tabName) {
    var tabArray = eval(formName+'_tabs_array');
    var tabCaptionArray = eval(formName+'_tabs_caption_array');
    for(i=0; i<tabArray.length; i++){
        var viewTab = formName+'_'+tabName;
        var elestyle = itpGetElementById(tabArray[i]).style;
        var tab_td1 = itpGetElementById('tab_td1_'+tabArray[i]);
        var tab_td2 = itpGetElementById('tab_td2_'+tabArray[i]);
        var tab_td3 = itpGetElementById('tab_td3_'+tabArray[i]);
        var sTabCaption = tabCaptionArray[i];
        if (tabArray[i]==viewTab){
            tab_td1.className = "activetd1";
            tab_td2.className = "activetd2";
            tab_td3.className = "activetd3";
//          tab.innerHTML = sTabCaption;
            elestyle.display = "block";
        } else {
            tab_td1.className = "nonactivetd1";
            tab_td2.className = "nonactivetd2";
            tab_td3.className = "nonactivetd3";
//          tab.innerHTML = "<a href='javascript:setTab(\""+formName+"\", \""+tabName+"\");'>"+sTabCaption+"</a>";
            elestyle.display = "none";
        }
    }
}


function itpGetElementById(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 itpSetElementProp(name, prop, val) {
    var elt=itpGetElementById(name);
    if (elt) elt[prop]=val;
}

function itpSetElementStyle(name, prop, val) {
    var elt=itpGetElementById(name);
    if (elt && elt.style) elt.style[prop]=val;
}

function itpGetFormElement(fname, ctlname) {
    var frm=document.forms[fname];
    return frm?frm.elements[ctlname]:null;
}

function justReturn() {
    return;
}

function openWithSelfMain(url,name,width,height) {
    var options = "width=" + width + ",height=" + height + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";

    new_window = window.open(url, name, options);
    window.self.name = "main";
    new_window.focus();
}

function setElementColor(id, color){
    itpGetElementById(id).style.color = "#" + color;
}

function setElementFont(id, font){
    itpGetElementById(id).style.fontFamily = font;
}

function setElementSize(id, size){
    itpGetElementById(id).style.fontSize = size;
}

function changeDisplay(id){
    var elestyle = itpGetElementById(id).style;
    if (elestyle.display == "") {
        elestyle.display = "none";
    } else {
        elestyle.display = "block";
    }
}

function setVisible(id){
    itpGetElementById(id).style.visibility = "visible";
}

function setHidden(id){
    itpGetElementById(id).style.visibility = "hidden";
}

function makeBold(id){
    var eleStyle = itpGetElementById(id).style;
    if (eleStyle.fontWeight != "bold" && eleStyle.fontWeight != "700") {
        eleStyle.fontWeight = "bold";
    } else {
        eleStyle.fontWeight = "normal";
    }
}

function makeItalic(id){
    var eleStyle = itpGetElementById(id).style;
    if (eleStyle.fontStyle != "italic") {
        eleStyle.fontStyle = "italic";
    } else {
        eleStyle.fontStyle = "normal";
    }
}

function makeUnderline(id){
    var eleStyle = itpGetElementById(id).style;
    if (eleStyle.textDecoration != "underline") {
        eleStyle.textDecoration = "underline";
    } else {
        eleStyle.textDecoration = "none";
    }
}

function makeLineThrough(id){
    var eleStyle = itpGetElementById(id).style;
    if (eleStyle.textDecoration != "line-through") {
        eleStyle.textDecoration = "line-through";
    } else {
        eleStyle.textDecoration = "none";
    }
}

function appendSelectOption(selectMenuId, optionName, optionValue){
    var selectMenu = itpGetElementById(selectMenuId);
    var newoption = new Option(optionName, optionValue);
    selectMenu.options[selectMenu.length] = newoption;
    selectMenu.options[selectMenu.length].selected = true;
}

function disableElement(target){
    var targetDom = itpGetElementById(target);
    if (targetDom.disabled != true) {
        targetDom.disabled = true;
    } else {
        targetDom.disabled = false;
    }
}
function itpCheckAll(formname, switchid) {
    var ele = document.forms[formname].elements;
    var switch_cbox = itpGetElementById(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 itpCheckGroup(formname, switchid, groupid) {
    var ele = document.forms[formname].elements;
    var switch_cbox = itpGetElementById(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 itpCheckAllElements(elementIds, switchId) {
    var switch_cbox = itpGetElementById(switchId);
    for (var i = 0; i < elementIds.length; i++) {
        var e = itpGetElementById(elementIds[i]);
        if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
            e.checked = switch_cbox.checked;
        }
    }
}

function itpSavePosition(id)
{
    var textareaDom = itpGetElementById(id);
    if (textareaDom.createTextRange) {
        textareaDom.caretPos = document.selection.createRange().duplicate();
    }
}

function itpInsertText(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 itpCodeSmilie(id, smilieCode) {
    var revisedMessage;
    var textareaDom = itpGetElementById(id);
    itpInsertText(textareaDom, smilieCode);
    textareaDom.focus();
    return;
}

function showImgSelected(imgId, selectId, imgDir, extra, itpUrl) {
    if (itpUrl == null) {
        itpUrl = "./";
    }
    imgDom = itpGetElementById(imgId);
    selectDom = itpGetElementById(selectId);
    imgDom.src = itpUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
}

function itpCodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
    if (enterUrlPhrase == null) {
        enterUrlPhrase = "Enter the URL of the link you want to add:";
    }
    var text = prompt(enterUrlPhrase, "");
    var domobj = itpGetElementById(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]";
            }
            itpInsertText(domobj, result);
        }
    }
    domobj.focus();
}

function itpCodeImg(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 = itpGetElementById(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]";
        itpInsertText(domobj, result);
    }
    domobj.focus();
}

function itpCodeEmail(id, enterEmailPhrase){
    if (enterEmailPhrase == null) {
        enterEmailPhrase = "Enter the email address you want to add:";
    }
    var text = prompt(enterEmailPhrase, "");
    var domobj = itpGetElementById(id);
    if ( text != null && text != "" ) {
        var result = "[email]" + text + "[/email]";
        itpInsertText(domobj, result);
    }
    domobj.focus();
}

function itpCodeQuote(id, enterQuotePhrase){
    if (enterQuotePhrase == null) {
        enterQuotePhrase = "Enter the text that you want to be quoted:";
    }
    var text = prompt(enterQuotePhrase, "");
    var domobj = itpGetElementById(id);
    if ( text != null && text != "" ) {
        var pos = text.indexOf(unescape('%00'));
        if(0 < pos){
            text = text.substr(0,pos);
        }
        var result = "[quote]" + text + "[/quote]";
        itpInsertText(domobj, result);
    }
    domobj.focus();
}

function itpCodeCode(id, enterCodePhrase){
    if (enterCodePhrase == null) {
        enterCodePhrase = "Enter the codes that you want to add.";
    }
    var text = prompt(enterCodePhrase, "");
    var domobj = itpGetElementById(id);
    if ( text != null && text != "" ) {
        var result = "[code]" + text + "[/code]";
        itpInsertText(domobj, result);
    }
    domobj.focus();
}

function itpCodeText(id, hiddentext, enterTextboxPhrase){
    var textareaDom = itpGetElementById(id);
    var textDom = itpGetElementById(id + "Addtext");
    var fontDom = itpGetElementById(id + "Font");
    var colorDom = itpGetElementById(id + "Color");
    var sizeDom = itpGetElementById(id + "Size");
    var itpHiddenTextDomStyle = itpGetElementById(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 (itpHiddenTextDomStyle.fontWeight == "bold" || itpHiddenTextDomStyle.fontWeight == "700") {
            textDomValue = "[b]" + textDomValue + "[/b]";
            itpHiddenTextDomStyle.fontWeight = "normal";
        }
        if (itpHiddenTextDomStyle.fontStyle == "italic") {
            textDomValue = "[i]" + textDomValue + "[/i]";
            itpHiddenTextDomStyle.fontStyle = "normal";
        }
        if (itpHiddenTextDomStyle.textDecoration == "underline") {
            textDomValue = "[u]" + textDomValue + "[/u]";
            itpHiddenTextDomStyle.textDecoration = "none";
        }
        if (itpHiddenTextDomStyle.textDecoration == "line-through") {
            textDomValue = "[d]" + textDomValue + "[/d]";
            itpHiddenTextDomStyle.textDecoration = "none";
        }
        itpInsertText(textareaDom, textDomValue);
        textDom.value = "";
        itpHiddenTextDomStyle.color = "#000000";
        itpHiddenTextDomStyle.fontFamily = "";
        itpHiddenTextDomStyle.fontSize = "12px";
        itpHiddenTextDomStyle.visibility = "hidden";
        textareaDom.focus();
    }
}

function itpValidate(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
    var maxchars = 65535;
    var subjectDom = itpGetElementById(subjectId);
    var textareaDom = itpGetElementById(textareaId);
    var submitDom = itpGetElementById(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 checkCatalogOrder(sUrl){
    var oLoader = new DownLoader();
        oLoader.load(sUrl);
}
