﻿function correctURLs()
{

    var arr = getElementsByClassName(document, "a", "")
    for (var i = 0; i < arr.length; i++) 
    {
    
        if ( arr[i].href ) 
            arr[i].href = arr[i].href.replace('ViewPoint2008','community');
            
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////
//Used on hookup default text in login boxes on left
/////////////////////////////////////////////////////////////////////////////////////////////

function hookUpLoginBox() {
    obj=FindControlLike('username');
    hookUpDefaultText(obj, 'Username');
    
	var theTextBox = FindControlLike('passwordTextBox');
	var thePassBox = FindControlLike('password');
	
    if ( theTextBox != null && thePassBox != null ) {
        
        theTextBox.style.display = 'block';
        thePassBox.style.display = 'none';             
              
        if ( theTextBox != null ) {
            theTextBox.onfocus = function () {
                changeTextToPass();
            };
        }
        
        if ( thePassBox != null) {
            thePassBox.onblur = function () {
                restorePassToText();
            };
        }
    }
}

// This function swaps the passed TextBox to a Password Box.
function changeTextToPass ()
{
	var theTextBox = FindControlLike('passwordTextBox');
	var thePassBox = FindControlLike('password');
       
    theTextBox.style.display = 'none';
    thePassBox.style.display = 'block';
    thePassBox.focus(); 
}

// This function restores the password box back to a text box

function restorePassToText ()
{
	var theTextBox = FindControlLike('passwordTextBox');
	var thePassBox = FindControlLike('password');
	
	// If the passbox has no content, then change it back to a TextBox.
	if (thePassBox.value == "")
	{
	  theTextBox.style.display = 'block';
      thePassBox.style.display = 'none';		
	}
}



/////////////////////////////////////////////////////////////////////////////////////////////
//Utility functions
/////////////////////////////////////////////////////////////////////////////////////////////
function hookUpDefaultText( obj, defaultText  ) {
    if ( obj != null && obj != 'undefined') {
        obj.value = defaultText;
        obj.onfocus = function () {
            this.value= (this.value==defaultText) ? '' : this.value;
        };
        obj.onblur = function () {
            this.value= (this.value=='') ? defaultText : this.value;
        };
    }
    
}

function FindControlLike(searchTerm)
{    
    var tags = document.getElementsByTagName("input"); 
    for (var i = 0; i < tags.length; i++) 
    {
        if ( endsWith(tags[i].id, searchTerm) == false ) {
            continue;
        }
      
        return tags[i];
    }   
    
    return null;
    
}

function endsWith(testString, endingString){
      if(endingString.length > testString.length) return false;
      return testString.indexOf(endingString)==(testString.length-endingString.length);
}
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
function OpenPopupTarget(myUrl, myTarget) {
    window.open(myUrl, myTarget, "left=200,top=20,width=720,height=550,location=0,status=0,scrollbars=1,toolbar=0,menubar=0,resizable=1");
    return false;
}