/**
* FILENAME: common.js
* DESCRIPTION :Common Javascript code
* AUTHOR: Dan Ruspini and Louis Baliotis
**/

/*
 *  General Cross Browser Java Script Function 
 */
 
 
//++
// cross browser get object by id or name.  if the name is
// not a string, it is passed by unchanged since it can't be an id.
// if it is a string, it tries DOM first, then IE 4/5 then Netscape 4
// if forceIEBehavior is true and the getElementById
// fails, routine will try to find a name instead of IE
//--
function getObj( name, forceIEBehavior )
{
    var newObj;
    if ( typeof name == "string" ) {
        if (document.getElementById) {
            newObj = document.getElementById(name);
            if ( newObj == null && forceIEBehavior != null & forceIEBehavior ) {
                var newObjArray = document.getElementsByName( name );
                if ( newObjArray != null && newObjArray.length > 0 ) 
                    newObj = newObjArray[ 0 ];
            }else{
                var newObjArray = document.getElementsByName( name );
                if ( newObjArray != null && newObjArray.length > 0 ) 
                    newObj = newObjArray[ 0 ];
            }
        }
        else if (document.all) {
            newObj = document.all[name];
        }
        else if (document.layers) {
            newObj = document.layers[name];
        }
    }
    else
        newObj = name;
    return newObj;
}
//++
// cross browser get all objects with the same name in an array.
// tries DOM first, then IE 4/5 then Netscape 4
//--
function getObjArray( name )
{
    var newObjArray;
    if ( typeof name == "string" ) {
        if (document.getElementById) {
			 newObjArray = document.getElementsByName(name);
        }
        else if(document.getElementsByName)
            newObjArray = document.getElementsByName(name);
        else if (document.all)
            newObjArray = document.all[name];
        else if (document.layers)
            newObjArray = document.layers[name];
    }
    else
        newObjArray = name;
    return newObjArray;
}
//++
// cross browser update inner HTML object
// --
function doUpdateHtml(obj,text) {
	if(obj.innerHTML != null)
		obj.innerHTML = text;
	else if(obj.insertAdjacentHTML != null) {
		obj.insertAdjacentHTML("beforeEnd",text);
	}
	else if(document.createElement != null) {
	
	}
}
function doUpdateText(obj,text) {
	if(obj.innerText != null)
		obj.innerText = text;
	else if(obj.innerHTML != null)
		obj.innerHTML = text;
	else if(obj.insertAdjacentHTML != null) {
		obj.insertAdjacentHTML("beforeEnd",text);
	}
	else if(document.createElement != null) {
	}
}
function doGetText(obj) {
	if(obj.innerText != null)
		return obj.innerText;
	else if(obj.innerHTML != null)
		return obj.innerHTML;
}


//++
// cross browser get style object by id or name.
// tries DOM first, then IE 4/5 then Netscape 4
// if forceIEBehavior is true and the getElementById
// fails, routine will try to find a name instead of IE
//--
function getStyle( name, forceIEBehavior )
{
    var myObj = getObj( name, forceIEBehavior );
    return myObj == null ? null : myObj.style;
}

//++
// cross browser routine to hide an element
//--
function hideElement( name )
{
	if ( document.getElementById )
		getStyle( name ).visibility="hidden";
	else if ( document.layers )
		getObj( name ).visibility = "hide";
}

//++
// cross browser routine to show an element
//--
function showElement( name )
{
	if ( document.getElementById )
		getStyle( name ).visibility="visible"
	else if ( document.layers )
		getObj( name ).visibility = "show";
}

//++
// cross browser routine to hide/show an element
//--
function menuElementStatus( name )
{
	if ( document.getElementById ){
		if(getStyle( name ).visibility == "visible")
			return true
		else
			return false
	}else if ( document.layers ){
		if(getObj( name ).visibility == "show")
			return true
		else
			return false
	}
}
function checkboxClick(id) {
	cb = getObj(id);
	if(cb.click != null && cb.click != "undefined")
		cb.click();
		
	cb.checked = !cb.checked;
}

function radioClick(id, val) {
	r = getObj(id);
	if(r.click != null && r.click != "undefined")
		r.click();
		
	r.checked = true;
}
function getLoginHostName(strPath) {
	var strLocation = "";

  	strLocation = "https://" + document.location.hostname.toLowerCase() + strPath;
	return strLocation;
}

function secureFormValidate(form) {
	var bValid = false;

	if (form.dnqualifier.value.length == 0)
	{
		alert("You must enter your user ID.");
		form.dnqualifier.focus();
	}
	else
	{
		if (form.userpassword.value.length == 0)
		{
			alert("You must enter your password.");
			form.userpassword.focus();
		}
		else
			bValid = true;
	}

	return bValid;

}

function loginValidForm() {
	return secureFormValidate(document.mainlogon);
}

function loginValidateForm() {
	return secureFormValidate(document.mainlogon);
}

function focusCursor()
{
	document.mainlogon.dnqualifier.focus();
}


function submitForm()
{
	document.mainlogon.submit();
}