

//*******  Старый скрипт калькулятора сайтов ************************************
/********************************************************************************
 $(document).ready(function(){

    $('.main').click(function(){
      $('.overlay').removeClass('hidden');     
      $('.inputlevel').fadeOut('slow',function(){ 
         $(this).remove();
         prices();
      });
    }); 
   
   
    $('.level1').live("click",function(){
       if(this.checked) {
          $('.overlay').removeClass('hidden');
          if(!$($(this).parent().find('.inputlevel:first')).length) {
             $('<div/>',{
                "class": "inputlevel"
             }).appendTo($(this).parent());
             $($(this).parent().find('.inputlevel:first')).css('display', 'none');
          }                
          $($(this).parent().find('.inputlevel:first')).load('/_ajax/structLoad.php',{SECTION_ID: $(this).attr('id')},function(){
             $(this).css('margin-left','50px');
             $(this).fadeIn('slow');
             $('.overlay').addClass('hidden');
             prices();
          });   
       }
       else
          $(this).parent().find('.inputlevel:first').fadeOut('slow',function(){
             $(this).remove();
             prices();
          });
    });   
   
    $('.level_inner').live("click",function(){   
       prices();
    });
 });

 function prices() {
    var prices = 0;
    $('input').each(function(){
       if(this.checked){
          prices=prices + parseInt($(this).attr('price'));   
       }
    });
    $('#totalPrice').html(prices);
 }

********************************************************************************
*******************************************************************************/

	function flashGetHref() { return location.href; }
	function flashPutHref(href) { location.href = href; }
	function flashGetTitle() { return document.title; }
	function flashPutTitle(title) { document.title = title; }
	function getRandomInt(min, max)
	{
	return Math.floor(Math.random() * (max - min + 1)) + min;
	}
	
	function gotoVinPage(nubmerOfVin){
		var ar_sums = new Array(13,8,14,19,21);
		code='';
		i=1;
		for (var key in ar_sums) {
			var val = ar_sums [key];
			do {
				r1=getRandomInt(1,9);
				if (i==3) { 
					r2=nubmerOfVin;
				}
				else {
					r2=getRandomInt(1,9);
				}
				r3=getRandomInt(1,9);
				sum=r1+r2+r3;
				part=String(r1)+String(r2)+String(r3);
			} while (!((r1!=r2)&&(r2!=r3)&&(r3!=r1)&&(sum==val)));
			code=code+part;
			i++;
		}
		//alert(code);
		str='index.php?coupon='+code;
		str='/game/index.php?coupon='+code;
		//alert('/index.php?coupon='+code);
		
		//document.location.replace(url());
		window.open(str, null); 
		

		
		
	}







	function show()
	{
		var tel=document.getElementById('telef');
		tel.style.display=(tel.style.display=='none'?'block':'none');
                jQuery('.tel-overlay').toggle();
	}
	function close()
	{
		var tel=document.getElementById('telef2');
		tel.style.display=(tel.style.display=='none'?'block':'none');
	}

	function clear()
	{
		var fm=document.getElementById('fm');
		alert(fm);
	}

	function AcceptDigits(objtextbox)
	{
	   var exp = /[^\d]/g;
	   objtextbox.value = objtextbox.value.replace(exp,'');
	}

 var step=1;

 $(document).ready(function(){





$('#fm2 .link_close img').click(function(){
	$('.tel-overlay').css('display','none');
});
    $("a[rel='lightbox[photo]']").colorbox();

    $('.left-qu-block:first').addClass('qu-curr');
    $('#main_div').removeClass('hide');
    $('.right-qu-block:first').removeClass('hide');

    $(".phones").mask("(999) 999-9999");
    //$(".call-time").mask("99.99.99 99:99:99");

    $("#phones").mask("(999) 999-9999");
    //$("#call-time").mask("99.99.99 99:99:99");

    validateFields('cforms', '/_ajax/calculate.php', 'aj_templates');
    validateFields('cformsorder', '/_ajax/order.php', 'aj_result');

    $('.radio_site').live('click', function(){
          $('#main_div').removeClass('hide');
          $('.left-qu-block ').each(function(){ $(this).removeClass('qu-curr');});
          $(this).parent().parent().parent().find('.left-qu-block:first').addClass('qu-curr');
          $('.right-qu-block').each(function(){ $(this).addClass('hide');});      
          $('#section_'+$(this).attr('value')).removeClass('hide');
    });

    $('.mindex').live('click', function(){

       if($(this).parent().parent().hasClass('qu-curr')) {
          $('#main_div').addClass('hide');
          $('.left-qu-block ').each(function(){ $(this).removeClass('qu-curr');});
          $('.right-qu-block').each(function(){ $(this).addClass('hide');});      
       } 
       else {
          $(this).parent().find('input:first').attr('checked', 'checked');
          $('#main_div').removeClass('hide');
          $('.left-qu-block ').each(function(){ $(this).removeClass('qu-curr');});
          $(this).parent().parent().parent().find('.left-qu-block:first').addClass('qu-curr');
          $('.right-qu-block').each(function(){ $(this).addClass('hide');});      
          $('#section_'+$(this).attr('id')).removeClass('hide');
       }
       
       return false;
    });

    $('.qu-close').live('click',function(){
       $('#main_div').addClass('hide');
       $('.left-qu-block ').each(function(){ $(this).removeClass('qu-curr');});
       $(this).parent().addClass('none');

       return false;
    });

    $('.qu').live("click", function(){
       $(this).parent().find('.mini-hint:first').toggleClass('none');

       return false;
    });

    $('.inner-catalog').live('click', function(){
       if(!this.checked) {
          $('.block-'+$(this).attr('id')).each(function(){ $(this).fadeOut('slow');});
          $('.block-'+$(this).attr('id')).each(function(){
             $(this).find('input:radio').each(function(){ $(this).removeAttr('checked');});
          });
          $('ul #label-'+ $(this).attr('id')).remove();
          prices();
       }
       else {
          $('.block-'+$(this).attr('id')).each(function(){ 
             $(this).fadeIn('slow');
//             $(this).find('input:first').attr('checked','checked');
             $(this).find('input:first').trigger('click');
//             $('.price-add-too').trigger('click');
             prices();
          });      
       }
    });

    $('.price-add').live('click', function(){
       var text = $(this).parent().parent().find('td').next().find('strong:first').html();
       if(this.checked) {
//          $('.left-blocks-wrapper-step2 ul:first').append('<li id="label-'+$(this).attr("id")+'">&gt; '+ text +'</li>');
          $('#dop_options').append('<li id="label-'+$(this).attr("id")+'">&gt; '+ text +'</li>');
       }
       else {
          $('ul #label-'+$(this).attr('id')).remove();
       }
       prices();
    });

    $('.price-add-too').live('click', function(){
       var clas = $(this).parent().parent().parent().parent().attr('class');
       var currId = parseInt(clas.indexOf('-'))+1;
       var currIdend = parseInt(clas.indexOf(' '));
       var id = clas.substring(currId, currIdend);
       var text = $(this).parent().find('strong:first').html();
       var sText = $('#'+id).parent().parent().find('td').next().find('strong:first').html();


       if($('#'+id).attr('checked')) {
          if($('#dop_options').has('#label-'+id).length) {

             if($('#label-'+id).has('#label-'+$(this).attr('name')).length) {
                $('#label-'+$(this).attr('name')).html(text);
             }
             else {
                $('#label-'+id +' ul').append('<li id="label-' + $(this).attr("name") + '">'+ text +'</li>');
             }
          }
          else {
             $('#dop_options').append('<li id="label-' + id + '">&gt; '+ sText +'</li>');
             $('#label-'+id).append('<ul><li id="label-' + $(this).attr('name')  + '">' + text + '</li></ul>');
          }
       }       
       prices();
    });

    $('.design-add-price').live('click', function(){
       if(this.checked) {
          if($('#add-options').has('strong').length)
             $('#add-options').append('<strong id="add-option-'+ $(this).attr('id') +'">, '+ $(this).parent().parent().find('td').next().find('label:first').html() +'</strong>');
          else
             $('#add-options').append('<strong id="add-option-'+ $(this).attr('id') +'"> '+ $(this).parent().parent().find('td').next().find('label:first').html() +'</strong>');
       }
       else
          $('#add-option-'+ $(this).attr('id')).remove();
       prices();
    });

    $('.prev-step').live('click', function(){
       $('#step').attr('value', $(this).html());
       $('#cforms').submit();

       return false;
    });

    $('#backButton').live('click', function(){
       $('#step').attr('value', $('#step').attr('value')-2);
       $('#cforms').submit();
       
       return false;
    });

 });

 function initButton() {
    step = $('#step').attr('value')-0;

    $('#curStep').html(step-1);
    if(step<=2)
       $('#back-button').addClass('hide');
    else
       $('#back-button').removeClass('hide');
    if(step==4) {
       $('#next').addClass('oformit');
        $('#zakaz').remove();
        $('#pricezakaz').remove();
        $('.site-overall-desc').append("<input type='hidden' value='"+$('.site-type').html()+"' name='zakaz' id='zakaz'>");
        $('.site-overall-desc').append("<input type='hidden' value='"+$('#price').html()+"' name='pricezakaz' id='pricezakaz'>");
    }
    else if(step>4)
       $('.calculate').remove();
    else {
       $('#next').removeClass();
       $('#next').addClass('dalee');
    }
 }

 function prices() {
   var prices = 0;
   var sPrice = $('#main_sect').attr('value')-0;
   if(sPrice) prices=sPrice;

   $('.center-options-list input').each(function(){
      if(this.checked){
         if(parseInt($(this).attr('price')))
            prices=prices + parseInt($(this).attr('price'));  
      }
   });
   $('#price').html(prices);
   tree();
   initButton();
 }

 function tree() {
    var color = new Array();
        color[1]='b4ed5a';
        color[2]='d9e139';
        color[3]='e8e32d';
        color[4]='ffd909';
        color[5]='f99c1c';
        color[6]='f15f22';
        color[7]='cb2026';

    var sectionValue = Math.floor(parseInt($('#maxprice').attr('value'))/8);
    var procent = Math.floor(parseInt($('#maxprice').attr('value'))/100)+1;
    var cProcent = Math.floor(parseInt($('#price').html()/procent));
    var cStep = Math.floor(parseInt($('#price').html()/sectionValue))

    $('.bgb').css('width', Math.floor(cProcent*1.5) +'px');
    var $tree = $('.tree-bg').removeClass();
    $tree.addClass('tree-bg step'+cStep);
    if(cStep>=8)
       $('.bgb').css('background', 'url(/i/kosmos.png) #000 no-repeat 0px 14px');
    else
       $('.bgb').css('background', 'url(/i/kosmos.png) #'+ color[cStep]  +' no-repeat 0px 0px');  
 }


function validateFields(form_name, url, target) {

  $.validator.addMethod('validName', function (value) {
      var result = true;
      var iChars = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
      for (var i = 0; i < value.length; i++) {
          if (iChars.indexOf(value.charAt(i)) != -1) {
              return false;
          }
      }
      return result;
  }, ''); 


  var options = { 
    target: "#"+target,
    url: url,
    timeout: 15000, 
    beforeSubmit: function() {
	$('.overlay').removeClass('hide');
    },
    success: function() {
        prices();
        $('.overlay').addClass('hide');
        $(".phones").mask("(999) 999-9999");
        //$(".call-time").mask("99.99.99 99:99:99");
        $('#aj_image').load('/_ajax/captcha.php',{},function(){
           $('#captcha_word').attr('value','');
        });	
    }
  };

  $("#"+form_name).validate({
     submitHandler: function(form) {
        $(form).ajaxSubmit(options);
   
    },  
    ignore: '.ignore',
    focusInvalid: false,
    focusCleanup: true,
    rules: {
      type: {
         required: true
      },
      name: { 
         required: true
      },
      email: { 
         required: true,
	 email: true
      },
      phone: { 
         required: true
      }
    },
    messages: {
      type: {
        required: "Выберите тип заказываемого сайта"
      },
      name: {
        required: "Введите контактное лицо"
      },
      email: {
        required: "Введите адрес ящика",
        email: "Введите корректный адрес"
      },
      phone: {
        required: "Введите телефон"
      }
    }, 
    errorPlacement: function(error, element) {
        $('#errorbl').html('Заполните обязательные поля *');
        error.appendTo( element.parents().find("label[for='" + element.attr("name") + "']").find("span") );
    }
  }); 
}
