var i = 0;
$(document).ready(function() {
	
	//pageTracker._trackPageview('/stranka/detail-spusten/zpozahrobi');
	
	// Tlacitka slideshow
	$('div#extra ul.slideshow li').mouseover(function () {
		$('div#extra ul.slideshow li').removeClass('selected');
	});
	
	$('div#extra ul.slideshow li').eq(0).mouseover(function(){
		$(this).addClass('selected');
		i = 0;
		$('div#extra div.nav a').eq(0).click();
		
		
		return false;
		
	});
	
	$('div#extra ul.slideshow li').eq(1).mouseover(function(){
		$(this).addClass('selected');
		i = 1;
		$('div#extra div.nav a').eq(1).click();
		
		return false;
		
	});
	
	$('div#extra ul.slideshow li').eq(2).mouseover(function(){
		$(this).addClass('selected');
		i = 2;
		$('div#extra div.nav a').eq(2).click();
		
		return false;
		
	});
	
	$('div#extra ul.slideshow li').eq(3).mouseover(function(){
		$(this).addClass('selected');
		i = 3;
		$('div#extra div.nav a').eq(3).click();
		
		return false;
		
	});
	
	$("#emailLoadDataWeb")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	$("#emailCartype").change(function(){
 		$('#emailcityP').remove(); 
 		
		var cartype = $('#emailCartype').val()
		if(cartype!=""){
		
			$.ajax({
					
					 type: "POST",
					 url: "/helper/serviceemail/",   				 
	             	 data: "cartype="+ cartype,            	
					 success: function(html){ 
					 	
					 	$('#cartypeP').after(html);		 	 		      	            
			         } 
			});
			
		}
		
	});
	
	$("input.company").change(function(){		
	       checkForm();
	});
	
	
	$("input.Customertype").change(function(){		
	        if ($("input.Customertype:checked").val() == 'Stálý zákazník') {
	        
	            $('#caroseryNumberName').attr("disabled", true); 
	            $('#caroseryNumberLabel').css("color",'#DAD9D9');
	            $('#caroseryNumberSpan').css("color",'#DAD9D9');    
	            
	            $('#caroseryNumber').val("");         
	            
	        }
	        else {
	            $('#caroseryNumber').attr("disabled", false); 
	            $('#caroseryNumberLabel').css("color",'#333333');
	            $('#caroseryNumberSpan').css("color",'red'); 
	        }
	});
	
	checkMenu();
	addLinks();
	
});
function showNewModel(target){
	window.location = target;
}

$(function()
{
	 $('div.imageFrame')
	 
	 .cycle({
		 fx: 'fade',
		 timeout: 5000,
		 before: onBefore,
		 pager:  'div#extra div.nav'
	
	});
 }); 

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
function checkForm(){
	 
	 	 if ($("input.company:checked").val() == 'Firma') {
	        
	            $('#companyName').attr("disabled", false); 
	            $('#IN').attr("disabled", false); 
	            $('#companyNameLabel').css("color",'#333333'); 
	            $('#INLabel').css("color",'#333333'); 
	            $('#companyNameSpan').css("color",'red'); 
	            $('#INSpan').css("color",'red'); 
	            
	            $('#nejm').attr("disabled", true); 
	            $('#surnejm').attr("disabled", true);
	            $('#vocative').attr("disabled", true);	            
	            $('#vocativeLabel').css("color",'#DAD9D9');             
	            $('#nejmLabel').css("color",'#DAD9D9'); 
	            $('#surnejmLabel').css("color",'#DAD9D9'); 	            
	            $('#nejmNameSpan').css("color",'#DAD9D9'); 
	            $('#surnejmSpan').css("color",'#DAD9D9');
	            
	            $('#nejm').val("");
	            $('#surnejm').val("");
	            $('#vocative').val("");
	        }
	        else if ($("input.company:checked").val() == 'Fyzická osoba') {
	            $('#nejm').attr("disabled", false); 
	            $('#surnejm').attr("disabled", false); 	
	            $('#vocative').attr("disabled", false);	            
	            $('#vocativeLabel').css("color",'#333333');             
	            $('#nejmLabel').css("color",'#333333'); 
	            $('#surnejmLabel').css("color",'#333333');	           
	            $('#nejmSpan').css("color",'red'); 
	            $('#surnejmSpan').css("color",'red');
	            
	            $('#companyName').attr("disabled", true); 
	            $('#IN').attr("disabled", true); 
	            $('#companyNameLabel').css("color",'#DAD9D9'); 
	            $('#INLabel').css("color",'#DAD9D9'); 
	            $('#companyNameSpan').css("color",'#DAD9D9'); 
	            $('#INSpan').css("color",'#DAD9D9'); 
	            
	            $('#companyName').val("");
	            $('#IN').val("");
	        }
}
function onBefore() { 
    $('div.imageInfo h2').html(this.alt); 
    $('div#content div.slideshow p').html($('div#extra ul.slideshow li').eq(i).find('p').html());
    var atribut = $('div#extra ul.slideshow li').eq(i).find('a').attr('href');
    
    
    
    $('div#content div.slideshow a.information:first').attr( { href: atribut } );
    
    $('div#extra ul.slideshow li').removeClass('selected');
    $('div#extra ul.slideshow li').eq(i).addClass('selected');
    i++;
    if(i == 4) i = 0;
       
}

function addLinks()
{
	$("#ostravaLink").attr('href', 'http://www.volkswagen.cz/skladove_vozy/search.php?vwdb_prodejce_id=27');
	$("#opavaLink").attr('href', 'http://www.volkswagen.cz/skladove_vozy/search.php?vwdb_prodejce_id=42');
	$("#skodaLink").attr('href', 'http://centria.skoda-auto.com/cze/autoheller/services/pages/newcars.aspx');
	$("#audiLink").attr('href', 'http://app.audi.cz/heller/show/dealer/20/page/2');
	$("#seatLink").attr('href', 'http://www.autoheller.cz/seat/vozy_skladem.php');
}
function showHideContact(element)
{ 	 		
 
 	var el = $("#"+element);
 	var button = $("."+element);
 	if( el.is(':hidden') )
 	{
 		el.slideDown('slow');
 		button.html('Skrýt další kontakty');
 	}else{
 		el.slideUp('slow');
 		button.html('Zobrazit všechny kontakty');
 	}
}
function slide(month)
 	{ 	
 		
 		if( $("#"+month).is(':hidden') )
 		{ 		
 			$("#subul1").slideUp("slow");
 			unSetSessvar("subul1");
 			
 			if(month != 'subul3')
 			{
	 			$("#subul2").slideUp("slow");
	 			unSetSessvar("subul2");
 			}
 			
 			$("#subul3").slideUp("slow");
	 		unSetSessvar("subul3");
 			
 			$("#subul4").slideUp("slow");
	 		unSetSessvar("subul4");
 			
 			$("#subul5").slideUp("slow");
	 		unSetSessvar("subul5");
	 		
	 		
	 		if( month != 'subul7' && month != 'subul8' && month != 'subul9' && month != 'subul10' && month != 'subul14')
	 		{
	 			
	 			$("#subul6").slideUp("slow");
		 		unSetSessvar("subul6");
	 		}
 			
 			$("#subul7").slideUp("slow");
	 		unSetSessvar("subul7");
 			
 			$("#subul8").slideUp("slow");
	 		unSetSessvar("subul8");
 			
 			$("#subul9").slideUp("slow");
	 		unSetSessvar("subul9");
 			
 			$("#subul10").slideUp("slow");
	 		unSetSessvar("subul10");
 			
 			$("#subul14").slideUp("slow");
	 		unSetSessvar("subul14");
 			
 			$("#subul11").slideUp("slow");
	 		unSetSessvar("subul11");
 			
 			if( month != 'subul13')
	 		{		 		
	 			$("#subul12").slideUp("slow");
		 		unSetSessvar("subul12");
 			}
 			
 			$("#subul13").slideUp("slow");
	 		unSetSessvar("subul13");
	 		
      		$("#"+month).slideDown("slow");
      		setSessvar(month);
      	}
      	else
      	{
      		$("#"+month).slideUp("slow");
      		unSetSessvar(month);
      	}  
      	    
      	
	}
	function slideUpAll()
 	{ 	
 				
 			$("#subul1").slideUp("slow");
 			unSetSessvar("subul1");
	 		$("#subul2").slideUp("slow");
	 		unSetSessvar("subul2");
 			$("#subul3").slideUp("slow");
	 		unSetSessvar("subul3");
 			$("#subul4").slideUp("slow");
	 		unSetSessvar("subul4");
 			$("#subul5").slideUp("slow");
	 		unSetSessvar("subul5");
	 		$("#subul6").slideUp("slow");
		 	unSetSessvar("subul6");
 			$("#subul7").slideUp("slow");
	 		unSetSessvar("subul7");
 			$("#subul8").slideUp("slow");
	 		unSetSessvar("subul8");
 			$("#subul9").slideUp("slow");
	 		unSetSessvar("subul9");
 			$("#subul10").slideUp("slow");
	 		unSetSessvar("subul10");
 			$("#subul14").slideUp("slow");
	 		unSetSessvar("subul14");
 			$("#subul11").slideUp("slow");
	 		unSetSessvar("subul11");
	 		$("#subul12").slideUp("slow");
		 	unSetSessvar("subul12");
 			$("#subul13").slideUp("slow");
	 		unSetSessvar("subul13");
      	
	}
	function setSessvar(sessvarI)
	{
		switch(sessvarI)
		{
		
		case 'subul1':
  			sessvars.subul1='true';
  		break;
  		
		case 'subul2':
  			sessvars.subul2='true';
  		break;
  		
		case 'subul3':
  			sessvars.subul3='true';
  		break;
  		
		case 'subul4':
  			sessvars.subul4='true';
  		break;
  		
		case 'subul5':
  			sessvars.subul5='true';
  		break;
		
		case 'subul6':
  			sessvars.subul6='true';
  		break;
  		
		case 'subul7':
  			sessvars.subul7='true';
  		break;
  		
		case 'subul8':
  			sessvars.subul8='true';
  		break;
  		
		case 'subul9':
  			sessvars.subul9='true';
  		break;
  		
		case 'subul10':
  			sessvars.subul10='true';
  		break;
  		
		case 'subul11':
  			sessvars.subul11='true';
  		break;
  		
		case 'subul12':
  			sessvars.subul12='true';
  		break;
  		
		case 'subul13':
  			sessvars.subul13='true';
  		break;
  		
		case 'subul14':
  			sessvars.subul14='true';
  		break;
  		
  		
  		}
	}
	
	function unSetSessvar(sessvarI)
	{
		switch(sessvarI)
		{
		
		case 'subul1':
  			sessvars.subul1='false';
  		break;  		
  		
		case 'subul2':
  			sessvars.subul2='false';
  		break;
  		
		case 'subul3':
  			sessvars.subul3='false';
  		break;
  		
		case 'subul4':
  			sessvars.subul4='false';
  		break;
  		
		case 'subul5':
  			sessvars.subul5='false';
  		break;
		
		case 'subul6':
  			sessvars.subul6='false';
  		break;  		
  		
		case 'subul7':
  			sessvars.subul7='false';
  		break;
  		
		case 'subul8':
  			sessvars.subul8='false';
  		break;
  		
		case 'subul9':
  			sessvars.subul9='false';
  		break;
  		
		case 'subul10':
  			sessvars.subul10='false';
  		break;
  		
		case 'subul11':
  			sessvars.subul11='false';
  		break;
  		
		case 'subul12':
  			sessvars.subul12='false';
  		break;
  		
		case 'subul13':
  			sessvars.subul13='false';
  		break;
  		
		case 'subul14':
  			sessvars.subul14='false';
  		break;
  		
  		
  		}
	}
	
	
	function checkMenu()
	{
		if(sessvars.subul1 == 'true')$('#subul1').show();
		if(sessvars.subul2 == 'true')$('#subul2').show();
		if(sessvars.subul3 == 'true')$('#subul3').show();
		if(sessvars.subul4 == 'true')$('#subul4').show();
		if(sessvars.subul5 == 'true')$('#subul5').show();		
		if(sessvars.subul6 == 'true')$('#subul6').show();
		if(sessvars.subul7 == 'true')$('#subul7').show();
		if(sessvars.subul8 == 'true')$('#subul8').show();
		if(sessvars.subul9 == 'true')$('#subul9').show();
		if(sessvars.subul10 == 'true')$('#subul10').show();
		if(sessvars.subul11 == 'true')$('#subul11').show();
		if(sessvars.subul12 == 'true')$('#subul12').show();
		if(sessvars.subul13 == 'true')$('#subul13').show();
		if(sessvars.subul14 == 'true')$('#subul14').show();
		
	}
	function unsetSessvars()
	{	
		unSetSessvar("subul1");
		unSetSessvar("subul2");
		unSetSessvar("subul3");
		unSetSessvar("subul4");
		unSetSessvar("subul5");
		unSetSessvar("subul6");
		unSetSessvar("subul7");
		unSetSessvar("subul8");
		unSetSessvar("subul9");
		unSetSessvar("subul10");
		unSetSessvar("subul11");
		unSetSessvar("subul12");
		unSetSessvar("subul13");
		unSetSessvar("subul14");
	}
	
	
	function addBanner(bannerName,width,height,element){
	    html = '<embed wmode="transparent" width="'+width+'" height="'+height+'" quality="high" name="mymovie" id="mymovie" style="" src="/Public/Images/Banner/'+bannerName+'" type="application/x-shockwave-flash"/>';
	    $(element).append(html);
                    
	}
	
	
	function getPlayer(videoName,i,width,height){
					
	                // -----------------------------------------------------------------------------
	                // Globals
	                // Major version of Flash required
	                var requiredMajorVersion = 9;
	                // Minor version of Flash required
	                var requiredMinorVersion = 0;
	                // Minor version of Flash required
	                var requiredRevision = 0;
	                // -----------------------------------------------------------------------------
	                
	    
	                    function playerReady(thePlayer) {
	                      playing=1;
	                        player1 = document.getElementById("video");
	                      
	                    }
	                    
	                    
	                    var hasProductInstall = DetectFlashVer(6, 0, 65);
	                    
	                    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	                    
	                    
	                    
	                    if ( hasProductInstall && !hasReqestedVersion ) {
	                        var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
	                        var MMredirectURL = window.location;
	                        document.title = document.title.slice(0, 47) + " - Flash Player Installation";
	                        var MMdoctitle = document.title;
	                        AC_FL_RunContent(
	                            "src", "playerProductInstall",
	                            "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
	                            "width", "550",
	                            "height", "300",
	                            "align", "middle",
	                            "id", "detectionExample",
	                            "quality", "high",
	                            "bgcolor", "#3A6EA5",
	                            "name", "detectionExample",
	                            "allowScriptAccess","always",
	                            "type", "application/x-shockwave-flash",
	                            "pluginspage", "http://www.adobe.com/go/getflashplayer"
	                        );
	                    } else if (hasReqestedVersion) {
	                        var so = new SWFObject('/Public/player/player1.swf','video',width,height,'7');
	                        so.addParam('allowfullscreen','true');
	                        so.addParam('allowscriptaccess','always');
	                        so.addParam('wmode','opaque');
	                        so.addVariable('file','heller/'+videoName+'_www.mp4');
	                        so.addVariable('hd.file','heller/'+videoName+'_tv.mp4');
	                        so.addVariable('streamer','rtmpt://213.195.200.44:80/wowza');
	                        so.addVariable('image','/Public/nahledy/velke/'+videoName+'_nahled.png');
	                        so.addVariable('type','rtmp');
	                        so.addVariable('autostart','false');
	                        so.addVariable('bufferlength',5);
	                        so.write('video'+i);
	                        
	                            
	                    } else { 
	                        var alternateContent = 'Alternate HTML content should be placed here.<BR>'
	                        + 'This content requires the Adobe Flash Player. '
	                        + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
	                        document.write(alternateContent);
	                    }
	                
	                
	
	}
	function printBanner(width,height,type,file,link,text){
	text = decodeURIComponent(text);
     newWidth  = parseInt(width) + 20;
    newHeight = parseInt(height) + 40;

    var documentHeight = parseInt($(document).height());
    var documentWidth  = parseInt($(document).width());
    
    var marginLeft     = ((documentWidth - newWidth)/2);
    var marginTop      = 50;
        
     html  = '<div id="overlay"></div>';
    html += '<div id="overlayContent" style="width:'+newWidth+'px;margin-left:'+marginLeft+'px;margin-top:'+marginTop+'px;">';
    html += '    <script type="text/javascript" src="/Public/player/swfobject.js"></script> ';
    html += '    <div class="closeDiv"><a class="close" href="javascript:void(0);" title="" onclick="closeWindow()"></a><p>asdf</p></div>';
    if(type == 'swf'){
        html += ' <div id="banner" style="width:'+width+'px;height:'+height+'px;"><div>';
    }else{
         html += ' <div class="advImage"><a href="'+link+'" title=""><img alt="'+file+'" src="/Public/Images/Advertisement/'+file+'" /></a><div>';
    }
    html += '</div>';
    
     $("body").append(html);
     if(type == 'swf'){
          var so = new SWFObject('/Public/Images/Advertisement/'+file+'','mpl1',width,height,'10');
          so.addParam('allowscriptaccess','always');
         so.addParam('wmode','transparent');
          so.write('banner');
     }
     $('#overlayContent').append('<div class="text">'+text+'</div>');
     countDownBanner();
	}
	
	function closeWindow(){
	
	     $("div#overlay").fadeOut(600, function() { $(this).remove(); });
	    $("div#overlayContent").fadeOut(600, function() { $(this).remove(); });
	}
	
	var second = 15;
	function countDownBanner(){
	
	     second -= 1;
	     $("div#overlayContent div.closeDiv p").html("Okno se zavře za "+second+" vteřin. ")
	     if(second > 0)setTimeout(countDownBanner,1000);
	     if(second == 0){
	          closeWindow();
	     }
	}
	
	function selectSparePart(){
		
		var section = $("select[name='sectionSelect'] option:selected").val();
		
		var content = "<select name='subsectionSelect'>";
				content+= "<option value=''>-- vyberte podsekci --</option>";
				content+= "<option value='vyprodej'>Výprodej</option>";
				content+= "<option value='prislusenstvi'>Příslušenství</option>";
				content+= "<option value='pneumatiky'>Pneumatiky</option>";
			content+= "</select>";
			
			
		if(section != "" && section != "akce"){
			$("span#podsekceSelect").html(content);
		}else $("span#podsekceSelect").html('');
	}
	
	function checkServicebooking(inputName){	
		var date 		= $('input[name="'+inputName+'"]').val();
		var partsArray 	= date.split('.');
		var checkDay 	= new Date();
			checkDay.setDate(checkDay.getDate()+2);
		
		var insertedDate	= new Date(partsArray[2], partsArray[1]-1, partsArray[0]);
		var compareDate		= new Date(checkDay.getFullYear(),checkDay.getMonth(),checkDay.getDate());
		if(compareDate>insertedDate){
			$('input[name="'+inputName+'"]').next().next().css('color','#fd4a4a');
			$('input[name="'+inputName+'"]').next().next().css('font-weight','bold');
		}else{
			
			$('input[name="'+inputName+'"]').next().next().css('font-weight','normal');
			$('input[name="'+inputName+'"]').next().next().css('color','#333333');
		}
		
	}
