function scrollDiv(tagDiv, interval)
{
	var div = document.getElementById(tagDiv);
	if (interval > div.scrollHeight)
		interval = 0;
	div.scrollTop = interval;
	setTimeout("scrollDiv('"+tagDiv+"', "+(interval+1)+")",40);
}

function disableThis(button, message) {
	if (!message) {
		message = "Processing ...";
	}
	button.innerHTML = message;
	button.innerText = message;
	// button.value = message;

    if (button.className != 'disabled') {
		button.className = 'disabled button-green';
		var hidden = document.createElement("input");
		hidden.type = "hidden";
		hidden.name = button.name;
		hidden.value = button.value;
		button.form.appendChild(hidden);
		try {
			button.form.submit();
		} catch (ex) {
			return true;
		}
		//button.disabled = 'disabled';//when disabled, not submitting form in ff2.
		return true;
	}

	return false;
}


function getRealPos(el, which)
{
	var iPos = 0;
	while (el!=null) 
	{
	 	iPos += el["offset" + which];
		el = el.offsetParent;
	}
	return iPos;
}

function showTip(link, index)
{
	var displayTip = document.getElementById("tipDiv"); 
	displayTip.style.top = getRealPos(link, "Top") + 35;
	displayTip.style.left = getRealPos(link, "Left") -105;
	displayTip.innerHTML = tips[index];
	displayTip.style.display = "block";
}

function hideTip()
{
	var displayTip = document.getElementById("tipDiv"); 
	displayTip.style.display = "none";
}

function show(object) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';
}
function hide(object) {
    if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
        document.all[object].style.visibility = 'hidden';
}

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
	newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
}

function clearfield(mytarget)
{
		mytarget.value= "";
}


// This shows and hides certain table rows based on a filter.
//
// selectObj:	The Select Object containing the filter.
// class:		The class to be applied to every odd row for zebra striping.
//					Use an empty string if you do not want striping.
// tableId:		The id of the table to be filtered.
function filterRows( selectObj, idClass, tableId )
{
	var table = document.getElementById( tableId );
	var trCollection = new Array();
	var trs = table.getElementsByTagName('tr');
	// If the current tr has any th child elements then skip it..
    for(var i = 0, tr; tr = trs[i]; i++)
    {
            if(tr.getElementsByTagName('th').length == 0) trCollection.push(tr);
    }
        
	var selectedOption = selectObj.options[selectObj.selectedIndex].value
   	var rowObj;
    var stripe = 'no';

	for(var i = 0, tr; tr = trCollection[i]; i++)
	{
		if ( tr.className.search(selectedOption) != -1 || selectedOption == "all")
		{ 
			 tr.style.visibility="visible";
		     tr.style.display="";
		     if (idClass != '')
		     {
		     	tr.className = tr.className.replace(idClass,'');
		     	if ( stripe == 'no' ) {
        			stripe = 'yes';
        		}
        		else {
		     		tr.className = tr.className + " " + idClass;
        			stripe = 'no';   
        		}
		     }
		}
		else
        {
	   		tr.style.visibility="hidden";
		   	tr.style.display="none";
        }
	}
}

// This shows and hides certain table rows based on a filter.
//
// selectObj:	The Select Object containing the filter.
// class:		The class to be applied to every odd row for zebra striping.
//					Use an empty string if you do not want striping.
// tableId:		The id of the table to be filtered.
function filterRowsByMultipleValues( values, idClass, tableId )
{
	var table = document.getElementById( tableId );
	var trCollection = new Array();
	var trs = table.getElementsByTagName('tr');
	// If the current tr has any th child elements then skip it..
    for(var i = 0, tr; tr = trs[i]; i++)
    {
            if(tr.getElementsByTagName('th').length == 0) trCollection.push(tr);
    }
   	var rowObj;
    var stripe = 'no';

	for(var i = 0, tr; tr = trCollection[i]; i++)
	{
        var matchAllValueIndex = 0;
        for(var v = 0; v < values.length; v++){
            if ( tr.className.search(values[v]) != -1 || values[v] == "all") {
                  matchAllValueIndex += 1;
            }
        }


         if ( matchAllValueIndex == values.length)
            {
                    tr.style.visibility="visible";
                 tr.style.display="";
                 if (idClass != '')
                 {
                    tr.className = tr.className.replace(idClass,'');
                    if ( stripe == 'no' ) {
                        stripe = 'yes';
                    }
                    else {
                        tr.className = tr.className + " " + idClass;
                        stripe = 'no';
                    }
                 }
            }
            else
            {
                tr.style.visibility="hidden";
                tr.style.display="none";
            }
    }
}

function hideElement( eleId ) 
{
   var obj = document.getElementById(eleId);
   if( obj )
   {
	 	obj.style.visibility="hidden";
		obj.style.display="none";
  }
}

function showElement( eleId ) 
{
   var obj = document.getElementById(eleId);
   if( obj )
   {
	   obj.style.visibility="visible";
   	   obj.style.display="block";
  }
}

function showHideElement ( elementName )			
{	
	//Alternate between showing and hiding divs 
	var divToShow = document.getElementById( elementName );	
	
		
	if ( divToShow.style.visibility == "visible")
	{
		divToShow.style.visibility= "hidden";
		divToShow.style.display= "none";
	}	
	else
	{
		divToShow.style.visibility= "visible";
   		divToShow.style.display="block";			
	}				
}

function displayHideElement ( elementName )			
{	
	//Alternate between showing and hiding divs 
	var divToShow = document.getElementById( elementName );	
	
		
	if ( divToShow.style.display == "block")
	{;
		divToShow.style.display= "none";
	}	
	else
	{
   		divToShow.style.display="block";			
	}				
}

function showPopUpImage( divId, imgId, src)
{
	var img = document.getElementById(imgId);
	img.src = src;
	showElement(divId);
}


// Code for updating state field length depending on country
function updateStateField( stateFieldId, country )
{
	var stateField = document.getElementById( stateFieldId );
	stateField.value = "";
	if ( country == "US" )
	{		
		stateField.maxLength = 2;
	}
	else
	{
		stateField.maxLength = 50;
	}
}