// wx: jquery functions
function load()
{
	jQuery.validator.setDefaults({
		debug: false,
		success: "valid"
	});
	
	
	$('#contest_form').validate();
	
	
	$('#feedback_form').validate(
	{
		rules:
		{  
			'2[]': 		{required: function(element)
						   {
						   	
						   	if ( $("#check_y_2:checked").attr("checked") )
						   	{
						   		if( $("#print_music_mag_other").val() != "")
   								{
						   			return false;
						   		}
						   	}
						   	else if ( $("#check_n_2:checked").attr("checked") )
						   	{
						   		return false;
						   	}
						   }
					},
			'3[]': 		{required: function(element)
						   {
						   	if ( $("#check_y_3:checked").attr("checked") )
						   	{
						   		if( $("#music_web_mag_other").val() != "")
   								{
						   			return false;
						   		}
						   	}
						   	else if ( $("#check_n_3:checked").attr("checked") )
						   	{
						   		return false;
						   	}
						   }
					},
			'4[]': 		{required: function(element)
						   {
						   	if ( $("#check_y_4:checked").attr("checked") )
						   	{
						   		if( $("#blog_other").val() != "")
   								{
						   			return false;
						   		}
						   	}
						   	else if ( $("#check_n_4:checked").attr("checked") )
						   	{
						   		return false;
						   	}
						   }
					},
			'5[]': 		{required: function(element)
						   {
						   	if ( $("#check_y_5:checked").attr("checked") )
						   	{
						   		if( $("#life_news_cult_other").val() != "")
   								{
						   			return false;
						   		}
						   	}
						   	else if ( $("#check_n_5:checked").attr("checked") )
						   	{
						   		return false;
						   	}
						   }
					},
			'6[]': 		{required: function(element)
						   {
						   	if ( $("#check_y_6:checked").attr("checked") )
						   	{
						   		if( $("#social_network_other").val() != "")
   								{
						   			return false;
						   		}
						   	}
						   	else if ( $("#check_n_6:checked").attr("checked") )
						   	{
						   		return false;
						   	}
						   }
						   
					},
			radio_list:	{required: function(element)
						   {
						   	return $("#radio_yn:checked").val() == 'Y'; 
						   } 
					},
			online_radio_list: {required: function(element)
						   {
						   	return $("#online_radio_yn:checked").val() == 'Y'; 
						   }
					},
			newspaper_list:	{required: function(element)
						   {
						   	return $("#newspaper_yn:checked").val() == 'Y'; 
						   } 
					},
			purchase_percent_digital: {required: true, number: true, min: 1, max: 100}
		},
		
		messages: 
		{
			2:		"This field is required",
			3:		"This field is required",
			4:		"This field is required",
			5:		"This field is required",
			6:		"This field is required",
			radio_list:	"Enter in the stations",
			online_radio_list: "Enter in the websites",
			newspaper_list:	"Enter in which ones",
			purchase_percent_digital: "Enter in a valid number"
		}
   	});
   	
   	$("#check_y_2, #check_n_2").click(function(){ 
   		if ($("#check_n_2:checked").attr("checked"))
   		{ 
   			$(".2").removeAttr("checked"); 
   			$(".2, #print_music_mag_other").attr("disabled","disabled");
   		} 
   		else
   		{ 
   			$(".2, #print_music_mag_other").removeAttr("disabled");
   		}
   		
   		if ($("#print_music_mag_other").val() != "")
   		{
   			$("#print_music_mag_other").val(""); 
   		}
   		$(".2").valid();
   			
   	});
   	$("#print_music_mag_other").keyup(function()
   	{
   		$(".2").valid();
   	});
   	
   	$("#check_y_3, #check_n_3").click(function(){
   		if ($("#check_n_3:checked").attr("checked")) { 
   			$(".3").removeAttr("checked"); 
   			$(".3, #music_web_mag_other").attr("disabled","disabled");
   		} else
   		{
   			$(".3, #music_web_mag_other").removeAttr("disabled"); 
   		}
   		if ($("#music_web_mag_other").val() != "") {
   			$("#music_web_mag_other").val(""); 
   		}
   		$(".3").valid();
   	});
   	$("#music_web_mag_other").keyup(function()
   	{
   		$(".3").valid();
   	});
   	
   	$("#check_y_4, #check_n_4").click(function(){
   		if ($("#check_n_4:checked").attr("checked")){ 
   			$(".4").removeAttr("checked"); 
   			$(".4, #blog_other").attr("disabled","disabled");
   		} else
   		{
   			$(".4, #blog_other").removeAttr("disabled");
   		}
   		if ($("#blog_other").val() != ""){ 
   			$("#blog_other").val(""); 
   		}
   		$(".4").valid();
   	});
   	$("#blog_other").keyup(function()
   	{
   		$(".4").valid();
   	});
   	
   	$("#check_y_5, #check_n_5").click(function(){
   		if ($("#check_n_5:checked").attr("checked")){ 
   			$(".5").removeAttr("checked");
   			$(".5, #life_news_cult_other").attr("disabled","disabled"); 
   		} else
   		{
   			$(".5, #life_news_cult_other").removeAttr("disabled");
   		}
   		if ($("#life_news_cult_other").val() != ""){ 
   			$("#life_news_cult_other").val(""); 
   		}
   		$(".5").valid();
   	});
   	$("#life_news_cult_other").keyup(function()
   	{
   		$(".5").valid();
   	});
   	
   	$("#check_y_6, #check_n_6").click(function(){
   		if ($("#check_n_6:checked").attr("checked")){ 
   			$(".6").removeAttr("checked"); 
   			$(".6, #social_network_other").attr("disabled","disabled"); 
   		} else {
   			$(".6, #social_network_other").removeAttr("disabled");
   		}
   		if ($("#social_network_other").val() != ""){ 
   			$("#social_network_other").val(""); 
   		}
   		$(".6").valid();
   	});
   	$("#social_network_other").keyup(function()
   	{
   		$(".6").valid();
   	});
   	
   	$("input:radio").click(function() {
   		switch(this.name)
   		{
   			case 'radio_yn':	
   				if( $("#radio_yn:checked").val() == undefined ){
   					$("#radio_list").attr("disabled","disabled");
   				} else {
   					$("#radio_list").removeAttr("disabled");
   				}
   				if ($("#radio_list").val() != ""){ 
   					$("#radio_list").val(""); 
   				} 
   				$("#radio_list").valid();	
   				break;
   			case 'online_radio_yn':	
   				if( $("#online_radio_yn:checked").val() == undefined ){
   					$("#online_radio_list").attr("disabled","disabled");
   				} else {
   					$("#online_radio_list").removeAttr("disabled");
   				}
   				if ($("#online_radio_list").val() != ""){ 
   					$("#online_radio_list").val(""); 
   				} 
   				$("#online_radio_list").valid();
   				break;
   			case 'newspaper_yn':	
   				if( $("#newspaper_yn:checked").val() == undefined ){
   					$("#newspaper_list").attr("disabled","disabled");
   				} else {
   					$("#newspaper_list").removeAttr("disabled");
   				}
   				if ($("#newspaper_list").val() != ""){ 
   					$("#newspaper_list").val(""); 
   				} 
   				$("#newspaper_list").valid();	
   				break;
   		}
   	});
   	
   	$("#purchase_percent_digital").keyup(function(){ $("#purchase_percent_digital").valid(); });
}




function launchPlayer() {
	if(arguments.length > 0) var upc_arg = '?upc=' + arguments[0];
	else upc_arg = '';

	playerWindow = window.open('media_player/player.php'+upc_arg,'playerWindow','width=475,height=175,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no,location=no,history=no');
	playerWindow.focus();
}

function writeEncodedLink(input){
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
	
	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	
	do {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));
		
		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;
		
		output = output + String.fromCharCode(chr1);
		
		if (enc3 != 64) {
			output = output + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			output = output + String.fromCharCode(chr3);
		}
	} while (i < input.length);
	document.write(output);
}


