// JavaScript Document

$(document).ready(function() {

    //Hoofdnavigatie mouseovers
    $(".menuitem").hover(
		function() {
		    var imgsrc = $(this).find('img').attr("src");
		    if (!imgsrc) imgsrc = '';
		    if (imgsrc.indexOf('_o.gif') == -1) {
		        imgsrc = imgsrc.replace('.gif', '_o.gif');
		        $(this).find('img').attr('src', imgsrc);
		    }

		    $(this).attr('class', 'active hover');
		},
		function() {
		    var thisid = $(this).attr("id")
		    if (thisid.indexOf('active') == -1) {
		        var imgsrc = $(this).find('img').attr("src");
		        if (imgsrc) $(this).find('img').attr('src', imgsrc.replace('_o.gif', '.gif'));
		    }

		    if (thisid.indexOf('activestate') == -1) {
		        $(this).attr('class', 'menuitem');
		    }
		}
	);

    //hoofdnavigatie, mouseovers van submenu items
    $(".menuitem li").hover(
		function() {
		    $(this).attr('class', 'active');
		},
		function() {
		    $(this).attr('class', '');
		}
	);
    
    $(".search input").focus(
		function() {
		    $(this).parent('li').attr('class', 'searchactive');
		    document.getElementById('loader').innerHTML = '<img src="' + PROJECT_URL + 'content/img/icon_close.gif" alt="" onclick="closeSearch()" style="cursor:pointer;" />';
		}
	);

	$(".loginblock .check").click(
		function() {
		    var id = $(this).attr('id');
		    if ($('#' + id + '-check').attr('checked') == true) {
		        $('#' + id + '-check').attr('checked', '');
		        $(this).removeClass('active');
		    } else {
		        $('#' + id + '-check').attr('checked', 'checked');
		        $(this).addClass('active');
		    }
		}
	);
		
    //	input blur en focus
    $(".blur").blur(
		function() {
		    if (!$(this).parent('div').attr('class') == 'inputerror') {
		        $(this).parent('div').attr('class', 'input');
		    }
		}
	);
    $(".blur").focus(
		function() {
		    if (!$(this).parent('div').attr('class') == 'inputerror') {
		        $(this).parent('div').attr('class', 'active');
		    }
		}
	);

    //	input blur en focus
    $(".blurPOP").blur(
		function() {
		    if (!$(this).parent('div').attr('class') == 'inputerror') {
		        $(this).parent('div').attr('class', 'input');
		    }
		}
	);
    $(".blurPOP").focus(
		function() {
		    if (!$(this).parent('div').attr('class') == 'inputerror') {
		        $(this).parent('div').attr('class', 'active');
		    }
		}
	);

})

function display(id,arr) {
	if(arr!=undefined) {
		var a = arr.split(',')
		for(i=0;i<a.length;i++){
			if(document.getElementById(a[i])) document.getElementById(a[i]).style.display='none'
		}
	}
	if(id!=''){
		if(document.getElementById(id)){
			var obj = document.getElementById(id).style
			if(obj.display=='none'){
				obj.display='block'
			}
		}
	}
	return false
}

function rollme(){
	if($('#container_header').css('height') == '4px'){
		$('#container_header').css('height','auto')
		$('#container_header').css('display','none')
		$('#container_header').slideDown("slow")
	}else{
		$('#container_header').slideUp("slow", function(){
			$('#container_header').css('height','4px')
			$('#container_header').slideDown("fast")
		})
	}
}

function openFaqItem(id, totalitems) {

    if (document.getElementById('faqI_' + id).className == 'selected') {
        document.getElementById('faqI_' + id).className = ''
        document.getElementById('faqI_' + id + '_block').style.display = 'none'
    } else {
        document.getElementById('faqI_' + id).className = 'selected'
        document.getElementById('faqI_' + id + '_block').style.display = 'block'
        //$("#faq div").each(function ()  {
           // alert(this.id)
            //$('#' + this + ' ul li').each(function(){
            //   alert('x'); 
            //});
        //});        
    }
}

function openNewsItem(id, totalitems) {

    if (document.getElementById('iNews_' + id).className == 'selected') {
        if (id == "iNews_1") {
            document.getElementById('iNews_' + id).className = 'first'
        } else {
        document.getElementById('iNews_' + id).className = ''
        }
        document.getElementById('iNews_' + id + '_block').style.display = 'none'
    } else {
    document.getElementById('iNews_' + id).className = 'selected'
    document.getElementById('iNews_' + id + '_block').style.display = 'block'
    }
}

function closeSearch() {
    $("#searchli").attr('class', 'search');
    document.getElementById('loader').innerHTML = '<img src="' + PROJECT_URL + 'content/img/icon_search.gif" alt="" onclick="openSearch()" style="cursor:pointer;" />';
}

function openSearch() {
    $("#searchli").attr('class', 'searchactive');
    document.getElementById('loader').innerHTML = '<img src="' + PROJECT_URL + 'content/img/icon_close.gif" alt="" onclick="closeSearch()" style="cursor:pointer;" />'
}

function handleSearch(o) {

    if (o.value.length > 2) {
        document.getElementById('loader').innerHTML = '<img src="' + PROJECT_URL + 'content/img/icon_search_loader.gif" alt="""" />'
        $.get("" + PROJECT_URL + "" + LANG_ID + "/ajax/GetItemsBySearch/" + o.value, {}, function(data) { $('#searchContainer').html(data); });
        document.getElementById('loader').innerHTML = '<img src="' + PROJECT_URL + 'content/img/icon_close.gif" alt="" onclick="closeSearch()" style="cursor:pointer;" />'
    } else {
        $('#searchContainer').html('<li>Vul een specifiekere zoek opdracht in.</li>');
        document.getElementById('loader').innerHTML = '<img src="' + PROJECT_URL + 'content/img/icon_close.gif" alt="" onclick="closeSearch()" style="cursor:pointer;" />';
    }

}


var originalHref;

function findCheckedItems(elm) {
    // deze functie checked welke items zijn gemarkeerd en stuurde variable items
    // door in de url in een highslide
    
    var values = [];

    if (!originalHref) {
        originalHref = elm.href;
    }
    $('input:checked').each(function() {
        values.push($(this).val());
    });
    elm.href = originalHref.replace('{ids}', values.join(","));

    if (!values.length == 0) {
        return hs.htmlExpand(elm, { objectType: 'iframe', contentId: 'my-content', width: 550, height: 340 })
    } else {
        alert('U moet eerst artikelen selecteren voordat u een selectie kunt printen.');
        return false;
    }
}

function markItem(id) {
    var obj = document.getElementById(id);
    var objimg = document.getElementById('img_'+id);
    if (!obj.checked) {
        // item aanzetten
        objimg.src = objimg.src.replace('.gif', '_a.gif');
        obj.checked = true;
    } else {
        // item uitzetten
        objimg.src = objimg.src.replace('_a.gif', '.gif');
        obj.checked = false;
    }
}

function mOButton(elm) {  
    if (elm.src.indexOf('_o.gif') == -1) {
        // item aanzetten
        elm.src = elm.src.replace('.gif', '_o.gif');
    } else {
        // item uitzetten
        elm.src = elm.src.replace('_o.gif', '.gif');
    }
}

function ShowContactFormResult(content) {
    document.getElementById("formHolder").style.display = 'none';
    document.getElementById("formHolderResult").style.display = 'block';
}

function fillSpanWithValue(obj) {
    //alert('lbl_' + obj.name);
    document.getElementById('lbl_'+obj.name).innerHTML = document.getElementById(obj.id).value;
}

function openTextFieldsOnChange(elm,i) {
    if (elm.value == "tijdschrift") {
        document.getElementById('bookmagchange1' + i).style.display = "block";
        document.getElementById('bookmagchange1input' + i).style.display = "block";
        document.getElementById('bookmagchange2' + i).style.display = "none";
        document.getElementById('bookmagchange2input' + i).style.display = "none";
    } else {
        document.getElementById('bookmagchange2' + i).style.display = "block";
        document.getElementById('bookmagchange2input' + i).style.display = "block";
        document.getElementById('bookmagchange1' + i).style.display = "none";
        document.getElementById('bookmagchange1input' + i).style.display = "none";
    }
}

function openTextFieldsElseOnChange(elm, i) {
    if (elm.value == "Nederland") {
        document.getElementById('coutrypublisherelse' + i).style.display = "none";
        document.getElementById('coutrypublisherelseinput' + i).style.display = "none";
    } else {
        document.getElementById('coutrypublisherelse' + i).style.display = "block";
        document.getElementById('coutrypublisherelseinput' + i).style.display = "block";
    }
}

function openBoxpoezie(elm, i) {
    if (elm.value == "Nee") {
        document.getElementById('aantalovergenomenpoezietext' + i).style.display = "none";
        document.getElementById('aantalovergenomenpoezietextinput' + i).style.display = "none";
        document.getElementById('aantalovergenomenpoezie' + i).title = "";
    } else {
        document.getElementById('aantalovergenomenpoezietext' + i).style.display = "block";
        document.getElementById('aantalovergenomenpoezietextinput' + i).style.display = "block";
        document.getElementById('aantalovergenomenpoezie' + i).title = "verplicht";
    }
}

function countPages(i) {
    var plus1
    var plus2
    var plus3
    var plus4
    var plus5
    var plus6
    var plus7
    var plus8
    var plus9
    var plus10
    var plusAll
    plusAll = 0;
    
    plus1 = (parseInt(document.getElementById('pagenumbertakeovertill' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom' + i).value) + 1);
    plus2 = (parseInt(document.getElementById('pagenumbertakeovertill_2' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_2' + i).value) + 1);
    plus3 = (parseInt(document.getElementById('pagenumbertakeovertill_3' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_3' + i).value) + 1);
    plus4 = (parseInt(document.getElementById('pagenumbertakeovertill_4' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_4' + i).value) + 1);
    plus5 = (parseInt(document.getElementById('pagenumbertakeovertill_5' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_5' + i).value) + 1);
    plus6 = (parseInt(document.getElementById('pagenumbertakeovertill_6' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_6' + i).value) + 1);
    plus7 = (parseInt(document.getElementById('pagenumbertakeovertill_7' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_7' + i).value) + 1);
    plus8 = (parseInt(document.getElementById('pagenumbertakeovertill_8' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_8' + i).value) + 1);
    plus9 = (parseInt(document.getElementById('pagenumbertakeovertill_9' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_9' + i).value) + 1);
    plus10 = (parseInt(document.getElementById('pagenumbertakeovertill_10' + i).value) - parseInt(document.getElementById('pagenumbertakeoverfrom_10' + i).value) + 1);

    if (plus1) {
        plusAll = plusAll + parseInt(plus1);
    }
    if (plus2) {
        plusAll = plusAll + parseInt(plus2);
    }
    if (plus3) {
        plusAll = plusAll + parseInt(plus3);
    }
    if (plus4) {
        plusAll = plusAll + parseInt(plus4);
    }
    if (plus5) {
        plusAll = plusAll + parseInt(plus5);
    }
    if (plus6) {
        plusAll = plusAll + parseInt(plus6);
    }
    if (plus7) {
        plusAll = plusAll + parseInt(plus7);
    }
    if (plus8) {
        plusAll = plusAll + parseInt(plus8);
    }
    if (plus9) {
        plusAll = plusAll + parseInt(plus9);
    }
    if (plus10) {
        plusAll = plusAll + parseInt(plus10);
    }

    document.getElementById('pagenumbertakeover' + i).value = plusAll;
    document.getElementById('fakepagenumbertakeover' + i).value = plusAll;
    
}

function checkotherfieldvalue(i, field1, field2, lbl) {
    first = document.getElementById(field1 + i);
    second = document.getElementById(field2 + i);

    if (parseInt(first.value) > parseInt(second.value)) {
        document.getElementById(lbl).innerHTML = 'Er komt een negatieve waarde uit de berekening.'
        second.value = parseInt(first.value) + 1;
        countPages(i);
    } else {
        document.getElementById(lbl).innerHTML = ''
    }
}

function showTooltip(strCont, msg) {    
    $('#' + strCont).hide(100);
    if (msg.length > 0) {
        $('#' + strCont).html(msg);
        $('#' + strCont).show(200)
    }
}

function showLoader() {
    document.getElementById('sub_button').innerHTML = '<img src="' + PROJECT_URL + 'content/img/form_loader.gif" alt="">'
}

function placeChilds(obj) {
//    alert($('#menu').height() + '::' + obj.offsetTop + '::' + $(obj).find('ul').height() + '::' + (obj.offsetTop - $(obj).find('ul').height()))
//    if((obj.offsetTop - $(obj).find('ul').height()) < 0){
//        $(obj).find('ul').css('bottom', obj.offsetTop + 'px'); $(obj).find('ul').css('bottom');
//    }else{    
        $(obj).find('ul').css('top', obj.offsetTop + 'px'); $(obj).find('ul').css('top');
//    }
    }

    function collapseExpand(obj, obj2) {
        if ($('#'+obj).css('display') == 'none') {
            $('#' + obj2).attr('src', $('#' + obj2).attr('src').replace('icon_plus.gif', 'icon_minus.gif'));
            $('#'+obj).show(100);
        } else {
        $('#' + obj2).attr('src', $('#' + obj2).attr('src').replace('icon_minus.gif', 'icon_plus.gif'));
        $('#'+obj).hide(60);
    }
    $('#pane1').jScrollPane();
        return false
    }
