// Common Javascript Functions
// (c) 2010 WZND.com

// VIP Form Eval
function vipEval() {
	var emailC = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var noE = true;
	
	if(document.vipSignup.first.value == '') {
		alert("Please enter your first name");
		document.vipSignup.first.focus();
		noE = false;
	}
	else if(document.vipSignup.first.value.indexOf("http") != -1) {
		alert("Please enter a valid first name");
		document.vipSignup.first.focus();
		noE = false;
	}
	else if(document.vipSignup.last.value == '') {
		alert("Please enter your last name");
		document.vipSignup.last.focus();
		noE = false;
	}
	else if(document.vipSignup.last.value.indexOf("http") != -1) {
		alert("Please enter a valid last name");
		document.vipSignup.flast.focus();
		noE = false;
	}
	else if(!emailC.test(document.vipSignup.email.value)) {
		alert("Please enter a valid email address");
		document.vipSignup.email.focus();
		noE = false;
	}
	
	if(noE) {
		alert("Thank you for signing up for VIP access!");
	}
	return noE;
}

// Sports Calendar
function getSport(date, sport) {
	var calPop = document.getElementById("cPop");
	
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			calPop.innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.open("GET", "/OnAir/sportCal.php?s=get&date="+date+"&sport="+sport, true);
	xmlhttp.send();
	
	cal("open");
}

function cal(type) {
	var calPop = document.getElementById("cPop");
	
	if(type == "open") {
		calPop.style.display = "block";
	}
	else if(type == "close") {
		calPop.style.display = "none";
	}
}

function hideListen() {
	var div = document.getElementById("lPop");
	var fade = document.getElementById("fade");
	
	document.getElementById("columnIntro").removeChild(div);
	document.getElementById("columnIntro").removeChild(fade);
}

// jQuery Functions
//
jQuery.noConflict();

jQuery(document).ready(function($){
	$("#lPop a").live('click', function() {
		$("#lPop").remove();
		$(".fade").remove();
	});
	
	$(".fade").live('click', function() {
		$("#lPop").remove();
		$(".fade").remove();
	});
						   
	// Listen Live Pop-up
	//
	$("[href='#listen']").click(function() {
		$("#columnIntro").prepend('<div id="fade" class="fade"></div><div id="lPop" class="listenPop"><a href="/Streams/wznd.asx" target="_blank" class="windows">Windows Media Player</a><a href="/Streams/wznd.aspx" target="_blank" class="itunes">iTunes Stream</a><a href="/Streams/wznd.ram" target="_blank" class="real">Real Player Stream</a><a href="/Streams/wznd.aspx" target="_blank" class="winamp">Winamp Stream</a><div class="bot"><a href="javascript:hideListen();" class="close">close</a></div></div>');
		$("#lPop").css({top:'50%',left:'50%',margin:'-'+ ($("#lPop").height() / 2)+ 'px 0px 0px -' +($("#lPop").width() / 2)+ 'px'});
		$(".fade").show();
		$("#lPop").slideDown();
	});
	
	
	//
	// Grill Promo Sign-Up
	//
	$("form[name=grillSignup]").submit(function(){
		var emailC = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var phoneC = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
		var noE = true;
		
		if($(this).find("input[name=firstName]").val() == '') {
			alert("Please enter in your first name.");
			noE = false;
			$(this).find("input[name=firstName]").focus();
		}
		else if($(this).find("input[name=lastName]").val() == '') {
			alert("Please enter in your last name.");
			noE = false;
			$(this).find("input[name=lastName]").focus();
		}
		else if(!phoneC.test($(this).find("input[name=phone]").val())) {
			alert("Please enter a valid phone number.");
			noE = false;
			$(this).find("input[name=phone]").focus();
		}
		else if(!emailC.test($(this).find("input[name=email]").val())) {
			alert("Please enter a valid email address.");
			noE = false;
			$(this).find("input[name=email]").focus();
		}
		else if($(this).find("input[name=fav]").val() == '') {
			alert("Please enter in your favorite artist/band.");
			noE = false;
			$(this).find("input[name=fav]").focus();
		}
		
		
		if(noE) {
			$.ajax({
			   type: "POST",
			   url: "/promos/grillsignup.php",
			   data:  $("form[name=grillSignup]").serialize()+"&js=true",
			   success: function(msg){
				   if(msg == "success") {
					 $("form[name=grillSignup] input").val("");
					 $("form[name=grillSignup] input.btn").val("Sign Up");
					 $("#columnIntro").prepend('<div id="fade" class="fade"></div><div id="lPop" class="listenPop"><p>Thank you for signing up!</p><a href="/promos/index.aspx" title="WZND Promotions" class="link">Sign Up to be VIP</a><a href="http://cas.illinoisstate.edu/sites/wznd/category/promotions/grill-giveaway/" title="WZND\'s Thrillin\', Chillin\' and Grillin\' Giveaway" class="link">Giveaway information</a><a href="http://www.wznd.com" title="WZND Radio" class="link">Go back to homepage</a><div class="bot"><a href="javascript:hideListen();" </div></div>');
					$("#lPop").css({top:'50%',left:'50%',margin:'-'+ ($("#lPop").height() / 2)+ 'px 0px 0px -' +($("#lPop").width() / 2)+ 'px'});
					$(".fade").show();
					$("#lPop").slideDown();
				   }
				   else {
					   alert(msg);
				   }
			   }
			});
		}
		return false;
	});
	
	//
	// Left Nav Slidedowns
	//
	
});
