/*
  @project conversion.pl
  @name engine.js
  @created 2010-06-29
  @author Athena interactice(TM) Polska (http://athenainteractive.pl/)
  @description  jQuery powered JavaScript for page effects

  This file contains functions based on jQuery and intended to either add
  dynamic content and usability features to the site or supports the CSS
  file in making thing pretty. All following the Progressive Enhancement
  approach.

*/
var $j = jQuery.noConflict();


$j(document).ready(function() {
								
	$j("input#searchsubmit").val('');
	
	
// Makes inputs blank when input gets focus.
	$j("#mc_mv_EMAIL").val("Twój adres e-mail");
	$j("#mc_mv_EMAIL").attr("title", "Twój adres e-mail");
	$j("#s").val("Szukaj w serwisie");
	$j("#s").attr("title", "Szukaj w serwisie");
	
	
	$j("#mc_mv_EMAIL, input#s").focus(function() {
		var org_value = $j(this).val();          // Get a start value.
		var foc_value = ''                      // Focused value (empty).
		$j(this).addClass('writing');
		var title = $j(this).attr("title");      // Get a title attribute...

		if (title == org_value){                 // ... and if no user input...
			$j(this).val(foc_value);               // ... set the focused value.
		}

		$j(this).blur(function() {
			if ($j(this).val() == ''){              // If no input from user...
				$j(this).val(org_value);             // ... set the start value.
				$j(this).removeClass('writing');
			}
		}); // /.blur
	}); // /INPUTS HOVERING
	
	
	$j("#submenu li ul li:last").addClass("last");
	
	$j("#orderForm").validate();
	$j("#orderForm2").validate();
	
	
	/*
	$j("#fMOrder").change(function(event) {
  		var mtpl = $j(this).text();
		$j("#fYOrder").val(mtpl * 12);	    
  	});
	
	
	$j("#fEOrder").keyup(function(event) {
  		var mtpl = $j(this).val();
		var mtpl2 = $j("#fYOrder").val();
		$j("#fYSell").val(mtpl * mtpl2);	    
  	});
	*/
	
		/*auto complete 1*//*
		$j("#fMOrder").keyup(function() {
    	var mtpl = $j(this).val().replace(new RegExp(" ", 'g'), "");				
		if (mtpl.length > 0){
			
			$j("#fYOrder").val(mtpl * 12);
      		
   		 }
    	else {
     		//
    	}
		
		
 		});
		
		/*auto complete 2*//*
		$j("#fEOrder").keyup(function() {
    	var mtpl = $j(this).val().replace(new RegExp(" ", 'g'), "");	
		var mtpl2 = $j("#fYOrder").val();
		if (mtpl.length > 0){
			
			$j("#fYSell").val(mtpl * mtpl2);
			$j("#fYGain").val($j("#fYSell").val().replace(new RegExp(" ", 'g'), "") - $j("#fBudget").val().replace(new RegExp(" ", 'g'), ""));
      		
   		 }
    	else {
     		//
    	}
		
		
 		});
		
		/*Nowe*/
		
		
		
		/*auto order form*/
		$j("#fEOrder, #fMOrder, #fBudget").keyup(function() {
									  
			var mtpl1 = $j("#fMOrder").val().replace(new RegExp(" ", 'g'), "");
			var mtpl = $j("#fEOrder").val().replace(new RegExp(" ", 'g'), "");	
			var mtpl2 = $j("#fYOrder").val();
			if (mtpl.length > 0 || mtpl1.length > 0 || mtpl2.length > 0){
				
				$j("#fYOrder").val(mtpl1 * 12);
				$j("#fYSell").val(mtpl * mtpl2);
				$j("#fYGain").val($j("#fYSell").val().replace(new RegExp(" ", 'g'), "") - $j("#fBudget").val().replace(new RegExp(" ", 'g'), ""));
				
			 }
			else {
				//
			}
		
		
 		});
		
		/*auto complete generate client form*/
		$j("#f2MContract, #f2ESell, #f2MOrder, #f2Budget").keyup(function() {
									  
			var f2_budget = $j("#f2Budget").val().replace(new RegExp(" ", 'g'), "");
			var f2_ask = $j("#f2MOrder").val().replace(new RegExp(" ", 'g'), "");
			var f2_contract = $j("#f2MContract").val().replace(new RegExp(" ", 'g'), "");
			var f2_value = $j("#f2ESell").val().replace(new RegExp(" ", 'g'), "");
			
			
			if (f2_ask.length > 0 || f2_contract.length > 0 || f2_value.length > 0){
				
				$j("#f2YOrder").val(f2_contract * 12);
				$j("#f2YSell").val(f2_value * $j("#f2YOrder").val());					
				$j("#f2YGain").val($j("#f2YSell").val().replace(new RegExp(" ", 'g'), "") - $j("#f2Budget").val().replace(new RegExp(" ", 'g'), ""));
				
			 }
			else {
				//
			}
		
		
 		});
		
		/*switch calculator*/
		
		$j("#switchCalc").change(function() {
										  
		var toshow = $j("select option:selected").val();
		if(toshow == 'formMakeOrder') {$j("#clientsFormWrapp").hide(); $j("#orderFormWrapp").show(); }
		if(toshow == 'formGanerateClients') {$j("#orderFormWrapp").hide(); $j("#clientsFormWrapp").show(); }
	
		});

		
		
		
		
	

	
	/*$j("#faceboxInit").click(function() {
		//jQuery.facebox({ ajax: 'http://localhost:8888/wordpress/wp-content/themes/conversion/newsletter.php' });
		jQuery.facebox({ div: '#newsletterBox' });
		
		
		$j("#mc_signup_form").submit(function(){ 
		alert("poszło");
		return 0;
		}); 
		
		//return 0;							  
	});
	
	*/


	
	  

});   
