var saList = "/web/uploads/videoPlayer/VideoPlaylist_v4.swf?playlist=sa_preview";
var alList = "/web/uploads/videoPlayer/VideoPlaylist_v4.swf?playlist=al_preview";
var stList = "/web/uploads/videoPlayer/VideoPlaylist_v4.swf?playlist=st_preview";
var openSign = false;
var setSecondCookie = false;

if(location.href.match("lg=")){
	var lgval = location.href.substr((location.href.indexOf("lg=")+3));
	
	if(lgval.indexOf("&")!=-1){
		lgval = lgval.substr(0,lgval.indexOf("&"));	
	}
	switch(lgval){
		case "0":
			openSign = true;
			break;
		case "1":
			setFormCookie();
			setSecondCookie = true;
			break;
		default:
			break;
	}
}

$(document).ready(function(){
	if(getCookie("loggedIn") == "true"){	
		saList = "/web/uploads/videoPlayer/VideoPlaylist_v4.swf?playlist=sa";
		alList = "/web/uploads/videoPlayer/VideoPlaylist_v4.swf?playlist=al";
		stList = "/web/uploads/videoPlayer/VideoPlaylist_v4.swf?playlist=st";
	}		
	
		
	$('.AlcoholAbusePrevention #VideoPlaylist_v4').flash({
		src: alList,
		width: 928,
		height: 520,
		wmode: 'transparent'
	}, {expressInstall: true});
	$('.SexualAssaultPrevention #VideoPlaylist_v4').flash({
		src: saList,
		width: 928,
		height: 520,
		wmode: 'transparent'
	}, {expressInstall: true});
	$('.StudyAbroad #VideoPlaylist_v4').flash({
		src: stList,
		width: 928,
		height: 520,
		wmode: 'transparent'
	}, {expressInstall: true});
	
	$(".tbFtest").click(function(){
		tb_show("Sign Up","#TB_inline?height=690&width=408&inlineId=signUpForm",false);
		this.blur();
		return false;					 						 
	});
	
	if(openSign == true){
		var t = setTimeout('tb_show("Sign Up","#TB_inline?height=690&width=408&inlineId=signUpForm",false)',500);
	}
	if(setSecondCookie == true){
		$("a").each(function(){
			if(this.href.match("sexual-assault-prevention") || this.href.match("alcohol-abuse-prevention") || this.href.match("study-abroad")){
				this.href= this.href+"?lg=1";				   
			}
		});
	}
	$("#subContainer input").click(function(){
		if(validateSignUp()==true){
			return true;
		}else{
			return false;
		}
	});

});

function setFormCookie()
{
	var days = 1;
	setCookie("loggedIn","true",days);
	return true;
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function validateSignUp()
{
	$("#pg")[0].value = $("#wrap")[0].className.replace("UnlessTheresConsent ","").replace(" UnlessTheresConsent","").replace(" Zombies,Alcohol&You","").replace("Zombies,Alcohol&You ","");
	var valid = true;
	var problem = "";
	
	if(!isValid($("#n_name")[0].value)){ valid = false; problem += "n_name|";}
	if(!isValid($("#n_email")[0].value)){ valid = false; problem += "n_email|";}
	if(!isValid($("#n_phone")[0].value)){ valid = false; problem += "n_phone|";}
	if(!isValid($("#n_org")[0].value)){ valid = false; problem += "n_org|";}
	if(!isValid($("#n_title")[0].value)){ valid = false; problem += "n_title|";}
	
	function isValid(val){
		if(val){
			if(val==""){return false;}
			else{return true;}
		}else{ return false;}
	}
	
	if(valid==true){
		return true;
	}else{
		$("#formBox fieldset label").css({'color':'#333333'});
		var problemList = problem.split("|");
		for(var i=0;i<problemList.length;i++){
			$("#lbl_"+(problemList[i].substring(2))).css({'color':'red'});		
		}
		$("#formBox fieldset .error")[0].innerHTML = "(Please fill in all fields)";
		return false;
	}
}


