
//Weekly demos registrants
function GetRegistrants( webinar, topicid, topicdate, topicdetail ){
	$.get("/cfc/WeeklyDemoRegistrants.cfc",{method:'GetRegistrantsByDemo',topic_id:eval( topicid ),topic_date:topicdate,topic_detail:topicdetail}, function ( reply ){
	$('#' + webinar).html(reply).slideDown('slow');	
	});
}

//Weekly number of registrants by solution
function GetRegistrantBySolution( monthy, yeary, divid, subdivid ){
	$.get("/cfc/WeeklyDemoRegistrants.cfc",{method:'GetNumberRegistrantsByDate',month:eval( monthy ),year:eval( yeary )}, function ( reply ){
		$( '#' + divid ).html(reply).slideDown('slow');	
		$( '#' + subdivid ).slideDown('slow');	
	});
}

//Weekly registrants information by solution
function GetRegistrantInfoBySolution( topic, monthy, yeary, divid ){
	$.get("/cfc/WeeklyDemoRegistrants.cfc",{method:'GetRegInfoBySolution',topic_detail:topic,month:eval( monthy ),year:eval( yeary )}, function ( reply ){
		$('#' + divid ).html(reply).slideDown('slow');	
	});
}

//Weekly demos registrants Approval Update
function UpdateRegistrants( recordid, screened, divId ){
	$.get("/cfc/WeeklyDemoRegistrants.cfc",{method:'UpdateRegistrant',record_id:eval( recordid ),screened_value:eval( screened )}, function ( reply_update ){
	$("#" + recordid).slideUp('slow');	
	$("#" + recordid).slideDown('slow')
	$("#update_result").slideDown('slow' , function updatereply(){$("#" + divId ).html(reply_update);	});
	});																												   
}

function displayDetails(prospect, action ){
	if( action != 'hide' )
		$("#" + prospect).slideDown('slow');
	else
		$("#" + prospect).slideUp('slow');
}

function hideDetails(id, email ){
	$("#" + id).slideUp('slow');
	//$("#" + id).slideDown('slow');
}	

function ShowUpdate(){
	$("#upd").slideDown('slow');
	$("#upds").slideDown('slow');
}	

//function SendWebexInfo( id, recordid ){
function SendWebexInfo( recordid, email, reminder, days, divid, emailrec, emaildiv  ){
	
	//$.get("/cfc/WeeklyDemoRegistrants.cfc",{method:'WebExInfo',record_id:eval( recordid ), email:name}, function ( reply ){
	$.get("/cfc/WeeklyDemoRegistrants.cfc",{method:'WebExInfo',record_id:eval( recordid ),email:email,reminder:eval(reminder),days:eval(days),emailreceived:eval(emailrec)} , function ( reply ){
		$("#" + divid).slideDown('slow');
		setTimeout('$("#' + divid + '").slideUp();',4500);	
		$("#" + recordid).css({display:'none'});
})};

//check if the member has already downloaded specific asset
function CheckForAsset( userid, ids ){
	$.get("/cfc/learning_center.cfc",{method:'GetBookshelfById',userid:(userid),asset_id:eval(ids)} , function ( reply ){
	if( reply.indexOf("yes") != -1 )
		$("#" + ids ).fadeIn('slow');
	//else
	//	$("#" + ids ).fadeOut('slow');
})};

//hides the span that displays the asset saved in the bookshelf
function HideAsset( id ){
	$("#" + id ).fadeOut('fast');
}

//get list of assets
function GetAssetList( solutionid, pageid, assets ){
	$.get("/cfc/learning_center.cfc",{method:'GetAssetsBySolution',solution_id:eval(solutionid),page_id:eval(pageid), assets_selected:(assets)} , function ( reply ){
	$("#assetslist").html("");
	$("#assetslist").html(reply).slideDown('slow');
	$("#submit_assets").fadeIn('slow');
	
})};


function FillAssetsTaken(ast){
	var temp = $("#ast_taken").val();
	
	if($("#" + ast.id).attr('checked') == true){
		if($("#ast_taken").val() == ""){
			$("#ast_taken").val(temp + ast.value ) ;
		}
		else{
			$("#ast_taken").val(temp + "," + ast.value ) ;
		}
	}	
	else{
		var ArrayWithoutNewElement = $("#ast_taken").val().split(",");
		var ArrayWithoutNewElement = ArrayWithoutNewElement.splice(ArrayWithoutNewElement.indexOf(ast.value),1);
		$("#ast_taken").val(ArrayWithoutNewElement);
	}

	if($('#email_c').attr('checked') == true)
	$("#form_contact").slideDown('slow');
}

//FastTrack suppliers registrants
function GetFastTrackSuppliers( supdiv, supanid ){
	$.get("/cfc/FastTrack.cfc",{method:'CheckFastTrackSupplierByANID',anid:supanid}, function ( reply ){
	$('#' + supdiv).html(reply).slideDown('slow');	
	});
}

//Get the flag from the specified language
function ShowFlag(){
	var flagLang = document.getElementById("p_language").value;
	$.get("/cfc/languages.cfc",{method:'GetLanguageFlag',language_id:(flagLang)} , function ( reply ){
	var dri = reply;
	$("#droga").attr("src",dri);
	
//	 loader.html(‘<img src="’ + gLoadSpinnerUrl + ‘"/>’);

	
})};

	
//Weekly demos registrants Approval Update
function SelectAssets( solutionid, str, lang ){
	if(str != 'n'){
		$("#proc").show();
	}
	$.get("/cfc/AssetLibrary.cfc",{method:'GetAssets',solution:eval( solutionid ),language_id:eval(lang)}, function ( reply_assets ){
	$("#assetsresults").html(reply_assets);
	$("#proc").slideUp();
	});																												   
}

function GetLanguages(){
	$.get("/cfc/AssetLibrary.cfc",{method:'GetAssetsLanguages'}, function ( reply_lang ){
	$("#langa").html(reply_lang);
	});																												   
}

function GetStartSourcingPromos(promo){
	$("#loading").html("Loading...<img src='/images/wait.gif'>");
	$.get("/cfc/start_sourcing_admin.cfc",{method:'GetPromos'}, function ( reply ){
	$('#promo_list_option').html(reply).slideDown('slow');	
	$("#loading").html("");
	});
}

function SelectPromo(promoid){
	if(promoid != 9999){
		$("#loading").html("Loading...<img src='/images/wait.gif'>");
			$.get("/cfc/start_sourcing_admin.cfc",{method:'GetTables', promo_code:eval(promoid)}, function ( reply ){
			$('#mainpromos').html(reply);	
			});
		$("#loading").html("");
	}
}

function open_StartSourcing_Div(divid,elem,term){
	$("#cmds").val("add");
	$("#addupdates").val("notnormal");
	$("#cancelbutton_" + term).removeAttr("disabled"); 
	$("#" + divid).slideDown();
	if(elem == 'addbutton'){
		$("#addbutton_" + term).attr("disabled", true);
	}
	else{
		$("#updatebutton").attr("disabled", true);
	}
}

function close_StartSourcing_Div(divid,elem,error_div,term){
	$("#cancelbutton_" + term).attr("disabled", true);
	$("#" + divid).slideUp('fast');
	$("#" + error_div).slideUp('fast');
	$("#addbutton_" + term).removeAttr("disabled"); 
	$("#updatebutton_" + term).removeAttr("disabled"); 
	$("#cmds").val('normal');
}

function checkFields(formid,divid,term){
	if($("#cmds").val() != 'normal'){
		if($("#promoprice_" + term).val() == "" || $("#promousers_" + term).val() == ""){
			$("#"+divid).html('Price and User fields are required<br>').slideDown('slow');
			return false;
		}
		else{
			var r=confirm("Are you sure you want to add/update?");
			if (r==true){
				$("#" + formid).submit();
			}
			else{
				return;
			}
		}
	}
	else{
		var r=confirm("Are you sure you want to add/update?");
		if (r==true){
			$("#" + formid).submit();
		}
		else{
			return;
		}	
	//$("#" + formid).submit();
	}
}

function CheckAdminToolNewUserForm(){
	$.post("/admin_tools/cfc/users.cfc", $('#newuser > form').serializeArray(), function(reply){
		if (reply.indexOf("ERROR") >= 0){
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Please complete all fields of the form.</strong>');
			var errorArray = reply.split(",");
			for (i=0; i < errorArray.length; i++) {
				$("input[name=" + errorArray[i] + "]", "#newuser > form").css({backgroundColor:"#fbd7d7"});	
			}
		}
		else if(reply.indexOf("already") >= 0){
			var errorEmail = reply.split("|");
			$("#existent_user").css({color:"#dd0000"}).html('&nbsp;&nbsp;<strong>' + errorEmail[1] + ' is already registered.</strong>');
		}
		else if(reply.indexOf("updated") >= 0){
			var errorEmail = reply.split("|");
			$("#existent_user").css({color:"#dd0000"}).html('&nbsp;&nbsp;<strong>' + errorEmail[1] + ' information updated.</strong>');
		}		
		else{
			var user_name = reply.split('|');
			$("#newuser").slideUp('slow', function () {
			$("#status_reply").css({color:"#dd0000"}).html('  <strong>"' + user_name[1] + '"</strong>');
			$("#status_reply1").html(" <strong>has been added.</strong>");
			});
		}
	});																										   
}

function CheckAdminToolNewPageForm(){
	$.post("/admin_tools/cfc/users.cfc", $('#newpage > form').serializeArray(), function(reply){
		if (reply.indexOf("ERROR") >= 0){
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Please complete all fields of the form.</strong>');
			var errorArray = reply.split(",");
			for (i=0; i < errorArray.length; i++) {
				$("input[name=" + errorArray[i] + "]", "#newuser > form").css({backgroundColor:"#fbd7d7"});	
			}
		}	
		else if (reply.indexOf("page already") >= 0){	
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Page already exists with on this location.</strong>');
		}
		else{
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Page Updated.</strong>');
		}
	});																										   
}

function CheckAdminToolNewUserPageForm(){
	$.post("/admin_tools/cfc/users.cfc", $('#newpageuser > form').serializeArray(), function(reply){	
		if (reply.indexOf("already linked") >= 0){	
			$("#existent_user").css({color:"#dd0000"}).html('<br><br><strong>Page already linked to this user.</strong>');
		}
		else{
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Page Linked.</strong>');
		}
	});																										   
}

function VerifyInternalToolsLogin(){
	$.post("/admin_tools/cfc/users.cfc", $('#loginForm > form').serializeArray(), function(reply){
		if (reply.indexOf("ERROR") >= 0){
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Please complete all fields of the form.</strong>');
			var errorArray = reply.split(",");
			for (i=0; i < errorArray.length; i++) {
				$("input[name=" + errorArray[i] + "]", "#loginForm > form").css({backgroundColor:"#fbd7d7"});	
			}
		}
		else if(reply.indexOf("yes") >= 0){
			window.location="/admin_tools/core/index.cfm";
		}
		else{
			$("#existent_user").css({color:"#dd0000"}).html(' <strong>Login not found.</strong>');
		}
	});																										   
}

function clear_admin_tool_new_user_email_message(){
	$("#existent_user").html("");
}

function GetPages(id){
	$.get("/admin_tools/cfc/users.cfc", {method:'GetUserPageLinked',user_id:eval(id.value)}, function ( reply_pages ){
		if(reply_pages.indexOf("no data") >= 0){
		$("#showPages").fadeOut('fast');
			$("#existent_user").css({color:"#dd0000"}).html('<br><br><strong>No page(s) linked to this user."</strong>');
			
		}
		else{
			$("#showPages").fadeIn('slow', function() {$("#showPages").html(reply_pages)});
		}
	});		
}

function enableUnlink(){
	if($("#rmvlnk").attr('checked') == true){
		$("#ulinkuser").removeAttr("disabled");
	} 
	else{
		$("#ulinkuser").attr("disabled", true);
	}
}

function UnlinkUserPage(){
	$.post("/admin_tools/cfc/users.cfc", $('#removepageuserid > form').serializeArray(), function(reply){
		$("#existent_user").css({color:"#dd0000"}).html('<br><br><strong>Page has been unliked from this user.</strong>');
	});	
}

function addStartSourcingPromo(){
	$.get("/cfc/start_sourcing_admin.cfc", {method:'AddNewPromo'}, function ( reply_newpromo ){
		$("#promo_list_option").html('');
		$("#mainpromos").html(reply_newpromo);
	});
}

function editStartSourcingPromo(promocode){
	$.get("/cfc/start_sourcing_admin.cfc", {method:'EditNewPromo', promo_code:eval(promocode)}, function ( reply_editpromo ){
		$("#promo_list_option").html('');
		$("#mainpromos").html(reply_editpromo);
	});
}

function listStartSourcingPromo(){
	$.get("/cfc/start_sourcing_admin.cfc", {method:'GetPromoList'}, function (reply_promo_list){
		$("#promo_list_option").html('');
		$("#mainpromos").html(reply_promo_list);
	});
}

function checkNewPromoForm(){
	$("#existent_user").html("");
	$.post("/cfc/start_sourcing_admin.cfc", $('#newaddpromoprice > form').serializeArray(), function(reply_newpromo){
		if(reply_newpromo.indexOf("ERRORS") >= 0 ){
			$("#existent_user").css({color:"#dd0000", fontSize:"8pt"}).html(' <strong>&nbsp;Please complete all fields of the form.</strong>');
			var errorArray = reply_newpromo.split(",");
			for (i=0; i < errorArray.length; i++) {
				$("input[name=" + errorArray[i] + "]", "#newaddpromoprice > form").css({backgroundColor:"#fbd7d7"});	
			}
		}
		else{
			if(reply_newpromo.indexOf("yes") >= 0 ){
				$("#alreadypromo").css({color:"#dd0000", fontSize:"8pt"}).html('<br><strong>Promo Name already exists!!!</strong>');
			}
			else{
				$("#alreadypromo").css({color:"#dd0000", fontSize:"8pt"}).html('<br><strong>Promo Created</strong>')
			}
		}
		//$("#promo_list_option").html('');
		//$("#mainpromos").html(reply_newpromo);
	});
}

function editNewPromoForm(){
	$("#existent_user").html("");
	$.post("/cfc/start_sourcing_admin.cfc", $('#editpromoprice > form').serializeArray(), function(reply_newpromo){
		$("#alreadypromo").css({color:"#dd0000", fontSize:"8pt"}).html('<br><strong>Record Updated</strong>');
	});
}

function clearNewAddPromo(){
	$("#alreadypromo").html("");
}