// JavaScript Document

function operateMenu() {
			var menu=document.getElementById('menu');
			var Lists=menu.getElementsByTagName('LI');
			for(var i=0; i<Lists.length; i++) {
				Lists[i].onmouseover=function() {
					this.className=(this.className=='drop')?'':'drop';
				}
				Lists[i].onmouseout=function() {
					this.className=(this.className=='drop')?'':'drop';
				}
			}
}

$(document).ready(function() {
	if($("ul#left-menu")){
		$("ul#left-menu ul").hide();		
		/*$('ul#left-menu li:has(ul)').each(function() {
			$(this+" ul").slideUp(400);
		});*/
		$("li.clicked ul").show();
		
		$('ul#left-menu li:has(ul) a').click(function(){
			if ($(this).parent().hasClass ("clicked")){
				//$(this).parent().parent().removeClass("clicked");
				//$(this).parent().parent().children("ul").slideUp(400);
			}else{
				if (!$(this).parent().parent().hasClass ("second-menu")){
					$('ul#left-menu li:has(ul)').removeClass("clicked");
					$('ul#left-menu li:has(ul) ul').slideUp(400);
					$(this).parent().addClass("clicked");
					$(this).parent().children("ul").slideDown(400);
				}
			}
		});
	}
});

$(document).ready(function() {  
 	
    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
    	
    	var idColors = new Array();
    	var ii =1;
    	$("input[id*='colors_']").each(function(){
			if($(this).attr('checked')){
				idColors[ii] = $(this).attr('value');
				ii++;
			}
		});
		
		if(!idColors[1]) {
				alert('Не е избран цвят за който да направите запитване!');
				return false;
		}
		else{
			var p = '';	
			for (x in idColors){ 
					var a = idColors[x];
					
					var aa = a.split("_");
					p = p + aa[0]+'-'+aa[1]+';&nbsp; ';
				 }
			$("#colorsValueSet").html(p);
			$("#colors").val(p);
		}
    	
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect     
        $('#mask').fadeIn(1000);    
        $('#mask').fadeTo("slow",0.8);  
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2+$(window).scrollTop());
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(1000); 
     
    });
     
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });     
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });         
     
});

