var documentReady = false;		
// ------------------------------------------------------------------------------------------------------
//FUNCTIONS
// ------------------------------------------------------------------------------------------------------
//onLoad

function init() {

	documentReady = true;
	fixscrollbars();
	removeBorder();
	breakout_of_frame();
}
// ------------------------------------------------------------------------------------------------------
function getImgName(imgRef) {
	// returns a name based on the image reference given
	return (imgRef.indexOf("/")==-1)?imgRef.substring(0,imgRef.lastIndexOf(".")):imgRef.substring((imgRef.lastIndexOf("/")+1),imgRef.lastIndexOf("."));
}

function preload() {
	// loads N images passed as a parameter, gives each a unique name based on src
	// to be referred later by "changeImages"
	var tempImgName="";
	if (document.images) {
		for (i=0;i<preload.arguments.length; i++) {
			tempImgName = getImgName(preload.arguments[i]);
			eval(tempImgName + "= new Image()");
			eval(tempImgName + ".src='" + preload.arguments[i] + "'");
		}
	}
}

function changeImages(loc,imgObjName,newImgRef) {
	if ((documentReady)&&(document.images)) {
		//image path insert here
		var imgHold = loc+"/images/" +newImgRef+ ".gif";
		var newImgObj = eval(getImgName(imgHold));
		var obj=eval("document."+imgObjName);
		obj.src=newImgObj.src;
	}
}

// ----------------------------------------------------------------------------------------------------------------
//new window


function getPlacementStr(w,h,full) {
	var left = Math.round((screen.availWidth/2)-(w/2));
	var top = Math.round((screen.availHeight/2)-(h/2));
	if (full!="full"){
	return (browser=="NN")?"screenX="+left+",screenY="+top:"left="+left+",top="+top;
	} else{
	return (browser=="NN")?"screenX=0,screenY=0":"left=0,top=0";
	}
}

function openBasicWindow(name,url,w,h,scrollbars,toolbar,statusbar,resize,full,menubar) {
	// opens a window with no extras, centered in screen, with unique name
	var placementStr = getPlacementStr(w,h,full);
	var x,y;
	
	// resize,scrollbar,full should be yes/no
	
	// set toolbar
	var tools = (toolbar=="tools")?"yes":"no";
	
	// set statusbar
	if (statusbar=="NSstatus") { 
		var status= ((browser=="NN")&&(bPlatform="Mac"))?"yes":"no"
	} else {
		var status = (statusbar=="status")?"yes":"no";
	}
	
	eval(name + "Window = window.open(url,'" + name + "', 'toolbar=" + tools + ",location=no,directories=no,status=" + status + ",scrollbars=" + scrollbars + ",menubar=" + menubar + ",resizable=" + resize + ",copyhistory=no," + placementStr + ",width=" + w + ",height=" + h + "')");                     

	// make sure window comes to the front
	eval(name + "Window.focus()");
	eval("setTimeout('"+name+"Window.focus()',50)");
	
	// move window to center after the fact (ie mac problem)
	if((browser=="IE")&&(bPlatform=="Mac")) {
		x = Math.round((screen.availWidth/2)-(w/2));
		y = Math.round((screen.availHeight/2)-(h/2));
		eval(name + "Window.moveTo(x,y)"); 
	}
}

// General Pop
function GeneralPop(url,w,h) {
	openBasicWindow("name",url,w,h,"yes","no","no","no","no","no");
}

//With Menu Bar Invoice
function MenuPop(url,w,h) {
	openBasicWindow("name",url,w,h,"yes","no","no","yes","no","yes");
}

// specific pop command
function popDirections(href) {
	openBasicWindow("directions",href,570,450,"yes","tools","no","yes","no","no");
}

// opens a window the same size as the opener window
function blankWindow(url){
	var width = document.all ? document.body.clientWidth : window.innerWidth;
	var height = document.all ? document.body.clientHeight : window.innerHeight;
	window.open(url,'blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height);
}


// open full screen

function openMaxedWindow(url) {
	var x, y = 0;
	var width  = 600;
	var height = 800;
	if (screen) {
      if (screen.availLeft) {
         x = screen.availLeft;
         y = screen.availTop;
      }
      width  = screen.availWidth - 6;
	   height = screen.availHeight - 29;
   }
	var reference = openBasicWindow("name",url,width,height,"no","no","no","no","full");
	return reference;
}


//print friend
function PrintThisPage(sborder) 
{ 
   var sOption="toolbar=no,location=no,directories=no,menubar=yes,"; 
       sOption+="scrollbars=yes,width=650,height=600,left=100,top=25"; 

   var sWinHTML = document.getElementById('contentstart').innerHTML; 
   
   var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write('<html><body onload=self.print()>'); 
	   if (sborder=="y"){
	   winprint.document.write('<style>#HidePrint{visibility:hidden}table,td{border:1px solid #999}.NoBorder{border:0px}body,table,tr,td{font: 11px Tahoma, Arial, Verdana, Helvetica, sans-serif;}</style>'); 
       }else{
	   winprint.document.write('<style>#HidePrint{visibility:hidden}table{border:1px solid #999}.NoBorder{border:0px}body,table,tr,td{font: 11px Tahoma, Arial, Verdana, Helvetica, sans-serif;}</style>'); 
       }
	   winprint.document.write(sWinHTML);        
       winprint.document.write('</body></html>'); 
       winprint.document.close(); 
       winprint.focus(); 
} 
// ------------------------------------------------------------------------------------------------------
//General functions
//used for the  roll over effects
function Over(loc,bg){
	loc.style.backgroundColor = '#cccccc';
	//loc.style.color = '#ffffff';
	loc.style.cursor='hand';
}
function Out(loc){
	loc.style.backgroundColor = '#f1f1f1';
	loc.style.cursor='hand';
}

function chgBg(obj,color){
if (document.all || document.getElementById)
  obj.style.backgroundColor=color;
else if (document.layers)
  obj.bgColor=color;
}

function redirect(url) {
	// redirects the browser to the given url
	document.location.href = url;
}

function newWin(url) {
	// go to the url
	window.open(url);
}

// Fixes IE/MAC disappearing scrollbar bug
function fixscrollbars(){
	if(is_mac && document.all){
		document.body.scroll = 'yes';
	}
}


// Remove anchor outlines from all links in the document
function removeBorder(){
	if(document.getElementById){
		var a = document.getElementsByTagName('a');
		for(i=0; i<a.length; i++){
			a[i].onfocus = function(){this.blur()};
		}
	}
}



//netscape reload
function fixNetscape(){		  
	if(innerWidth != originalWindowWidth || innerHeight != originalWindowHeight) 
		window.location.reload() ;
}

if ((browser=="NN")&&(is_major==4)){
    originalWindowWidth = innerWidth;
    originalWindowHeight = innerHeight;
	window.onresize = fixNetscape;
}

//quick show hide layer functions for when an order is processed
function hideDiv() { 
if (document.getElementById) {  
document.getElementById('processing').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { 
document.processing.visibility = 'hidden'; 
} 
else { 
document.all.processing.style.visibility = 'hidden'; 
} } } 

function showDiv() { 
if (document.getElementById) {  
document.getElementById('processing').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { 
document.processing.visibility = 'visible'; 
} 
else { 
document.all.processing.style.visibility = 'visible'; 
} } } 


function Notify(str){
alert(str);
}

function breakout_of_frame()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}

//auto tab form fields
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
// ------------------------------------------------------------------------------------------------------





