$(document).ready(function() {
	
	//Mascaras
	$(".decimal").numeric({allow:".,"});
	$(".numeric").numeric();
	$(".date").mask("99/99/9999");
	$(".cpf").mask("999.999.999-99");
	$(".cnpj").mask("99.999.999/9999-99");
	$(".cep").mask("99999-999");
	$(".phone").mask("(99)9999-9999");
	
	//Mascara de Preco
	$(".price").priceFormat({
	    prefix: '',
	    centsSeparator: ',',
	    thousandsSeparator: '.'
	}); 
	
	$(".price").blur(function(){
		
		var price = this;
		
		if(price.value=='0,00'){
			price.value='';
		}
		
	});
	
	//Lightbox
	$(function() {
		$('.box_image a').lightBox({fixedNavigation:true});
	});
	
	
	
	//Ordenacao de Galeria
	$(".sort").sortable();
	$(".sort").disableSelection();
		 
	
	//Banner home
	$('.banner_images').cycle({
		fx: 'fade', 
		pause:  1,
		timeout: 5000, 
		pager: '.banner_nav',
		after: setAfter,
		before: setBefore		    
	});
	
	$('form[name=frm_search]').submit(function(){
		if($('form[name=frm_search] input[name=search]').val().length<2){
			alert("Digite ao menos 2 caracteres na busca");
			return false;
		}
	});
	
	
	$('form[name=frm_home_box]').submit(function(){
		$location = $('form[name=frm_home_box] select').val();
				
		if($location=='america_do_norte'){
			parent.window.location = 'http://www.hawsco.com/';
		} else if($location=='america_do_sul'){
			
			if($('form[name=frm_home_box] input[name="location_check"]').is(':checked')){
				$.ajax({
				   type: "GET",
				   url: "/acoes",
				   data: "action=setlocation&location="+$location,
				   async: false,
				   sucess: function(){
						$return = "true";
					}, 
					error: function(){ 
						$return = "false";
					}
				 });
			
				parent.window.location = '/';
			}
			
		} else if($location=='asia'){
			parent.window.location = 'http://www.haws.sg/';
		} else if($location=='europa'){
			parent.window.location = 'http://www.haws.ch/www/index.php';
		}
		
		return false;
	});
	
	
	function setBefore(){
		
	}
	
	function setAfter(){
		
	}
	
	//Galeria de Imagens
	$('.thumb_gallery ul li').click(function(){
		$index = $(this).index();
		$('.company_gallery_image ul li').removeClass('gallery_show');
		$('.company_gallery_image ul li:eq('+$index+')').addClass('gallery_show');
	});
	
	
	//Set Language
	$('select[name=lang]').change(function(){
		$('form[name=frm_lang]').submit();
	});
	
	$(function(){
	    // Tabs
	    $('#tabs').tabs();
	    
	    //hover states on the static widgets
	    $('#dialog_link, ul#icons li').hover(
		    function() { $(this).addClass('ui-state-hover'); }, 
		    function() { $(this).removeClass('ui-state-hover'); }
	    );		
	});

});
	

function contact(){
	
	$(document).ready(function() {
		
		//Form Validator
		array_validator=new Array();
		cnt=0;
		array_validator[cnt++]='contact_name,1,text';
		array_validator[cnt++]='contact_email,1,email';
		array_validator[cnt++]='contact_phone,1,text';
		array_validator[cnt++]='contact_city,1,text';
		array_validator[cnt++]='contact_state,0,select';
		array_validator[cnt++]='contact_group,0,select';
		array_validator[cnt++]='contact_message,1,text';
		
			
		setValidatorFields('form[name=frm_contact]', array_validator);
	});
	
}

function newsletter(){
	
	$(document).ready(function() {
		
		//Form Validator
		array_validator=new Array();
		cnt=0;
		array_validator[cnt++]='newsletter_name,1,text';
		array_validator[cnt++]='newsletter_mail,1,email';
		array_validator[cnt++]='newsletter_area,0,select';
			
		setValidatorFields('form[name=frm_newsletter]', array_validator);
	});
	
}


function sendPaginator($newPage){
	document.getElementById('paginator_page').value=$newPage;
	document.getElementById('frm_paginator').submit();
}
