function el(id){
return document.getElementById(id);
}
function OverMenu(tdName, className){
    if (el(tdName)){
	    el(tdName).className = className;
	}else if (el("Header1_" + tdName)){
	    el("Header1_" + tdName).className = className;
	}else if (el("_ctl0_header1_" + tdName)){
	    el("_ctl0_header1_" + tdName).className = className;
	}else if(el("_ctl0_header_" + tdName)){
	    el("_ctl0_header_" + tdName).className = className;
	}else if(el("_ctl0_" + tdName)){
	    el("_ctl0_" + tdName).className = className;
	}else if(el("_ctl0_main_Header1_" + tdName)){
	    el("_ctl0_main_Header1_" + tdName).className = className;
	}
}
function ToggleActivities(evt, bodyName){

    var evt = (evt) ? evt : ((window.event) ? window.event : "");
    var elem = (evt.target) ? evt.target : evt.srcElement
	var chunks = elem.src.split('/');
	var length = chunks.length;
	
	if (chunks[length -1] == 'plus.gif')
	{
	    elem.src = 'images/minus.gif';
		if ( document.all )
		{
			//document.all[bodyName].style.display = '';
            $("tr[id$='" + bodyName + "']").css("display", "");
		}
        else if (document.getElementById){
            $("tr[id$='" + bodyName + "']").css("display", "");


        }
    }
	else {
	    elem.src = 'images/plus.gif';
		if ( document.all )
		{
			$("tr[id$='" + bodyName + "']").css("display", "none");

		}
		else if (document.getElementById){

           $("tr[id$='" + bodyName + "']").css("display", "none");

        }
	}
}

function Expand(divName)
{
	var chunks = event.srcElement.src.split('/');
	var length = chunks.length;
	
	var div = document.all[divName];
	
	if (chunks[length - 1] == 'uparrows_white.gif')
	{
		div.style.overflow = 'scroll';
		event.srcElement.src = 'images/downarrows_white.gif';
	} else {
		div.style.overflow = 'visible';
		event.srcElement.src = 'images/uparrows_white.gif';
	}
}
// JSpell gets the spell check items
function getSpellCheckArray() {
	
	var sources = document.getElementById(SpellCheckControlID).value.split("|");
	var fieldsToCheck = new Array();
	
	for(srcCnt=0; srcCnt<sources.length; srcCnt++)
	{
		if ( sources[srcCnt] != null && sources[srcCnt].length > 0 )
		{
			fieldsToCheck[srcCnt] = 'document.forms["aspnetForm"].' + sources[srcCnt];
		}
	}
	return fieldsToCheck;
}
function MoveForceToSpellCheck()
{
	document.getElementById(SpellCheckControlID).value = theForm.ForcedSpellCheckItems.value;
}
// JSpell Don't proceed with click until completed spell checking
var lastClicked = null;
var checkerWindow = null;
function WaitForSpellComplete( btn )
{
    return true;
    
	MoveForceToSpellCheck();
	
	if ( lastClicked != null || getSpellCheckArray().length == 0)
	{
		return true;
	}
	lastClicked = btn;
		
	checkerWindow = spellcheck();
	setTimeout( 'CheckComplete();', 1000 ); 
	return false;
}
// JSpell capture for tabs
var firedTab = null;
var firedWebTab = null;
function Tabs_BeforeSelectedTabChange(oWebTab, oTab, oEvent){
    Page_ClientValidate("");
	ValidationSummaryOnSubmit('');
	if ( Page_IsValid == false )
	{
	   oEvent.cancel = true;
	   return;
	}
	
	MoveForceToSpellCheck();
	
	if ( getSpellCheckArray().length > 0 )
		if ( checkerWindow == null )
		{
			oEvent.cancel = true;
			checkerWindow = spellcheck();
			setTimeout( 'CheckComplete();', 1000 ); 
			firedTab = oTab;
			firedWebTab = oWebTab;
		}
}
function CheckComplete()
{
	// if already closed
	if ( checkerWindow == null )
		return;
		
	var closeButton;
	try
	{
		if ( checkerWindow.document.forms[0] != null )
			closeButton = checkerWindow.document.forms[0].closeButton;
	} catch (e)
	{ }
		
	if ( ! checkerWindow.closed && closeButton == null )
	{
		setTimeout( 'CheckComplete();', 350 );
		return;	
	}

	if ( ! checkerWindow.closed )
		checkerWindow.close();
	
	checkerWindow = null;
	
	// re-click button
	if ( lastClicked != null )
	{
		lastClicked.click();
		return;
	}
		
	// re-fire event
	if ( firedTab != null )
	{
		firedWebTab.update(-1, "SelectedTab", firedTab.index, 1);
		return;
	}
}
function OpenFees(appraisalID)
{
	window.open('Appraisal_Fees_detail.aspx?AppraisalID=' + appraisalID, '_blank', 'menubar=0,scrollbars=1,status=0,width=550,height=500', true);
}
function OpenPage( pageToSend, target, height, width )
{
	window.open(pageToSend, 'Fees', 'menubar=0,status=0,scrollbars=1,width=' + width +',height=' + height, true);
}
//Converts string to ProperCase with spaces and hyphens
function toPC(s){
	var i;
	var returnString = "";
	var tmpS=s.toLowerCase();
	var arrS= new Array();
	var arrS2 = new Array();

	//search each word in array arrS
	arrS=tmpS.split(" ");

	for (i = 0; i < arrS.length; i++){ 
		var thisWord=arrS[i];
		//Check to see if word contains a hyphen
		if(thisWord.indexOf("-")!=-1){
			arrS2 = thisWord.split("-");
			for(var j=0; j < arrS2.length; j++){
				var thisWord2=arrS2[j];
				returnString = returnString + thisWord2.charAt(0).toUpperCase() + thisWord2.substring(1,thisWord2.length)+"-";
			}
			returnString = returnString.substring(0,returnString.length-1)+" ";
		} else {
			returnString = returnString + thisWord.charAt(0).toUpperCase() + thisWord.substring(1,thisWord.length)+" ";
		}
	}
	returnString = returnString.substring(0,returnString.length-1);
	return returnString;
}
function UploadDone(){
	window.location = window.location;
}
function CopyFileName(upload, textbox){
	var iName = el(upload).value.lastIndexOf("\\") + 1;
	el(textbox).value = el(upload).value.substring(iName);
}

function ValidateIfVisibleRadioButton( source, arguments )
{
    var control = document.getElementById(source.controltovalidate);
    if(arguments.Value.length > 0)
    {
        arguments.IsValid = true;
        control.style.backgroundColor = 'white';
        return;
    }
    var item = control;
    while(item)
    {
        if(item.style)
        {
            if(item.style.display)
            {
                if(item.style.display == 'none')
                {
                    arguments.IsValid = true;
                    control.style.backgroundColor = 'white';
                    return;
                }
            }   
        }     
        item = item.parentNode;
    }
    control.style.backgroundColor = 'Red';
    arguments.IsValid = false;
    return;
}

function ValidateIfVisible( source, arguments )
{
    if(arguments.Value.length > 0)
    {
        arguments.IsValid = true;
        return;
    }
    var control = document.getElementById(source.controltovalidate);
    var item = control;
    while(item)
    {
        if(item.style)
        {
            if(item.style.display)
            {
                if(item.style.display == 'none')
                {
                    arguments.IsValid = true;
                    return;
                }
            }   
        }     
        item = item.parentNode;
    }
    control.style.backgroundColor = 'Red';
    control.onfocus = clearBackground;
    arguments.IsValid = false;
    return;
}

function ValidateIfVisibleComboBox( source, arguments )
{
    var control = document.getElementById(source.controltovalidate + '_Text');
    if(control.value.length > 0)
    {
        arguments.IsValid = true;
        return;
    }
    var item = control;
    while(item)
    {
        if(item.style)
        {
            if(item.style.display)
            {
                if(item.style.display == 'none')
                {
                    arguments.IsValid = true;
                    return;
                }
            }   
        }     
        item = item.parentNode;
    }
    control.style.backgroundColor = 'Red';
    control.onfocus = clearBackground;
    arguments.IsValid = false;
    return;
}

function clearBackground()
{
    this.style.backgroundColor = 'white';
}