//WDDX Parsing
function getWDDXMessage(xml){
var message = $("data",xml).text();
return message;
};
function getWDDXString(xml){
var message = $("string",xml).text();
return message;
};
function getWDDXBoolean(xml){
var message = $("boolean",xml).attr("value");
return message;
};
//Left Column Menu
var state = 'none';
function showhide(layer_ref) {
//$("#"+layer_ref).slideDown("normal",function(){balanceColumns();});
}
// Function to Change onclick of Menu Divisions
function setTarget(anchor,url){
anchor.onclick = function(){
window.location = url;
};
};
//Balance Columns-Footer Relationships
function balanceColumns(){
if (document.getElementById("lftcol")) {
	var navHeight = $("#lftcol").height();
	var contentHeight = $("#main_content").height();
	if (navHeight >= contentHeight) {
		//Double down since Safari/IE handle this differently than FF
		$("#main_content").height(navHeight+15);
		//$("#main_content").css({
		//	"height": navHeight + "px!important"
		//});
	};
};
};
//Prep Adv Search Form (Landing)
function hideAdvSearch(){
var addSearch = document.getElementById("additional_search");
$("#advSearchForm .hidelink").remove()
$(addSearch).slideUp();
$(addSearch).before("<a class=\"showlink\" href=\"javascript:void(0)\" onclick=\"showAdvSearch\(\)\"><img src=\"/images/icons/plus_20.gif\" alt=\"Show\"/>Additional Search Options</a>");
}
function showAdvSearch(){
var addSearch = document.getElementById("additional_search");
$("#advSearchForm .showlink").remove()
$(addSearch).slideDown();
$(addSearch).before("<a class=\"hidelink\" href=\"javascript:void(0)\" onclick=\"hideAdvSearch\(\)\"><img src=\"/images/icons/minus_20.gif\" alt=\"Hide\"/>Hide Extra Options</a>");
}
//Languages Block
function showLangOptions(){
	$("#lang-link ul").prepend("<a href=\"javascript:void(0)\" onclick=\"hideLangOptions()\" id=\"hidelang\"><img src=\"/images/close_15.gif\" alt=\"Hide This\"/></a>");
	$("#lang-link ul").slideDown();
};
function hideLangOptions(){
	$("#hidelang").remove();
	$("#lang-link ul").slideUp();
}
// Search an Paging Functions
function getListPage(uri){
$("div.paging,div.sorting,a.backtop,#main_content span").fadeOut("fast");
$("#main_content table").fadeOut("normal",function(){
$("#main_content h3").after("<div align=\"center\" style=\"font-size: 1.4em;\" id=\"load-msg\">Loading Records...<br/><img src=\"/images/loading.gif\" alt=\"content loading icon\"/></div>");
});
window.setTimeout(function(){
$.get(uri+"&jquery=true",{},function(data){
$("#main_content").html(data);
$("#load-msg").remove();
if(document.getElementById("cat_desc")){hideCatDesc();};
});
},400);
};
function pageNext(){
var nexturi = document.getElementById("paging_next_uri").href;
//$("#main_content h3").fadeOut("fast");
$("div.paging").fadeOut("fast");
$("#main_content span").fadeOut("fast");
$("#main_content table").fadeOut("normal",function(){
$("#main_content h3").after("<div align=\"center\" style=\"font-size: 1.4em;\" id=\"load-msg\">Loading Records...<br/><img src=\"/images/loading.gif\" alt=\"content loading icon\"/></div>");
});
window.setTimeout(function(){
$.get(nexturi+"&jquery=true",{},function(data){
$("#main_content").html(data);
$("#load-msg").remove();
if(document.getElementById("cat_desc")){hideCatDesc();};
});
},400);
}

function pageBack(qs){
var backlink = document.getElementById("paging_back_uri");
var backuri = backlink.href;
//$("#main_content h3").fadeOut("fast");
$("#main_content span").fadeOut("fast");
$("#main_content span").fadeOut("fast");
$("#main_content table").fadeOut("normal",function(){
$("#main_content h3").after("<div align=\"center\" style=\"font-size: 1.4em;\" id=\"load-msg\">Loading Records...<br/><img src=\"/images/loading.gif\" alt=\"content loading icon\"/></div>");
});
window.setTimeout(function(){
$.get(backuri+"&jquery=true",{},function(data){
$("#main_content").html(data);
$("#load-msg").remove();
if(document.getElementById("cat_desc")){hideCatDesc();};
});
},400);
}
// Course List Sort
function sortList(link,orderby,sorttype){
var linkID = link.id;
var actLink = link;
var pageLink = document.getElementById("page_uri");
var pageURI = pageLink.href;
var pageParams = '';
var clickParams = 'this'
if(orderby){
pageParams = pageParams + "&orderby="+orderby;
if(sorttype){
pageParams = pageParams + "&sorttype="+sorttype;
clickParams = clickParams+",'"+orderby+"'";
}else{
clickParams = clickParams+",'"+orderby+"','desc'";
};
}else{
if(sorttype){
pageParams = pageParams + "&sorttype="+sorttype;
}else{
clickParams = clickParams+",null"+",'desc'";
};
};
$("#main_content h3").after("<div align=\"center\" style=\"font-size: 1.4em;\" id=\"load-msg\">Sorting Results...<br/><img src=\"/images/loading.gif\" alt=\"content loading icon\"/></div>");
$("#main_content span").fadeOut("fast");
$("#main_content table").fadeOut("normal",function(){
});
$.get(pageURI+pageParams+"&jquery=true",{},function(data){
$("#load-msg").remove();
document.getElementById("main_content").innerHTML = data;
if (document.getElementById("cat_desc")) {
	hideCatDesc();
};
if (document.getElementById(linkID)) {
	document.getElementById(linkID).attributes["onclick"].value = "sortList(" + clickParams + ");return false;";
	document.getElementById(linkID).attributes["class"].value = "sorted";
};
if(sorttype){
document.getElementById(linkID).attributes["class"].value = document.getElementById(linkID).attributes["class"].value + " desc";
}
});
}
//UID/PWD Auto-suggest 
var uidHelp = "<tr id=\"uidHelp\"><th colspan=\"2\"><p style=\"clear: both;\" class=\"notice\"><a style=\"display: block; float: right; clear: right; margin-top: 0px; margin-right: 0px;\" href=\"javascript:void(0)\" onclick=\"$(\'#uidHelp\').remove()\"><img style=\"border: none;\" src=\"/images/close_15.gif\"></a>Creating a username and password is required to help track course completion and allow for future purchases.</p></th></tr>";
var pwdHelp = "<tr id=\"pwdHelp\"><th colspan=\"2\"><p style=\"clear: both;\" class=\"notice\"><a style=\"display: block; float: right; clear: right; margin-top: 0px; margin-right: 0px;\" href=\"javascript:void(0)\" onclick=\"$(\'#pwdHelp\').remove()\"><img style=\"border: none;\" src=\"/images/close_15.gif\"></a>Creating a username and password is required to help track course completion and allow for future purchases.</p></th></tr>";
function showUIDHelp(){
    if(!document.getElementById("uidHelp")){
    $("#loginrow").after(uidHelp);
    };
};
function suggestUser(firstname,lastname){
var uidField = document.getElementById("newuserLogin");
var pwdField = document.getElementById("newuserPassword");
if(document.getElementById("suggpass")){
$("#suggpass").remove();
};
$.ajax({
   type: "GET",
   url: "/geslogic/tags/uidpwd.cfm?firstname="+firstname+"&lastname="+lastname,
   dataType: "xml",
   processData: true,
   success: function(msg){
   $(msg).find("suggestion").each(function(){
   username =$("username",this).text();
   password = $("password",this).text();
   //alert(username);
   //return false;
   uidField.value=username;
   pwdField.value=password;
   $("#pwdrow").after("<tr id=\"suggpass\"><th colspan=\"2\" style=\"text-align:center:\"><span style=\"font-size:.95em; color: maroon;\">Suggested Password: "+password+"</span></th></tr>");
   pwdField.attributes["type"].value = "text";
   pwdField.onclick = function(){$("#suggpass").remove()};
   pwdField.attributes["onclick"].value = function(){$("#suggpass").remove()};
   });
   }
});
};
//Show-Hide for Category Descriptions on Course List Pages
function hideCatDesc(){	
$(".cat_desc_text").hide();
$("#cat_desc").prepend("<h5><a href=\"javascript\:void\(0\)\" onclick=\"revealCatDesc\(\)\">More about this category \&gt\;\&gt\;<\/a><\/h5>");
}
function hideCatDescEffect(){	
$(".cat_desc_text").slideUp("normal",function(){$("#cat_desc").prepend("<h5><a href=\"javascript\:void\(0\)\" onclick=\"revealCatDesc\(\)\">About this Category<\/a><\/h5>");});
}
function revealCatDesc(){
$("#cat_desc h5").fadeOut("normal",function(){$("#cat_desc h5").remove()});
$(".cat_desc_text").slideDown();
}
$(document).ready(function(){
balanceColumns();
//If Landing Advanced Search Form
if (document.getElementById("cust_intro"),document.getElementById("advSearchForm")){
hideAdvSearch();
}
//If category description exists on list Page
if (document.getElementById("cat_desc")) {
	hideCatDesc();
}
//Tooltips
$('#main_content a').ToolTip({className: 'linksTooltip',position: 'mouse'});
$('#shop-nav a').ToolTip({className: 'linksTooltip',position: 'mouse'});
});	

//Preempt confirmation with lightbox for vendor disclaimers
function pauseConfirmation(vendor,msg,type,url){
//First add our onclick event to the submit button
var cSubmit = document.getElementById("confirmSubmit");
var cForm = document.getElementById("purch_confirm");

//If we have form type
if (type == "form") {
	cForm.onsubmit = function(){
		showVendorForm(msg, url);
		return false;
	}
}
//Otherwise use the verfication template
else {
	cForm.onsubmit = function(){
		showVendorMsg(msg);
		return false;
	};
};	
};
function modalForm(data,title){
	if(!title){
	var title = "Complete The Form Below";
	};
	f_content = "<div id=\"modal_form\">"+data+"</div>";
	$(f_content).dialog({ 
    modal: true, 
	title:title,
	height: 600,
	width: 600,
	overlay: { 
        opacity: 0.5, 
        background: "black" 
    }
});
};
function modalOverlay(data,title){
	if(!title){
	var title = "Complete The Form Below";
	};
	f_content = "<div id=\"modal_overlay\"><div class=\"modal_content\">"+data+"</div></div>";
	$(f_content).dialog({ 
    modal: true, 
	title:title,
	height: 500,
	width: 600,
	overlay: { 
        opacity: 0.5, 
        background: "black" 
    }
});
};

function modalAdvSearch(){
	if(adv_search){
	title="Advanced Course Search";
	f_content = "<div id=\"modal_overlay\"><div class=\"modal_content\">"+adv_search+"</div></div>";
	$(f_content).dialog({ 
    modal: true, 
	title:title,
	height: 500,
	width: 560,
	overlay: { 
        opacity: 0.75, 
        background: "black" 
    }
	});
	}
};

function showVendorMsg(msg){
var msgHeader = "<p class=\"warning\">Attention: One of the courses you are purchasing needs your review of some additional information.  Please read the info below and acknowledge that you understand and agree before proceeding.</p>"
	//$.prompt(msgHeader+msg,{buttons: { Ok: true,Cancel: false }, prefix: "jqiDoc", callback: submitConfirm});
	modalOverlay(msgHeader+msg,"Notice of Terms");
	//Append confirmation button
	$("div#modal_overlay div.modal_content").append("<input type=\"button\" class=\"modal_submit\" onclick=\"submitConfirm\(\)\" value=\"I Understand and Agree\" name=\"modal_submit\"/>");
};
function showVendorForm(msg,url,prefill){
if (!prefill) {
	var msgHeader = "<p class=\"warning\">Attention: One of the courses you are purchasing requires additional information to process your enrollment.  Please complete the form fields below.<\/p>"
}
else {
	var msgHeader = "";
};
//	$.prompt(msgHeader+msg,{buttons: { Ok: true,Cancel: false }, prefix: "jqiDoc", callback: postVendorExtras});
	modalForm(msgHeader+msg,"Additional Information Required");
	//place our url as an appended value to the form
	$("#modal_form form").append("<input type=\"hidden\" name=\"post_url\" value=\""+url+"\"\/>");
	//Append confirmation button
	$("div#modal_form").append("<input type=\"button\" class=\"modal_submit\" onclick=\"postVendorExtras\(\)\" value=\"Submit and Confirm Order\" name=\"modal_submit\"/>");
};
var submitConfirm = function(){
		document.purchConfirm.submit();
};
var postVendorExtras = function(){
	if (document.getElementById("modal_form")) {
		//Parse m for our url value
		var fax = $("div#modal_form").children("#athealth_extras").children("#extra_inputs").children("#fax").val();
		var license = $("div#modal_form").children("#athealth_extras").children("#extra_inputs").children("#license").val();
		var dl_state = $("div#modal_form").children("#athealth_extras").children("#extra_inputs").children("#dl_state").val();
		var education = $("div#modal_form").children("#athealth_extras").children("#extra_inputs").children("#education").val();
		var fri_prog = $("div#modal_form").children("#athealth_extras").children("fieldset").children("input[name='fri_prog']").val();
		var ce_cal = $("div#modal_form").children("#athealth_extras").children("fieldset").children("input[name='ce_cal']").val();
		var ah_password = $("div#modal_form").children("#athealth_extras").children("fieldset").children("input[name='ah_password']").val();
		var post_url = $("div#modal_form").children("#athealth_extras").children("input[name='post_url']").val();
		if (license.length>1,dl_state.length>1,education.length>1) {
			$.post(post_url, {
				fax: fax,
				license: license,
				dl_state: dl_state,
				education: education,
				fri_prog: fri_prog,
				ce_cal: ce_cal,
				ah_password: ah_password
			}, function(data){
				var tfResponse = getWDDXBoolean(data);
				if (tfResponse = "true") {
					document.purchConfirm.submit();
				}
				else {
				
				};
							}, "xml");
		}else{
			//Alert 'em
			if (confirm("Whoops!  You must provide education and license information in order to qualify for CE credits for your selected courses.\n\n  Please verify that all of the requested fields are completed before proceeding. \n\n If the information requested does not apply to you, please enter N/A in the input field.")){
			//re-focus form
			$("div#modal_form input#fax").focus();
			//form prefills
			window.setTimeout(function(){
			$("form#athealth_extras input#fax").val(fax);
			$("form#athealth_extras input#license").val(license);
			$("form#athealth_extras input#dl_state").val(dl_state);
			$("form#athealth_extras input#education").val(education);
			$("form#athealth_extras input[name='fri_prog']").val(fri_prog);
			$("form#athealth_extras input[name='ce_cal']").val(ce_cal);
			},1500);
			};
		};
			};
};

//Javascript Popups of ElementK Syllabi
function show(id) {document.getElementById(id).style.display = "block"; }
function hide(id) {document.getElementById(id).style.display = "none"; }
	
function popupSyllabus(lngProductId, intProductType) {
	   var strURL = "http://knowledge.learnitonline.com/educate/onlinelearning/marketing/course/syllabus.jsp?productId=" + escape(lngProductId) + "&productType=" + escape(intProductType);
	   var intWidth = screen.width * 0.50;
	   var intHeight = screen.height * 0.50;
	
	   window.open(strURL, "OnlineLearningSyllabus", "width=" + intWidth + ",height=" + intHeight + ",scrollbars=yes,resizable=yes");
};
//Javascript popups of course descriptions
function popShortCourse(course_id){
var uri = "/views/viewShortCourse.cfm?course_id="+course_id;
$.get(uri+"&jquery=true",{},function(data){
var f_content = "<div class=\"modal_course\" id=\"pop_"+course_id+"\"><div class=\"modal_content\">"+data+"</div></div>"
//Pop Modal Window
$(f_content).dialog({ 
    modal: true, 
	title:"Course Detail",
	height: 500,
	width: 560,
	overlay: { 
     opacity: 0.40, 
     background: "black" 
    }
	});
});
};
//XML Deserialization Methods
function getWDDXMessage(xml){
var message = $("data",xml).text();
return message;
};
//Coupon & Promo Functions
var cancelPromo = "<a class=\"cancel\" href=\"javascript:void(0)\" onclick=\"removePromoField()\">Cancel</a>";
function addPromoField(link){
var pContainer = '<div id=\"promo_container\" style=\"display: none\;\"></div>';
var pField = '<label for=\"promo_code\">Enter Your Promo Code</label><input type=\"text\" name=\"promo_code\" id=\"promo_code\" value=\"\"\ onblur=\"validatePromoEntry\(this\)\"/>'+cancelPromo;
$(link).after(pContainer);
$("#promo_container").append(pField);
$("#promo_container").slideDown("normal",function(){$("#promo_code").focus();});
};
function removePromoField(){
$("#promo_container").slideUp("normal",function(){$("#promo_container").remove()});	
};
function validatePromoEntry(input){
$(".p_valid").remove();
$.post("/views/ajaxProxy.cfc?method=promoIsActive",{promo_code:input.value},function(data){returnPromoValidation(getWDDXMessage(data),input)},"xml");
}
function returnPromoValidation(active,input){
//Remove any existing warning messages
$("#promo_container p.notice").remove();
$("#promo_container p.warning").remove();
//Make sure we have our cancel link if it doesn't exist
$("a.cancel").remove();
$(input).after(cancelPromo);
if(active=="true"){
$("a.cancel").remove();
$(input).after("<img class=\"p_valid\" src=\"/images/check_15.gif\" alt=\"Validation Successfull\"\/>")
$(input.nextSibling).after("<p class=\"notice\">Thank you. The promo code you entered is valid. We will calculate your savings in the next step.</p>");
}
else{
$(input.nextSibling).after("<p class=\"warning p_valid\">The promotional code you entered is incorrect or is no longer valid.</p>")	
};
};

