	$(document).ready(function() {
		$('li.active').attr('curr', 'active');
		$(".left-menu>li").click(function(){
			if ( $(this).attr('curr') != 'active')
			{
				$('li.active').attr('curr', '');
				$(this).attr('curr', 'active');
				$('li.active').removeClass('active');
				$('.left-menu ul').slideUp(200);
				$(this).addClass("active");
				$('.active ul').slideDown(200);
			}
		});
		$(".login-tabs>span").click(function(){
			$('.login-tabs span').removeClass('active');
			$(this).addClass("active");
			if ($('#dlg-user').css('display')=='none')
			{
				$('#dlg-forgot').slideUp(100);
				$('#dlg-user').slideDown(100);
			}
			else {
				$('#dlg-forgot').slideDown(100);
				$('#dlg-user').slideUp(100);
			}
		});
	});
	Cufon.replace('.cufon');
	Cufon.replace('.plumb');
	Cufon.replace('.page-title');
	Cufon.replace('.green-button-next100', {
		textShadow: '0 1px 0 #fff',
		hover: {
			color: '#000000'
		}
	});
	Cufon.replace('.green-button-prev100', {
		textShadow: '0 1px 0 #fff',
		hover: {
			color: '#000000'
		}
	});
	Cufon.replace('.green-on-button', {
		textShadow: '0 1px 0 #fff',
		hover: {
			color: '#000000'
		}
	});
	Cufon.replace('.green-button', {
		textShadow: '0 1px 0 #015812',
		hover: {
			color: '#ace4b4'
		}
	});
	
	function sendMail()
	{
	  var name     = $('#name').val();
		var email    = $('#email').val();
		var phone    = $('#phone').val();
		var comment  = $('#comment').val();
		var captchaCode = $('#captcha').val();
				
		if(name != '' && validateEmail(email) && comment != '')
		{
  		 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'mailSent', name : name, email : email, phone : phone, comment : comment, captchaCode : captchaCode}, function(data) {
  		  $('#error').hide();
  			$('#ok').show();
				$('#name').val('');
				$('#email').val('');
				$('#phone').val('');
				$('#comment').val('');
  		 });
		}
		else
		{
		  $('#error').show();
			$('#ok').hide();
		} 
	}
	
	function changeUserData()
	{
	  var err = 0;
		for(var i=1;i<9;i++)
		{
		  if($('#tr_'+i).val() == '')
			{
			  err = 1;
			}
		}
		if(validateEmail($('#tr_1').val()) == false || err == 1)
		{
		  $('#error').show();
		}
		else
		{
		  document.changeF.submit();
		}
	}
	
	function checkOrder()
	{				 		
		  var flag = 0;
			
			for(var i = 1; i < 20; i++)
			{				
			 if($('#signprod_'+i).attr('checked'))
			 flag = 1;
			}			
			
			if((($('#sign_1').attr('checked') || $('#sign_2').attr('checked')) && $('#agreement').attr('checked')) || flag == 1)
			 if(flag == 1 && ($('#sign_1').attr('checked') || $('#sign_2').attr('checked')))
			 {
			   if($('#agreement').attr('checked'))
				 document.orderF.submit();
				 else
				 {
				 	 $('#error').show();
					 $('#error2').hide();  
				 } 
			 }
			 else
			 document.orderF.submit();
			else		
			{
		    if(($('#sign_1').attr('checked') || $('#sign_2').attr('checked')) && $('#agreement').attr('checked') == false)
				{
				  $('#error').show();
					$('#error2').hide();  
				}
				else
				{
				  $('#error').hide();
					$('#error2').show();
				}
			}	
	}
	
	function checkOrderTrikolor()
	{				 		
		  var flag = 0;
			
			for(var i = 1; i < 20; i++)
			{				
			 if($('#signprod_'+i).attr('checked'))
			 flag = 1;
			}			
			
			for(var i = 1; i < 20; i++)
			{
			  if($('#sign_'+i).attr('checked'))
			 	flag = 1;
			}			
			
			if(flag == 1)
			{
			 	document.orderF.submit();
			}	
			else		
			{				
				$('#error2').show();
			}	
	}
	
	function checkOrderNewShop()
	{				 		
		  var flag = 0;
			
			for(var i = 1; i < 20; i++)
			{				
			 if($('#signprod_'+i).attr('checked'))
			 flag = 1;
			}			
			
			/*for(var i = 1; i < 20; i++)
			{
			  if($('#sign_'+i).attr('checked'))
			 	flag = 1;
			}	*/		
			
			if(flag == 1)
			{
			 	document.orderF.submit();
			}	
			else		
			{				
				$('#error2').show();
			}	
	}	
	
	function replace(f, r, s){
  	var ra = r instanceof Array, sa = s instanceof Array, l = (f = [].concat(f)).length, r = [].concat(r), i = (s = [].concat(s)).length;
  	while(j = 0, i--)
  		while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j < l);
  	return sa ? s : s[0];
  }

	
	function changeCartSums()
	{
	  var total = 0;
		
		for(var i = 1; i < 25; i++)
		{
		  var price = $('#price_'+i);
			var amount = $('#amount_'+i); 
			
			if(price.length != 0 && amount.length != 0)
			{
			  var amount = $('#amount_'+i).val();
				var price = replace(',', '', $('#price_'+i).html());
				
				if (amount == parseInt(amount) && amount < 99 && amount > 0)
				{
				   $('#total_'+i).html(number_format((parseInt(amount) * parseFloat(price)), 2));
					 total = total + (parseInt(amount) * parseFloat(price)); 
				}
				else
				{
				   $('#total_'+i).html(number_format((parseInt(1) * parseFloat(price)), 2));
					 $('#amount_'+i).val('');
					 total = total + (parseInt(1) * parseFloat(price));
				}				
			}
		}
		
		var delivery   = $('#delivery');
		var connection = $('#connection');
		
		if(delivery.length != 0 || connection.length != 0)
		{
		  if(delivery.length != 0 && $('#delivery').attr('checked'))
			{
			  var del_price = replace(',', '', $('#del_price').html());
				$('#del_total').html(number_format((parseInt(1) * parseFloat(del_price)), 2));
				 total = total + (parseInt(1) * parseFloat(del_price)); 
			}
			else
			{
			  if(delivery.length != 0)
				{
				  $('#del_total').html('0.00');
				}
			}
			
			if(connection.length != 0 && $('#connection').attr('checked'))
			{
			  var connection_price = replace(',', '', $('#connection_price').html());
				$('#connection_total').html(number_format((parseInt(1) * parseFloat(connection_price)), 2));
				 total = total + (parseInt(1) * parseFloat(connection_price));
			}
			else
			{
			  if(connection.length != 0)
				{
				  $('#connection_total').html('0.00');
				}
			}			
		}
		
		$('#final_total').html(number_format(total, 2));
	}
	
	function checkCartContent()
	{
	  var payment_type = $('#payment_type').val();
		
		if(payment_type != '')
		{
		  document.orderF.submit();
		}
		else
		{		
		  $('#error').show();
		}
	}
	
	function number_format (number, decimals, dec_point, thousands_sep) 
	{
	  number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');    }
    return s.join(dec);
  }
	
	function isNumeric(value) {
    var bool = isNaN(+value);
    bool = bool || (value.indexOf('.') != -1);
    bool = bool || (value.indexOf(",") != -1);
    return !bool;
  }

	
	function checkRegistration2()
	{	  
		var email 			= $('#tr_1').val();						
		var regType     = $('#regType').val();
		
		if(regType == 'Ntv2')
		{					 
		  var contract_nr = $('#contract_nr').val();
			var card_nr = $('#card_nr').val();						
			
			if((isNumeric(contract_nr) && contract_nr.length == 10) && (isNumeric(card_nr) && card_nr.length == 12))
			{
			  var email 			= $('#tr_1').val();
    		var pass  	    = $('#tr_2').val();
    		var pass2 			= $('#tr_3').val();
    		var captchaCode = $('#captcha').val();
  			
  			if(validateEmail(email))
      		{
      			if(pass == pass2 && pass.length > 5)
      			{		
      				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode, email : email}, function(data) {
              	  if(data != 'error')
              		{  		  
      							if(data == 'emailerror')
										{
										  $('#error1').hide();
              				$('#error2').hide();
        							$('#error4').hide();
              				$('#error3').hide();
  										$('#error5').hide();
											$('#error6').show();
										}
										else
										{
  										var is_ok = 1;
                  		for(var i=1;i<12;i++)
                  		{
                  		  if($('#tr_'+i).val() == '')
                  			is_ok = 0;
                  		}
              				
              				if(is_ok == 1)
              				{
              				  document.registerF.submit();					
              				}
              				else
              				{
              				  $('#error1').hide();
              					$('#error2').hide();
        								$('#error4').hide();
              					$('#error3').show();
  											$('#error5').hide();
												$('#error6').hide();
              				}
										}	  								
              		}			  		
            			else
            			{
            			  $('#error4').show();
      							$('#error1').hide();
      							$('#error2').hide();
										$('#error5').hide();
										$('#error6').hide();
            			}						
              	});		
      			}
      			else
      			{
      			  $('#error2').show();	
      				$('#error1').hide();
							$('#error5').hide();
							$('#error6').hide();			
      			}
      		}
      		else
      		{
      		  $('#error1').show();
						$('#error5').hide();
						$('#error6').hide();
      		}
			}
			else
			{
			  $('#error5').show();
    		$('#error1').hide();
    		$('#error2').hide();
				$('#error4').hide();
    		$('#error3').hide();
				$('#error6').hide();
			}
		}
		
		if(regType == 'Ntv')
		{					 
		  var kortti_id = $('#kortti_id').val();						
			
			if(isNumeric(kortti_id) && kortti_id.length > 2 && kortti_id.length < 5)
			{
			  var email 			= $('#tr_1').val();
    		var pass  	    = $('#tr_2').val();
    		var pass2 			= $('#tr_3').val();
    		var captchaCode = $('#captcha').val();
  			
  			if(validateEmail(email))
      		{
      			if(pass == pass2 && pass.length > 5)
      			{		
      				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode, email : email}, function(data) {
              	  if(data != 'error')
              		{  		  
      							if(data == 'emailerror')
										{
  										$('#error1').hide();
              				$('#error2').hide();
        							$('#error4').hide();
              				$('#error3').hide();
  										$('#error5').hide();
  										$('#error6').show();
										}
										else
										{
										  var is_ok = 1;
                  		for(var i=1;i<11;i++)
                  		{
                  		  if($('#tr_'+i).val() == '')
                  			is_ok = 0;
                  		}
              				
              				if(is_ok == 1)
              				{
              				  document.registerF.submit();					
              				}
              				else
              				{
              				  $('#error1').hide();
              					$('#error2').hide();
        								$('#error4').hide();
              					$('#error3').show();
  											$('#error5').hide();
  											$('#error6').hide();
              				}
										}	  								
              		}			  		
            			else
            			{
            			  $('#error4').show();
      							$('#error1').hide();
      							$('#error2').hide();
										$('#error5').hide();
										$('#error6').hide();
            			}						
              	});		
      			}
      			else
      			{
      			  $('#error2').show();	
      				$('#error1').hide();
							$('#error5').hide();	
							$('#error6').hide();		
      			}
      		}
      		else
      		{
      		  $('#error1').show();
						$('#error5').hide();
						$('#error6').hide();
      		}
			}
			else
			{
			  $('#error5').show();
    		$('#error1').hide();
    		$('#error2').hide();
				$('#error4').hide();
    		$('#error3').hide();
				$('#error6').hide();
			}
		}
		
		if(regType == 'Trikolor')
		{
		  var dre_id = $('#dre_id').val();						
			
			if(isNumeric(dre_id) && (dre_id.length == 12 || dre_id.length == 14))
			{
			  var email 			= $('#tr_1').val();
    		var pass  	    = $('#tr_2').val();
    		var pass2 			= $('#tr_3').val();
    		var captchaCode = $('#captcha').val();
  			
  			if(validateEmail(email))
      		{
      			if(pass == pass2 && pass.length > 5)
      			{		
      				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode, email : email}, function(data) {
              	  if(data != 'error')
              		{  		  
      							if(data == 'emailerror')
										{
  										  $('#error1').hide();
              					$('#error2').hide();
        								$('#error4').hide();
              					$('#error3').hide();
  											$('#error5').hide();
  											$('#error6').show();
										}
										else
										{
										  var is_ok = 1;
                  		for(var i=1;i<11;i++)
                  		{
                  		  if($('#tr_'+i).val() == '')
                  			is_ok = 0;
                  		}
              				
              				if(is_ok == 1)
              				{
              				  document.registerF.submit();					
              				}
              				else
              				{
              				  $('#error1').hide();
              					$('#error2').hide();
        								$('#error4').hide();
              					$('#error3').show();
  											$('#error5').hide();
  											$('#error6').hide();
              				}
										}	  								
              		}			  		
            			else
            			{
            			  $('#error4').show();
      							$('#error1').hide();
      							$('#error2').hide();
										$('#error5').hide();
										$('#error6').hide();
            			}						
              	});		
      			}
      			else
      			{
      			  $('#error2').show();	
      				$('#error1').hide();
							$('#error5').hide();	
							$('#error6').hide();		
      			}
      		}
      		else
      		{
      		  $('#error1').show();
						$('#error5').hide();
						$('#error6').hide();
      		}
			}
			else
			{
			  $('#error5').show();
    		$('#error1').hide();
    		$('#error2').hide();
				$('#error4').hide();
    		$('#error3').hide();
				$('#error6').hide();
			}
		}
		
		if(regType == 'Kartina')
		{
		  var email 			= $('#tr_1').val();
  		var pass  	    = $('#tr_2').val();
  		var pass2 			= $('#tr_3').val();
  		var captchaCode = $('#captcha').val();
			
			if(validateEmail(email))
    		{
    			if(pass == pass2 && pass.length > 5)
    			{		
    				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode, email : email}, function(data) {
            	  if(data != 'error')
            		{  		  
    							if(data == 'emailerror')
									{
  									 $('#error1').hide();
            				 $('#error2').hide();
      							 $('#error4').hide();
            				 $('#error3').hide();
  									 $('#error6').show();
									}
									else
									{
									  var is_ok = 1;
                		for(var i=1;i<11;i++)
                		{
                		  if($('#tr_'+i).val() == '')
                			is_ok = 0;
                		}
            				
            				if(is_ok == 1)
            				{
            				  document.registerF.submit();					
            				}
            				else
            				{
            				  $('#error1').hide();
            					$('#error2').hide();
      								$('#error4').hide();
            					$('#error3').show();
  										$('#error6').hide();
            				}
									}	  								
            		}			  		
          			else
          			{
          			  $('#error4').show();
    							$('#error1').hide();
    							$('#error2').hide();
									$('#error6').hide();
          			}						
            	});		
    			}
    			else
    			{
    			  $('#error2').show();	
    				$('#error1').hide();	
						$('#error6').hide();		
    			}
    		}
    		else
    		{
    		  $('#error1').show();
					$('#error6').hide();
    		}
		}
		
		
   //////////////////////////OLD PART		
		
		
		/*if(reg_type == 'Kartina')
		{
    		if(validateEmail(email))
    		{
    			if(pass == pass2 && pass.length > 5)
    			{		
    				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode}, function(data) {
            	  if(data != 'error')
            		{  		  
    							var is_ok = 1;
              		for(var i=1;i<11;i++)
              		{
              		  if($('#tr_'+i).val() == '')
              			is_ok = 0;
              		}
          				
          				if(is_ok == 1)
          				{
          				  document.registerF.submit();					
          				}
          				else
          				{
          				  $('#error1').hide();
          					$('#error2').hide();
    								$('#error4').hide();
          					$('#error3').show();
          				}  								
            		}			  		
          			else
          			{
          			  $('#error4').show();
    							$('#error1').hide();
    							$('#error2').hide();
          			}						
            	});		
    			}
    			else
    			{
    			  $('#error2').show();	
    				$('#error1').hide();			
    			}
    		}
    		else
    		{
    		  $('#error1').show();
    		}
			}
			else
			{		
			  var korti 			= $('#korti').val();
				var contract_nr = $('#contract_nr').val();
				var card_nr 		= $('#card_nr').val();
				
				if(korti != '' || (contract_nr != '' && card_nr != ''))
				{
				    if(validateEmail(email))
        		{
        			if(pass == pass2 && pass.length > 5)
        			{		
        				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode}, function(data) {
                	  if(data != 'error')
                		{  		  
        							var is_ok = 1;
                  		for(var i=1;i<11;i++)
                  		{
                  		  if($('#tr_'+i).val() == '')
                  			is_ok = 0;
                  		}
              				
              				if(is_ok == 1)
              				{
              				  document.registerF.submit();					
              				}
              				else
              				{
              				  $('#error1').hide();
              					$('#error2').hide();
        								$('#error4').hide();
              					$('#error3').show();
              				}  								
                		}			  		
              			else
              			{
              			  $('#error4').show();
        							$('#error1').hide();
        							$('#error2').hide();
              			}						
                	});		
        			}
        			else
        			{
        			  $('#error2').show();	
        				$('#error1').hide();			
        			}
        		}
        		else
        		{
        		  $('#error1').show();
        		} 
				}
				else
				{		
				  $('#error1').hide();
          $('#error2').hide();
        	$('#error4').hide();
          $('#error3').show();
				}
			}		*/			 	  
	}
	
	function checkRegistration()
	{
	  var email 			= $('#tr_1').val();
		var pass  	    = $('#tr_2').val();
		var pass2 			= $('#tr_3').val();
		var captchaCode = $('#captchaCode').val();
		
		if(validateEmail(email))
		{
			if(pass == pass2 && pass.length > 5)
			{			  
				 $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkCaptha', captchaCode : captchaCode}, function(data) {
        	  if(data != 'error')
        		{  		  
      				var is_ok = 1;
          		for(var i=1;i<11;i++)
          		{
          		  if($('#tr_'+i).val() == '')
          			is_ok = 0;
          		}
      				
      				if(is_ok == 1)
      				{
      				  document.registerF.submit();					
      				}
      				else
      				{
      				  $('#error1').hide();
      					$('#error2').hide();
								$('#error4').hide();
      					$('#error3').show();
      				}  								
        		}			  		
      			else
      			{
      			  $('#error4').show();
							$('#error1').hide();
							$('#error2').hide();
      			}						
        	});																
			}
			else
			{
			  $('#error2').show();	
				$('#error1').hide();			
			}
		}
		else
		{
		  $('#error1').show();
		}				 
	}
	
	function validateEmail(id) 
  { 
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/; 
    return emailPattern.test(id); 
  } 
	
	function sendLoginPass()
	{
	  var email = $('#semail').val();
		
		$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'newpass', email : email}, function(data){
			if (data.length>0){
				if(data != 'error')
				{																			
					/*$('.login-tabs #login_s').removeClass('active');
      		$('.login-tabs #login_f').addClass("active");
      		
      		$('#dlg-forgot').slideUp(100);
      		$('#dlg-user').slideDown(100);*/
					$('#login_error3').show();	
					$('#login_error').hide();		
				}		
				else
				{					
					$('#login_error3').hide();
					$('#login_error').show();
				}			
			} 					
		})			
	}
	
	function login()
	{
	  var email = $('#email').val();
		var pass = $('#password').val();
		
		/*$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'login', email : email, pass : pass}, function(data){
			if (data.length>0){
				if(data != 'error')
				{																			
					document.loginF.submit();
				}		
				else
				{					
					$('#login_error2').show();
				}			
			} 					
		})	*/		
		
		document.loginF.submit();
	}
	
	function sendNewPass()
	{	  
		$('#logBox').hide();
		$('#forgotPassD').show();
	}
	
	function sendPass()
	{
	  var email = $('#newemail').val();
		
		$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'newpass', email : email}, function(data){
			if (data.length>0){
				if(data != 'error')
				{																			
					$('#logBox').show();
					$('#forgotPassD').hide();
				}		
				else
				{					
					$('#lerror').show();
				}			
			} 					
		})				
	}
	
	function checkOrderLogin()
	{
	  var email = $('#email').val();
		var pass 	= $('#pass').val();
		
		if(email != '' && pass != '')
		{
  		$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkuser', email : email, pass : pass}, function(data){
  			if (data.length>0){
  				if(data != 'error')
  				{																			
  					document.orderF.submit();
  				}		
  				else
  				{					
  					$('#lerror2').show();
  				}			
  			} 					
  		})
		}
		else
		{
		  $('#lerror2').show();
		}				
	}
	
  	/* Tooltip actions. */
  function showTooltip(ref,txt,opt){
  	jQuery('body').append('<div id="tooltip"><div id="tooltip-ending"></div><div id="tooltip-inner">' + txt + '</div></div>');
  	if(opt){ helper = opt; } else { helper = ref; }
  	fit = jQuery(document).width() - jQuery(helper).offset().left - jQuery('#tooltip').width();
  	jQuery('#tooltip')[0].style.top = jQuery(helper).offset().top + jQuery(helper).height() + 'px';
  	if( fit < 0 ){
  		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + fit + 'px';	
  		jQuery('#tooltip-ending')[0].style.backgroundPosition = fit - fit - (jQuery(document).width() - jQuery(ref).offset().left) + 'px 0';
  	} else {
  		jQuery('#tooltip')[0].style.left = jQuery(helper).offset().left + 'px';
  	}
  	jQuery(ref).bind('mouseout',function() {
  		jQuery('#tooltip').unbind('mouseout');
  		jQuery('#tooltip').remove();
  	});
  }
	
	function setBank(bank)
  {
    $('#bank').val(bank);
  	document.bankF.submit();
  }
	
	function setOrderBank(pid, bank)
	{
		$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'setbank', pid : pid, bank : bank}, function(data){					 					
		})			
	}
	
	function setOrderBank2(pid, bank, cnt)
	{
		video.overlay();
		$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'setbank', pid : pid, bank : bank}, function(data){					 					
		})
		
		$('#bank_id').val(cnt);						
	}
	
	function sendToBank()
	{
	  var bank_id = $('#bank_id').val();
		$('#bankF_'+bank_id).submit();				
	}
	
	function SetRedOrder(pid)
	{
	  $.post("http://www.telemax.fi/ajax.php", {ajax_act: 'setRedOrder', pid : pid}, function(data){	
		  if (data.length>0){
				if(data != 'error')
				{																							
					$('#order_done_content').html($('#order_done_text').val());
				}							
			}		 								 					
		})
	}
	
	function checkRegisterType()
	{
	  var regType = $('#reg_type').val();
		
		if(regType == 'Kartina')
		{
		  $('#korti').val('');
			$('#contract_nr').val('');
			$('#card_nr').val('');
			
			$('#tr_korti').hide();
			$('#tr_contract_nr').hide();
			$('#tr_card_nr').hide();
		}
		else
		{
		  $('#korti').val('');
			$('#contract_nr').val('');
			$('#card_nr').val('');
			
			$('#tr_korti').show();
			$('#tr_contract_nr').show();
			$('#tr_card_nr').show();
		}
	}
	
	function checkRegisterKorti()
	{
	  var korti = $('#korti').val();
		
		if(korti != '')
		{
		  $('#contract_nr').val('');
			$('#card_nr').val('');
			$('#contract_nr').attr("readonly", true);
			$('#card_nr').attr("readonly", true); 
		}
		else
		{
		  $('#contract_nr').val('');
			$('#card_nr').val('');
			$('#contract_nr').removeAttr("readonly");
			$('#card_nr').removeAttr("readonly"); 
		}
	}		
	
	function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '',        strict = !! argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {                return true;
            }
        }
    } else {
        for (key in haystack) {            if (haystack[key] == needle) {
                return true;
            }
        }
    } 
    return false;
	}
	
	function checkPackages(currID)
	{
		var common_package = 0;
		
		for(var i=1;i<200;i++)
		{
		  if($('#common_'+i).is(':checked') == true)
			common_package = i;
		}
		
		var diabledChannels = new Array(); 
		
		$.post("http://www.telemax.fi/ajax.php", {ajax_act: 'checkNtvPackages', common_package : common_package}, function(data){
		  	if(data != 'error')
				{
				  var allData = data.split('__'); 
					//allData[0] -- common package data
					//allData[1] -- sub package data
					//allData[2] -- channels data
					
					//first part
					var common_package  = allData[0].split(',');
					var channels_amount = parseFloat(common_package[0]);
					var euro_amount 		= parseFloat(common_package[1]);					
					
					//second part sub package
					var sub_package = allData[1].split('|');
					
					//check how much sub package selected
					var check_amount = 0;
					for(var z=1;z<sub_package.length;z++)
					{									  						
						var tmp = sub_package[z].split(',');
						if(tmp[3] == 'no')
						{
						  $('#sub_'+tmp[0]).removeAttr('checked');
							$('#sub_disabled_'+tmp[0]).addClass('disabled');
							$('#sub_'+tmp[0]).attr('disabled', true);							
						}
						else
						{
						  if($('#sub_'+tmp[0]).is(':checked') == true)
							{							 	 								
								 if(currID != 0)
								 {
									 if(currID != tmp[4])
									 {									 	 
										 check_amount++;
									 } 
								 }
								 else
								 {
								   check_amount++;
								 }	 
							}	 
						}
					}
					//end of check
					
					for(var z=1;z<sub_package.length;z++)
					{
					  var tmp = sub_package[z].split(',');
						if(tmp[3] == 'no')
						{
						  $('#sub_'+tmp[0]).removeAttr('checked');
							$('#sub_disabled_'+tmp[0]).addClass('disabled');
							$('#sub_'+tmp[0]).attr('disabled', true);							
						}
						else
						{
							 if(tmp[5] != 0 && $('#sub_'+tmp[0]).is(':checked') == true)
							 {							 	 
								 diabledChannels[tmp[5]] = tmp[5];	
							 }
							 
							 $('#sub_disabled_'+tmp[0]).removeClass('disabled');
							 $('#sub_'+tmp[0]).removeAttr('disabled');
							 
							 if($('#sub_'+tmp[0]).is(':checked') == true)
							 {							 	 								
								 if(currID != 0)
								 {
									 if(currID == tmp[4])
									 {									 	 
										 $('#sub_'+tmp[0]).removeAttr('checked');
									 } 
									 else
									 {	 									   
										 var channels_amount = channels_amount + parseFloat(tmp[1]);
								   	 
										 if(check_amount > 1)
										 {
										   var euro_amount 		 = euro_amount + parseFloat( parseFloat(tmp[2]) - (parseFloat(tmp[2]) * parseFloat(allData[3] / 100)));
										 }	
										 else
										 {
										 	 var euro_amount 		 = euro_amount + parseFloat(tmp[2]);
										 }  
									 }
								 }
								 else
								 {
								   var channels_amount = channels_amount + parseFloat(tmp[1]);
								   if(check_amount > 1)
									 {
										 var euro_amount 		 = euro_amount + parseFloat(parseFloat(tmp[2]) - (parseFloat(tmp[2]) * parseFloat(allData[3] / 100)));
									 }	
									 else
									 {
									 	 var euro_amount 		 = euro_amount + parseFloat(tmp[2]);
									 }
								 }	 
							 }	 
						}
					}
					
					//third part channels
					var channels = allData[2].split('|');
					
					for(var z=1;z<channels.length;z++)
					{
					  var tmp = channels[z].split(',');
						
						if(in_array(tmp[0], diabledChannels))
						{
						  tmp[3] = 'no';
						}
						
						if(tmp[3] == 'no')
						{
						  $('#channels_'+tmp[0]).removeAttr('checked');
							$('#channels_disabled_'+tmp[0]).addClass('disabled');
							$('#channels_'+tmp[0]).attr('disabled', true);							
						}
						else
						{
						   //SET SUB PACKAGE DISABLED if not with this channel
							 if(tmp[4] != 0 && $('#channels_'+tmp[0]).is(':checked') == true)
							 {
							 	 $('#sub_'+tmp[4]).removeAttr('checked');
								 $('#sub_disabled_'+tmp[4]).addClass('disabled');
								 $('#sub_'+tmp[4]).attr('disabled', true);	
							 }
							 
							 $('#channels_disabled_'+tmp[0]).removeClass('disabled');
							 $('#channels_'+tmp[0]).removeAttr('disabled');
							 
							 if($('#channels_'+tmp[0]).is(':checked') == true)
							 {							 	 								 
								 var channels_amount = channels_amount + parseFloat(tmp[1]);
								 var euro_amount 		 = euro_amount + parseFloat(tmp[2]);
							 }	 
						}
					}
					
					 
				  $('#calcchannels').html(channels_amount);
					
					var ntvmonth = $('#ntvmonth').val();
					$('#calcprice').html(number_format(euro_amount*ntvmonth, 2));
				}			 					
		})	
	}
