

function clearField( field_name )
{
	document.getElementById( field_name ).value = '';
	document.getElementById( field_name ).style.backgroundColor = '';
}

function highlightFields( field_str )
{
	var fields = field_str.split(',');
	
	for( var i=0; i<fields.length; i++ )
	{
		highlightField( fields[i], '#F6F5CF' ); 
	}
	
}


function referenced_link(elementId, link)
{
    var objElement = window.opener.document.getElementById(elementId)
    if (objElement) 
    {
        objElement.value = link;
        
    }   //end if
    
	return;
	
}   //end function

function highlightField( field_name, field_color )
{
	document.getElementById( field_name ).style.backgroundColor = field_color;
}


function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') +  num + '.' + cents);
}	//end function

function validate_required_fields(frmName, strTextBoxes)
{
	var oForm = document.getElementById(frmName);
	
	//turn the comma separated list into an array
	var arrBoxes = strTextBoxes.split(",");
	
	error = 0;
	
	//loop thru each box and determine if the text value is empty
	for( var intCount = 0; intCount < arrBoxes.length; intCount++ )
	{
		arrBoxes[intCount] = arrBoxes[intCount].trim_spaces();
		
		//alert( "inCount: " + intCount + " - text box: -->" + arrBoxes[intCount] + "<--" );
		
		var strText = document.getElementById(arrBoxes[intCount]).value;
		
		if( strText.length == 0 )
		{
			error++;
			
		}	//end if
		
	}	//end for loop
	
	//if any errors, then user did not enter all the required fields
	if( error > 0 )
	{
		alert( "Please enter all the required fields." );
		
		valid = false;
		
	}	//end if
	
	else
	{
		valid = true;
		
	}	//end else
	
	return valid;
	
}	//end function

function pop_templates()
{
	window.open('pop_templates.php','admin_pop','width=600,height=400,scrollbars=yes,resizable=yes');	
}

//removes all spaces in a string
function removespaces() 
{
	return this.replace(/.*\S/,'');
	
}	//end function

//trims leading and trailing spaces
function trim_spaces() 
{
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
	
}	//end function


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;
}


function iconRollover(icon,action) {
	var element = document.getElementById('home_'+icon+'_links');
	if( element ) {
		if( action=='1' ) {
			//new Effect.Appear(element);
			element.style.display='block';
		}
		else if( action=='0' ) {
			//new Effect.Fade(element);
			element.style.display='none';
		}
	}
}

function clear_image( field_id )
{
    document.getElementById( field_id + "_src" ).src = '../images/spacer.gif';
	document.getElementById( field_id ).value = '0';
	document.getElementById( field_id + '_filename' ).value = '';
}

function clear_link( field_id )
{
	document.getElementById( field_id + '_id' ).value = '';
	document.getElementById( field_id + '_text' ).value = '';
	document.getElementById( field_id + '_display' ).innerHTML = '&nbsp;';
	document.getElementById( field_id + '_nw' ).value = 0;
	
	if( document.getElementById( field_id + '_name' ) )
	    document.getElementById( field_id + '_name' ).value = '';
	    
}

function clear_page_reference( field_id )
{
	document.getElementById( field_id + '_name' ).value = '';
	document.getElementById( field_id + '_text' ).value = '';
	document.getElementById( field_id + '_display' ).innerHTML = '';
	document.getElementById( field_id + '_name_display' ).innerHTML = '';
}

function clear_document( field_id )
{
	document.getElementById( field_id ).value = '';
	document.getElementById( field_id + '_display' ).innerHTML = '';
	document.getElementById( field_id + '_h' ).value = '';
}

function create_external_link(element_id)
{
	var blnTargetNew = false;
	
	link = document.getElementById('address').value;
	
	short_link = link;
	
	var strURL = link;
	
	//check to see if the httP is missing
	if ( link.indexOf("http://") == -1 )
	{
	   // strURL = "http://" + link;        commented out by Tri
	   
	    if(link.indexOf("www.")== -1 && link.indexOf(".com") == -1){
	        strURL = link;	        
	    }
	    else {
	        strURL = "http://" + link;
	    }
	}   //end if
	
	if( document.getElementById('new_win_yes').checked )
	{	
		window.opener.document.getElementById(element_id+"_nw").value=1;
	}
	else
	{
		window.opener.document.getElementById(element_id+"_nw").value=0;
	}
		
	window.opener.document.getElementById(element_id+"_text").value=link;
	
	window.opener.document.getElementById(element_id+'_display').innerHTML=short_link;
	   	
	//if _name is present, then we are the page.aspx, use the strURL for _text
	if( window.opener.document.getElementById( element_id + '_name' ) )
	{
	    window.opener.document.getElementById( element_id + '_name' ).value = link;
	    
	    window.opener.document.getElementById(element_id+'_display').innerHTML=strURL;
	    
	    window.opener.document.getElementById(element_id+"_text").value = strURL;
	    
	}   //end if
	
}

function toggleCheckBoxesWithMatchingID( chkBoxAll, intItemID )
{
    //get all the input elements
    var arrElements = document.getElementsByTagName("input");
    
    var strType = "";
    
    var strElementId = "";
    
    var blnCheckValue = false;
    
    var intLastIndex = 0;
    
    var strSearch = "_id";
    
    var arrElementId;
    
    var intElementsItemId = 0;
    
    //use the value of the calling checkbox to determine the value of the other checkboxes
    if( chkBoxAll.checked )
    {
        blnCheckValue = true;
        
    }   //end if
    
    else
    {
        blnCheckValue = false;
        
    }   //end else
    
    //loop through all the input elements
    for( var intIndex = 0; intIndex < arrElements.length; intIndex++ )
    {
        //get the type attribute
        strType = arrElements[intIndex].getAttribute("type");     
               
        if( strType == "checkbox" )
        {
            strElementID = arrElements[intIndex].getAttribute("id"); 
            
            //split the element into an array
            arrElementId = strElementID.split(strSearch);
            
            //the last element will be the id number
            intLastIndex = arrElementId.length - 1;
            
            intElementsItemId = arrElementId[intLastIndex];
            
            //if the id number matches the id number in the element name, then toggle the checkbox
            if( intElementsItemId == intItemID )
            {
                arrElements[intIndex].checked = blnCheckValue;
             
            }   //end if
            
        }   //end if
        
    }   //end for loop
    
}   //end function


function toggleCheckBoxesWithName( chkBoxAll, strPartialName )
{    
    //get all the input elements
    var arrElements = document.getElementsByTagName("input");
    
    var strType = "";
    
    var strElementId = "";
    
    var blnCheckValue = false;
    
    var intLastIndex = 0;
    
    var strSearch = "_id";
    
    var arrElementId;
    
    var intElementsItemId = 0;
    
    //use the value of the calling checkbox to determine the value of the other checkboxes
    if( chkBoxAll.checked )
    {
        blnCheckValue = true;
        
    }   //end if
    
    else
    {
        blnCheckValue = false;
        
    }   //end else
    
    //loop through all the input elements
    for( var intIndex = 0; intIndex < arrElements.length; intIndex++ )
    {
        //get the type attribute
        strType = arrElements[intIndex].getAttribute("type");     
               
        if( strType == "checkbox" )
        {
            strElementID = arrElements[intIndex].getAttribute("id"); 
            
            //if there's a partial match, then check it
            if( strElementID.indexOf(strPartialName) != -1)
            {
                arrElements[intIndex].checked = blnCheckValue;
             
            }   //end if
            
        }   //end if
        
    }   //end for loop
    
}   //end function

//----------- kevin's ----------------------------
// nav drop downs
startList = function() {

	if (document.all && document.getElementById("menu_main") ) {
		menuItems = document.getElementById("menu_main").getElementsByTagName("li");

		for (i=0; i<menuItems.length; i++) {
			menuItems[i].onmouseover = function() {
				this.className += " sfhover";
			}
			menuItems[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	
}
window.onload = startList;

function showHideTags( strTagName, blnShowTags)
{
    arrTags = document.getElementsByTagName(strTagName);
    
    for (i=0; i<arrTags.length; i++)
    {
        if( blnShowTags )
        {
            arrTags[i].style.display = "";
                
        }   //end if
            
        else
        {
            //hide the element
            arrTags[i].style.display = "none";
                
        }   //end else
         
    }   //end for loop

}   //end function 

//<SCRIPT LANGUAGE="JavaScript">
//<!-- Idea by:  Nic Wolfe (Nic@TimelapseProductions.com) -->
//<!-- Web URL:  http://fineline.xs.mw -->

//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->

function popUp(URL, intWidth, intHeight) 
{
    day = new Date();
    
    id = day.getTime();

    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + intWidth + ",height=" + intHeight + "');");
}


//------------------------------------------

//assigns a new function to string types
String.prototype.removespaces = removespaces;
String.prototype.trim_spaces = trim_spaces;

function saveLanguagePreference( strLanguageCode )
{

    if( strLanguageCode == "en" )
    {
        //erase the cookie
        eraseCookie( "language" );
        
    }   //end if
    
    else
    {
        createCookie( "language", strLanguageCode, 90 );
        
    }   //end else

}   //end function

function redirectToTranslatedPage(strFileName)
{
    var strLanguageCode = "";
    
    if ( strLanguageCode = readCookie("language") )
    {
        var strRedirect = ""
        
        var arrFileName = strFileName.split(".")
    
        strRedirect = arrFileName[0] + "-" + strLanguageCode + "." + arrFileName[1] 
        
         window.location = strRedirect;
    
    }   //end if
    
}   //end function

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function selectDeselectAll(allSelected, allDeselected)
{
    if (document.getElementById('chbSelectAllBranches').checked)
    {
        document.getElementById('branches').innerHTML = allSelected
    }
    else
    {
        document.getElementById('branches').innerHTML = allDeselected
    }
}

function setRteImageFilename(filename, imageName, width, height)
{
 document.getElementById('divImageSize').style.display = "block";
 document.getElementById('hfRteImageFilename').value = filename;
 document.getElementById('rteImageFilename').innerHTML = "Image: " + imageName;
 document.getElementById('ctl00_cphMainColumn_txtWidth').value = width;
 document.getElementById('hdnOriginalWidth').value = width;
 document.getElementById('ctl00_cphMainColumn_txtHeigth').value = height;
 document.getElementById('hdnOriginalHeight').value = height;
 
 // make sure the radio buttons are unselected
 if( document.getElementById('rdImageSizeSmall').checked )
    document.getElementById('rdImageSizeSmall').checked = false;
    
 if( document.getElementById('rdImageSizeMedium').checked )
    document.getElementById('rdImageSizeMedium').checked = false;
    
 if( document.getElementById('rdImageSizeLarge').checked )
    document.getElementById('rdImageSizeLarge').checked = false;
    
}

function updateImageSize( strSize )
{
    var intNewWidth;
    
    var intOldWidth;
    
    var intOriginalWidth;
    
    var intOriginalHeight;
    
    var dblRatio;
    
    // Get the original width and height
    intOriginalWidth = document.getElementById('hdnOriginalWidth').value;
    
    intOriginalHeight = document.getElementById('hdnOriginalHeight').value;
    
    if( intOriginalHeight > 0 )
    {
        dblRatio = intOriginalWidth / intOriginalHeight;
        
    }   //end if
    
    else
    {
        dblRatio = 0;
        
    }   //end else
    
    switch(strSize)
    {
        case "small":
        
            intNewWidth = 150;
            
            break;
        
        case "medium":
            
            intNewWidth = 250;
        
            break;
        
        case "large":
            
            intNewWidth = 350;
        
            break;
        
        default:
    
    }   //end switch

    // calculate the new height
    if( intOriginalWidth > 0 )
    {
        intNewHeight = ( intNewWidth * intOriginalHeight ) / intOriginalWidth;
        
    }   //end if
    
    else
    {
        intNewHeight = 0;
    
    }   //end else
    
    // now update the text boxes
    document.getElementById('ctl00_cphMainColumn_txtWidth').value = parseInt(intNewWidth);
 
    document.getElementById('ctl00_cphMainColumn_txtHeigth').value = parseInt(intNewHeight);

}   //end function

/******** FUNCTION FOR READING PROGRAM **********/
function updateProgramGoalsLabel( strElementId, strLogTypeId )
{
    // logtype id is the key for the global page measures array
    var strTitle = arrMeasures[strLogTypeId];
    
    document.getElementById( strElementId ).innerHTML = strTitle;

} 

function showHideLoggingFields( blnChecked )
{
    var strClass = "";
    
    var strKey = "";
    
    var strValue = "";
    
    var objRow = "";
    
    if( blnChecked )
    {
        strClass = "";
    }
    
    else
    {
        strClass = "hide-row";
    }   
    
    // loop through each logging row array and update the css class
    for ( strKey in arrLogRows  )
    {
        strValue = arrLoRows[strKey];
        
        objRow = document.getElementById(strValue);
        
        // update the rows class
        objRow.className = strClass;
        
    }
    
}

// handles the event when one of the radio buttons is clicked inside the radio button list
function restrictionTable_onClick(strElementId)
{
    var intIndex = "";
    
    var arrControls = "";
    
    var objControl = "";
    
    if( gRestrictionTableId.length )
    {
        strElementId = gRestrictionTableId;
    }
    
    // replace the underlines with $ signs - g means global replace, i means case insenstive
    strElementId = strElementId.replace( new RegExp( "_", "g" ), "$" );
    
    // get the controls witht the same name as the elementId
    arrControls = document.getElementsByName(strElementId);
    
    // loop through each control inside the table
    // if it's checked then call the showHide function
    for( intIndex = 0; intIndex < arrControls.length; intIndex++ )
    {
        if( arrControls[intIndex].checked )
        {
            showHideRestrictionFields(arrControls[intIndex].value);
                
            break;
            
        }   //end if
        
    }   //end for loop

}   //end function

function showHideRestrictionFields(strRestrictionType)
{
    // first step is hide all the fields
    var strKey = "";
    
    var strValue = "";
    
    var objRow = "";
    
    var strClass = "hide-row";
    
    // hide age fields
    for( strKey in arrAgeRows )
    {
        strValue = arrAgeRows[strKey];
        
        objRow = document.getElementById(strValue);
        
        // update the rows class
        objRow.className = strClass;
    }

    // hide grade fields
    for( strKey in arrGradeRows )
    {
        strValue = arrGradeRows[strKey];
        
        objRow = document.getElementById(strValue);
        
        // update the rows class
        objRow.className = strClass;
    }
    
    // hide classification fields
    for( strKey in arrClassRows )
    {
        strValue = arrClassRows[strKey];
        
        objRow = document.getElementById(strValue);
        
        // update the rows class
        objRow.className = strClass;
    }
    
    // show the fields based on restriction code
    switch(strRestrictionType)
    {
        // -------------------
        case "age":
        
            // hide age fields
            for( strKey in arrAgeRows )
            {
                strValue = arrAgeRows[strKey];
                
                objRow = document.getElementById(strValue);
                
                // update the rows class
                objRow.className = "";
            }
        
        break;
        
        // -------------------
        case "grade":
            
            for( strKey in arrGradeRows )
            {
                strValue = arrGradeRows[strKey];
                
                objRow = document.getElementById(strValue);
                
                // update the rows class
                objRow.className = "";
            }
    
        
        break;
        
        // -------------------
        case "class":
        
            // hide classification fields
            for( strKey in arrClassRows )
            {
                strValue = arrClassRows[strKey];
                
                objRow = document.getElementById(strValue);
                
                // update the rows class
                objRow.className = "";
            }    
        
        break;
    
    }   //end switch
    
}   //end function


gRestrictionTableId = "";

function applyOnClickToTableCells( strElementId )
{
    var myTblCells = document.getElementById(strElementId).getElementsByTagName("td");
    
    var strScript = "restrictionTable_onClick('" + strElementId + "')";
    
    gRestrictionTableId = strElementId;
    
    if( myTblCells.attachEvent )
    {
        myTblCells.attachEvent('onclick', restrictionTable_onClick );
        
    }
    
}   //end function

function postNewTag(strTagNameElementId, strTagPageElementId, strTagPageTypeIdElementId, strIdForTitle, strTagsForPage, btnSubmitTag )
{
    var txtTagName = document.getElementById(strTagNameElementId);

    var hdnTagPage = document.getElementById(strTagPageElementId);
    
    var hdnTagPageTypeId = document.getElementById(strTagPageTypeIdElementId);
    
    var hdnIdForTitle = document.getElementById(strIdForTitle);

    //------------------------------
    // get the newly entered name
    var strNewTagName = txtTagName.value;
    
    strNewTagName = strNewTagName.trim_spaces();
    
    //------------------------------
    // use jQuery to send an Ajax call for adding the the tag
    if( strNewTagName.length > 0 )
    {
        btnSubmitTag.value = "Sending..."
        
        btnSubmitTag.disabled = true;
    
        $.post("ajax/tags.aspx", { action: "addtags", tagtextbox: strTagNameElementId, tagname: strNewTagName, page: hdnTagPage.value, type: hdnTagPageTypeId.value, idfortitle: hdnIdForTitle.value, tagsforpage: strTagsForPage, button: btnSubmitTag.id }, function(data) { postNewTagCallBackHandler( data ); } );
        
    }   //end if
    
    else
    {
        alert( "Please enter a tag." );
       
    }   //end else
    
    return false;
    
}   //end function

// this function will update the tabname for both the display tab and in the arrTabs
function postNewTagCallBackHandler( data )
{
    var arrData = new Array();
    
    var arrKeyValuePair = new Array();
    
    var intIndex = 0;
    
    var strKey = "";
    
    // split the data into an array
    var arrKeyValuePairs = new Array();
    
    arrKeyValuePairs = data.split("&");
    
    // loop through each item and add to the data array as key: value
    for( intIndex = 0 ; intIndex < arrKeyValuePairs.length; intIndex++ )
    {
        arrKeyValuePair = arrKeyValuePairs[intIndex].split("=");
        
        strKey = arrKeyValuePair[0]; 
        
        // 1st element is the key, 2nd element is the value
        arrData[strKey] = arrKeyValuePair[1];

    }   //end for loop
    
    var strTagNames = arrData['tagname'];
    
    var arrTagNames = "";
    
    var strTagName = "";
    
    var strButtonId = arrData['button'];
    
    var strTagsForPage = arrData['tagsforpage'];
    
    var strTagNameElementId = arrData['tagtextbox'];
    
    var btnSubmitTag = document.getElementById(strButtonId);
    
    var lblTagsForPage = document.getElementById(strTagsForPage);
    
    var txtTagName = document.getElementById(strTagNameElementId);
    
    btnSubmitTag.disabled = false;
    
    btnSubmitTag.value = "Add Tag";
    
    txtTagName.value = "";
    
    if( strTagNames.length > 0 )
    {
        if( strTagNames.indexOf(",") > -1 )
        {
            // if there's a comma, then split into an array
            arrTagNames = strTagNames.split(",");
            
        }   //end if
        
        else
        {
            // if no comma, then create an array and add the tag to it
            arrTagNames = new Array();
            
            arrTagNames[0] = strTagNames;
            
        }   //end else
    
        // loop through each array and the item to the list
        for( intIndex = 0; intIndex < arrTagNames.length; intIndex++ )
        {
            strTagName = arrTagNames[intIndex];
            
            if( strTagName.length > 0 )
            {
                lblTagsForPage.innerHTML += "<span style=\"color: red;\">" + strTagName + "</span>&nbsp;&nbsp;";
                
             }  //end if
            
        }   //end for loop
    
        txtTagName.value = "";
    
        alert( "The following tags were successfully added: " + strTagNames );
        
        showHideTagForms( "mytags" );
        
    }   //end if
    
    else
    {
        
        alert('An error occurred while attempting to add the tag OR you may have already entered a tag name for this page. Please try again.');
        
    }   //end else     
    
}   //end function

function focusToNext(objEvent, strElement)
{
    if ( objEvent.keyCode == 13)
    {
        oNextObj = document.getElementById(strElement);
      
        if( oNextObj )
        {
            oNextObj.focus();
          
            oNextObj.click();
                
        }   //end if
    
        return;
          
    }    //end if
       
}   //end function


function hide_show(nodeIds, visTo, visType)
{
	var nodeIdArr = nodeIds.split("|");
	
	for(i=0; i<nodeIdArr.length; i++) {
		var nodeId = nodeIdArr[i];
		var thisNode = document.getElementById(nodeId);
		
		// check for node's current visibility
		if(visTo == 1) {
			if(visType) {
				if( (visType == "table-row-group" || visType == "table-row") && document.all ) visType = "block";
				thisNode.style.display = visType;
			} else {
				thisNode.style.display = "block";
			}
		} else if(visTo == 0) {
			thisNode.style.display = "none";
		} else { // find node current vis and assume the opposite
			var currVis = thisNode.style.display;
			
			if(currVis) {
				if(currVis == "none")
					thisNode.style.display = ( visType ? visType : "block" );
				else
					thisNode.style.display = "none";
			} else if(thisNode.className == "no_show") {
				thisNode.style.display = ( visType ? visType : "block" );
			} else { // assume element starts as visible
				thisNode.style.display = "none";
			}
		}
	}
}

function swap_expand_icons(clicked_header) {
	var curr_class = clicked_header.className;

	if( curr_class == "expandable")
		var new_class = "contractable";
	else
		var new_class = "expandable";

	clicked_header.className = new_class;
}


function showTags(strSelectedListItem, hdnTagPageId, lblTagsForPageId )
{
    if( document.getElementById("liMyTags") )
    {
        // the my tags form is being displayed
        
    }   //end if
    
    else
    {
        // else the my tags form is not present, return nothing
        return;
    
    }   //end esle
    
    // get all the list items
    var liMyTags = document.getElementById("liMyTags");
    
    var liAllTags = document.getElementById("liAllTags");
    
    var liAddTags = document.getElementById("liAddTags");
    
    liMyTags.className = "";
    
    liAllTags.className = "";
    
    liAddTags.className = "";
    
    switch( strSelectedListItem )
    {
        case "liMyTags":
        
            liMyTags.className = "active";
            
            getTagsForPage( "mytags", hdnTagPageId, lblTagsForPageId  );
            
        break;
        
        case "liAllTags":
        
            liAllTags.className = "active";
            
            getTagsForPage( "alltags", hdnTagPageId, lblTagsForPageId  );
        
        break;
        
        case "liAddTags":
            
            liAddTags.className = "active";
            
            showHideTagForms( "addtags" );
            
        break;
    
    }   //end switch  
    
}   //end function

function getTagsForPage( strType, hdnTagPageId, lblTagsForPageId  )
{
    var hdnTagPage = document.getElementById(hdnTagPageId);

    var lblTagsForPage = document.getElementById(lblTagsForPageId);
    
    lblTagsForPage.innerHTML = "Loading...";
    
    var strTagsForPage = lblTagsForPageId;
    
    $.post("ajax/tags.aspx", { action: strType, page: hdnTagPage.value, tagsforpage: strTagsForPage }, function(data) { getTagsForPageCallBackHandler( data ); } );
    
}   //end function 

function getTagsForPageCallBackHandler( data )
{
    var arrData = new Array();
    
    var arrKeyValuePair = new Array();
    
    var intIndex = 0;
    
    var strKey = "";
    
    // split the data into an array
    var arrKeyValuePairs = new Array();
    
    arrKeyValuePairs = data.split("&");
    
    // loop through each item and add to the data array as key: value
    for( intIndex = 0 ; intIndex < arrKeyValuePairs.length; intIndex++ )
    {
        arrKeyValuePair = arrKeyValuePairs[intIndex].split("=");
        
        strKey = arrKeyValuePair[0]; 
        
        // 1st element is the key, 2nd element is the value
        arrData[strKey] = arrKeyValuePair[1];

    }   //end for loop
    
    var lblTagsForPage = document.getElementById( arrData["tagsforpage"] );
    
    var arrTags = arrData['tags'].split(',');
    
    var intIndex = 0;
    
    var strTags = "";
    
    for( intIndex = 0; intIndex < arrTags.length; intIndex++ )
    {
        strTags += arrTags[intIndex] + "&nbsp;&nbsp;"
    
    }   //end for loop
    
    lblTagsForPage.innerHTML = strTags;

    showHideTagForms( arrData['action'] );
    
}   //end function

function showHideTagForms( strSelectedTag )
{
    var divTagsDisplayList = document.getElementById("divTagsDisplayList");
    
    var divTagsAddForm = document.getElementById("divTagsAddForm");

    divTagsDisplayList.style.display = "none";
    
    divTagsAddForm.style.display = "none";
    
    // get all the list items
    var liMyTags = document.getElementById("liMyTags");
    
    var liAllTags = document.getElementById("liAllTags");
    
    var liAddTags = document.getElementById("liAddTags");
    
    liMyTags.className = "";
    
    liAllTags.className = "";
    
    liAddTags.className = "";
    
    switch( strSelectedTag )
    {
        case "mytags":
        
            liMyTags.className = "active";
            
        break;
        
        case "alltags":
        
            liAllTags.className = "active";
            
        break;
        
        case "addtags":
            
            liAddTags.className = "active";
            
        break;
    
    }   //end switch  
    
    if( strSelectedTag == "addtags" )
    {
        divTagsAddForm.style.display = "";
        
    }   //end if
    
    else
    {
        divTagsDisplayList.style.display = "";
        
    }   //end else
    
}   //end function

function getUsersWeather()
{
    data = "";
   
    var spnWeatherLocation = document.getElementById("weather-location");
    
    var spnWeatherTemp = document.getElementById("weather-temperature");
    
    var spnWeatherCondition = document.getElementById("weather-condition");
    
    spnWeatherLocation.innerHTML = "Loading...";
        
    spnWeatherTemp.innerHTML = "Temp";
        
    spnWeatherCondition.innerHTML = "Condition";
    
    $.post("ajax/weather.aspx", { action: "get" } , function(data) { getUsersWeatherCallBackHandler( data ); } );
    
}   //end function

function getUsersWeatherCallBackHandler( data )
{
    var arrData = new Array();
    
    var arrKeyValuePair = new Array();
    
    var intIndex = 0;
    
    var strKey = "";
    
    // split the data into an array
    var arrKeyValuePairs = new Array();
    
    arrKeyValuePairs = data.split("&");
    
    // loop through each item and add to the data array as key: value
    for( intIndex = 0 ; intIndex < arrKeyValuePairs.length; intIndex++ )
    {
        arrKeyValuePair = arrKeyValuePairs[intIndex].split("=");
        
        strKey = arrKeyValuePair[0]; 
        
        // 1st element is the key, 2nd element is the value
        arrData[strKey] = arrKeyValuePair[1];

    }   //end for loop
    
    var spnWeatherLocation = document.getElementById("weather-location");
    
    var spnWeatherTemp = document.getElementById("weather-temperature");
    
    var spnWeatherCondition = document.getElementById("weather-condition");
    
    var imgWeather = document.getElementById("weather-image");
    
    if( data == "" )
    {
        alert( "Could not retrieve weather information" );
        
    }   //end if
    
    else
    {
        spnWeatherLocation.innerHTML = arrData["location"];
        
        spnWeatherTemp.innerHTML = arrData["temp"] + "&deg; " + arrData["degree_unit"];
        
        spnWeatherCondition.innerHTML = arrData["condition"];
        
        imgWeather.src = arrData["image"];
    
    }   //end else
    
    data = "";
    
}   //end function


function swapStyleSheets( strTitle )
{
    // get all the link elements
    var arrSheets = document.getElementsByTagName('link');
                
    // loop through each one until we find the main link
    for( var intIndex = 0; intIndex < arrSheets.length; intIndex++ )
    {
        // get the title, if present
        objLink = arrSheets[intIndex];
        
        // check to see if it's style link and it has a title
        if( objLink.getAttribute("rel").indexOf("style") != -1 && objLink.getAttribute("title") )
        {
            // if the titles match, then enable the link
            if( objLink.getAttribute("title") == strTitle )
            {
                objLink.disabled = false;
                
            }   //end if
            
            // if no match, disable the stylesheet
            else
            {
                objLink.disabled = true;
            
            }   //end else
            
        }   //end if
            
    }   //end for
   
}   //end function

// This function show and hide the selective media group under organization drop down list
// If the private check box is checked then it's show the group for select
function showHideDDLOrg(chkBoxID, ddlMediaID){
   var objDDL = document.getElementById(ddlMediaID);

   if(chkBoxID.checked){
      objDDL.style.display = "";
   }
   else {
      objDDL.style.display = "none";
   }

} //end of showHideDDLOrg function

//Handle enter key press to trigger button click
function focusNext(objEvent, strElement){
        if ( objEvent.keyCode == 13)
        {
            oNextObj = document.getElementById(strElement);
            if( oNextObj )    {
                oNextObj.focus();
                oNextObj.click();
            }   //end if
    
            return false;
          
        }    //end if
       
}   //end function


function addBreakTag(eventObj, elementId) {
    var obj = document.getElementById(elementId);
    
    if(obj != null && eventObj != null) {
        if(eventObj.keyCode == 13){
            obj.innerHTML += "&lt;br/&gt;";
            alert(obj.innerHTML);
        }
    }
    return false;
}
