//This file includes the core javascript required for the portal. //It also sets up HTTP headers that force visitors browsers to cache the javascript and will gzip compress the javascript if the zlib library is available in PHP //The files included are: // prototype.js // scriptaculous/effects.js // DynamicOptionList.js (used for drill down custom fields) // jscal2/js/jscal2.js(used for date custom fields) document.write(''); //Function that shows appropriate custom fields for each category function ShowCategoryCustomFields(category_id){ //Find the ID of the currently selected category var selected_category = category_id ? category_id : ($("xCategory") ? $F("xCategory") : 0); //Create javascript array of custom field ID's, excludes always visible custom fields var custom_field_ids = new Array("14","10","15","11","12","6","16","5","20","7","9","3","8","4","19","17","13"); var field_count = custom_field_ids.length; //Create javascript array of custom fields each category should display var category_custom_fields = new Array(); category_custom_fields[23] = new Array("3"); category_custom_fields[24] = new Array("4"); category_custom_fields[26] = new Array("6"); category_custom_fields[27] = new Array("13"); category_custom_fields[28] = new Array("17"); category_custom_fields[29] = new Array("14","15"); category_custom_fields[30] = new Array("7"); category_custom_fields[34] = new Array("16"); category_custom_fields[25] = new Array("5"); category_custom_fields[35] = new Array("9"); category_custom_fields[31] = new Array("19"); category_custom_fields[32] = new Array(""); category_custom_fields[22] = new Array(""); category_custom_fields[13] = new Array(""); category_custom_fields[3] = new Array(""); category_custom_fields[37] = new Array("20"); //Hide all fields on category change for(i=0;i < field_count;i++){ if($("Custom" + custom_field_ids[i] + "_wrapper")) $("Custom" + custom_field_ids[i] + "_wrapper").hide(); } //Show fields which are for this category if(selected_category != 0){ var custom_field_len = category_custom_fields[selected_category] ? category_custom_fields[selected_category].length : 0; for(i=0;i < custom_field_len;i++){ if($("Custom" + category_custom_fields[selected_category][i] + "_wrapper")){ $("Custom" + category_custom_fields[selected_category][i] + "_wrapper").show(); } } } } //Function that resets a portal login password function ChangePortalLoginPassword(){ //Find the new password they've set var password_new = $F('new_password'); //Find the password confirmation they've set var password_confirm = $F('new_password_confirm'); //Check if the password and the password confirm field match and that the password is not empty. if(password_new != password_confirm || password_new.empty()){ //Popup an alert to notify the user that the passwords must match show_feedback("Passwords must match. Please try again.","error"); }else{ //Everything is OK so send the new password to the server new Ajax.Request("index.php?pg=password.change", { method: "post", parameters: {password: password_new}, onSuccess: function(transport) { show_feedback("Password saved","success"); //Hide the password box and clear the form fields $("change_password_box").hide(); $("new_password").value = ""; $("new_password_confirm").value = ""; }, onFailure: function(transport){ show_feedback("Could not save password","error"); } }); } } //Function that sends the retrieve password email function RetrievePortalLoginPassword(){ //If there's no email in the box show feedback that an email needs to be entered if($F("login_email").empty()){ show_feedback("Please enter your email","error"); return; }else{ //Change link text to loading $("retrievePortalPasswordLink").update('Sending...'); //An email is available so send the password email new Ajax.Request("index.php?pg=password.retrieve", { method: "post", parameters: {login_email: $F("login_email")}, onSuccess: function(transport) { show_feedback("Reset email sent. Please check your email account.","success"); }, onFailure: function(transport){ show_feedback("Please enter a valid email","error"); }, onComplete: function(){ //Remove sending text $("retrievePortalPasswordLink").update(); } }); } } //Function to create a feedback box at the top of the right column. function show_feedback(message,type){ //Style the feedback box as appropriate for each type of feedback if(type == "error"){ $("feedback_box").addClassName("feedback_box_error"); }else{ //By default shows positive feedback $("feedback_box").addClassName("feedback_box_positive"); } //Show the box $("feedback_box").show(); //Insert message into the feedback box $("feedback_box").update(message); }