/**************************************************************
 * @function script
 * @description disable the contextmenu
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return 
 **************************************************************/
document.oncontextmenu = function() {
    //return false;
}
/**************************************************************/

/**************************************************************
 * @function writeStartMarquee
 * @description writes out the hidden, non-standard marquee 
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return 
 **************************************************************/
function switchLanguage(lang) {
    var strLoc = ""+ document.location;
    
    if(strLoc && lang!="") {
        if(strLoc.indexOf("lang=")>0) {
            document.location = ""+ strLoc.substring(0, strLoc.indexOf("lang=") + 5) + lang + strLoc.substring(strLoc.indexOf("lang=") + 7, strLoc.length);
        }
        else {
            if(strLoc.indexOf("?")>0) {
                document.location = document.location +"&lang="+ lang;
            }
            else {
                document.location = document.location +"?lang="+ lang;
            }
        }
    }
}
/**************************************************************/

/**************************************************************
 * @function writeStartMarquee
 * @description writes out the hidden, non-standard marquee 
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return 
 **************************************************************/
function writeStartMarquee() {
    document.write("<marquee scrollamount=\"2\" align=\"left\" valign=\"middle\">");
}
/**************************************************************/

/**************************************************************
 * @function writeEndMarquee
 * @description writes out the hidden, non-standard marquee 
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return 
 **************************************************************/
function writeEndMarquee() {
    document.write("</marquee>");
}
/**************************************************************/

/**************************************************************
 * @function noNumbers
 * @description allow only chars
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (event) e
 * @return 
 **************************************************************/
function noNumbers(e) {
    var keynum;
    var keychar;
    var numcheck;
    
    if(window.event) { // IE
        keynum = e.keyCode;
    }
    else if(e.which) { // Netscape/Firefox/Opera
        keynum = e.which;
    }
    
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    
    //return ok if backslash for eg Firefox
    if(keynum==8) {
        return true;
    }
    else {
        return !numcheck.test(keychar);
    }
}
/**************************************************************/

/**************************************************************
 * @function noChars
 * @description allow only chars
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (event) e
 * @return 
 **************************************************************/
function noChars(e) {
    var keynum;
    var keychar;
    var numcheck;
    
    if(window.event) { // IE
        keynum = e.keyCode;
    }
    else if(e.which) { // Netscape/Firefox/Opera
        keynum = e.which;
    }
    
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    
    //return ok if backslash for eg Firefox
    if(keynum==8) {
        return true;
    }
    else {
        return numcheck.test(keychar);
    }
}
/**************************************************************/
    
/**************************************************************
 * @function ibAlert
 * @description popup a configured alert
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) txt
 * @return 
 **************************************************************/
function ibAlert(txt) {
    alert(convertToJsText(txt));
}
/**************************************************************/

/**************************************************************
 * @function ibConfirm
 * @description popup a configured confirm
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) txt
 * @return 
 **************************************************************/
function ibConfirm(txt) {
    return confirm(convertToJsText(txt));
}
/**************************************************************/

/**************************************************************
 * @function ibConfirmHTML
 * @description popup a configured confirm
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) txt
 * @return 
 **************************************************************/
function ibConfirmHTML(txt, url) {
    document.write(txt);
}
/**************************************************************/

/**************************************************************
 * @function convertToJsText
 * @description replace special chars
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) txt
 * @return 
 **************************************************************/
function convertToJsText(txt) {
    for(var i=0; i<txt.length; i++) {
        txt = txt.replace(/&#229;/g, "a");
        txt = txt.replace(/&#228;/g, "a");
        txt = txt.replace(/&#246;/g, "o");
        
        txt = txt.replace(/&#197;/g, "A");
        txt = txt.replace(/&#196;/g, "A");
        txt = txt.replace(/&#214;/g, "O");
        
        txt = txt.replace(/&#232;/g, "e");
        txt = txt.replace(/&#233;/g, "e");
        
        txt = txt.replace(/&#224;/g, "a");
        txt = txt.replace(/&#225;/g, "a");
        
        txt = txt.replace(/&#220;/g, "u");
        txt = txt.replace(/&#252;/g, "U");
        
        txt = txt.replace(/&#255;/g, "y");
    }    
    
    return txt;
}
/**************************************************************/

/**************************************************************
 * @function addToFavorites
 * @description popup add to favorite window if IE, else alert
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) url, (string) name
 * @return null
 **************************************************************/
function addToFavorites(url, name) {
    // @debug  ibAlert("function: addToFavorites");
    
    if(window.external) {
        window.external.AddFavorite(url, name);
    }
    else {
        ibAlert("Ctrl + D");
    }
}
/**************************************************************/

/**************************************************************
 * @function changeImg
 * @description checks the image src and alters it (1:2)
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (object) obj
 * @return null
 **************************************************************/
function changeImg(obj) {
    // @debug  ibAlert("function: changeImg");
    if(obj) {
        if(obj.src!="") {
            if(obj.src.indexOf("_f1.")>0) {
                obj.src = obj.src.replace(/_f1./g, "_f2.");
            }
            else if(obj.src.indexOf("_f2.")>0) {
                obj.src = obj.src.replace(/_f2./g, "_f1.");
            }
        }
    }
}
/**************************************************************/

/**************************************************************
 * @function changeClass
 * @description checks and alters the objects class
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (object) obj, (string) cls
 * @return null
 **************************************************************/
function changeClass(obj, cls) {
    // @debug  ibAlert("function: changeClass");
    if(obj) {
        if(cls!="" && obj.className) {
            obj.className = cls;
        }
    }
}
/**************************************************************/

/**************************************************************
 * @function getObj
 * @description gets and returns an object from document
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) n
 * @return (object) object
 **************************************************************/
function getObj(n) {
    var p;
    var i;
    var x;
            
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        document = parent.frames[n.substring(p+1)].document;
        n = n.substring(0,p);
    }
            
    if(!(x=document[n])&&document.all) {
        x = document.all[n];
    }
                
    for(i=0; !x&&i<document.forms.length; i++) {
        x = document.forms[i][n];
    }
    
    for(i=0; !x&&document.layers&&i<document.layers.length; i++) {
        x = getObj(n);
    }
    
    if(!x && document.getElementById) {
        x = document.getElementById(n);
    }

    return x;
}
/**************************************************************/

/**************************************************************
 * @function showObj
 * @description sets the visibility property to visible
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) object_name
 * @return 
 **************************************************************/
function showObj(object_name) {
    var obj;
    
    if(object_name) {
        if(object_name!="") {
            obj = getObj(object_name);
        
            if(obj) {
                obj.style.visibility = "visible";
            }
        }
    }
}
/**************************************************************/

/**************************************************************
 * @function hideObj
 * @description sets the visibility property to hidden
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) object_name
 * @return 
 **************************************************************/
function hideObj(object_name) {
    var obj;
    
    if(object_name) {
        if(object_name!="") {
            obj = getObj(object_name);
        
            if(obj) {
                obj.style.visibility = "hidden";
            }
        }
    }
}
/**************************************************************/

/**************************************************************
 * @function validateForm
 * @description checks the form that is being submitted
 *              and hilites errors (elements background)
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (object) obj
 * @return (boolean) true|false
 **************************************************************/
function validateForm(obj) {
    // @debug ibAlert("function: validateForm");
    var i;
    var xVal;
    var objX;
    
    //first reset all the hilited labels if any
    for(i=0; i<obj.length; i++) {
        if(getObj("td_"+ obj.name +"_"+ obj[i].name.toLowerCase())) {
            objX = getObj("td_"+ obj.name +"_"+ obj[i].name.toLowerCase());
            
            if(objX.className) {
                if(objX.className.toLowerCase().indexOf("td_form_input_label_hilite")>=0) {
                    changeClass(objX, "td_form_input_label");
                }
            }
        }
    }
    
    //begin validation
    // - obj[i]   = the input and value
    // - obj[i+1] = the validation
    // - obj[i+2] = the required
    // - obj[i+3] = the unique
    for(i=0; i<obj.length; i++) {
        xVal = false;
        
        if(obj[i].name) {
            if(obj[i].name!="") {
                if(obj[i].name.toLowerCase().indexOf("input_")==0 && obj[i].name.toLowerCase().indexOf("_select")<0) {
                    if(i<(obj.length-1)) {
                        if(obj[i+1]) {
                            if(obj[i+1].name) {
                                /*if(obj[i+1].name.toLowerCase().indexOf("validate_input_")==0) {*/
                                if((obj[i].value!='' && obj[i+1].value!='') || obj[i+2].value==1 || obj[i+3].value==1) {
                                    if(obj[i+1].value) {
                                        if(obj[i+1].value!="") {
                                            if(obj[i+1].value.toLowerCase()=="radiobuttongroup" || obj[i+1].value.toLowerCase()=="radiobutton" || obj[i+1].value.toLowerCase()=="radio") {
                                                // loop the group to find if any marks
                                                for(j=0; j<obj.length; j++) {
                                                    if(obj[j].name && obj[j].name!="") {
                                                        if(obj[j].name.toLowerCase()==obj[i].name.toLowerCase()) {
                                                            if(obj[j].checked) {
                                                                xVal = true;
                                                            }
                                                        }
                                                    }
                                                }
                                                
                                                // if no marks then hilite
                                                if(!xVal) {
                                                    // hilite the label
                                                    changeClass(getObj("td_"+ obj.name +"_"+ obj[i].name.toLowerCase()), "td_form_input_label_hilite");
                                                    
                                                    return false;
                                                }
                                            }
                                            else {
                                                // no group, validate as set (if "password (confirm)" - include the "password" field, else null)
                                                // bit of a hustle here:
                                                // - if confirm then its this value (i) + validation field (i+1) + the real passwords value field (i-5)
                                                //   requires the confirmation field to be directly after the password field (to aviod even more complexity)
                                                if(obj[i+1].value.toLowerCase().indexOf("password (confirm)")>=0 || obj[i+1].value.toLowerCase().indexOf("password_confirm")>=0) {
                                                    if(!validateInput(obj[i], obj[i+1], obj[i+2], obj[i-4])) {
                                                        changeClass(getObj("td_"+ obj.name +"_"+ obj[i].name.toLowerCase()), "td_form_input_label_hilite");
                                                        
                                                        if(obj[i].type.toLowerCase()=="text" || obj[i].type.toLowerCase()=="password" || obj[i].type.toLowerCase()=="select" || obj[i].type.toLowerCase()=="textarea") {
                                                            obj[i].focus();
                                                        }
                                                        
                                                        return false;
                                                    }
                                                }
                                                else {
                                                    if(!validateInput(obj[i], obj[i+1], obj[i+2], null)) {
                                                        changeClass(getObj("td_"+ obj.name +"_"+ obj[i].name.toLowerCase()), "td_form_input_label_hilite");
                                                            
                                                        if(obj[i].type.toLowerCase()=="text" || obj[i].type.toLowerCase()=="password" || obj[i].type.toLowerCase()=="select" || obj[i].type.toLowerCase()=="textarea") {
                                                            obj[i].focus();
                                                        }
                                                        
                                                        return false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }    
        
    // if here - all seems ok to submit
    return true;
}
/**************************************************************/

/**************************************************************
 * @function validateInput
 * @description validates an element of the form, *element
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (object) obj, (object) objVal, (object) objReq, (object) objX
 * @return boolean true|false
 **************************************************************/
function validateInput(obj, objVal, objReq, objX) {
//function validateInput(obj, objVal, objX) {
    /** 
     * space = 32
     * !"#*  = 33-43
     * ,     = 44
     * -     = 45
     * .     = 46
     * /     = 47
     * 0-9   = 48-57
     * <?=   = 58-63
     * @     = 64
     * A-Z   = 65-90
     * _     = 95
     * a-z   = 97-122
     * '´    = 145-146
     * ­     = 173
     * ,     = 184
     * ÅÄÖ   = 192-255
     */
    var x;
    var n;
    var val = "";
    var validate = "";
    var charPassed = false;
    
    if(obj) {
        val = obj.value;
    }
    
    //whether or not this field should be validated it's still not necessary to hilite if no value has been written (IF not required)
    if(objReq && val=="") {
        if(""+ objReq.value=="0") {
            return true;
        }
    }    
    
    if(objVal) {
        validate = objVal.value;
    }
    
    if(validate=="text") {
        // text is any kind of input characters with at least one character
        
        if(val.length>0) {
            charPassed = true;
        }
        else {
            charPassed = false;
        }
    }
    else if(validate=="name") {
        // name must be at least two chars and is only characters {a-z} and {A-Z} and some special charactes as { .,-} and blank space
        
        if(val.length>1) {
            for(x=0; x<val.length; x++) {
                n = val.charCodeAt(x);
                
                if(n==32 || n==44 || n==45 || n==46 || (n>=65 && n<=90) || (n>=97 && n<=122) || n==145 || n==146 || n==173 || n==184 || (n>=192 && n<=255)) {
                    charPassed = true;
                }
                else {
                    charPassed = false;
                    break;
                }
            }
        }
    }
    else if(validate=="email") {
        // email must be at least 7 chars and contain {prefix @ domain . topdomain} and no spaces
        if(val.length>6) {
            for(x=0; x<val.length; x++) {
                n = val.charCodeAt(x);
                
                if(n==45 || n==46 || (n>=48 && n<=57) || n==64 || (n>=65 && n<=90) || n==95 || (n>=97 && n<=122) || n==173) {
                    charPassed = true;
                }
                else {
                    charPassed = false;
                    break;
                }
            }
        }
        
        if(val.indexOf("@")<=0) {
            charPassed = false;
        }
        
        if(val.indexOf(".")<=0) {
            charPassed = false;
        }
    }
    else if(validate=="username") {
        // username must be at least four chars and is only characters {a-z} and {A-Z} and some special charactes as {.-} and no blank space
        
        if(val.length>3) {
            for(x=0; x<val.length; x++) {
                n = val.charCodeAt(x);
                
                if((n>=33 && n<=90) || n==95 || (n>=97 && n<=122) || n==173 || n==184) {
                    charPassed = true;
                }
                else {
                    charPassed = false;
                    break;
                }
            }
        }
    }
    else if(validate=="password") {
        // password is special characters like {@#$%&?+-!_} and characters between {a-z} and {A-Z} and numbers between {0-9} and no spaces
        
        if(val.length>3) {
            for(x=0; x<val.length; x++) {
                n = val.charCodeAt(x);
                
                if((n>=33 && n<=90) || n==95 || (n>=97 && n<=122) || n==173 || n==184) {
                    charPassed = true;
                }
                else {
                    charPassed = false;
                    break;
                }
            }
        }
    }
    else if(validate=="password (confirm)" || validate=="password_confirm") {
        // password_confirm must match password in same form to be included as param
        
        if(objX) {
            if(objX.value==val) {
                return true;
            }
        }
    }
    else if(validate=="socialnumber") {
        var year = 10;
        var month = 10;
        var day = 10;
        var sep = "";
        var p1 = 0;
        var p2 = 0;
        var p3 = 0;
        var p4 = 0;
        var sum = 0;
        var s = new Array();

        if(val) {
            /* we have a value */
            if(isNaN(val.replace(/-/g, ""))==false) {
                /* value is numeric (check without the '-') */

                if(val.length==13) {
                    /* correct validation length (19710101-0101), no edit necessary */
                }
                else if(val.length==12) {
                    /* not correct validation length, assume it's without the '-' */
                    return false;
                }
                else if(val.length==11) {
                    /* not correct validation length, assume it's without the starting year as eg.19 or 20 */
                    return false;
                }
                else if(val.length==10) {
                    /* not correct validation length, assume it's without the starting year as eg.19 or 20 and also without the "-" */
                    return false;
                }

                year = val.substring(2, 4);
                month = val.substring(4, 6);
                day = val.substring(6, 8);
                sep = val.substring(8, 9);
                p1 = val.substring(9, 10);
                p2 = val.substring(10, 11);
                p3 = val.substring(11, 12);
                p4 = val.substring(12, 13);

                if((isNaN(year)==false) && (isNaN(month)==false) && (isNaN(day)==false)) {
                    if((val.charCodeAt(8)==45) || (val.charCodeAt(8)==173)) {
                        if((isNaN(p1)==false) && (isNaN(p2)==false) && (isNaN(p3)==false) && (isNaN(p4)==false)) {
                            s[0] = parseInt(year.substring(0, 1))*2;
                            s[1] = parseInt(year.substring(1, 2))*1;
                            s[2] = parseInt(month.substring(0, 1))*2;
                            s[3] = parseInt(month.substring(1, 2))*1;
                            s[4] = parseInt(day.substring(0, 1))*2;
                            s[5] = parseInt(day.substring(1, 2))*1;
                            s[6] = parseInt(p1)*2;
                            s[7] = parseInt(p2)*1;
                            s[8] = parseInt(p3)*2;

                            for(var i=0; i<s.length; i++) {
                                if(s[i]>=10) {
                                    s[i] = ""+ s[i];
                                    sum = parseInt(parseInt(sum) + parseInt(s[i].substring(0, 1)) + parseInt(s[i].substring(1, 2)));
                                }
                                else {
                                    sum = parseInt(parseInt(sum) + parseInt(s[i]));
                                }
                            }

                            if((parseInt(sum)%10)>0) {
                                sum = parseInt(10-(parseInt(sum)%10));
                            }
                            else {
                                sum = parseInt(sum)%10;
                            }
                        }
                    }
                }
            }
        }

        if(parseInt(sum)==parseInt(p4)) {
            charPassed = true;
        }
        else {
            charPassed = false;
        }
    }
    else if(validate=="address") {
        // address is any kind of input characters with at least 1 character
        
        if(val.length>0) {
            charPassed = true;
        }
        else {
            charPassed = false;
        }
    }
    else if(validate=="number") {
        // number must be any combination of numbers {0-9}
        
        for(x=0; x<val.length; x++) {
            n = val.charCodeAt(x);
                
            if(n>=48 && n<=57) {
                charPassed = true;
            }
            else {
                charPassed = false;
                break;
            }
        }
    }
    else if(validate=="phone") {
        // phone must be any combination of numbers {0-9} and space and "-"
        if(val.length>4) {
            /*for(x=0; x<val.length; x++) {
                n = val.charCodeAt(x);
                
                if((n>=48 && n<=57) || n==32 || n==45 || n==173) {
                    charPassed = true;
                }
                else {
                    charPassed = false;
                    break;
                }
            }*/
            
            //new setting not allowing " ", "-", or "(" and ")". only numbers and not starting with 00 or + as for foreign numbers
            if(val.charCodeAt(0)==48 && val.charCodeAt(1)==48) {
                charPassed = false;
            }
            else {    
                for(x=0; x<val.length; x++) {
                    n = val.charCodeAt(x);
                    
                    if((n>=48 && n<=57) || n==45 || n==173) {
                        charPassed = true;
                    }
                    else {
                        charPassed = false;
                        break;
                    }
                }
            }
        }
    }
    else if(validate=="zipcode") {
        // zipcode must be a combination of 5 to 6 numbers with one space at either 4th position if 6 characters or at 7th position if 8 characters
        
        if(val.length>4) {
            for(x=0; x<val.length; x++) {
                n = val.charCodeAt(x);
                
                if((n>=48 && n<=57) || n==32) {
                    charPassed = true;
                }
                else {
                    charPassed = false;
                    break;
                }
            }
        }
    }
    else if(validate=="boolean") {
        // boolean must be either {yes|ja|1|true} or {no|nej|0|false}
        
        if(val.toLowerCase()=='yes' || val.toLowerCase()=='ja' || parseInt(val.toLowerCase())==1 || val.toLowerCase()==true) {
            charPassed = true;
        }
    }
    else if(validate=="single") {
        // single must be one number between {0-9}
        
        if(val.length==1) {
            if(NaN(val)==false) {
                charPassed = true;
            }
        }
    }
    else if(validate=="radiobuttongroup") {
        // radiobuttongroup should allready be handled in main validation check
        
        //so... return ok
        charPassed = true;
    }
    else if(validate=="radio" || validate=="radiobutton") {
        // radio or radiobutton should be checked for marked if not within a group and set to validation as radio or radiobutton
        
        //so... if not marked, it's not handled either, return true anyways
        charPassed = true;
    }
    else if(validate=="checkbox") {
        // checkbox should be checked for marked if not within a group and set to validation as checkbox
        
        //so... if not checked, it's not handled either, return true anyways
        charPassed = true;
    }
    else if(validate=="file") {
        // file is to be checked for a valid extension
        /*
        if(val!="") {
            var sf = val.substring(parseInt(val.length)-4, parseInt(val.length)).toLowerCase();
            
            if(sf==".jpeg"||sf==".jpg"||sf==".gif"||sf==".gif"||sf==".bmp"||sf==".png"||sf==".pdf"||sf==".doc"||sf==".xls"||sf==".txt"||sf==".wmv"||sf==".avi"||sf==".wma"||sf==".mov"||sf==".3gp"||sf==".mpg"||sf==".mpeg"||sf==".mp3") {
                charPassed = true;
            }
        }
        else {
            charPassed = true;
        }*/
        charPassed = true;
    }
    else if(validate=="match()") {
        // match( - matching text - ) is to be checked for any matching occurences of text like spelled within parenthesis 
        
        charPassed = true;
    }
    else if(validate=="no validation") {
        // dont validate this
        charPassed = true;
    }
    else {
        // not a handled input, will cause a false return
        charPassed = false;
    }
    
    // if here - check if ok
    if(charPassed) {
        return true;
    }
    else {
        return false;
    }
}
/**************************************************************/

/**************************************************************
 * @function openNewWin
 * @description opens a new window
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) url
 * @return none
 **************************************************************/
function openNewWin(url) {
    if(url!='http://'&&url!='') {
        window.open(url);
    }
}
/**************************************************************/

/**************************************************************
 * @function openNewWin
 * @description opens a new window
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) url
 * @return none
 **************************************************************/
function openMp3Win() {
    var w = 280;
    var h = 280;
    
    window.open("mp3", "MP3", "width="+ w +", height="+ h +", top="+ ((screen.availHeight/2)-(h/2)) +", left="+ ((screen.availWidth/2)-(w/2)) +", status=no, statusbar=no, directories=no, dependant=yes, menubar=no, toolbar=no, scrollbars=no, location=no, resizable=no");
}
/**************************************************************/

/**************************************************************
 * @function openCleanWin
 * @description opens a new clean window
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) url
 * @return none
 **************************************************************/
function openCleanWin(url, w, h) {
    if(url!='http://'&&url!='') {
        self.open(url, "", "width="+ w +", height="+ h +", top="+ ((screen.availHeight/2)-(h/2)) +", left="+ ((screen.availWidth/2)-(w/2)) +", status=no, statusbar=no, directories=no, dependant=yes, menubar=no, toolbar=no, scrollbars=no, location=no, resizable=no");
    }
}
/**************************************************************/

/**************************************************************
 * @function openEditWin
 * @description opens a new edit window
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) url
 * @return none
 **************************************************************/
function openEditWin(url, winname, w, h) {
    if(url!='http://'&&url!='') {
        self.open(url, winname, "width="+ w +", height="+ h +", top="+ ((screen.availHeight/2)-(h/2)) +", left="+ ((screen.availWidth/2)-(w/2)) +", status=no, statusbar=no, directories=no, dependant=yes, menubar=no, toolbar=no, scrollbars=1, location=no, resizable=no");
    }
}
/**************************************************************/

/**************************************************************
 * @function openUploadWin
 * @description opens a new upload window
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (string) url
 * @return none
 **************************************************************/
function openUploadWin(url) {
    if(url!='http://'&&url!='') {
        self.open(url, "Upload", "width=480, height=280, top="+ ((screen.availHeight/2)-(280/2)) +", left="+ ((screen.availWidth/2)-(480/2)) +", status=no, statusbar=no, directories=no, dependant=yes, menubar=no, toolbar=no, scrollbars=no, location=no, resizable=no");
    }
}
/**************************************************************/

/**************************************************************
 * @function printWin
 * @description 
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return  
 **************************************************************/
function printWin() {
    self.print(); 
}
/**************************************************************/
 
/**************************************************************
 * @function validateFileName
 * @description validates name of file nad returns the name
 * @author James Palm, jp@interaktionsbolaget.se
 * @param (object) obj
 * @return (string) newVal
 **************************************************************/
function validateFileName(obj) {
    var retVal = "";
    var newVal = "";
    var i = 0;
    var x;
    var n;
    
    if(navigator.userAgent.toLowerCase().indexOf("macintosh")>=0&&(obj.value.toLowerCase().indexOf("/")>=0||obj.value.toLowerCase().indexOf(":")>=0)) {
        retVal = obj.value.toLowerCase();
            
        i = retVal.lastIndexOf("/");
        
        if(i>0) {
            retVal = retVal.substring(i+1, retVal.length);
            
            for(x=0; x<retVal.length; x++) {
                n = retVal.charCodeAt(x);
                
                if((n>=48 && n<=57) || (n>=97 && n<=122) || n==46 || n==95) {
                    newVal += retVal.charAt(x);
                }
            }
        }
        else {
            i = retVal.lastIndexOf(":");
            
            if(i>0) {
                retVal = retVal.substring(i+1, retVal.length);
                
                for(x=0; x<retVal.length; x++) {
                    n = retVal.charCodeAt(x);
                    
                    if((n>=48 && n<=57) || (n>=97 && n<=122) || n==46 || n==95) {
                        newVal += retVal.charAt(x);
                    }
                }
            }
        }
    }
    else {
        if(obj.value!="") {
            retVal = obj.value.toLowerCase();
            
            i = retVal.lastIndexOf("\\");
            
            if(i>0) {
                retVal = retVal.substring(i+1, retVal.length);
                
                for(x=0; x<retVal.length; x++) {
                    n = retVal.charCodeAt(x);
                    
                    if((n>=48 && n<=57) || (n>=97 && n<=122) || n==46 || n==95) {
                        newVal += retVal.charAt(x);
                    }
                }
            }
        }
    }
    
    return newVal;
}
/**************************************************************/

/**************************************************************
 * @function writeBannerTable
 * @description 
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return  
 **************************************************************/
function writeBannerTable(heading, img, url) {
    var banner_target;
    
    if(url!="") {
        if(url.indexOf("?type=")==0) {
            banner_target = "";
        }
        else {
            banner_target = "_blank";
        }
    
        document.write("<table width=\"215\" cellspacing=\"0\" cellpadding=\"0\">");
        document.write("    <tr>");
        document.write("        <td align=\"center\" valign=\"top\" width=\"215\" style=\"padding-bottom: 3px;\">");
        document.write("            <a href=\""+ url +"\" target=\""+ banner_target +"\">");
        document.write("                <img alt=\""+ heading +"\" hspace=\"0\" vspace=\"0\" border=\"0\" src=\""+ img +"\"/>");
        document.write("            </a>")
        document.write("        </td>");
        document.write("    </tr>");
        document.write("</table>");
    }
 }
/**************************************************************/

/**************************************************************
 * @function showSelect
 * @description 
 * @author James Palm, jp@interaktionsbolaget.se
 * @param 
 * @return  
 **************************************************************/
function showSelect(mode) {
    var selectBoxes = document.getElementsByTagName("select");
    var show = document.layers ? "show" : "visible";
    var hide = document.layers ? "hide" : "hidden";
    
    for(i=0; i<selectBoxes.length; i++) 
        selectBoxes[i].style.visibility = mode ? show : hide;
}
/**************************************************************/

/**************************************************************
 * @function xhref
 **************************************************************/
function xhref(strHref, strTarget, aData, strXsl, strRefObjId) {
    var x;
    var tmp;
    
    if(typeof(aData)=="string") {
        if(aData.indexOf("&amp;")>0) {
            aData = aData.replace(/&amp;/g, "&");
            aData = aData.replace(/undefined/g, "");
        }
        
        if(aData.indexOf("=")>0) {
            var tmp = new Array();
            tmp.push(aData);
            xhref(strHref, strTarget, tmp, strXsl, strRefObjId);
            return;
        }
    }
    
    if(strHref!="" && strHref.indexOf("http://")<0) {
        strHref = "http://"+ document.domain +"/"+ strHref;
    }
    
    if(strXsl!="" && strXsl.indexOf("http://")<0) {
        strXsl = "http://"+ document.domain +"/"+ strXsl;
    }
    
    if(strTarget==null || strTarget=="" || strTarget=="_self" || strTarget=="_upload" || strTarget=="upload" || strTarget=="_hidden" || strTarget=="hidden" || strTarget=="_byref" || strTarget=="byref" || strTarget=="debug" || strTarget=="_debug") {
        if((strTarget=="_hidden" || strTarget=="hidden") && (strRefObjId=="_hidden" || strRefObjId=="hidden")) {
            x = new XmlHttpRequest("_hidden", null, strXsl);
        }
        else if((strTarget=="_byref" || strTarget=="byref") && (strRefObjId=="_byref" || strRefObjId=="byref")) {
            x = new XmlHttpRequest("_byref", strRefObjId, strXsl);
        }
        else if((strTarget=="_debug" || strTarget=="debug") && (strRefObjId=="_debug" || strRefObjId=="debug")) {
            x = new XmlHttpRequest("_debug", null, strXsl);
        }
        else if(strRefObjId!="") {
            x = new XmlHttpRequest(strTarget, getObj(strRefObjId), strXsl);
        }
        else {
            x = new XmlHttpRequest(strTarget, null, strXsl);
        }
        
        x.async = true;
        x.url = strHref;
        
        if(strTarget=="_upload") {
            x.content_type = "multipart/form-data";
        }
        
        if(aData!=null) {
            x.method = "POST";
            
            if(aData.length>0) {
                for(var i=0; i<aData.length; i++) {
                    aData[i] = aData[i].replace(/&amp;/g, "&");
                    
                    if(i>0) {
                        x.data += "&"+ aData[i];
                    }
                    else {
                        x.data += aData[i];
                    }
                }
            }
        }
        else {
            x.method = "GET";
        }
        
        x.load();
    }
    else if(strTarget=="_top") {
        top.document.location = strHref;
    }
    else if(strTarget=="_new" || strTarget=="_blank") {
        self.open(strHref);
    }
    else {
        document.location = strHref;
    }
}
/**************************************************************/

/**************************************************************
 * @function XmlHttpRequest
 **************************************************************/
function XmlHttpRequest(mode, refObj, strRefXsl) {
    var xmlHttp = null;
    var strResponseText;
    var strOut;
    
    this.async = true;
    this.method = "GET";
    this.url = "";
    this.data = "";
    this.content_type = "application/x-www-form-urlencoded";
    
    if(window.ActiveXObject) {
        xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
        
        if(typeof(xmlHttp)=="object") {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    else {
        xmlHttp = new XMLHttpRequest();
    }
    
    this.load = function() {
        if(xmlHttp && this.url!="") {
            xmlHttp.onreadystatechange = process;
        
            if(this.method.toUpperCase()=="POST") {
                xmlHttp.open("POST", this.url, this.async);
                xmlHttp.setRequestHeader("Content-Type", this.content_type);
                xmlHttp.send(this.data);
            }
            else {
                xmlHttp.open("GET", this.url, this.async);
                xmlHttp.send(null);
            }
        }
    };
    
    function process() {
        var xmlDom = null;
        var xslDom = null;
        var strMsg = "";
        var strOut = "";
        
        if(xmlHttp.readyState==4) { 
            if(xmlHttp.status!=200) {
                alert("Error code "+ xmlHttp.status +": "+ xmlHttp.statusText);
            }
            else {
                if(strRefXsl!="") {
                    strResponseXml = xmlHttp.responseXml;
                    
                    if(window.ActiveXObject) {
                        xmlDom = new ActiveXObject("MSXML2.DOMDocument");
                        xslDom = new ActiveXObject("MSXML2.DOMDocument");
                        
                        if(typeof(xmlDom)!="object") {
                            xmlDom = new ActiveXObject("Microsoft.DOMDocument");
                            xslDom = new ActiveXObject("Microsoft.DOMDocument");
                        }
                    }
                    else {
                        xmlDom = new DOMDocument();
                        xslDom = new DOMDocument();
                    }
                    
                    if(typeof(xmlDom)=="object") {
                        try {
                            xmlDom.loadXML(strResponseXml);
                            xslDom.load(strRefXsl);
                        }
                        catch(e) {}
                    }
                    
                    if(typeof(xmlDom)=="object") {
                        try {
                            strOut = xmlDom.transformNode(xslDom);
                        }
                        catch(e) {}
                    }
                    
                    if(strOut=="") {
                        alert("Error: transform error");
                    }
                    else {
                        if(mode=="_hidden") {
                            /* hidden, not viewable output */
                        }
                        else if(mode=="_byref") {
                            objXmlHttpRequestRetVal = strOut;
                        }
                        else if(refObj=="_debug") {
                            /* debug, alert output */
                            alert("@DEBUG: "+ strOut);
                        }
                        else if(refObj!=null && refObj!="" && refObj!="undefined") {
                            refObj.innerHTML = strOut;
                        }
                        else {
                            if(strOut!=null && strOut!="undefined") {
                                document.write(strOut);
                            }
                            else {
                                document.write("data not available");
                            }
                        }
                    }
                }
                else {
                    strResponseText = ""+ xmlHttp.responseText;
                
                    if(mode=="_hidden") {
                        /* hidden, not viewable output */
                    }
                    else if(mode=="_byref") {
                        refObj = strResponseText;
                    }
                    else if(mode=="_debug") {
                        /* debug, alert output */
                        alert("@DEBUG: "+ strResponseText);
                    }
                    else if(refObj!=null && refObj!="" && refObj!="undefined") {
                        refObj.innerHTML = strResponseText;
                    }
                    else {
                        if(strResponseText!=null && strResponseText!="undefined") {
                            document.write(strResponseText);
                        }
                        else {
                            document.write("data not available");
                        }
                    }
                }
            }
        }
    };
}
/**************************************************************/