/**********************************************************************************
 - RollOvers -
**********************************************************************************/
$(document).ready(function() {

	$(function() {
		$(".rollOverButton").hover(function() {
		var defaultPath = $(this).attr("src");
		var MIMEtype = defaultPath.substr((defaultPath.length-3),3);
			$(this).attr("src", defaultPath.substr(0,(defaultPath.length-6))+"_b."+MIMEtype);
			//alert(MIMEtype);
		}, function() {
		var defaultPath = $(this).attr("src");
		var MIMEtype = defaultPath.substr((defaultPath.length-3),3);
			$(this).attr("src", defaultPath.substr(0,(defaultPath.length-6))+"_a."+MIMEtype);
			//alert(MIMEtype);
		});
	});

});
/**********************************************************************************
 - Poll Functions -
**********************************************************************************/
$(document).ready(function() {

	$('.radio_poll').click(onPollClick);

});

function onPollClick(){

	var pollScope = $(this).parent().parent().parent();
	//alert($(this).attr("value"));
	if(confirm("Are you sure you want to select this option?")){
		$.post("backends/setPollAnswers.php", {poll_answer_id:$(this).attr("value"), poll_id:$(this).attr("name")}, function($data){
			pollScope.html($data);
		});
	}

}
/**********************************************************************************
 - Coupons & Login Functions -
**********************************************************************************/
$(document).ready(function() {

	$('#login').children("a").click(onLoginClick);
	$('#tf_usr').click(onUserClick);
	$('#cpn_button a').click(onCouponClick);

});

function onCouponClick(){

	var clickType = $(this).attr("rel");
	var couponID = $(this).attr("id");
	var baseDir = $(this).attr("title");
	if(clickType == 1){
		//alert("esta logeado");
		openPopup(baseDir+"coupon.php?couponID="+couponID,400,500,25,25,0,1);
	}else{
		if(confirm("You need to Login in order to get the coupon. If you are not register please click yes to register. Otherwise click cancel and fill the Login form at the top of the page.")){
			window.location = baseDir+'en/home/register.html';
		}
		$('#tf_usr').css('border-color','#FF0000');
		$('#tf_pas').css('border-color','#FF0000')
	}
	return false;

}

function onUserClick(){

	$(this).attr("value","");

}

function onLoginClick(){

	var loginField = $('#tf_usr');
	var passField = $('#tf_pas');
	if(loginField.attr("value") != "" && loginField.attr("value") != "email" && loginField.attr("value") != 0){
		if(passField.attr("value") != ""){
			//alert("se va");
			document.forms["login"].submit();
		}else{
			passField.focus();
			passField.css('border-color','#FF0000');
			passField.attr("value","");
		}
	}else{
		loginField.focus();
		loginField.css('border-color','#FF0000');
		loginField.attr("value","");
	}
	
	return false;

}