//globals.js

//start search focus function
function scanfocus(){document.scanform.itemid.focus();}
//end confirm delete function


//start confirm delete function
function confirmdelete(url) {
	if(confirmThis('Are you sure you want to do this?\nThis cannot be undone.')) {
		window.location.href = url;
	}
}
//end confirm delete function

//start confirm remove function
function confirmremove(url) {
	if(confirmThis('Are you sure you want to do this?\nThis will remove all products\nassociated with this Manufacturer.')) {
		window.location.href = url;
	}
}
//end confirm delete function

//start confirm function
function confirmThis(message) {
	if(confirm(message)) return true;
	return false;
}
//end confirm function

//start print function
function printWin(){
	if (  ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4)) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))  ) {
		print();
	}
	else{
		alert('Your browser does not support this feature.\rIf you would like to use this feature please upgrade to the latest browser.');
	}
}
//end print function

//start: image function
function isOpen(winName) {
	alert(winName);	
}

function popUpWin(url,windowName, windowOptions) {
	windowName = window.open(url,windowName,windowOptions);
	windowName.focus();
	//setTimeout("isOpen('"+windowName+"')",5000);
	if(windowName) {
		popups = true;
	} else {
		popups = false;
		alert('We have detected that you are using\npopup blocking software. To view\nthis link you must disable the popup\nblocker for this site');
	}
}

// view admin help pop-up
function viewAdminHelp() {
	mypage = 'view_help.cfm';
	myname = 'help';
	w=450;
	h=350;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes";
	help = window.open(mypage, myname, winprops);
	help.focus();
}

// view archive image pop-up
function viewArchive(id) {
	mypage = 'view_archive.cfm?id=' + id;
	myname = 'image';
	w=500;
	h=500;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes";
	image = window.open(mypage, myname, winprops);
	image.focus();
}

function show(id) {
	document.getElementById(id).style.display = 'block';
}
function hide(id) {
	document.getElementById(id).style.display = 'none';
}
function menuSwap(bool,id) {
	menuItem = document.getElementById(id + 'Button');
	if(bool) {
		menuItem.src = '/images/menu/menu_' + id + '.gif';
	} else {
		menuItem.src = '/images/menu/menu_' + id + '_f2.gif';
	}
}

function isValidEmail(email){
	var results;
	var str=document.getElementById(email).value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		results = true;
	else{
		alert("Please input a valid email address!")
		results = false;
	}
	return results;
}

function init() {
   // quit if this function has already been called
   if (arguments.callee.done) return;

   // flag this function so we don't do the same thing twice
   arguments.callee.done = true;

   // create the "page loaded" message
   if(document.getElementById('currentWeek')) {
		setWeek();
   }
};

/* for Mozilla */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", init, false);
}

// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
        init(); // call the onload handler
    }
};
/*@end @*/


/* for other browsers */
window.onload = init;