var previousValue; // global variable that holds the previous textbox quantity value

function savePreviousValue(txtTextBox)
{
	if(txtTextBox != null)
	{	
		previousValue = txtTextBox.value; // save previous textbox quantity
	}
}

/* clears the text box if the value is equal to zero
	-take the textbox object as a parameter
*/
function clearTextBox(txtTextBox)
{
	if((txtTextBox != null) && (txtTextBox.value == 0))
	{	
		txtTextBox.value = "";
	}
}

/* checks for correct input in the textbox and resets if data is bad
	-take the object and its value as parameters
	-valid data is non-negative integers 
*/
function checkQuantity(txtQuantity)
{	
	if(txtQuantity != null)
	{
		// make sure the quantity is non-negative
		if((isNaN(txtQuantity.value) == false) && (txtQuantity.value >= 0)) 
		{	// Remove leading zeros and round the quantity to remove any decimals because they are not allowed
			txtQuantity.value = Math.round(Number(txtQuantity.value));
		}
		else // reset to previous valid value
		{
			txtQuantity.value = previousValue;
		}
	}
}

/* Sets the focus to a particular page element if it exists
	-takes the name of the element as a string as the parameter
*/
function setElementFocus(elementName)
{
	if(document.getElementById(elementName) != null)
	{
		document.getElementById(elementName).focus();
	}
}

function popUpConstrained(url, windowName, width, height)
{
	var myCourseWindow = window.open(url, '', 'scrollbars=no,menubar=no,width=' + width + ',height=' + height + ', left=' + ((screen.width/2) - (width/2)) + ',top=' + ((screen.height/2) - (height/2)) + ',resizable=no,toolbar=no,location=no,status=no'); 
	myCourseWindow.focus();
}


function makeCloseLink()
{
		document.write("<br><br><a href='javascript:window.close();'class='tealLink'>Close</a><br><img src='images/1.gif' height='200'>");
}


function addBookmark(title,url)
{
	if( document.all )
	{
		window.external.AddFavorite( url, title);
	} 
	else if (window.sidebar) 
	{ 
		window.sidebar.addPanel(title, url,""); 
	} 
}





									
function swapImgRestore() { //v3.0
	var i;
	var x;
	var a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){
		x.src=x.oSrc;
	}
}

function preloadImages() { //v3.0
	var d=document;
	if(d.images){
		if(!d.MM_p){
			d.MM_p=new Array();
		}
		var i
		var j=d.MM_p.length
		var a=preloadImages.arguments;
		for(i=0;i<a.length;i++){
			if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function findObj(n, d) { //v4.0
	var p;
	var i;
	var x;
	if(!d){
		d=document;
	}
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all){
		x=d.all[n];
	}
	for (i=0;!x&&i<d.forms.length;i++){
		x=d.forms[i][n];
	}
	for(i=0;!x&&d.layers&&i<d.layers.length;i++){
		x=findObj(n,d.layers[i].document);
	}
	if(!x && document.getElementById){
	x=document.getElementById(n);
	}
	return x;
}

function swapImage() { //v3.0
	var i;
	var j=0;
	var x;
	var a=swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3){
		if ((x=findObj(a[i]))!=null){
			document.MM_sr[j++]=x;
			if(!x.oSrc){
				//if (x.src.indexOf("/menu_")>-1){
				//x.src=x.src.replace(/.gif/,'Off.gif');//replace original static image with animated image that restores initial state
				//}
				x.oSrc=x.src;
			}
			x.src=a[i+2];
		}
	}
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function signIn(isIntranetLogin){
	//alert("***dev note - make sure to add client services: access to:\n- Database and Automated Certificate Production\n- Absolute Hire link for background checks");
	var myMsg = "";
	var usernameObj = document.getElementById("username");
	var passwordObj = document.getElementById("password");
	var submitWhatObj = document.getElementById("submitWhat");
	if (usernameObj && passwordObj && submitWhatObj){
		if((usernameObj.value=="")){
			myMsg = "Please supply your username and password to sign in.\n\nThank you."
		}else{
			if(usernameObj.value==""){
				myMsg = "Please supply your username to sign in.\n\nThank you."
			}
			//if(passwordObj.value==""){
				//myMsg = "Please supply your password to sign in.\n\nThank you."
			//}
		}
		if (myMsg==""){
			if (isIntranetLogin){
			submitWhatObj.value="loginIntranet";
			}else{
			submitWhatObj.value="login";
			}
			document.myForm.submit();
		}else{
			alert(myMsg);
		}
	}
}


function newWindow(windowName, desiredWidth, desiredHeight, URL) {
var totalscreenwidth = screen.width;
var totalscreenheight = screen.height;
var calculatedwidth = parseInt((totalscreenwidth - desiredWidth) / 2);
var calculatedheight = parseInt((totalscreenheight - desiredHeight) / 2);
newWindow = window.open(URL, windowName,'scrollbars=yes,status=yes,resizable=yes,width=' + desiredWidth + ',height=' + desiredHeight + ',screenX=' + calculatedwidth + ',screenY=' + calculatedheight + ',left=' + calculatedwidth +',top=' + (calculatedheight - 20) + '');
newWindow.focus();
}


////////////////////////////
//image ready functions

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

