<!--
//********************************************************************************
// Description: Global javascript used by all pages, for form validation, page flow
//                              and page display
// 
// Assumptions: None
//               
// Authors:     Brian McGovern
// Assumptions: The form being validated is the only form on page. Update coming soon.
//********************************************************************************
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Define Global Variables
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Error Messages
// NYCB Specific 
if (document.domain == "www.gomennekes.com"){
	location.href = "http://www.mennekes.com/print.html?promo=febprint";
}

var CONF_DELETE_REP = "Are you sure you want to delete this rep? Remember to delete Performance Mappings before deleting Reps."
// end


var err0 = "Please enter your Full Name.";
var ERR_VALID_FIRST_NAME = "Please enter your First Name.";
var ERR_VALID_QUANTITY = "Please enter a valid Quantity.";
var ERR_CART_EMPTY = "You cannot checkout because your cart is empty.";
var ERR_VALID_LAST_NAME = "Please enter your Last Name.";
var ERR_VALID_CITY = "Please enter your City.";
var ERR_VALID_STATE = "Please select a State.";
var ERR_VALID_STREET = "Please enter your Street Address.";
var err5 = "Please enter a valid User ID.  It is your Email Address.";
var ERR_VALID_COUNTRY = "Please select a Country.";
var ERR_VALID_ZIP = "Please enter your Zip Code.";
var err7 = "Please select a City.";
var ERR_VALID_EMAIL = "Please enter a valid e-mail address.";
var ERR_VALID_PASSWORD = "Please enter your Password.";
var ERR_VALID_CC = "Please enter your Credit Card Number."
var ERR_VALID_CC_NAME = "Please enter the Full Name that appears on your Credit Card."
var err10 = "Please enter Confirmation Password.";
var err11 = "The password does not match, please re-confirm your password.";
var err12 = "The company web id and company secret code does not match.  Please try again.";
var err13 = "The company secret code you entered is invalid.  Please check the code and try again.";
var err14 = "The User Id and Password entered are invalid.  Please try again.";
var err15 = "There was no match to your search criteria.";
var err16 = "The logo file entered does not exist.  Please check the file path.";
var err17 = "The old password entered is invalid.";
var err18 = "There was a problem in delivering your email.  Please try again.";
var err19 = "Company Web Id is invalid. Please try again.";
var err20 = "The user id entered is being used, please pick a new id.";
var err21 = "Please enter your Comment.";
var err22 = "Please enter a valid Phone Number.";
var err23 = "Please enter your search criteria.";
var err24 = "Please enter your Question.";
var err25 = "Please enter a Subject.";
var err26 = "Please enter a valid Expiration Date.";
var err27 = "Please enter the Article Text.";
var err28 = "Please select a Servicing Division.";
var err29 = "Please enter a Course Name.";
var err30 = "Please enter your Street Address.";

var err32 = "Please enter a valiod Start Date and End Date.";
var err33 = "Please enter a valid Start Time and End Time.";
var err34 = "Please enter a Location Name.";
var err35 = "Please enter your Postal Code.";
var err36 = "Please select an Industry.";
var err37 = "Please select an Category.";
var err38 = "Please enter an Answer.";
var err39 = "Please enter your Job Title.";
var err40 = "Please enter a New Logo.";
var err41 = "Please enter a Description.";
var err42 = "Please enter a Course Name.";
var err43 = "Please enter a Contact Name.";
var err44 = "Please enter a Contact Phone.";
var err45 = "Please enter a Contact Email Address.";
var err47 = "Please enter a Company.";
var err53 = "The logo file format you entered is invalid. Logos must be in GIF format.";
var err54 = "In order to personalize your home page, you must be a registered user.";
var err55 = "The text you typed is longer then __LENGTH__ characters and has been truncated to fit that length.";
var err57 = "The search field may not contain single quotation mark (').";
var err58 = "Your Password must me at least 4 characters in length.";
var err59 = "Please select a Service Industry.";
var err60 = "A user type must be entered.";
var err61 = "The password clue cannot be blank.";
var err62 = "The format for the zip code for your country must be __FORMAT__";
var err63 = "Please enter a valid Manufacturer Phone Number.";
var err64 = "Please enter a Model Number.";
var err65 = "Please select at least one Equipment Category.";
var err66 = "Please enter an Equipment Model Description.";
var err67 = "Please enter a Manufacturer Name.";
var err68 = "Please select a User.";
var err69 = "Please select a Manufacturer.";
var err71 = "Please select an Equipment Type.";
var err72 = "Please select an Equipment Model.";
var err73 = "Please select an Post Type.";
var err74 = "Please select an Equipment Condition.";
var err75 = "Please enter a valid Asking Price.";
var err76 = "Please select an Available Date.";
var err77 = "Please enter an Equipment Model.";
var err78 = "Please enter an Equipment Detail.";
var err79 = "Please enter a Year Made.";
var err80 = "Please enter a valid Manufacturer Fax Number.";
var err81 = "Please enter a valid Maximum Used Equipment Listing Number. This must be a positive number.";
var err82 = "Please select a Sale Date.";
var err83 = "Please enter a valid Selling Price.";
// Date Errors                                                                  
var err48 =  "The Start Date you entered is invalid. Please try again.";
var err49 =  "The End Date you entered is invalid. Please try again.";
var err50 =  "The End Date cannot be before the Start Date. Please try again.";
var err51 =  "The Date you entered is invalid. Please try again.";
var err52 =  "The Start Date cannot be before the today's date. Please try again.";

var err56 = "The Expiration Date cannot be before the today's date. Please try again.";

var err70 = "Please select an Available Divison/Location.";

// User Confirmation Messages
var message1 = "The changes made will be published to the site instantly. Do you wish to continue?";
var message2 = "Are you sure you want to delete this item?";
var message3 = "The FAQ will be published to the database instantly? Do you want to continue?";
var message4 = "Did you preview your ad? Continue to publish.?";
var message5 = "Did you preview your logo? Continue to publish.?";
var MESS_LOGOFF = "Logging off will will remove any items you currently have in your cart.  Are you sure you want to logoff?";
var message7 = "The action you clicked will take you out of the administration area of the site.  As a site administrator you can modify a manufacturer's information, add equipment etc.  To do this you will be taken to the Contractor's Marketplace area of the site acting as the manufacturer administrator."
var message8 = "The action you clicked will take you out of the administration area of the site.  As a site administrator you can add or delete users.  To do this you will be taken to the Contractor's Marketplace area of the site and walk through the same process as a user."
var message9 = "The action you clicked will take you out of the administration area of the site.  As a site administrator you can modify a user's used equipment listing.  To do this you will be taken to the Used Equipment area of the site as a site administrator."

// Browser Detection
sAgent = navigator.userAgent;
bIsMac = sAgent.indexOf("Mac") > -1;
bIsIE = sAgent.indexOf("MSIE") > -1;
bIsIE3 = sAgent.indexOf("IE 3") > -1;
bIsIE4 = sAgent.indexOf("IE 4") > -1;
bIsIE5 = sAgent.indexOf("IE 5")  > -1;
bIsNav = sAgent.indexOf("Mozilla") > -1 && !bIsIE;
bIsNav3 = sAgent.indexOf("Mozilla\/3") > -1 && !bIsIE;
bDoesAll = (bIsIE4 || bIsIE5) && !bIsMac;


var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var AppVer = parseInt(navigator.appVersion);





if (navigator.appVersion.indexOf("Mac") != -1){
        var mac = true;
}else{
    var mac = false;
}




// Rollover Preloading 
 

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Validation Functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsValidZip(field, format) 
// Arguments: 'field'  -the name of the field in the form to be validated
//			  'format' -the zip input mask from db.  
//				LV-####
//				####
//				A####AAA
//				####-####
//				######
//				#####
//				### ##	
//   Returns: Boolean
// Objective: Dynamically checks the value of the data in 'field' for a correctly formatted zip.
////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsValidZip(field, format){
	var value;
	document.forms[0][field].value = document.forms[0][field].value.toUpperCase();
	value = document.forms[0][field].value;
	if (value.length != format.length){
		err62 = err62.replace(/__FORMAT__/, format);
		alert(err62);
		return false;
	}
	for (i = 0; i < format.length; i++){
		//alert("Format: " + format.charAt(i) + " Value: " + value.charAt(i));
		if (format.charAt(i) != "#"){
			if ((format.charAt(i)) != (value.charAt(i))){
				err62 = err62.replace(/__FORMAT__/, format);
				alert(err62);
				return false;
				break;
			}
		}else{
			//alert("in isNaN");
			if (isNaN(value.charAt(i)) || (value.charAt(i) == " ") ){
				err62 = err62.replace(/__FORMAT__/, format);
				alert(err62);
				return false;
				break;
			}
		}
	}
return true;	
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsValidPhone() 
// Arguments: dial_code, phone1, phone2, phone3
//   Returns: Boolean
// Objective: Checks the value of the data in phone1, phone2, phone3 for a positive number based on dial_code
////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsValidPhone(dial_code, phone1, phone2, phone3){
	var format = "";
	if (document.forms[0][dial_code].value != ""){
		if ((document.forms[0][dial_code].value == 1) || (document.forms[0][dial_code].value == "-")){
			//alert("In US");
			//alert(document.forms[0][phone1].value.length);
			//alert(document.forms[0][phone2].value.length);
			//alert(document.forms[0][phone3].value.length);
			if ((document.forms[0][phone1].value.length < 3) || (document.forms[0][phone2].value.length < 3) || (document.forms[0][phone3].value.length < 4)){
				//alert("lenght");
				return false;
			}
		}
	}
	// no country code for this country in DB or its a "+" country code either way  just check that its not letters
	if (!IsBlank(phone1) || !IsBlank(phone2) || !IsBlank(phone3)){
		return false;
	}
	if ( (!IsPosNumber(phone1)) || (!IsPosNumber(phone2)) || (!IsPosNumber(phone3))){
		return false;
	}
	return true;
}
	
////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Validate_IsPosNumber() 
// Arguments: 'field'  -the name of the field in the form to be validated
//   Returns: Boolean
// Objective: Checks the value of the data in 'field' for a positive number.
////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsPosNumber(field){
var the_length = (document.forms[0][field].value.length - 1);
        for(i=0; i<=the_length; i++){
                if ((document.forms[0][field].value.charAt(i) == "-") || (document.forms[0][field].value.charAt(i) == " ")){
                        return false;
                        break;
                }
        }
        if (isNaN(document.forms[0][field].value)){
                return false;
        }
        return true;
}

                
////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsPosDate() 
// Arguments: 'field'  - a variable 
//   Returns: Boolean
// Objective: Used by functions on variables, check that 'field' is a number. 
////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsPosDate(field){
        if (isNaN(field)){
                return false;
        }else{
                if (field == ""){
                        return false;
                }else{
                        return true;
                }
        }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsValidDate() 
// Arguments: 'field1','field2','field3','field4','field5','field6'  -names of fields in html form
//   Returns: Boolean, and Alerts
// Objective: 1. If all fields are passed , performs check on start date and end date fields in 
//                               mm/dd/yyyy format. Checks Y2K validity, and valid date format. Makes sure that the 
//                               start date is not less than the current date and the end date is not less than the 
//                               start date.                            
//                        2. If only the first 3 fields are passed, it only checks those fields for correct date 
//                               format and checks that the date in not less than the current date.  
////////////////////////////////////////////////////////////////////////////////////////////////////////
function IsValidDate(field1, field2, field3, field4, field5, field6){
var d = new Date();
var currmm = d.getMonth();
var curryyyy = (d.getYear());
var currdd = d.getDate();
if (curryyyy < 1000) curryyyy += 1900;

currmm++;

var currdate = Date.UTC(curryyyy, currmm, currdd);
var smm = document.forms[0][field1].value;
var sdd = document.forms[0][field2].value;
var syyyy = document.forms[0][field3].value;
var emm, edd, eyyyy, startdate, enddate;
    // Objective 1.
        if ((field4) && (field5) && (field6)){
                var emm = document.forms[0][field4].value;
                var edd = document.forms[0][field5].value;
                var eyyyy = document.forms[0][field6].value;
                if ((IsPosDate(smm)) && (IsPosDate(sdd)) && (IsPosDate(syyyy)) && (IsPosDate(emm)) && (IsPosDate(edd)) && (IsPosDate(eyyyy))){
                // Check the month field
                        if ((smm < 1) || (smm > 12)){
                                alert(err48);
                                //alert("Start Month");
                                return false;
                        }else{
                                // Check that for each month, entered the input doesnt exceed the max number of days
                                if (((smm == 4) || (smm == 6) || (smm == 9) || (smm == 11)) && (sdd > 30)) {
                                        alert(err48);
                                        //alert("Start Day Correspond to month 1");
                                        return false;           
                                }else{
                                        if (((smm == 1) || (smm == 3) || (smm == 5) || (smm == 7) || (smm == 8) || (smm == 10) || (smm == 12)) && (sdd > 31)) {
                                                alert(err48);
                                                //alert("Start Day Correspond to month 2");
                                                return false;           
                                        }else{
                                                if ((syyyy < 2000) || (syyyy > 2078)){
                                                        alert(err48);
                                                        //alert("Start Y2K");
                                                        return false;
                                                }else{
                                                        //smm--;
                                                        //alert( syyyy + " " + smm + " " + sdd);
                                                        startdate = Date.UTC(syyyy, smm, sdd);
                                                        //**************************************************
                                                        // Begin End Date routine
                                                        //**************************************************    
                                                        if ((emm < 1) || (emm > 12)){
                                                                alert(err49);
                                                                //alert("End Month");
                                                                return false;
                                                        }else{
                                                                // Check that for each month, entered the input doesnt exceed the max number of days
                                                                if (((emm == 4) || (emm == 6) || (emm == 9) || (emm == 11)) && (edd > 30)) {
                                                                        alert(err49);
                                                                        //alert("End Date correspond to month1");
                                                                        return false;           
                                                                }else{
                                                                        if (((emm == 1) || (emm == 3) || (emm == 5) || (emm == 7) || (emm == 8) || (emm == 10) || (emm == 12)) && (edd > 31)) {
                                                                                alert(err49);
                                                                                //alert("End Date correspond to month2");
                                                                                return false;           
                                                                        }else{  
                                                                                if ((eyyyy < 2000) || (eyyyy > 2078)){
                                                                                        alert(err49);
                                                                                        //alert("End Y2K");
                                                                                        return false;
                                                                                }else{
                                                                                        //alert(startdate + "---" + currdate);
                                                                                        if (startdate < currdate){
                                                                                                alert(err52);
                                                                                                return false;
                                                                                        }else{
                                                                                                //emm--;
                                                                                                var enddate = Date.UTC(eyyyy, emm, edd);
                                                                                                //**************************************************
                                                                                                // Dates are valid at this point , compare them
                                                                                                //**************************************************    
                                                                                                if (enddate < startdate){
                                                                                                        alert(err50);
                                                                                                        //alert("End Date is less than start date");
                                                                                                        return false;
                                                                                                }else{
                                                                                                 
                                                                                                        if (document.forms[0][field2].value.length == 1) {
                                                                                                                document.forms[0][field2].value = "0" + document.forms[0][field2].value;
                                                                        
                                                                                                        }
                                                                                                        if (document.forms[0][field1].value.length == 1) {
                                                                                                                document.forms[0][field1].value = "0" + document.forms[0][field1].value;
                                                                         
                                                                                                        }
                                                                                                        if (document.forms[0][field5].value.length == 1) {
                                                                                                                document.forms[0][field5].value = "0" + document.forms[0][field5].value;
                                                                         
                                                                                                        }
                                                                                                        if (document.forms[0][field4].value.length == 1) {
                                                                                                                document.forms[0][field4].value = "0" + document.forms[0][field4].value;
                                                                 
                                                                                                        }
                                                                                                        return true;
                                                                                                }
                                                                                        }
                                                                                }
                                                                        }
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }else{
                        alert(err51);
                        return false;
                }
        // Objective 2.
        }else{
                if ((IsPosDate(smm)) && (IsPosDate(sdd)) && (IsPosDate(syyyy))){
                        // Check the month field
                        if ((smm < 1) || (smm > 12)){
                                alert(err51);
                                return false;
                        }else{
                                // Check that for each month, entered the input doesnt exceed the max number of days
                                if (((smm == 4) || (smm == 6) || (smm == 9) || (smm == 11)) && (sdd > 30)) {
                                        alert(err51);
                                        return false;           
                                }else{
                                        if (((smm == 1) || (smm == 3) || (smm == 5) || (smm == 7) || (smm == 8) || (smm == 10) || (smm == 12)) && (sdd > 31)) {
                                                alert(err51);
                                                return false;           
                                        }else{
                                                if ((syyyy < 2000) || (syyyy > 2078)){
                                                        alert(err51);
                                                        return false;
                                                }else{
                                                        //smm--;
                                                        startdate = Date.UTC(syyyy, smm, sdd);
                                                        //alert(startdate + "---" + currdate);
                                                        if (startdate < currdate){
                                                                alert(err56);
                                                                return false;
                                                        }else{
                                                                if (document.forms[0][field2].value.length == 1) {
                                                                        document.forms[0][field2].value = "0" + document.forms[0][field2].value;
                                                 
                                                                }
                                                                if (document.forms[0][field1].value.length == 1) {
                                                                        document.forms[0][field1].value = "0" + document.forms[0][field1].value;
                                                 
                                                                }
                                                                return true;
                                                        }
                                                }
                                        }
                                }
                        }
                }else{
                        alert(err51);
                        return false;
                }
        }               
}       

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsBlank() 
// Arguments: 'field'  - the name of the html form field 
//   Returns: Boolean
// Objective: Checks the field (Textbox, Textarea) for whitespace and blank
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function IsBlank(field){
var the_length;
var whitespace;
        if (document.forms[0][field].value == ""){
                return false;
        }else{
                the_length = (document.forms[0][field].value.length - 1);
                for(i=0; i<=the_length; i++){
                        if (document.forms[0][field].value.charAt(i) == " "){
                                whitespace = 1;
                        }else{
                                whitespace = 0;
                                break;
                        }
                }
                if (whitespace == 1){
                        return false;
                }
        }
        return true;
}

function IsBlankPHP(field){
var the_length;
var whitespace;
        if (document.phpSearch.query_string.value == ""){
               alert("Search field cannot be blank.");
			    return false;
				
        }else{
		
                the_length = (document.phpSearch.query_string.value.length - 1);
                for(i=0; i<=the_length; i++){
                        if (document.phpSearch.query_string.value.charAt(i) == " "){
                                whitespace = 1;
                        }else{
                                whitespace = 0;
                                break;
                        }
                }
                if (whitespace == 1){
                        return false;
                }
        }
        return true;
}
function IsBlankASP(field){
var the_length;
var whitespace;
        if (document.aspSearch.SearchString.value == ""){
                alert("Search field cannot be blank.");
				return false;
        }else{
                the_length = (document.aspSearch.SearchString.value.length - 1);
                for(i=0; i<=the_length; i++){
                        if (document.aspSearch.SearchString.value.charAt(i) == " "){
                                whitespace = 1;
                        }else{
                                whitespace = 0;
                                break;
                        }
                }
                if (whitespace == 1){
                        return false;
                }
        }
        return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsChecked() 
// Arguments: 'field'  - the name of the html form field 
//   Returns: Boolean
// Objective: Checks the field set (Checkbox, Radio) for one or more selections
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function IsChecked(field){
var the_length = (document.forms[0][field].length - 1);
var ischecked = 0;
        for (i=0; i<=the_length; i++){
                if (document.forms[0][field][i].checked){
                        ischecked = 1;  
                        break;
                }
        }
        if (ischecked == 0){
                return false;
        }else{
                return true;
        }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsSingleChecked() 
// Arguments: 'field'  1- the name of the html form field 
//   Returns: Boolean
// Objective: Checks the field set (Checkbox, Radio) for one or more selections
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function IsSingleChecked(field){
        if (!document.forms[0][field].checked){
                return false;
        }else{
                return true;
        }
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsEmail() 
// Arguments: 'field'  - the name of the html form field 
//   Returns: Boolean
// Objective: Checks the field (Text) an email address containing '@' and '.'
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function IsEmail(field){
var the_length;
        if (document.forms[0][field].value == ""){
                return false;
        }else{
                if ((document.forms[0][field].value.indexOf("@") > -1 ) && (document.forms[0][field].value.indexOf(".") > -1 )){
                        return true;
                }else{
                        return false;
                }
        }
        return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsSelected() 
// Arguments: 'field' - the name of the html form field,  
//                        'multiple'  - Boolean variable defining if that select box allows multiple selections
//   Returns: Boolean
// Objective: 1. If multiple == true checks that ANY of the options are selected
//                        2. If multiple == false checks that an option other than the first one is selected. The 
//                               first option has text like "Please select an option".
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function IsSelected(field, multiple){
        if (multiple){
                if (document.forms[0][field].options.selectedIndex >= 0){
                        return true;
                }else{  
                        return false;
                }
        }else{
                if (document.forms[0][field].options.selectedIndex > 0){
                        return true;
                }else{  
                        return false;
                }
        }
        return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: NumSelect() 
// Arguments: 'field' - the name of the html form field,
//   Returns: integer
// Objective: Returns the number of options in the selection list.
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function NumSelect(field) {
        return document.forms[0][field].length
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: IsPasswordValid() 
// Arguments: 'newpass', 'newpassconfirm' - names of html form fields
//   Returns: Boolean
// Objective: Checks that the newpass == newpassconfirm  (put in your password 2x to confirm) and that 
//                        Password is at least 8 chars.
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function IsPasswordValid(newpass, newpassconfirm){
		//alert("In IsPasswordValid");
        if (document.forms[0][newpass].value.length < 4) {      
                alert(err58);
                return false;
		}
        if (document.forms[0][newpass].value != document.forms[0][newpassconfirm].value){
   	    	alert(err11);
       	    return false;
		}
return true;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
//   function: GetItemForKey
//parameters : in_Array, in_Key
//    return: a_NameValuePairs
//    purpose: Returns an array of arrays
////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetItemsForKey(in_Array, in_Key){
	var a_NameValuePairs = new Array();
	var j = 0;
	for (var i=0; i<in_Array.length; i++){
		var unsplit_item = in_Array[i].split("::");
		if (in_Key == unsplit_item[0]){
			a_NameValuePairs[j] = unsplit_item[1].split("||");
			j++;
		}
	}
	return a_NameValuePairs;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Gather_Checkbox_Input() 
// Arguments: 'to_field'  -the name of the field (select) in the form to be moved
//			  'from_field'  - the name of the field (text) in the html form
//			  'delim' - delimiter
//   Returns: -
// Objective: Takes all the options in from_field checkbox and moves them to to_field, in the following format
//			  valuedelimvalue
////////////////////////////////////////////////////////////////////////////////////////////////////////
function Gather_Checkbox_Input(from_field, to_field, delim){
        document.forms[0].elements[to_field].value = "";
	var the_length = (document.forms[0].elements[from_field].length - 1); 
	if (the_length > -1) {
		for (i=0; i<=the_length; i++){
                        if (document.forms[0].elements[from_field][i].checked){
				if (document.forms[0].elements[to_field].value == ""){
					document.forms[0].elements[to_field].value = document.forms[0].elements[from_field][i].value;
				}else{
					document.forms[0].elements[to_field].value = ((document.forms[0].elements[to_field].value) + delim + (document.forms[0].elements[from_field][i].value));
				}
			}
		}
	}
	//alert(document.forms[0].elements[to_field].value);
}
// END


////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Gather_Input() 
// Arguments: 'to_field'  -the name of the field (select) in the form to be moved
//			  'from_field'  - the name of the field (text) in the html form
//   Returns: -
// Objective: Takes all the options in from_field and moves them to to_field, in the following format
//			  name::value;
////////////////////////////////////////////////////////////////////////////////////////////////////////
function Gather_Input(from_field, to_field, delim){
	document.forms[0].elements[from_field].value = "";
        document.forms[0].elements[to_field].value = "";
	var the_length = (document.forms[0].elements[from_field].options.length - 1); 
	if (the_length > -1) {
		//alert("test");
		for (i=0; i<=the_length; i++){
			if (document.forms[0].elements[to_field].value == ""){
				document.forms[0].elements[to_field].value = document.forms[0].elements[from_field].options[i].value;
			}else{
				document.forms[0].elements[to_field].value = ((document.forms[0].elements[to_field].value) + delim + (document.forms[0].elements[from_field].options[i].value));
			}
		}
	}
	//alert(document.forms[0].elements[to_field].value);
}
// END


////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Limit_Input() 
// Arguments: 'field' - names of html form fields
//                        'limit' - numeral variable holding the max length of text area
//   Returns: Boolean
// Objective: Trims the field (Textarea) to the amount of characters in 'limit'.  Done to avoid 
//                        database field limit errors
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Limit_Input(field,limit){
        if (document.forms[0][field].value.length > limit ) {
                document.forms[0][field].value = document.forms[0][field].value.substring(0,limit);
                err55 = err55.replace(/__LENGTH__/, limit);
                alert(err55);
        }
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Page Flow Functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Page_Submit() 
// Arguments: none
//   Returns: Page Submission
// Objective: Each page has a Validate_Page function within it, if that returns true, the page is 
//                        submitted
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Page_Submit(){
        if (Validate_Page()){
                document.forms[0].submit();
        }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Page_Cancel() 
// Arguments: none
//   Returns: page goes back 1 history
// Objective: performs the function of the browser back button
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Page_Cancel(){
        history.back(-1);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Confirm_Action() 
// Arguments: 'message' - The message to be displayed in confirm box.
//			  'dest'    - Target url
//   Returns: -
// Objective: Displays a warning message that the user has to accept in order for the action to occur
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Confirm_Action(message, dest){
	if (confirm(message)){
		window.location.href=dest;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Confirm_Action() 
// Arguments: 'message' - The message to be displayed in confirm box.
//			  'dest'    - Target url
//   Returns: -
// Objective: Displays a warning message that the user has to accept in order for the action to occur
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Confirm_Delete(message, action){
	if (confirm(message)){
		document.forms[0].action = action;
		document.forms[0].submit();
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: SelfClose() 
// Arguments: none
//   Returns: closes a window
// Objective: Used for pop up windows, session management. If the opener window was closed, this function
//                        will close a popup window and alert a message when called by onBlur.  
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function SelfClose(){   
        if (window.opener.closed){
        alert("No parent browser window, this window will close.");
        window.close();
   }
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Close_Popup() 
// Arguments: none
//   Returns: closes a window
// Objective: Simple window closer fucntion
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Close_Popup(){ 
        window.close();
        window.opener.focus();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Go_There() 
// Arguments: 'dest' - string url
//   Returns: links to a new page
// Objective: Used primarily for drop down navigation, where urls are the values of the drop down options.
//                        Takes window to page defined in 'dest'. Called by onChange.
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Go_There(dest) {
                window.location.href = dest;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Pop_Up() 
// Arguments: 'destination' - string url
//                        'width', 'height'  - dimensions of window to be opened
//   Returns: opens 'destination' in new window
// Objective: Opens a new window to url == 'destination' with dimensions desired
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Pop_Up(destination, width, height)   {
        var pop = window.open(destination,"newWindow","scroll=auto,status=no,width=" + width+ ",height=" + height + ",scrollbars=auto,copyhistory=no");
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Select_All() 
// Arguments: 'field' - name of html form field
//   Returns: -
// Objective: Selects every options in a select box 
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Select_All(field){
        var the_length = (document.forms[0].elements[field].options.length - 1);
        for (i=0; i<=the_length; i++) {
                document.forms[0].elements[field].options[i].selected = true;
        }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Deselect_All() 
// Arguments: 'field' - name of html form field
//   Returns: -
// Objective: De - Selects every options in a select box 
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Deselect_All(field){
        var the_length = (document.forms[0].elements[field].options.length - 1);
        for (i=0; i<=the_length; i++) {
                document.forms[0].elements[field].options[i].selected = false;
        }

}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: Portal_Close() 
// Arguments: 'portal_item' - numeral value
//   Returns: -page submission
// Objective: Populates a hidden field with 'portal_item' (the portal feed to be closed), submits the page
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function Close_Portal(portid){
        if (document.forms[0].UserId.value != ""){
                document.forms[0].PortId.value = portid;
                document.forms[0].submit();
        }else{
                alert(err54);
        }
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Page Display functions
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: imgOn() 
// Arguments: 'imgName' - string value of the img tag
//   Returns: -
// Objective: swaps the src of 'imgName' with preloaded 'imgName' + 'on' .src
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function imgOn(imgName) {
	
        if (document.images) {
				document[imgName].src = eval(imgName + "_img_on.src");

				 
        }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: imgOff() 
// Arguments: 'imgName' - string value of the img tag
//   Returns: -
// Objective: swaps the src of 'imgName' with preloaded 'imgName' + 'off' .src
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function imgOff(imgName) {
        if (document.images) {
                document[imgName].src = eval(imgName + "_img_off.src");

        }
}



////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Function: WriteDate() 
// Arguments: none
//   Returns: Document.write (Date)
// Objective: determines current date based on client clock and prints out date on html page
////////////////////////////////////////////////////////////////////////////////////////////////////////        
function WriteDate() {
var today=new Date();


if(today.getMonth() == 0){
        document.write("January");}
if(today.getMonth() == 1){
        document.write("February");}
if(today.getMonth() == 2){
        document.write("March");}
if(today.getMonth() == 3){
        document.write("April");}
if(today.getMonth() == 4){
        document.write("May");}
if(today.getMonth() == 5){
        document.write("June");}
if(today.getMonth() == 6){
        document.write("July");}
if(today.getMonth() == 7){
        document.write("August");}
if(today.getMonth() == 8){
        document.write("September");}
if(today.getMonth() == 9){
        document.write("October");}
if(today.getMonth() == 10){
        document.write("November");}
if(today.getMonth() == 11){
        document.write("December");}
document.write (" ");
document.write (today.getDate());
var y = today.getYear();
if ( y < 1000 ) y += 1900;
document.write (", " + y + " at ");

var tmp = today.getHours();
var hr = (tmp <= 12) ? tmp : (tmp-12);
hr = ( hr < 10 ) ? "0" + hr : hr;
var sym = (tmp < 12) ? " a.m." : " p.m.";
if (hr == "00"){hr=12;}

var TodayMinutes = (( today.getMinutes() < 10) ? "0" : "" ) + today.getMinutes();
var TodaySeconds = (( today.getSeconds() < 10) ? "0" : "" ) + today.getSeconds();
document.write(hr + ":" + TodayMinutes + " " + sym);
}










// END 
////////////////////////////////////////////////////////////////////////////////////////////////////////
//-->
