var actPopUp;
var actPopUpPosition;

function showLanguageList(elem){
    document.getElementById(elem).style.backgroundPosition = "0 0";
}

function hideLanguageList(elem){
    document.getElementById(elem).style.backgroundPosition = "0 190%";
}

function showSalutationList(elem){
    document.getElementById(elem).style.backgroundPosition = "0 0";
}

function hideSalutationList(elem){
    document.getElementById(elem).style.backgroundPosition = "0 100%";
}

function toggleCheckbox(elem){
    document.getElementById(elem).className = document.getElementById(elem).className == "checkbox" ? "checkboxChecked" : "checkbox";
    $("input[name=" + elem + "]").val(document.getElementById(elem).className == "checkboxChecked" ? "on" : "off");
}

function toggleCheckboxCart(elem){
    document.getElementById(elem).className = document.getElementById(elem).className == "checkboxCart" ? "checkboxCartChecked" : "checkboxCart";
    $("input[name=" + elem + "]").val(document.getElementById(elem).className == "checkboxCartChecked" ? "checked" : "");
}

function toggleCheckboxCartAll(elem){
    document.getElementById(elem).className = document.getElementById(elem).className == "checkboxCart" ? "checkboxCartChecked" : "checkboxCart";
    var val = document.getElementById(elem).className == "checkboxCartChecked" ? "checked" : "";
    $("input[name=" + elem + "]").val(val);

    if(elem=='col_all') {
        $('div[id^=row_all]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_all]').val(val);
    };

    if(elem=='col_1_all') {
        $('div[id^=row_1_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_1_]').val(val);
    };

    if(elem=='col_2_all') {
        $('div[id^=row_2_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_2_]').val(val);
    };

    if(elem=='col_3_all') {
        $('div[id^=row_6_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_6_]').val(val);
    };

    if(elem=='col_4_all') {
        $('div[id^=row_5_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_5_]').val(val);
        $('div[id^=row_10_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_10_]').val(val);
    };

    if(elem=='col_5_all') {
        $('div[id^=row_3_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_3_]').val(val);
        $('div[id^=row_4_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_4_]').val(val);
        $('div[id^=row_8_]').attr("class", val=='checked' ? "checkboxCartChecked" : "checkboxCart");
        $('input[name^=row_8_]').val(val);
    };
}

function toggleCheckboxBig(elem){
    document.getElementById(elem).className = document.getElementById(elem).className == "checkboxBig" ? "checkboxBigChecked" : "checkboxBig";
    $("input[name=" + elem + "]").val(document.getElementById(elem).className == "checkboxBigChecked" ? "true" : "false");
}

function clearValue(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function togglePopUp(elem){
    closePopUp();
    document.getElementById(elem).style.display = "block";
    actPopUp = elem;
}

var pdfURL;

function conditionsPopUp(elem, url, counter){
    closePopUp();
    document.getElementById("conditions_"+counter).checked = false;
    document.getElementById("butOk_"+counter).disabled = true;
    document.getElementById("butOk_"+counter).className = 'saveButDisabled';
    document.getElementById(elem).style.display = "block";
    actPopUp = elem;
    pdfURL = url;
}

function conditionsChecked(elem, counter){
    document.getElementById("butOk_"+counter).disabled = !document.getElementById(elem).checked;
        if (document.getElementById(elem).checked) {
            document.getElementById("butOk_"+counter).className = 'saveBut';
        } else {
            document.getElementById("butOk_"+counter).className = 'saveButDisabled';
        }
}

function openArticlePopup(modelId, artId, view, type, counter) {
    closePopUp();
    $("#popUp2_"+counter).load('popup.jsp?modelId=' + modelId + '&artId=' + artId + '&view=' + view + "&type=" + type + '&counter=' + counter, function() {
        $("#popUp2_"+counter).show();
        actPopUp = "#popUp2_"+counter;
//        alert(actPopUp);
    })
}

function openArticlePopupWhenOpened(modelId, artId, view, type, counter) {
    $("#popUp2_"+counter).load('popup.jsp?modelId=' + modelId + '&artId=' + artId + '&view=' + view + "&type=" + type + '&counter=' + counter, function() {
        $("#popUp2_"+counter).show();
        actPopUp = "#popUp2_"+counter;
    })
}

function closePopUp(){
    try {
        if(actPopUp!=null){
            $(actPopUp).hide();
        }
//        document.getElementById(elem).style.display = "none";
    } catch(err) {}
    try {
        if(actPopUp!=null){
            document.getElementById(actPopUp).style.display = "none";
//            document.getElementById(actPopUp).style.display = "none";
        }
    } catch(err) {}
}

function setPosition(elem){
//    alert(actPopUpPosition);
    clearPosition();
    document.getElementById(elem).style.position = "relative";
    actPopUpPosition = elem;
//    alert(actPopUpPosition);
}

function clearPosition(){
    try {
        if(actPopUpPosition!=null){
            document.getElementById(actPopUpPosition).style.position = "";
        }
    } catch(err) {}

}

function showMoreColors(counter){
    $("#moreColors_" + counter).slideDown("slow");
}

////create onDomReady Event
//      window.onDomReady = initReady;
//
//      // Initialize event depending on browser
//      function initReady(fn)
//      {
//      	//W3C-compliant browser
//      	if(document.addEventListener) {
//          document.addEventListener("DOMContentLoaded", fn, false);
//        }
//      	//IE
//      	else {
//          document.onreadystatechange = function(){readyState(fn)}
//        }
//      }
//
//      //IE execute function
//      function readyState(func)
//      {
//      	// DOM is ready
//      	if(document.readyState == "interactive" || document.readyState == "complete")
//      	{
//      		func();
//      	}
//      }

//execute as soon as DOM is loaded
//window.onDomReady(onReady);

//do when DOM is ready
//function onReady()
//{
//	getImgSize();
//}

//function getImgSize(){
//    $(document).ready(function(){
//
//              $(".thumbList ul li img").each(function() {
//
//               //Get the width of the image
//               var width = $(this).width();
//               var height = $(this).height();
////               alert(width);
//               //Max-width substitution (works for all browsers)
//                  if(width > 129){
//
//                            $(this).css("width", "38px");
////                            alert("w"+width);
//
//                  }else if(height > 39){
//                      $(this).css("height", "38px");
////                            alert("h"+height);
//                  }
//
//
//             });
//
//           });
//
//}
