//jQuery.noConflict();

function getURL(target) {
	window.open(target);
}

function facebook_invite_users() {

        var dialog = new FB.UI.FBMLPopupDialog('Invite your friends to join', '');
        var fbml = "<fb:fbml>"+"<fb:request-form style=\"width:630px; height:540px;\" action=\"" + document.location.href + "?\"\tmethod=\"POST\" invite=\"false\" type=\"\" "+"content=\"I'd like to add you as a friend: <fb:req-choice url='http://url.com' label='Confirm' />\">"+"<fb:multi-friend-selector\tshowborder=\"false\" exclude_ids=\"\" actiontext=\"Invite your friends\" rows=\"5\" bypass=\"cancel\"\tshowborder=\"false\" />"+"</fb:request-form>"+"</fb:fbml>";
        dialog.setFBMLContent(fbml);
        dialog.setContentWidth(630); 
        dialog.setContentHeight(540);
        dialog.show();


}

function checkFields() {
	jQuery("#showErrors").html("");
	error = false;
	fieldsRequired = [ 	"user_login_register", "user_email_register", "pass1", "pass2" 	];
	
	jQuery.each( fieldsRequired, function() {
		if(jQuery("#" + this).attr("value") == "") {
			jQuery("#showErrors").append(jQuery("#" + this).attr("title") + "<br />");
			error = true;
		}
	});
	
	if(jQuery("#pass1").attr("value") != jQuery("#pass2").attr("value")) {
		jQuery("#showErrors").append("Die angegebenen Passw&ouml;rter stimmen nicht &uuml;berein!<br />");
		error = true;
	}
		
	if(jQuery("#pass1").attr("value").length < 6) {
		jQuery("#showErrors").append("Ihr Passwort muss mindestens 6 Zeichen lang sein!<br />");
		error = true;
	}
	
	if (jQuery('#license:checked').val() == null) {
		jQuery("#showErrors").append("Bitte akzeptieren Sie die Teilnahmebedingungen!<br />");
		error = true;
	}
	
	if(error) {
		jQuery("#showErrors").css("display","block");
		return false;
	} else {
		jQuery("#showErrors").css("display","none");
		return true;
	}
}

function searchFan() {
	jQuery.get("./wp-includes/searchFans.php?firstName=" + jQuery("#first_name").val() + "&lastName=" + jQuery("#last_name").val(), function(text){
		location.href = "./?page_id=26&search=" + text;
	});
}

function sendMail() {
	jQuery("#hinweis").html('<img src="./wp-content/themes/videoplatform/img/loading.gif"/> Bitte warte einen Moment. Deine Nachricht wird gesendet...');
	jQuery.get("./wp-includes/sendmail.php?receiver=" + jQuery("#receiver").val() + "&message=" + jQuery("#mailMessage").val() + "&sendermail=" + jQuery("#sendermail").val() + "&sender=" + jQuery("#sender").val(), function(text){
//		if(text == true) {
			jQuery("#hinweis").html('<img src="./wp-content/themes/videoplatform/img/correct.gif"/> Nachricht erfolgreich gesendet!');
//		}
//		else {
//			jQuery("#hinweis").html('<img src="./wp-content/themes/videoplatform/img/wrong.gif"/> Fehler! Nachricht konnte nicht gesendet werden!');
//		}
	});
}

function gotoPage(target) {
	location.href = target;
}

function checkRegisterCode(path) {
	jQuery("#registerCodeLoading").html('&nbsp;<img width="12" src="' + path + '/wp-content/themes/videoplatform/img/loading.gif"');
	jQuery("#submitRegistration").attr("disabled", true);
	var code = jQuery("#fan_code").val();
	
	switch (code) {
		case "RSOLF203": 
			jQuery("#rs_gruppe").val("Ritter Sport Olympia Fan");
			break;
		case "315RSF": 
			jQuery("#rs_gruppe").val("Ritter Sport Freund");
			break;
		case "RS945M": 
			jQuery("#rs_gruppe").val("Ritter Sport Mitarbeiter");
			break;
		default:
			jQuery("#rs_gruppe").val("Standard");
			break;
	}
	
	jQuery.get(path + "/wp-includes/checkRegisterCode.php?code=" + code, function(text){
		if(text == "true") { //TODO AJAX Ueberpruefung des Codes
			jQuery("#personal_information").slideDown("slow");
			jQuery("#registerCodeLoading").html('&nbsp;<img width="12" src="' + path + '/wp-content/themes/videoplatform/img/correct.gif"');
			jQuery("#submitRegistration").attr("disabled", false);
		} else {
			jQuery("#registerCodeLoading").html('&nbsp;<img width="12" src="' + path + '/wp-content/themes/videoplatform/img/wrong.gif"');
			jQuery("#submitRegistration").attr("disabled", false);
		}		
	});
}

function popUp (url) {
	fenster = window.open(url, "Teilnahmebedingungen", "width=600,height=400,status=yes,scrollbars=yes,resizable=no");
	fenster.focus();
}

function setCookie(postID) {
	var time = new Date(2011, 6, 1, 0, 0, 0);
	document.cookie = 'voted=true; expires=' + time.toGMTString() + ';';
	document.cookie = 'votedProductID=' + postID + '; expires=' + time.toGMTString() + ';';
}

function publishStream() {
	var image = 'http://blog.ritter-sport.de/services/public/media/images/fbapp_icon.jpg';
	var link = 'http://www.facebook.com/RitterSportDeutschland?v=app_169872299711374';
	
	FB.Connect.streamPublish(
		// user_message
		null,
		 // attachment
		{
			name: 'RITTER SPORT Blog-Schokolade',
			href: link,
			caption: 'Caption',
			description: 'Habe gerade f&uuml;r die RITTER SPORT Blog-Schokoalde abgestimmt. Jetzt auch abstimmen!',
			media:[{'type':'image','src':image,'href':link}]
		}
	);
}
