function init() {

	theSiteName = "Stifel & Capra";

	//Add the site name to the status
	window.status = "Welcome to " + theSiteName;

	//Get the title
	thetitle = document.title;
	
	//reset the page title
	document.title = thetitle;
	
	//Add the title to the header
	theTitleObj = document.all["thepagetitle"];			
	theTitleObj.innerText = thetitle;
	
}

//validate the login page
function validateLoginFields() {
	
	form = document.forms[0];
	
	//Check that both fields are populated
	if(form.username.value == "" | form.password.value == "") {
		alert("You must enter a username and password before submitting");
		return false
	}
	
	//If we made it here submit it
	return true

}

//Validate the search field on the inventory page
function validateSubmit() {
			
	var allowSubmit = false;				
	var form = document.forms[0];

	if(form.searchfor.value != "") {
		allowSubmit = true;
	} 				
	
	return allowSubmit;
}

//Highlight/change style on navigator
function optionnav() {

	//Determine the cell and class
	theelement = window.event.srcElement
	theclassname = theelement.className

	//change the cell color
	if (theclassname == "NavigatorItem") {
		theelement.className = "NavigatorItemOn";
	} else {
		if(theclassname == "NavigatorItemOn") {
			theelement.className = "NavigatorItem";
		}
	}

}

//Highlight/change the style on the row when moused over
function optionrow() {

	//Determine the cell and class
	theelement = window.event.srcElement;								
	theclassname = theelement.className;
	
	//if not right, check the parent cell
	if(theclassname == undefined || theclassname == "") {
		theelement = theelement.parentElement;
		theclassname = theelement.className;
		if(theclassname == undefined || theclassname == "") {
			theelement = theelement.parentElement;
			theclassname = theelement.className;
		}
	}				

	//change the cell color
	if(theclassname == "InventoryRow" || theclassname == "InventoryRowOn") {
		if (theclassname == "InventoryRow") {
			theelement.className = "InventoryRowOn";
		} else {
			theelement.className = "InventoryRow";
		}
	}
	
	if(theclassname == "InventoryAdminRow" || theclassname == "InventoryAdminRowOn") {
		if (theclassname == "InventoryAdminRow") {
			theelement.className = "InventoryAdminRowOn";
		} else {
			theelement.className = "InventoryAdminRow";
		}
	}

}

function expcolSection(theObj) {

	if(theObj == undefined) {
		return;
	}

	if(theObj.style.display == "inline") {
		theObj.style.display = "none"
	} else {
		theObj.style.display = "inline"
	}

}

function numbersOnly(theEvent) {
	theCd = theEvent.keyCode;
	//Enter key
	if(theCd == 13) {
		return true
	}
	if(theCd >= 48 && theCd <= 57) {
		return true;
	} else {
		return false;
	}	
}

function moneyOnly(theEvent, theValue) {
	//get the key code
	theCd = theEvent.keyCode;	
	
	//Enter key
	if(theCd == 13) {
		return true
	}
	
	//where is the .
	perLoc = theValue.indexOf(".");
	
	//only allow one period
	if(perLoc == -1) {
		//period
		if(theCd == 46) {
			return true
		}
	} 	
	
	//only allow numbers before and 2 places after the .
	if(perLoc != -1) {
		subValue = theValue.substring(perLoc +1, theValue.length);
		if(subValue.length > 1) {
			return false;
		}
	}
	
	if(theCd >= 48 && theCd <= 57) {
		return true;
	} else {
		return false;
	}
}

//Function call for the inventory item
function gotoInventoryItem(itemno) {
	theurl = "InventoryDetail.php?itemId=" + itemno;
	goto(theurl);
}

//set the page url
function goto(thisurl) {				
	top.location = thisurl;
}

//Thisw code is to do the popup selection
//The functions below are used to display images in a sep window (resized)
function popitup(myimg){

	if(myimg == undefined) {
		alert("No image identified");
		return
	} else {
		img = myimg
	}

	//form = document.forms[0]
	//thefield = form.popupimagename
	//if(thefield == undefined) {
	//	return
	//} else {
	//	img = thefield.value
		if(img == "") {
			return
		} else {
			//Build a link to the image based on the url provided
			foto1= new Image();
			foto1.src=(img);
			Controlla(img);
		}
	//}
}

function Controlla(img){
   //Make sure I have an image height and width
  if( (foto1.width != 0) && (foto1.height!=0) ) {
  	//Then start to view it
  	viewFoto(img);
  }  else{
  	//Else, set a timeout and try again
    funzione="Controlla('"+img+"')";
    intervallo=setTimeout(funzione,20);
  }
}

//View the image in a new window
function viewFoto(img) {

	entree_textname = "Menu Item"
	//var theimage = document.images["entree_image"]
	//if(theimage != undefined) {
	//	entree_textname = theimage.alt
	//}

 	//Figure out how big it is
  largh=foto1.width + 20;
  altez=foto1.height + 60;  //was 20
  
  //Get the starting position of the window (left=?, screenX=?, top=?, screenY=?)
	var screenxandy = FindDialogStartPosition(altez, largh) 
	
	//now build the option
  	var stringa = "height=" + altez + ", width=" + largh + ", toolbar=0, resizable=1, menubar=0, dependent=1, " + screenxandy;

	//now open the window
  	finestra = window.open(img,"",stringa);
	
	//Can I write into this window?   
		finestra.document.writeln('<html><head><title>' + entree_textname + '</title><link rel="stylesheet" href="stylesheets/sgstyles.css" type="text/css"></head><body bgcolor="#364A41" text="white" oncontextmenu="return false">');
		finestra.document.writeln('<center><img src="' + img + '"><br>');
		finestra.document.writeln("<TABLE Width=100% border=0 cellpadding=0 cellspacing=0><TR><TD colspan=2 height=5></TD></TR>");
		finestra.document.writeln("<TR><TD Width=50 valign=left ><form><input class='buttons' type='Button' NAME='' VALUE='Close' onClick='top.close()'></form></TD>");
		finestra.document.writeln("<TD valign=top><h2>" + entree_textname + "</h2></TD>");
		finestra.document.writeln("</TR></TABLE></center></body></html>");
	
}

//This function finds the center of the screen when it is passed height and width params
function FindDialogStartPosition(dialog_width, dialog_height) {
	
	//make sure we get params
	if(isNaN(dialog_width)) {
		dialog_width = Number(dialog_width)
	}
		
	if(isNaN(dialog_height)) {
		dialog_height = Number(dialog_height)
	}
	
	//Standard height and width
	var aw = Number(800);
	var ah = Number(600);
	
	//If the screen size is available, get the value
	if (window.screen) {
		  ah = Number(screen.availHeight - 50); //was 30
		  aw = Number(screen.availWidth - 10);
	}
	
	//Now subtract the dialog width from the avail width
	var nw = Number((aw - dialog_width) / 2)
	var nh = Number((ah - dialog_height) / 2)

	//Now convert to a string	
	nw = String(parseInt(nw, 10))
	nh = String(parseInt(nh, 10))
	
	
	return "left=" + nw + ", screenX=" + nw + ", top=" + nh + ", screenY=" + nh;

}