var NS = (navigator.appName == "Netscape");
var MINUTE = 60 * 1000
var HOUR = MINUTE * 60
var DAY = HOUR * 24
var WEEK = DAY * 7

function LTrim(str)
{
	if (str.length > 0)
	{
		for (var i=0; str.charAt(i)<=" "; i++);
		return str.substring(i,str.length);
	}
	else
		return "";
}

function RTrim(str) 
{
	if (str.length > 0)
	{
		for (var i=str.length-1; str.charAt(i)<=" "; i--);
		return str.substring(0,i+1);
	}
	else
		return "";
}

function Trim(str) 
{
	if (str.length > 0)
	{
		return LTrim(RTrim(str));
	}
	else
		return "";
}


function checkSearch()
{
	var sSearchCriteria = document.SearchForm.q.value;
	if (sSearchCriteria == "")
	{
		alert("Please enter search criteria.");
		document.SearchForm.q.focus();
		return false;
	}
	else
	{
		return true;
	}
}

// initialize the clock value
function initClock()
{
	var itemDisplay = document.getElementById("timerClock");	
	var itemHidden = document.getElementById("hiddenTimerClock");	
	
	if (itemDisplay != null && itemHidden != null)
	{	
		var cDate = new Date();
		var theDate = cDate.getMonth() +  "/" + cDate.getDay() + "/" + cDate.getFullYear();		
		
		var tDate = new Date(theDate + " " + itemHidden.value);
		var hour = tDate.getHours();

		var ap = "AM";
		if (hour > 11) { ap = "PM"; }
		if (hour > 12) { hour = hour - 12; }
		if (hour == 0) { hour = 12; }
		
		var mins = tDate.getMinutes();
		if (mins < 10)
			mins = "0" + mins
			
	
		itemDisplay.innerHTML = hour + ":" + mins + " " + ap;		
		itemHidden.value = tDate.getHours() + ":" + tDate.getMinutes();
	}
	
	// call update in one minute
	window.setTimeout(updateClock, MINUTE);
}


// Called every minute to update the clock.
function updateClock()
{
	var itemDisplay = document.getElementById("timerClock");	
	var itemHidden = document.getElementById("hiddenTimerClock");	
	
	if (itemDisplay != null && itemHidden != null)
	{	
		var cDate = new Date();
		var theDate = cDate.getMonth() +  "/" + cDate.getDay() + "/" + cDate.getFullYear();		
		
		var tDate = (new Date(theDate + " " + itemHidden.value)).getTime();
		var rDate =  new Date(tDate + MINUTE);
		var hour = rDate.getHours();
		
		var ap = "AM";
		if (hour > 11) { ap = "PM"; }
		if (hour > 12) { hour = hour - 12; }
		if (hour == 0) { hour = 12; }
	
		var mins = rDate.getMinutes();
		if (mins < 10)
			mins = "0" + mins			
	
		itemDisplay.innerHTML = hour + ":" + mins + " " + ap;	
		itemHidden.value = rDate.getHours() + ":" + rDate.getMinutes();
	}
	
	// call again in one minute
	window.setTimeout(updateClock, MINUTE);
}

// function for checking all checkboxes that contain the name passed
// frm: pointer to the form
// chkName: text that is contained in the checkbox to find
// check: if the checkbox should be checked or not (true/false)
function checkCheckBoxes(frm, chkName, check) 
{
	var i;
	var numElements = frm.elements.length;
	
    for (i=0; i < numElements; i++)
    {
		if (frm.elements[i].name.indexOf(chkName) != -1)
			frm.elements[i].checked = check;
    }
}

// Returns 1 if all checked, 0 if all not checked, -1 if not the same
function checkAllCheckedSame(frm, chkName) 
{
	var i;
	var first;
	var found = false;
	var numElements = frm.elements.length;	

    for (i=0; i < numElements; i++)
    {
		if (frm.elements[i].name.indexOf(chkName) != -1)
		{
			if (found)
			{
				if (frm.elements[i].checked != first)
					return -1;
			}
			else
			{
				first = frm.elements[i].checked;
				found = true;
			}			
		}
    }
    
    if (first)
		return 1;
	else
		return 0;	
}

function selectAllOptions(element, select)
{
	var i;
	
	for (i=0; i < element.options.length; i++)
	{
		element.options[i].selected = select
	}
}

// Returns 1 if all selected, 0 if all not selected, -1 if not the same
function checkAllOptionsSame(element) 
{
	var i;
	var first;	

	for (i = 0; i < element.options.length; i++)
	{
		if (i == 0)
		{
			first = element.options[i].selected;
		}
		else
		{
			if (first != element.options[i].selected)
			{
				return -1;
			}
		}
	}
    
    if (first)
		return 1;
	else
		return 0;	
}


/* String length validating mechanism */
function ValidLength(item, len)
{
	return (item.length >= len);
}

function varitext(text)
{
	text=document
	print(text)
}

function ScreenPop2(sURL)
{
	screen_pop =  window.open(sURL,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=200'); 
	screen_pop.focus(); 
}

function ScreenPop3(sURL)
{
	screen_pop = window.open(sURL,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700,height=350'); 
	screen_pop.focus(); 
}

function ScreenPop4(sURL)
{
	screen_pop = window.open(sURL,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=800,height=600'); 
	screen_pop.focus(); 
}

function changeCase(Entry)
{
	var checkStr = Entry.value;
	var StringLength = Entry.value.length;
	var checkStr1 = checkStr.substring(1,StringLength);
	var ch = checkStr.charAt(0);
	ch = ch.toUpperCase();
	ch1 = checkStr1.toLowerCase();
	Entry.value = ch + ch1
}


function GoNext(Entry)
{
  if (Entry.value.length == 3)
  {
    for (var i=0; i < document.NewUser.elements.length; i++)
	{
	  if (document.NewUser.elements[i].name == Entry.name) {
	    document.NewUser.elements[i+1].focus()
	  }
	}
  }
}

function ToggleElementDisplay(element, display)
{
	if (display)
	{
		element.style.visibility = "visible";
		element.style.display = "inline";
		
	}
	else // hide
	{
		element.style.visibility = "hidden";			
		element.style.display = "none";
	}	
}

function IsNumericCharOnly(str)
{
	var validChars = "0123456789";
	var sChar;
	var rtn = true;

	if (str.length == 0) return true;

	for (i = 0; i < str.length && rtn == true; i++)
	{
      sChar = str.charAt(i);
      if (validChars.indexOf(sChar) == -1)
		rtn = false;
	}
	
	return rtn;
}

function CheckElementVisible(element)
{
	if (element.style.display == "block" || element.style.visibility == "visible")
		return true;
	else
		return false;
}

function GoNextZip(Entry)
{
  if (Entry.value.length == 5)
  {
    for (var i=0; i < document.NewUser.elements.length; i++)
	{
	  if (document.NewUser.elements[i].name == Entry.name) {
	    document.NewUser.elements[i+1].focus()
	  }
	}
  }
}

function checkIt(e)
{
	var charCode = ( navigator.appName == "Netscape") ? e.which : e.keyCode
	status = charCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		alert("Please make sure entries are numbers only.");
		return false;
	}
	return true;
}

/*
	Search & Replace Function...
	This function is specific to the user registration form.
*/
function stringReplace(charString)
{
	/* Start the position counter @ zero */
	var pos = 0;
	
	/* Search character is a space */
	var searchChar = (" ");
	
	/* Create a string object with our string */
	var myString = new String(charString);
	
	/* find the position of the first instance of our search character */
	pos = myString.indexOf(searchChar);
	
	/* loop until all search characters have been replaced */
	while (pos != -1)
	{
		/* Trim the Space to nothing */
		myString = myString.replace(" ", "");
		
		/* locate the next postion of the search character */
		pos = myString.indexOf(searchChar);
	}
	
	/* return the result back to the form control */
	return document.NewUser.username.value = myString;
}

function ScreenPop(sURL)
{
	screen_pop = window.open(sURL,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=450'); 
	screen_pop.focus(); 
}

function printit()
{  
	window.print();	
	return false;
}

// Sends values collected from screen pop window to screen that popped the window
function sendValue(s)
{	
	//var myValues;
	//myValues = s + "*";
	//alert(s);
	//window.opener.document.AssetListing.AssestRepository.value += myValues;
	//return true;	
}

function DisablePublicFields(enableFields)
{

	var docDom = document.AssetListing;
	var fontG = "<font color=silver>";
	var fontB = "<font color=black>";
	var fontE = "</font>";
	
	with (docDom)
	{
		if (enableFields == true)
		{
			/*
			User decided to turn off the Law Enforcement Only option so we must now
			turn the disabled form controls back on
			*/
			EnablePublicStartDate();
		}
		else 
		{	
			DisablePublicStartDate();
			
			cboNoGeneralPublic.disabled = true;
			na.innerHTML = (fontG + " <b>No Auction To General Public For This Lot</b> " + fontE);		
		}
	}
}

function DisablePublic()
{
	var docDom = document.AssetListing;
	var fontG = "<font color=silver>";
	var fontB = "<font color=black>";
	var fontE = "</font>";
	
	with (docDom)
	{
		/* 
		Check to see if the Law Enforcement Flag is 'checked'
		
		Business Rule: If Seller choose Law Enforcement then all of the
		other Auction Restrictions & Public Auction Options get locked
		down and are rendered unavailable to be selected. 
		*/
		
		if (docDom.cboLawEnforcementOnly.checked == true)
		{
			// Disable the Government Check box and set it to nothing
			cboGovernment.disabled = true;
			cboGovernment.checked = false;
			
			// Disable the Non Profit Check box and set it to nothing
			cboNonProfit.disabled = true;
			cboNonProfit.checked = false;
			
			// Disable the No Auction To General Public and set it to nothing
			cboNoGeneralPublic.disabled = true;
			cboNoGeneralPublic.checked = false;
			
			// Disable the public start date
			DisablePublicStartDate();
			
			na.innerHTML = (fontG + " <b>No Auction To General Public For This Lot</b> " + fontE);			
			cboNoGeneralPublic.disabled = true;
			
			// Grey out the HTML Text that surrounds the form controls that this
			// script is disabling to enhance the lock down effect.
			g.innerHTML = (fontG + " Government" + fontE);
			np.innerHTML = (fontG + " Non Profit" + fontE);
		}
		else 
		{	
			/*
			User decided to turn off the Law Enforcement Only option so we must now
			turn the disabled form controls back on
			*/
		
			// Enable the 'Government' checkbox to be checked
			cboGovernment.disabled = false;
			
			// Enable the 'Non Profit' Check Box to be checked
			cboNonProfit.disabled = false;
		
			/* 
			Reverse the Grey Efect and turn the background color on the form controls
			back to white for the elements that we just re-enabled and turn the text
			back to black so that these controls appear to be enabled again.
			*/
			g.innerHTML = (fontB + " Government" + fontE);
			np.innerHTML = (fontB + " Non Profit " + fontE);
		
		}
	}
}

function DisableReserve()
{
	var domDoc2 = document.AssetListing;
	with (domDoc2)
	{
							
		if (reserveprice.disabled == false)
		{
			reserveprice.disabled = true;
			reserveprice.value = "";
			reserveprice.style.background = "silver";		
			bidincrement.disabled = true;
			bidincrement.value= "";
			bidincrement.style.background = "silver";
			rp.innerHTML = "<font color=silver>Reserve Price</font>";
			bi.innerHTML = "<font color=silver>Bid Increment</font>";	
		}
		else
		{	
			reserveprice.disabled = false;
			reserveprice.style.background = "white";
			bidincrement.disabled = false;
			bidincrement.style.background = "white";
			rp.innerHTML = "<font color=black>Reserve Price</font>";
			bi.innerHTML = "<font color=black>Bid Increment</font>";
		}
	}
}

function disablePublicAttrs()
{
	if (document.AssetListing.StartDate_Month1.disabled == false)
	{
		DisablePublicStartDate();
	}
	else 
	{	
		EnablePublicStartDate();
	}
}



////////////////// NAVIGATION //////////////////////////////////////

var img1 = new Image();
img1 = "assets/icons/+.gif";

var img2 = new Image();
img2 = "assets/icons/minus.gif";

function doOutline() 
{
	var		srcId,
			srcElement,
			targetElement;

	//GET THE ELEMENT THAT WAS CLICKED ON		
	srcElement = window.event.srcElement;

	
	//SEE IF THE ELEMENT CLICKED WAS A TOP LEVEL ITEM
	if (srcElement.className.toUpperCase() == "LEVEL1") 
	{

		//SETTING SRC AND TARGET VALUES
		srcID = srcElement.id.substr(0, srcElement.id.length - 1);
		targetElement = (srcID + "s");
		srcElement = document.all(srcID + "i");
		
		//LOOP THROUGH ALL THE DOCUMENT ELEMENTS
		for (var i = 0; i < document.all.length; i++) 
		{
			if (document.all(i).id == targetElement) 
			{
		    
				if (document.all(i).style.display == "none")
				{
						document.all(i).style.display = "";
						srcElement.src = img2;
						
						break;
				}
				else
				{
					document.all(i).style.display = "none";
					srcElement.src = img1;
						
					break;
				} //end if
		  
			}//end if
		 
		}//end for
		
	}//end if
  
}//end function doOutline

function DisablePublicStartDate()
{
	var docDom = document.AssetListing;
	var fontG = "<font color=silver>";
	var fontB = "<font color=black>";
	var fontE = "</font>";	

	with (docDom)
	{
		// Disable the Public Auction Month and set the value to '-'
		StartDate_Month1.disabled = true;
		StartDate_Month1.selectedIndex = 12;
		
		// Disable the Public Auction Day and set the value to '-'
		StartDate_Day1.disabled = true;
		StartDate_Day1.selectedIndex = 31;
		
		// Disable the Public Auction Year and set the value to '-'
		StartDate_Year1.disabled = true;
		StartDate_Year1.selectedIndex = 3;				
		
		// Grey out the HTML Text that surrounds the form controls that this
		// script is disabling to enhance the lock down effect.
		as.innerHTML = (fontG + "Available to General Public on:" + fontE);
		StartDate_Month1.style.background = "silver";
		StartDate_Day1.style.background = "silver";
		StartDate_Year1.style.background = "silver";		
	}
}

function EnablePublicStartDate()
{
	var docDom = document.AssetListing;
	var fontG = "<font color=silver>";
	var fontB = "<font color=black>";
	var fontE = "</font>";
	
	with (docDom)
	{
		// No default for the date
		// Turn the 'Month' Back on and default the date
		StartDate_Month1.disabled = false;
		StartDate_Month1.selectedIndex = 12;//StartDate_Month.selectedIndex;
		
		// Turn the 'Day' back on and default the date
		StartDate_Day1.disabled = false;
		StartDate_Day1.selectedIndex = 31;//StartDate_Day.selectedIndex;
		
		// Turn the 'Year' back on and default the year
		StartDate_Year1.disabled = false;
		StartDate_Year1.selectedIndex = 3//;StartDate_Year.selectedIndex;
		
		// Enable the No 'Public Auction To General Public' to be checked
		cboNoGeneralPublic.disabled = false;
	
		/* 
		Reverse the Grey Efect and turn the background color on the form controls
		back to white for the elements that we just re-enabled and turn the text
		back to black so that these controls appear to be enabled again.
		*/
		StartDate_Month1.style.background = "white";
		StartDate_Day1.style.background = "white";
		StartDate_Year1.style.background = "white";
		as.innerHTML = (fontB + "Available to General Public on:" + fontE);
		na.innerHTML = (fontB + " <b>No Auction To General Public For This Lot</b> " + fontB);
	}	
}


document.onclick = doOutline;