window.onload = function() {
	init();
}

$(document).ready( function(){
	
	
	$('.ctn-product-links .lnk-friend').click( function (){
		var top=0, left=0;
		top = $(this).position().top+27;
		left = $(this).position().left-85;
		$('.ctn-tell-a-friend').css('display', 'block');
		$('.lnk-friend').addClass('lnk-friend2');
		$('.ctn-tell-a-friend').css('top', top+'px');
		$('.ctn-tell-a-friend').css('left', left+'px');
		return false;
	});
	$('.ctn-tell-a-friend .lnk-close').click( function (){
		$('.ctn-tell-a-friend').css('display', 'none');
		$('.lnk-friend').removeClass('lnk-friend2');
		return false;
	});
	
	$('.ctn-carousel .lnk-product').click( function (){
		var end_image = $(this).children().attr('src');
		$('.ctn-box-left .img-big-size').attr('src',end_image);
		return false;
	});
	
	$(".lnk-modal").click( function(){
		var top;
		top = $(this).offset().top;
		$("#ctn-modal").css('top', top)
		$("#ctn-modal").show();
		return false;
	});
	
	$("#ctn-modal").click( function(){
		$(this).hide();
		return false;
	});
	
	
	$('.lnk-send.contact').click( function (){
		
		var msg="";
		
		if($('#contact_yourname').val() == ''){
			msg += '<span>Your name is empty!</span><br />';	
		}
		
		if($('#contact_yourphone').val() == ''){
			msg += '<span>Your phone is empty!</span><br />';	
		}
		
		if($('#contact_youremail').val() == ''){
			msg += '<span>Your email is empty!</span><br />';	
		}
		
		if($('#contact_subject').val() == ''){
			msg += '<span>Subject is empty!</span><br />';	
		}
		
		if($('#contact_comments').val() == ''){
			msg += '<span>Comments is empty!</span><br />';	
		}
		
		if (msg != '') {
			msg = "<div id=\"topoValida\"><img src='http://test.avgproducts.com/_js/facebox/warning.png' align='absmiddle' /><b>The following problems were found:</b><br /><br /></div>" + msg;  
	        jQuery.facebox(msg);
	        return false;
	    }
	    
	    else{
			$('#contactform').submit();
	    }
	
	});
	
	$('.lnk-send.customer_care').click( function (){
		
		var msg="";
		
		if($('#customer_number').val() == ''){
			msg += '<span>Order number is empty!</span><br />';	
		}
		
		if($('#customer_name').val() == ''){
			msg += '<span>First name is empty!</span><br />';	
		}
		
		if($('#customer_lastname').val() == ''){
			msg += '<span>Last name is empty!</span><br />';	
		}
		
		if($('#customer_address').val() == ''){
			msg += '<span>Address is empty!</span><br />';	
		}

		if($('#customer_city').val() == ''){
			msg += '<span>City is empty!</span><br />';	
		}

		if($('#customer_state').val() == ''){
			msg += '<span>State is empty!</span><br />';	
		}
		
		if($('#customer_zipcode').val() == ''){
			msg += '<span>State is empty!</span><br />';	
		}
		
		if($('#customer_country').val() == ''){
			msg += '<span>Country is empty!</span><br />';	
		}

		if($('#customer_email').val() == ''){
			msg += '<span>Email is empty!</span><br />';	
		}
		
		if($('#customer_phone').val() == ''){
			msg += '<span>Phone is empty!</span><br />';	
		}

		if($('#customer_payment').val() == ''){
			msg += '<span>Payment method is empty!</span><br />';	
		}
		
		if($('#customer_item').val() == ''){
			msg += '<span>Item reference is empty!</span><br />';	
		}

		if($('#customer_reason').val() == ''){
			msg += '<span>Reason for Return is empty!</span><br />';	
		}	
		
		if($('#customer_date').val() == ''){
			msg += '<span>Todays date is empty!</span><br />';	
		}
		
		if (msg != '') {
			msg = "<div id=\"topoValida\"><img src='http://test.avgproducts.com/_js/facebox/warning.png' align='absmiddle' /><b>The following problems were found:</b><br /><br /></div>" + msg;  
	        jQuery.facebox(msg);
	        return false;
	    }
		
		else{
			$('#customerform').submit();
	    }
		
	});
	
	$('.lnk-send-question').click( function(){
		
		var msg="";
		
		if($('#question_name').val() == ''){
			msg += '<span>Name is empty!</span><br />';	
		}
		
		if($('#question_email').val() == ''){
			msg += '<span>Email is empty!</span><br />';	
		}
		
		if($('#question_message').val() == ''){
			msg += '<span>Message is empty!</span><br />';	
		}
		
		if (msg != '') {
			msg = "<div id=\"topoValida\"><img src='http://test.avgproducts.com/_js/facebox/warning.png' align='absmiddle' /><b>The following problems were found:</b><br /><br /></div>" + msg;  
	        jQuery.facebox(msg);
	        return false;
	    }
		
		else{
			$('#frmQuestion').submit();
	    }
			
	});
	
	$('#ctn-header .lst-header li').hover(
		function(){
		 	$('ul:first', this).fadeIn(300);	
		},
		
		function(){
			$('ul:first', this).fadeOut(300);

		}
		
	);
	
	$('#ctn-header .lst-menu li').hover(
		function(){
		 	$('ul:first', this).fadeIn(300);	
		},
		
		function(){
			$('ul:first', this).fadeOut(300);

		}
		
	);
	
	$('#ctn-content .ctn-center-zone .ctn-faq .lst-faq dt a').click( function(){
		var i;
		i = $(this).attr('href').split('#');
		$('#ctn-content .ctn-center-zone .ctn-faq .lst-faq #dd-'+i[1]).slideToggle("slow", function(){
			if( $('#ctn-content .ctn-center-zone .ctn-faq .lst-faq #dd-'+i[1]).css('display') == "block"){
				$('#ctn-content .ctn-center-zone .ctn-faq .lst-faq #dt-'+i[1]+' a.lnk-faq').text('(-)');
			}
			else{
				$('#ctn-content .ctn-center-zone .ctn-faq .lst-faq #dt-'+i[1]+' a.lnk-faq').text('(+)');
			}
		});
		
		return false;
	});
	
	$('#ctn-content .ctn-center-zone .ctn-party-ideas .lst-party-ideas dt a').click( function(){
		var i;
		i = $(this).attr('href').split('#');
		$('#ctn-content .ctn-center-zone .ctn-party-ideas .lst-party-ideas #dd-'+i[1]).slideToggle("slow", function(){
			if( $('#ctn-content .ctn-center-zone .ctn-party-ideas .lst-party-ideas #dd-'+i[1]).css('display') == "block"){
				$('#ctn-content .ctn-center-zone .ctn-party-ideas .lst-party-ideas #dt-'+i[1]+' a.lnk-resource span').text('(-)');
			}
			else{
				$('#ctn-content .ctn-center-zone .ctn-party-ideas .lst-party-ideas #dt-'+i[1]+' a.lnk-resource span').text('(+)');
			}
		});
		
		return false;
	});
	
	$('#ctn-content .ctn-center-zone .ctn-news-room .lst-news-room dt a').click( function(){
		var i;
		i = $(this).attr('href').split('#');
		$('#ctn-content .ctn-center-zone .ctn-news-room .lst-news-room #dd-'+i[1]).slideToggle("slow", function(){
			if( $('#ctn-content .ctn-center-zone .ctn-news-room .lst-news-room #dd-'+i[1]).css('display') == "block"){
				$('#ctn-content .ctn-center-zone .ctn-news-room .lst-news-room #dt-'+i[1]+' span').html('<a href=#'+i[1]+'><img src="/_img/bola_menos.jpg" /></a>');
			}
			else{
				$('#ctn-content .ctn-center-zone .ctn-news-room .lst-news-room #dt-'+i[1]+' span').html('<a href=#'+i[1]+'><img src="/_img/bola_mais.jpg" /></a>');
			}
		});
		
		return false;
	});
	$("#facebox .popup form .send").click( function(){
		$("#envie_amigo").submit();
	});
	
});

function show_login()
{
	document.getElementById("ctn-login").style.display = "";
}

function valida_login()
{
	if (!document.getElementById('login_email').value)
	{
		alert("Please inform your e-mail!");
		document.getElementById('login_email').focus();
		return false;
	}
	if (!document.getElementById('login_password').value)
	{
		alert("Please inform your password!");
		document.getElementById('login_password').focus();
		return false;
	}
	document.getElementById("flogin").submit();
}

function SendFriend(id){
	jQuery.facebox('<h3>Send to a friend!</h3><form id="envie_amigo" name="envie_amigo" method="POST" action="send_friend_msg.php"><table><tr><td align="right">Your name:</td><td><input type="text" id="name" name="name" size="50" /><input type="hidden" id="id" name="id" value="" /></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="right">Email:</td><td><input type="text" id="email" name="email" size="50" /></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="right">Recipient name:</td><td><input type="text" id="name_friend" name="name_friend" size="50" /></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="right">Recipient Email:</td><td><input type="text" id="email_friend" name="email_friend" size="50" /></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="right">Comment:</td><td><textarea id="content" name="comment" row="8" cols="38"></textarea></td></tr><tr><td colspan="2">&nbsp;</td></tr><td colspan="2"><input type="submit" value="Send" name="send" /></td></tr></table></form>');
	$('#id').val(id);
}

function AbrePopup(id){
	window.open ("http://bigchef.dynalias.net/popup_news_room.php?id="+id, "mywindow", "location=1, status=1, scrollbars=1, width=700, height=500");
}

function click() {
if (event.button==2||event.button==3) {
oncontextmenu='return false';
  }
}
document.onmousedown=click
document.oncontextmenu = new Function("return false;")

function reportSize() {
	myWidth = 0, myHeight = 0, w=0;
  	
	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
		myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
    	
  	} 
  	
  	
  	else {
    	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      		//IE 6+ in 'standards compliant mode'
	      	myWidth = document.documentElement.clientWidth;
	      	
	      	myHeight = document.documentElement.clientHeight;
	    } 
	    else {
      	
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		        //IE 4 compatible
		        myWidth = document.body.clientWidth;
		        myHeight = document.body.clientHeight;
	      	}
		      
	    }
	    
  	}
  	
  	if( ( ( (myWidth - 1100) / 2) ) <= 0){
  		
		$("#ctn-header2-left").hide();
		$("#ctn-header2-right").hide();
		
    }
    
    else{
    	
		w = (myWidth - 1100) / 2;
		
		$("#ctn-header2-left").show();
		$("#ctn-header2-right").show();
		
    	if(jQuery.browser.safari){
    		
			$("#ctn-header2-left").width(w-9);
			$("#ctn-header2-right").width(w-9);
		}
		
		else{
			
			if(jQuery.browser.msie){
				$("#ctn-header2-left").width(w);
				$("#ctn-header2-right").width(w);	
			}
			else{
			
				$("#ctn-header2-left").width(w-9);
				$("#ctn-header2-right").width(w-9);	
			}
		
    	}
    	
    }
	if(myWidth < 1100){
    	$("#ctn-footer .div-sitemap").width(1100);
	}
	else{
		$("#ctn-footer .div-sitemap").width(myWidth);
	}
}

function setInnerWidth(w,h){

	window.resizeTo(800, 800);
	reportSize();
	var oX = 800-myWidth;
	var oY = 800-myHeight;
	window.resizeTo( (w+oX) , (h+oY) );
	
}

function doTest(){
	reportSize();
}

function init(){
	window.onresize = doTest;
	doTest();
}


function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
                }
    }else{
        return false;
    }
}



function RemoveBad(strTemp) {
    strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g,"");
    return strTemp;
}
