﻿// JScript File

//Reads querystrings
function readQs( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}
//get element coordinates
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        return [curleft,curtop];
    }
}


//headerTag
function headerTagInit(){
    var myImg = document.getElementById("headerTag");
    var show = false;
    if (myImg != null){
        var cords = findPos(document.getElementById("homeContent"))
        myImg.style.left=cords[0]+"px"
        var groups = readQs("group")
        if (groups !=""){
            show = true;
            switch(groups){
                case "1":
                    myImg.src="/images/headerTag/tag_als_spring.gif";
                    break;
                case "2":
                    myImg.src="/images/headerTag/tag_als_summer.gif";
                    break;
                case "3":
                    myImg.src="/images/headerTag/tag_als_hotsummer.gif";
                    break;
                case "4":
                    myImg.src="/images/headerTag/tag_als_earlyfall.gif";
                    break;
                case "5":
                    myImg.src="/images/headerTag/tag_als_fall.gif";
                    break;
                case "6":
                    myImg.src="/images/headerTag/tag_als_earlywinter.gif";
                    break;
                case "7":
                    myImg.src="/images/headerTag/tag_als_winter.gif";
                    break;
                case "8":
                    myImg.src="/images/headerTag/tag_als_winter.gif";
                    break;
            }
            if (window.location.href.indexOf("/en/") != -1){
                myImg.src.replace(".gif", "_1.gif")
                show = true;
            }
            if (window.location.href.indexOf("/de/") != -1){
                myImg.src=myImg.src.replace(".gif", "_3.gif")
                show = true;
            }
        }
        var tags = readQs("tag");
        if (tags!=""){
//            tags = tags.split(",");
//            for(i =0; i<tags.length;i++){
//                switch (tags[i]){
//                    case "Early_Winter":
//                        if parent.document.url.indexOf("/en/")>0
//                            myImg.src="/images/headerTag/tag_als_earlywinter_1.gif";
//                        if parent.document.url.indexOf("/de/")>0
//                            myImg.src="/images/headerTag/tag_als_earlywinter_3.gif";
//                        show = true;
//                    continue;
//                    case "Early_Fall":
//                        myImg.src="/images/headerTag/tag_als_earlyfall.gif";
//                        show = true;
//                    continue;
//                    case "Fall":
//                        myImg.src="/images/headerTag/tag_als_fall.gif";
//                        show = true;
//                    continue;
//                    case "Spring":
//                        if (window.location.href.indexOf("/en/") != -1){
//                            myImg.src="/images/headerTag/tag_als_spring_1.gif";
//                            show = true;
//                        }
//                        if (window.location.href.indexOf("/de/") != -1){
//                            myImg.src="/images/headerTag/tag_als_spring_3.gif";
//                            show = true;
//                        }
//                    continue;
//                }
//            }
        }else{
            var categories = readQs("cat");
            categories = categories.split(",");
            sex =0
            for(i =0; i<categories.length;i++){
                if (categories[i] == 6)
                    sex=1
                if (categories[i]== 7)
                    sex=2            
                switch (categories[i]){
                    case "19":
                        if (sex==2){
                            myImg.src="/images/headerTag/ctw_f.gif";
                            show = true;
                        }else{
                            myImg.src="/images/headerTag/ctw_m.gif";
                            show = true;
                        }
                        continue;
                    case "20":
                        if (sex==2){
                            myImg.src="/images/headerTag/db_f.gif";
                            show = true;
                        }else{
                            myImg.src="/images/headerTag/db_m.gif";
                            show = true;
                        }
                        continue;
                }
                if (categories[i]== 58){
                    if (sex==2){
                        myImg.src="/images/headerTag/ltd_f.gif";
                        show = true;
                    }else{
                        myImg.src="/images/headerTag/ltd_m.gif";
                        show = true;
                    }
                }
            }
        }
        if (show)
            myImg.style.display="block";
        else
            myImg.style.display="none"; 
    } 
}

function setMale(isMale){
    var menu1st = document.getElementById("menu1st");
    var menu2nd = document.getElementById("menu2nd");
    var menu3d = document.getElementById("menu3d");
    var notSelected = "#F5CADE"
    var Selected = "#EE99C0"
    if (isMale == true){
        if (menu1st.className == "Selected female"){
            menu1st.className = "Selected"
        }
        if (menu1st.className == "notSelected female"){
            menu1st.className = "notSelected"
        }
        if (menu2nd.className == "Selected female"){
            menu2nd.className = "Selected"
        }
        if (menu2nd.className == "notSelected female"){
            menu2nd.className = "notSelected"
        }
        if (menu3d.className == "Selected female"){
            menu3d.className = "Selected"
        }
        if (menu3d.className == "notSelected female"){
            menu3d.className = "notSelected"
        }
        notSelected = "#D7D7D7"
        Selected = "#000000"
    }else{
        if (menu1st.className == "Selected"){
            menu1st.className = "Selected female"
        }
        if (menu1st.className == "notSelected"){
            menu1st.className = "notSelected female"
        }
        if (menu2nd.className == "Selected"){
            menu2nd.className = "Selected female"
        }
        if (menu2nd.className == "notSelected"){
            menu2nd.className = "notSelected female"
        }
        if (menu3d.className == "Selected"){
            menu3d.className = "Selected female"
        }
        if (menu3d.className == "notSelected"){
            menu3d.className = "notSelected female"
        }
        notSelected = "#F5CADE"
        Selected = "#EE99C0"
    }
    var menuBottomInfo = document.getElementById("MenuBottomInfo");
    var productsHeader = document.getElementById("productsHeader");
    menuBottomInfo.style.borderColor = notSelected;
    if (productsHeader != null)
        productsHeader.style.borderTopColor = Selected;
}

function imageSwitch(myId, newPic){
    //    var imagesContainer = document.getElementById("productImageContainer").firstChild.nextSibling
    var imagesContainer = $('#productImageContainer').children()[0]
    var id = imagesContainer.id+"_a"+myId
    var thisChild = imagesContainer.firstChild;
    var toContinue = true
    var toLoop = true
    while ( toLoop ){
        if(toContinue==false)
            toLoop=false;
        if ( thisChild.style.display == "" ){
            $("#"+thisChild.id).fadeOut("slow");
        }
        if ( thisChild.id == id ){
            var toShow = thisChild.id
            document.getElementById("imageFake").src=newPic
            $("#"+toShow).fadeIn("slow");
        }
        thisChild = thisChild.nextSibling;
        if(thisChild == imagesContainer.lastChild)
            toContinue=false;
    }
//switches borders
    //    var imgPrev = document.getElementById("productImageContainer").firstChild.nextSibling
    var imgPrev = $('#productImageContainer').children()[0]
    id =imgPrev+"_b"+myId;
    thisChild = imgPrev.firstChild;
    toContinue = true
    toLoop = true
    while ( toLoop ){
        if(toContinue==false)
            toLoop=false;
        if ( thisChild.className == "imgSelected" ){
            thisChild.className = "imgNotSelected"
        }
        if ( thisChild.id == id ){
            thisChild.className = "imgSelected" 
        }
        thisChild = thisChild.nextSibling;
        if(thisChild == imgPrev.lastChild)
            toContinue=false;
    }
}

//admin shop_orders
function changeMailStatus(id){
    var toChange = document.getElementById(id);
    if (document.getElementById("c"+id).checked == true){
        toChange.href=toChange.href.replace("&mail=False", "&mail=True");
    }else{
        toChange.href=toChange.href.replace("&mail=True", "&mail=False");
    }
}

function showComments(){
    var divContainer = document.getElementById("commentsSection");
    if (divContainer.style.display == "none")
        divContainer.style.display = "block";
    else if (divContainer.style.display == "block")
        divContainer.style.display = "none";
}

function showMe(me,id){
    var item = document.getElementById(id)
    if (me.checked == true){
        $('#' + id ).animate({
            height: "show",
            opacity: "show"
        }, 500);
        document.getElementById("ctl00_Zone2_23_shippingCountrys").options[0].selected=true
    }else{
        $('#' + id ).animate({
            height: "hide",
            opacity: "hide"
        }, 500);
        if ((document.getElementById("ctl00_Zone2_23_shippingCountrys").selectedIndex != document.getElementById("ctl00_Zone2_23_Country").selectedIndex) && document.getElementById("ctl00_Zone2_23_shippingCountrys").selectedIndex != 0)
            setTimeout('__doPostBack(\'ctl00$Zone2$23$Country\',\'\')', 0)
    }
}