var roleCookieName = "user_role_popup";
var roles = ["IT Executive","IT Director","IT Manager","IT Staff","Sales Consultant","Other"];
var isRoleSelected = false;
var isRoleSubmitted = false;
var selectedRole = null;
var randomLoad = getRandomInt(0,10);
/*
$(document).ready(function() {
	if(randomLoad == 1 || location.href.indexOf("test=true") >= 0) {
		initRolesPopup();
	}
});
*/
function initRolesPopup() {
	var role = readCookie(roleCookieName);
	if(role != null) return;
	$("#tier4, #tier3").append('<div id="npopup_roles"><div id="npopup_roles_container">'+
		'<div id="npopup_roles_head">'+
			'<h4><strong>A One Click Survey<\/strong> from the novell.com web team.<\/h4>'+
			'<div id="npopup_roles_headclose"><p><a href="#" onclick="hideRolesPopup(); return false;">Close<\/a><\/p><\/div>'+
		'</div>'+
		'<div id="npopup_roles_content">'+
			'<div id="npopup_roles_contentcontainer">'+
				'<h5>What&#039;s Your Role?<\/h5>'+
				'<p>Please help us improve our site by clicking on your primary role.<\/p>'+
				'<ul>'+
					'<li><a href="#" onclick="selectRole(this); return false;">'+roles[0]+'<\/a><\/li>'+
					'<li><a href="#" onclick="selectRole(this); return false;">'+roles[1]+'<\/a><\/li>'+
					'<li><a href="#" onclick="selectRole(this); return false;">'+roles[2]+'<\/a><\/li>'+
					'<li><a href="#" onclick="selectRole(this); return false;">'+roles[3]+'<\/a><\/li>'+
					'<li><a href="#" onclick="selectRole(this); return false;">'+roles[4]+'<\/a><\/li>'+
					'<li><a href="#" onclick="selectRole(this); return false;">'+roles[5]+'<\/a><\/li>'+
				'<\/ul>'+
			'<\/div>'+
			'<div id="npopup_roles_contentclose"><p><a href="#" onclick="hideRolesPopup(); return false;">Close<\/a><\/p><\/div>'+
		'<\/div>'+
	'<\/div><\/div>');
	var rolesTimer = setTimeout('showRolesPopup()', 1000);
	
}

function showRolesPopup() {
	s_eVar13="RolesPopup Open";
	s_gs('novellcom');
	hidePlugins();
	$("#npopup_roles").css("opacity","0").css("top",$(document).scrollTop()+30);
	$("#npopup_roles").animate({
			width: $("#npopup_roles_container").width(),
			opacity: 1
		}, 1000);
}

function hideRolesPopup() {
	if(!isRoleSelected) {
		// user closed popup without selecting role so log close
		s_eVar13="RolesPopup Close";
		s_gs('novellcom');
		createCookie(roleCookieName,"Do not ask",365);
	}
	if(isRoleSelected && !isRoleSubmitted) {
		submitRole(selectedRole, 'Not Provided');
	}
	$("#npopup_roles").animate({
			width: 0,
			opacity: 0
		}, 1000);
	showPlugins();
}

function selectRole(lnk) {
	isRoleSelected = true;
	selectedRole = $(lnk).html();
	if(selectedRole == "Other") {
		showSpecifyOther();
	}
	else {
		submitRole(selectedRole, 'Not Provided');
		showRolesThankYou();
	}
	s_eVar13="RolesPopup: "+selectedRole;
	s_gs('novellcom');
}

function submitRole(role, description) {
	//alert("submitting");
	createCookie(roleCookieName,role,365);
	$.post("/inc/util/survey/survey_save.jsp", { 'survey-id': "502", charset: "UTF-8", destination: "null", question_8151: role, question_8152: description, question_8153: ip, question_8154: location.href },
		function(data) {
			//alert(data);
		});
	isRoleSubmitted = true;
}

function submitRoleOther() {
	submitRole(roles[5], $("#roledescription")[0].value);
	$("#npopup_roles_specifyother").animate({opacity: 0}, 500);
	showRolesThankYou();
}

function showRolesThankYou() {
	$("#npopup_roles_content").css("opacity","1");
	$("#npopup_roles_contentcontainer").animate({opacity: 0}, 500, function() {
		$("#npopup_roles_content").append('<div id="npopup_roles_thankyou">'+
			'<h5>Thank You!<\/h5>'+
			'<p>We are striving to improve our web site and this information will help us a ton!  If you have specific suggestions, please submit <a href="http://www.novell.com/inc/feedback/feedback.jsp" onclick="window.open(this.href+\'?url=\'+escape(top.location.href),\'web_fb\',\'width=560,height=600,resizable=yes,scrollbars=no\'); return false;">feedback here<\/a>.<\/p>'+
			'<p id="npopup_roles_thankyou_close"><a href="#" onclick="hideRolesPopup(); return false;">Close Window</a><\/p>'+
		'<\/div>');
		$("#npopup_roles_thankyou").css("opacity","1");
		$("#npopup_roles_thankyou").show();
	});
}

function showSpecifyOther() {
	$("#npopup_roles_content").css("opacity","1");
	$("#npopup_roles_contentcontainer").animate({opacity: 0}, 500, function() {
		$("#npopup_roles_content").append('<div id="npopup_roles_specifyother">'+
			'<h5>Thank You!<\/h5>'+
			'<p>We are striving to improve our web site and this information will help us a ton!.  Please help us futher by telling us about your role.<\/p>'+
			'<p>Please describe your role.<br \/><input type="text" name="roledescription" id="roledescription" \/><\/p>'+
			'<p id="npopup_roles_submit"><a href="#" onclick="submitRoleOther(); return false;">Submit<\/a><\/p>'+
		'<\/div>');
		$("#npopup_roles_specifyother").css("opacity","1");
		$("#npopup_roles_specifyother").show();
	});
}