﻿//************************************************************************
//* GLOBAL VARIABLES
//************************************************************************
var basehref = location.protocol + "//" +  location.host + "/admin_content/";
//************************************************************************
//* Disable right mouse click Script
//* By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//* For full source code, visit http://www.dynamicdrive.com
//************************************************************************
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")

//******************************************************
//* getSecurityCode()
//******************************************************
function getSecurityCode(frm)
{
	var strResult = "";

	switch(frm.whichcode.value)
	{		
		case "1":
		    strResult = "train3rz";
		    break;
		case "2":
		    strResult = "in4mashon";
		    break;
		case "3":
			strResult = "par3ntz";
			break;
		case "4":
			strResult = "empow3rng";
			break;
		case "5":
			strResult = "5upport";
			break;
		case "6":
			strResult = "h3lping";
			break;
		case "7":
			strResult = "grantz";
			break;
		case "8":
			strResult = "train3rz";
			break;
		case "9":	
			strResult = "h3re to h3lp";
			break;
		case "10":
			strResult = "in4mashon";
			break;
	}

	return strResult;
}
//******************************************************
//* checkSecurityCode()
//******************************************************
function checkSecurityCode(frm)
{   
	var strValueToMatch = getSecurityCode(frm)

	if (fTrim(frm.code.value) == '' || fTrim(frm.code.value) != strValueToMatch)
    {
		alert('You have not entered the code correctly!')		
		return false;
 	} else {
		return true;
	}

}
//******************************************************
//* gotoPage()
//******************************************************
function gotoPage(sPageType,iSubContentID)
{
    var sPageName;
    var frm = document.frmAdmin;
    
    switch (sPageType)
    {
        case "ListFromDetail":
            sPageName = basehref + "AdminViewList.asp?files=1";
            break;
        case "ListFromArticle":
            sPageName = basehref + "AdminViewList.asp";
            break;
        case "Detail":
            sPageName = basehref + "AdminViewDetail.asp";
            frm.hdnZoneID = frm.cboZones.value;
            break;
        case "Article":
            sPageName = basehref + "AdminViewArticle.asp";
            break;
        default:
            //alert(sPageType);
            break;
    }
    if (iSubContentID > 0)
    {
        frm.hdnID.value = iSubContentID;
    } else {
        if (frm.hdnID)
        {
            frm.hdnID.value = "";
        }
    }        
    frm.action = sPageName;        
    frm.submit();

}
//******************************************************
//* submitFunctions()
//******************************************************        
function submitFunctions()
{
    frm = document.frmAdmin;
    
    frm.hdnPosted.value = "posted";
}
//******************************************************
//* selectedZone()
//******************************************************
function selectedZone()
{
   var frm = document.frmAdmin;
   var iZone = frm.cboZones.selectedIndex;
   var objToChange = document.getElementById("hrefCreateContent");
   var sResult = "";
   
   sResult = frm.cboZones[iZone].text;
   
   if (objToChange)
   {
        objToChange.innerHTML = "Create New \"" + sResult + "\" Blurb";
   }
}
//******************************************************
//* isLinkDynamic()
//******************************************************
function isLinkDynamic(iBlnValue)
{
   var frm = document.frmAdmin;
   var objToChange1 = document.getElementById("spanLink");
   var objToChange2 = document.getElementById("spanLinkExisting");
   var objToChange3 = document.getElementById("spanArticle");
   var objToChange4 = frm.txtLink;

   if (iBlnValue == 1)
   {
        objToChange1.style.display = "inline";  
        objToChange2.style.display = "inline";  
        objToChange3.style.display = "none"; 
        if (fTrim(objToChange4.value) == 'news.asp')
        {
            objToChange4.value = '';
        }   
        
   } else {
        objToChange1.style.display = "none";
        objToChange2.style.display = "none";  
        objToChange3.style.display = "inline";  
           
   }  
   
}
//******************************************************
//* selectPDF()
//******************************************************
function selectPDF()
{
    var frm = document.frmAdmin;

    if (frm.cboPDFExisting.value != '' && frm.cboPDFExisting.value != -1) 
    {
        // wipe out the value in the txtLink box, where
        // the user has entered a page to link to.
        frm.txtLink.value = "";
        
    }
}
//******************************************************
//* submitSort()
//******************************************************
function submitSort(fldSortValue,fldSortRec)
{
    var frm = document.frmAdmin;
    var elSortValue = fTrim(fldSortValue);
    var errMsg = "";
    var pass = true;
       
    if (elSortValue == '')
    {        
        pass = false;
        errMsg = 'You must enter a Sort value';
        
    } else {
        if (!IsNumeric(elSortValue))
        {
            pass = false;
            errMsg = 'Sort values must be numeric';
        }
    }
    if (pass)
    {
        frm.hdnPosted.value = "postedSortValue"; 
        frm.hdnSortValue.value = fldSortValue
        frm.hdnSortRec.value = fldSortRec
        frm.submit();
                        
    } else {
        alert(errMsg);
    }
    
    return pass;
     
}

//******************************************************
//* validate()
//******************************************************
function validate(bSubmit)
{

    var reqMsg = "";
    var errMsg = "";
    var pass = true;


    if (document.frmAdmin.cboZones.value == 0)
    {
        reqMsg += "You must select a Zone\n";
        pass = false;
        
        if (!bSubmit)
        {
            alert(reqMsg);
            return pass;
        }
        
    } else {
        if (document.frmAdmin.hdnZoneChanged && bSubmit == "zoneChange")
        {            
                document.frmAdmin.hdnZoneChanged.value = "true";
                document.frmAdmin.submit();            
        }
    }
    if (document.frmAdmin.cboNewsType)
    {
        if (document.frmAdmin.cboNewsType.value == 0)
        {
            reqMsg += "You must select a News Type\n";
            alert(reqMsg);
            pass = false;
        }
    }
        
    if (document.frmAdmin.taBody)
    {
        var taContent = fTrim(document.frmAdmin.taBody.value)

        if (taContent.length == 0)
        {
            reqMsg += "You must enter Body content\n";
            pass = false;
        }
    }

    if (pass && bSubmit) 
    {
        document.frmAdmin.hdnPosted.value = "posted";         
        document.frmAdmin.submit();
        return pass;
    } else {
       if (bSubmit)
        {
            alert(reqMsg) 
            return pass;                  
        }
   }
   
}
//********************************************************************************
// checkBoxInput
// Description: 
//      When user enters text in any of the "OTHER" fields, this function
//      is called on its onchange event, and ensures that the corresponding 
//      "Other" checkbox gets checked.
//      SLH, 05/30/2008
//*********************************************************************************
function checkBoxInput(fldName,chkBox,strValueToMatch) 
{
    var i           = 0;
    var sFieldValue = fTrim(fldName.value);
    var el          = document.form1;
    var elChkBox    = eval('el.' + chkBox);
    
    var iCtr = 0;
    for (i =0; i < 50; i++)
    {
        if (elChkBox[i].value == strValueToMatch)
        {
            
            elChkBox = elChkBox[i];
            break;
        }
    }
    if (sFieldValue.length > 0) 
    {
        // Check the checkbox.
        elChkBox.checked = true;
    } else {
        elChkBox.checked = false;
    }
}
//********************************************************************************
// radioInput
// Description: 
//      When user enters text in any of the "OTHER" fields, this function
//      is called on its onchange/form submission event, and ensures that
//      the corresponding "Other" radio button gets checked.
//      SLH, 07/08/2008
//*********************************************************************************

function radioInput(fldName,rdoButton) 
{
    var bRadioChecked = false;
    var i             = 0;
    var sFieldValue   = fTrim(fldName.value);
    var el            = document.form1;
    var elRadio       = eval('el.' + rdoButton);
    
    var iCtr = 0;
 
    for (i=0; i < elRadio.length; i++)
    {
        if (elRadio[i].checked)
        {
            bRadioChecked = true;
        }
        if (elRadio[i].value == 'Other')
        {            
            elRadio = elRadio[i];            
        }
        
    }
    if (sFieldValue.length > 0 && !bRadioChecked) 
    {
        // Check the "Other" radio box ... IF there aren't
        // any other radio buttons already checked. (If we
        // have a value in the Other input box, but a radio
        // button other than "OTHER" is checked, we will
        // alert the user via validation.)       
        elRadio.checked = true;
    } else {
        //-----------------------------------------------------
        // NOTE: Leaving the radio button checked if the user
        // has checked it ... this way it will show up in our 
        // validation routine as a red flag (they selected 
        // "OTHER" but didn't put a value in it.)
        //-----------------------------------------------------
        // elRadio.checked = false;
    }
}
//******************************************************
//* textCounter()
//*
// Original:  Ronnie T. Moore -->
// Web Site:  The JavaScript Source -->

// Dynamic 'fix' by: Nannette Thacker -->
// Web Site: http://www.shiningstar.net -->

// This script and many more are available free online at -->
// The JavaScript Source!! http://javascript.internet.com -->
//******************************************************
function textCounter(field, countfield, maxlimit) 
{
   	//alert(field.value.length + ', ' + maxlimit)

    if (field.value.length > maxlimit) // if too long...trim it!
    {            
        field.value = field.value.substring(0, maxlimit);

    } else { 
        // otherwise, update 'characters left' counter
		if (countfield.value)
		{
			countfield.value = maxlimit - field.value.length;
		} else {
			countfield.innerHTML = maxlimit - field.value.length + " characters left";
		} 
    }

}
//************************************************
//* isNumeric()
//************************************************
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;   
}
//************************************************
//* validCurrency()
//************************************************
function validCurrency(str)
{
    var strValue = trimString(str)
    var result = true;
    
    result = RegExp(/^\$?[0-9\,]+(\.\d{2})?$/).test(String(strValue).replace(/^\s+|\s+$/g, ""));
    return result;    
}
//************************************************
//* validPhoneNum()
//************************************************
function validPhoneNum(str)
{

    var strPhone = trimString(str);
    var result = true;
    
    strPhone = stripSymbols(strPhone);

     
    // Check to see that phone is numeric.
    if (!IsNumeric(strPhone))
    {
        result = false;                        
    }
    
    // Check to see that the phone number has 10 digits.
    if (strPhone.length != 10)
    {
        result = false;
    }
    return result;       
}
	
//************************************************
//* stripSymbols()
//************************************************
function stripSymbols(str)
{
    var s = str;
    filteredValues = "()-${}[] ";     // Characters stripped out
    var i;
    var returnString = "";
    
     for (i = 0; i < s.length; i++) 
     {  // Search through string and append to unfiltered values to returnString.
        var c = s.charAt(i);
        if (filteredValues.indexOf(c) == -1) returnString += c;
        } 
            str = returnString;

    return str   
}
   
//************************************************
// trimString()
// Date: 05/30/2008
// Description: 
//      Removes white space from start and/or end of given string
//************************************************
function trimString(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}
//************************************************
//* fTrim()
//*
//* Added By: Susan Henesy
//* Date: 04/11/2008
//* Description: 
//*     Another method of removing white spaces, similar to trimString above....
//*
//*     White Space is defined as:
//*        - Space
//*        - Carriage Return
//*        - newline
//*        - form feed
//*        - TABs
//*        - Vertical TABs
//************************************************
function fTrim(text)
{
   //   /            open search
   //     ^             beginning of string
   //     \s            find White Space, space, TAB and Carriage Returns
   //     +             one or more
   //   |            logical OR
   //     \s            find White Space, space, TAB and Carriage Returns
   //     $             at end of string
   //   /            close search
   //   g            global search

   return text.replace(/^\s+|\s+$/g, "");
}
//************************************************
//* resetElementColors
//*
//* Added By: Susan Henesy
//* Date: 05/30/2008
//* Description: 
//*     Used on form validation routines ... 
//*     resets any red element colors to black.
//************************************************
function resetElementColors()
{
   var i = 0;
   var el = document.form1;
   var elLabels = document.getElementsByTagName('label');
   var elTables = document.getElementsByTagName('table');
   var elTDs = document.getElementsByTagName('td');
   
   for (i=0; i < el.length; i++)
   {
        if (el[i].style.color == 'red')
        {
            el.style.color = '#000000';
        }
   }
   
   for (i=0; i < elLabels.length; i++)
   {
        if (elLabels[i].style.color == 'red')
        {
            elLabels[i].style.color = '#000000';
        }
   }
   
   for (i=0; i < elTables.length; i++)
   {
        if (elTables[i].style.color == 'red')
        {
            elTables[i].style.color = '#000000';
        }
   }
   
   for (i=0; i < elTDs.length; i++)
   {
        if (elTDs[i].style.color == 'red')
        {
            elTDs[i].style.color = '#000000';
        }
   }
}

//*****************************************************************************
// emailCheck
// -- This script and many more are available free online at -->
// -- The JavaScript Source!! http://javascript.internet.com -->
//*****************************************************************************
// -- V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
// -- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
// -- Changes:
// 
/*
// 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
// international characters) were allowed.

// 1.1.3: Added the restriction to only accept addresses ending in two
// letters (interpreted to be a country code) or one of the known
// TLDs (com, net, org, edu, int, mil, gov, arpa), including the
// new ones (biz, aero, name, coop, info, pro, museum).  One can
// easily update the list (if ICANN adds even more TLDs in the
// future) by updating the knownDomsPat variable near the
// top of the function.  Also, I added a variable at the top
// of the function that determines whether or not TLDs should be
// checked at all.  This is good if you are using this function
// internally (i.e. intranet site) where hostnames don't have to 
// conform to W3C standards and thus internal organization e-mail
// addresses don't have to either.
// Changed some of the logic so that the function will work properly
// with Netscape 6.

// 1.1.2: Fixed a bug where trailing . in e-mail address was passing
// (the bug is actually in the weak regexp engine of the browser; I
// simplified the regexps to make it work).

// 1.1.1: Removed restriction that countries must be preceded by a domain,
// so abc@host.uk is now legal.  However, there's still the 
// restriction that an address must end in a two or three letter
// word.

// 1.1: Rewrote most of the function to conform more closely to RFC 822.

// 1.0: Original  */
//----------------------------------------------------------------------------
function emailCheck(emailStr) {

    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */

    var emailPat=/^(.+)@(.+)$/;

    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ] */

    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed.*/

    var validChars="\[^\\s" + specialChars + "\]";

    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */

    var quotedUser="(\"[^\"]*\")";

    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */

    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* The following string represents an atom (basically a series of non-special characters.) */

    var atom=validChars + '+';

    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */

    var word="(" + atom + "|" + quotedUser + ")";

    // The following pattern describes the structure of the user

    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */

    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) {

    /* Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address. */

    //alert("Email address seems incorrect (check @ and .'s)");
    return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
    //alert("Ths username contains invalid characters.");
    return false;
       }
    }
    for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
    //alert("Ths domain name contains invalid characters.");
    return false;
       }
    }

    // See if "user" is valid 

    if (user.match(userPat)==null) {

    // user is not valid

   // alert("The username doesn't seem to be valid.");
    return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {

    // this is an IP address

    for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
    //alert("Destination IP address is invalid!");
    return false;
       }
    }
    return true;
    }

    // Domain is symbolic name.  Check if it's valid.
     
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat)==-1) {
    //alert("The domain name does not seem to be valid.");
    return false;
       }
    }

    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    if (checkTLD && domArr[domArr.length-1].length!=2 && 
    domArr[domArr.length-1].search(knownDomsPat)==-1) {
    //alert("The address must end in a well-known domain or two letter " + "country.");
    return false;
    }

    // Make sure there's a host name preceding the domain.

    if (len<2) {
    //alert("This address is missing a hostname!");
    return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}

//  End -->
