// JavaScript Document

function showHideLayerSearch(hideElement, showElement, showElementError) {
    if (document.getElementById(hideElement) != null) 
	    document.getElementById(hideElement).className = hideElement + " hideLayer";
	if (document.getElementById(showElement) != null) 
	    document.getElementById(showElement).className = showElement + " showLayer";
}

var mbOn = null;
var sbOn = null;
var musicClass = "music";
var sportClass = "sport";

function mbRollOver(oDiv) {
    mbOn = oDiv;
    RollOver(oDiv, musicClass);
}
function mbRollOut(oDiv) {    
    RollOut(oDiv, musicClass);
}
function mmRollOut() {
    if (mbOn) { 
        selBox(mbOn, musicClass);
    }
}
function sbRollOver(oDiv) {
    sbOn = oDiv;
    RollOver(oDiv, sportClass);
}
function sbRollOut(oDiv) {    
    RollOut(oDiv, sportClass);
}
function smRollOut() {
    if (sbOn) { 
        selBox(sbOn, sportClass);
    }
}

function RollOver(oDiv, clsName) {
    revertAll(clsName);
    selBox(oDiv, clsName);
}
function RollOut(oDiv, clsName) {
    oDiv.className = "box";    
    document.getElementById(clsName + "Bot").innerHTML = "";
}

function selBox(oDiv, clsName) {
    if (!oDiv) return;
    oDiv.className = "boxOn";
    //$get(oDiv.id + "-txt").style.display = none;
    //$get(oDiv.id + "-img").style.display = block;
    document.getElementById(clsName + "Bot").innerHTML = document.getElementById(oDiv.id + "-bot").innerHTML;    
}
function revertAll(clsName) {
  var divs = document.getElementById(clsName + "Main").getElementsByTagName("div");
  for (var i = 0; i < divs.length; i++) {
    if (divs[i].className == "boxOn") {
      divs[i].className = "box";
    }
  }
}

function homeLoad() {
    if (document.getElementById("mb1") != null) selBox(document.getElementById("mb1"), musicClass);
    if (document.getElementById("sb1") != null) selBox(document.getElementById("sb1"), sportClass);
}

function clickOffer() { /* click event on offer, in right side*/

}

function clickTicket() { /* click event on ticket, 20-DEFP ingelogd_profiel_access_card*/

}

function fold(obj, bExpanded) { //bExpanded = true (expand info), bExpanded = false (collapse info)
    if (obj == null || obj == "undefined") return false;
    var bExpand = false;
    if (bExpanded == null || bExpanded == "undefined" || typeof(bExpanded) != "boolean") {
        bExpand = true;
    } else {
        bExpand = bExpanded;
    }
    
    var trRowId = "";
    var trInfoId = "";
    var oOpenDataId = "";
    var oId = obj.id;
    
    if (bExpand) {
        trRowId = oId.replace("open", "row");
        trInfoId = oId.replace("open", "info");
        oOpenDataId = oId.replace("open", "close");
    } else {
        trRowId = oId.replace("close", "row");
        trInfoId = oId.replace("close", "info");
        oOpenDataId = oId.replace("close", "open");        
    }
    obj.style.display = "none";
    document.getElementById(oOpenDataId).style.display = "block";
    
    if (document.getElementById(trRowId) != null) {
        var sTrClass = document.getElementById(trRowId).className;
        if (bExpand) {
            sTrClass = sTrClass + " sel";
        } else {
            sTrClass = sTrClass.replace("sel", "");
        }        
        document.getElementById(trRowId).className = sTrClass;        
    }
    if (document.getElementById(trInfoId) != null) {
        var sClass = document.getElementById(trInfoId).className;
        if (bExpand) {
            sClass = sClass + " showRow";
        } else {
            sClass = sClass.replace(" showRow", "");
        }
        document.getElementById(trInfoId).className = sClass;
    }       
}

function clickFAQ(aId) {
    var oQtxt = document.getElementById("txt-" + aId);
    if (oQtxt == null || oQtxt == undefined) { return false; }
    if (oQtxt.style.display == "block") {
        oQtxt.style.display = "none";
    } else {
        oQtxt.style.display = "block";
    }
}

// Account data functions
function hideEl(id) {
    if (document.getElementById(id) != null)
	    document.getElementById(id).style.display = 'none';
}
function showEl(id) {
    if (document.getElementById(id) != null)
	    document.getElementById(id).style.display = 'inline';
}
function showBlockEl(id) {
    if (document.getElementById(id) != null)
	    document.getElementById(id).style.display = 'block';
}

function editMail(obj, txtId) {
    if (obj != null)
    //editMode(obj);
    editModeBlock(obj);
    if (document.getElementById("reEmail") != null)
        document.getElementById("reEmail").className = "showRow";

    hideEl(txtId);
    showEl(txtId.replace("txt", "inp"));
}

function saveMail(obj) {	
    if (document.getElementById("reEmail") != null)	
        document.getElementById("reEmail").className = "hideLayer";
    if (obj != null)	
        saveMode(obj);
}

function editPass(obj) {	
    editMode(obj);
    document.getElementById("rePass").className = "showRow";
}
function savePass(obj) {	
    document.getElementById("rePass").className = "hideLayer";
    saveMode(obj);
}
function editMode(obj){	
    if (obj == null || obj == undefined) return false;
    var sId = obj.id;
        
    hideEl(sId);
    showEl(sId.replace("edit", "save"));
    hideEl(sId.replace("edit", "txt"));
    showEl(sId.replace("edit", "inp"));
}

function editModeBlock(obj) {
    if (obj == null || obj == undefined) return false;
    var sId = obj.id;
    var sIdSave = sId.replace("edit", "save");
    hideEl(sId);
    
    //showEl(sId.replace("edit", "save"));

    if (document.getElementById(sIdSave) != null)
        document.getElementById(sIdSave).className = "btn bStorage";
    
    hideEl(sId.replace("edit", "txt"));
    showEl(sId.replace("edit", "inp"));
}

function saveMode(obj){
    if (obj == null || obj == undefined) return false;
    var sId = obj.id;
    hideEl(sId);
    showEl(sId.replace("save", "edit"));    
    
    var sInpId = sId.replace("save", "inp");
    var sTxtId = sId.replace("save", "txt");
    //TO DO: field value validation
    if (document.getElementById(sInpId).getElementsByTagName("INPUT").length > 0) {
        document.getElementById(sTxtId).innerHTML = document.getElementById(sInpId).getElementsByTagName("INPUT")[0].value;    
    }
    hideEl(sInpId);
    showEl(sTxtId);
}

function saveSex(obj) {
    if (typeof(obj) == "object") {
        var inpId = obj.id.replace("save","inp");
        var txtId = obj.id.replace("save","txt");
        if (typeof(document.getElementById(inpId)) === "object") {
            var val = 0;
            var collRadio = document.getElementById(inpId).getElementsByTagName("INPUT");
            for (i = 0; i < collRadio.length; i++) {
                if (collRadio[i].checked) {
                    //TO DO: validation
                    document.getElementById(txtId).innerHTML = collRadio[i].value;
                    hideEl(inpId);
                    showEl(txtId); 
                    hideEl(obj.id);
                    showEl(obj.id.replace("save", "edit"));                       
                    break;
                }
            }            
        }
    }
}

function editAdr(obj, bSave) { //bSave = true, if Save button clicked
    if (obj == null || obj == undefined) return false;
    var oId = obj.id;
    var tblId = oId.substring(0, oId.indexOf("-"));
    var oTbl = document.getElementById(tblId).getElementsByTagName("TD");
    
    var sTxtId = "";
    var oTxt = null;
    for (var i=0; i<oTbl.length; i++) {
        if (oTbl[i].className == "fAdr" || oTbl[i].className == "fAdr boxTitle") {
            for (var j=0; j<oTbl[i].childNodes.length; j++) {
                sTxtId = oTbl[i].childNodes[j].id;                
                if (sTxtId != null && sTxtId.indexOf("-txt") != -1) {
                    sInpId = sTxtId.replace("txt", "inp");
                    if (bSave) { // Save
                        //TO DO: field value validation for document.getElementById(sInpId).getElementsByTagName("INPUT")[0].value;
                    
                        hideEl(oId);
                        showEl(oId.replace("save", "edit"));
                        if (document.getElementById(sInpId).getElementsByTagName("INPUT").length > 0) {
                            document.getElementById(sTxtId).innerHTML = document.getElementById(sInpId).getElementsByTagName("INPUT")[0].value;    
                        }
                        hideEl(sInpId);
                        showEl(sTxtId);
                    } else {  // Edit
                        hideEl(oId);
                        showEl(oId.replace("edit", "save"));
                        if (document.getElementById(sInpId).getElementsByTagName("INPUT").length > 0) {
                            document.getElementById(sInpId).getElementsByTagName("INPUT")[0].value = document.getElementById(sTxtId).innerHTML.replace(/ /g,'');;
                        }
                        hideEl(sTxtId);
                        showEl(sInpId);                    
                    }
                    break;
                }                
            }
        }
    }
}
function clearField(el) {
	if (el) {
		el.value = "";
		}
}
// help and alert balloons
function showBalloon(id){
    if (document.getElementById(id) != null)	
        document.getElementById(id).style.display = 'inline';
}
function showAlBalloon(id){
    if (document.getElementById(id) != null)	
        document.getElementById(id).style.display = 'block';
}
function hideBalloon(id){
    if (document.getElementById(id) != null)	
        document.getElementById(id).style.display = 'none';
}
// shop
function showAlb(obj) {	
    if (document.getElementById("moreAlb") != null)	
        document.getElementById("moreAlb").className = "showRow";
    hideEl("moreA")
    showEl("lessA")
}
function hideAlb(obj) {	
    if (document.getElementById("moreAlb") != null)	
        document.getElementById("moreAlb").className = "hideLayer";
    hideEl("lessA")
    showEl("moreA")
}
function showCR(obj) {	
    if (document.getElementById("copyR") != null)	
    {
        document.getElementById("copyR").className = "showRow";
        if(document.getElementById("imageDescription") != null && obj.getAttribute("description") != null)
            document.getElementById("imageDescription").innerHTML = obj.getAttribute("description");
    }
}
function hideCR(obj) {
    if (document.getElementById("copyR") != null)	
        document.getElementById("copyR").className = "hideLayer";
}
function showCont(obj) {//foto container	
    if (document.getElementById("fCont") != null) 
        document.getElementById("fCont").className = "showLayer";
}
function hideCont(obj) {	
    if (document.getElementById("fCont") != null)
        document.getElementById("fCont").className = "hideLayer";
}

//(un)check all checkboxes in container's id=contId
//oAll - checkAll checkbox object
function checkAll(oAll, contId) { 
    var oCont = document.getElementById(contId); 
    if (typeof(oAll) === "object" && typeof(oCont) === "object") {
        var bChecked = oAll.checked;
        var collCB = oCont.getElementsByTagName("INPUT");
        for (var i=0; i<collCB.length; i++) {
            collCB[i].checked = bChecked;
        }
    }
}
//(un)check a checkbox in container's id=contId
//oCB - checkbox object
//allId - id of the 'All' checkbox object
function cbClick(oCB, allId, contId) { 
    var oContAll = document.getElementById(allId); 
    var oCont = document.getElementById(contId); 
    if (typeof(oCB) === "object" && typeof(oContAll) === "object" && typeof(oCont) === "object") {
        var cbAll = oContAll.getElementsByTagName("INPUT")[0]; //instance of 'All' checkbox object
        var bAllChecked = true;
        var bChecked = oCB.checked;
        if (bChecked) {
            var collCB = oCont.getElementsByTagName("INPUT");
            for (var i=0; i<collCB.length; i++) {
                if (!collCB[i].checked) {
                    bAllChecked = false;
                    break;
                }
            }
            if (bAllChecked) {
                cbAll.checked = true;
            } else {
                cbAll.checked = false;
            }
        } else if (cbAll.checked) {
            cbAll.checked = false;
        }
        
    }
}
// login
function showBasketPassword() {
    document.getElementById("basketLogin").className = document.getElementById("basketLogin").className.replace("blLogin", "blPassword");
}

/* Up/Down Counter Control */
    function bUpClick (inpId, intMaxValue) {
        var maxVal = 1000;
        if (intMaxValue != null && typeof(intMaxValue) != undefined )
            maxVal = intMaxValue;
        if (document.getElementById(inpId).value < maxVal)
            document.getElementById(inpId).value++;            
    }
    function bDownClick (inpId, intMinValue) {
        var minVal = 0;
        if (intMinValue != null && typeof(intMinValue) != undefined )
            minVal = intMinValue;
        if (document.getElementById(inpId).value > minVal)
            document.getElementById(inpId).value--;            
    }
/* / Up/Down Counter Control */

function showTT(obj, ev, txt) {
    domTT_activate(obj, ev, 'content', txt, 'type', 'velcro');
}

function EnableDisableAdvSearchDates(checkBox, dateFromId, dateToId)
{
    if(checkBox==null) return;
    
    var dateFrom = DateControl_LoadFromId(dateFromId);
    if(dateFrom==null) return;
    
    var dateTo = DateControl_LoadFromId(dateToId);
    if(dateTo==null) return;

    if(checkBox.checked)
    {
        dateFrom.enable();
        dateTo.enable();
    }
    else
    {
        dateFrom.disable();
        dateTo.disable();
    }
}


function getQS(nam){    
    var q = unescape(location.search.substr(1)).split('&');
    for(var i=0; i<q.length; i++){        
        var t=q[i].split('=');        
        if(t[0].toLowerCase()==nam.toLowerCase()) return t[1];    
    }    
    return '';
}

function newQry(nam,val){    
    var s = "?";
    var q = unescape(location.search.substr(1)).split('&');
    var f = false;
    for(var i=0; i<q.length; i++){        
        var t=q[i].split('=');        
        if(t[0].toLowerCase()==nam.toLowerCase()) { t[1]=val; f=true; } 
        s += t.join('=');   
        if(i<q.length-1) s+='&';
    }    
    if(!f) {
        if(s.length>1) s+='&';
        s+= (nam + '=' + val);
    }
    return s;
}

function OnProductSortChanged(ctl, prmn) {
    if(prmn=="") return;
    var idx = ctl.selectedIndex;
    if(idx==-1) idx=0;
    location.search = newQry(prmn, idx.toString());
}

//overlay popup
function hideOverlayPopup(popupId) {
    if (document.getElementById("updOverlay") != null)
	    document.getElementById("updOverlay").style.display = 'none';
	if (document.getElementById(popupId) != null)
	    document.getElementById(popupId).style.display = 'none';
}

function showOverlayPopup(popupId) {
    if (document.getElementById("updOverlay") != null)
	    document.getElementById("updOverlay").style.display = 'block';
	if (document.getElementById(popupId) != null)
	    document.getElementById(popupId).style.display = 'block';
}


//function showOverlayPopup(popupId) {
//    var overlayObj = document.getElementById("updOverlay");
//    var popupObj = document.getElementById(popupId);
//    if (!overlayObj || !popupObj) return;

//    var ie = document.all ? true : false;
//	var pageScrollTop = (ie) ? document.documentElement.scrollTop : window.pageYOffset

////	var pageSize = GetPageDimensions();

////	overlayObj.style.width = pageSize[0] + "px";
////	overlayObj.style.height = pageSize[1] + "px";

////	var topPositionSum = 300 + pageScrollTop;
////	var topPosition = topPositionSum + "px";

//	// show the popup and the overlay:
//	overlayObj.style.display = 'block';
//	popupObj.style.display = 'block';
////	
////	// set position of the popup:
////	//var popupLeft = '185px'; // default
////	//if (popupContainer.offsetWidth && popupContainer.offsetWidth > 0)
////	//{
////	//	var tmpPopupLeft = (pageSize[0] - popupContainer.offsetWidth) / 2;
////	//	popupLeft = tmpPopupLeft + "px";
////	//}
////	//popupObj.style.left = popupLeft;
////	
////	popupObj.style.top = topPosition;
//	
//}

/* returns page dimentions: */
function GetPageDimensions()
{
	var yScroll = 0;
	var xScroll = 0;

	// firefox:
  	if (window.innerHeight && window.scrollMaxY)
  	{	
		yScroll = window.innerHeight + window.scrollMaxY + 4;
		xScroll = window.innerWidth + window.scrollMaxX - 16;
	}
	else if (document.body.scrollHeight >= document.body.offsetHeight)
	{ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
		xScroll = document.body.scrollWidth;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		xScroll = document.documentElement.clientWidth;
		yScroll = document.documentElement.clientHeight + 51;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight - 12;
		xScroll = document.body.offsetWidth - 4;
	}
	
	return [xScroll, yScroll];
}
