// Scripts by kev (at) technotik (dot) com
// Copyright technotik.com
// unless stated otherwise in comments


function checkForAlert(error_message, user_message) {
	if(error_message != "")
		alert(error_message);
	if(user_message != "")
		alert(user_message);
} // end checkForAlert()


// From O'Reilly JavaScript: The Definitive Guide
function isBlank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '	')) return false;
    }
    return true;
} // end isBlank()


function checkForm(thisForm) {
	for(var i=0; i < thisForm.elements.length; i++) {
		if(thisForm.elements[i].value.length < 1) {
			alert("Please enter " + thisForm.elements[i].name);
			thisForm.elements[i].focus();
			return false;
		}
	}
	return true;
} // end checkForm()


function validateSearch(thisForm) {
	if((thisForm.quick_search.value.length < 3 || isBlank(thisForm.quick_search.value)) && (thisForm.manufacturer.value == 0 || thisForm.tooltype.value == 0)) {
		alert("Please enter a valid search word");
		return true;
	}
	else 
		return true;
} // end validateForm()


function	showPopUp(urlString) {
	var width = "500", height = "480";
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + width + ',height=' + height;

	popUpWindow = window.open(urlString, "popUpWindow", styleStr);
	if(popUpWindow)
		popUpWindow.focus();	
} // end showPopUp()
	

function	showPopOut(urlString, winWidth, winHeight) {
//	var width = winWidth;
//	var height = winWidth;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + winWidth + ',height=' + winHeight;

	popUpWindow = window.open(urlString, "popUpWindow", styleStr);
	if(popUpWindow)
		popUpWindow.focus();	
} // end showPopOut()


// Modified Clock functions to use DIV and 
// to just update once a minute
// to not drain resources or interupt other scripts
// too often
// Modified by kev (at) technotik (dot) com
// From original code by - 
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var clockID = 0;

function updateClock() {
	var currDate = new Date();
	var currHours, currMinutes, currPeriod, minuteString;
	
	if(clockID) {
		clearTimeout(clockID);
		clockID  = 0;
	}

   currHours = currDate.getHours(); 

   if(currHours > 12) {
   	currHours -= 12; 
   	currPeriod = 'pm';
   }
   else
   	currPeriod = 'am';

   currMinutes = currDate.getMinutes();
   	
   minuteString = currMinutes.toString();
   if(minuteString.length == 1)
   	minuteString = '0' + minuteString;
   	 
//	document.clockForm.theTime.value = currHours + ":" + minuteString;
 	document.getElementById("theClock").firstChild.data = currHours + ":" + minuteString + currPeriod;
	clockID = setTimeout("updateClock()", 60000);
}

function startClock() {
   clockID = setTimeout("updateClock()", 10);
}

function stopClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}


function validateLogin(thisForm) {
	
	if(thisForm.email.value.length < 9) {
		alert("Please enter your email address");
		thisForm.email.focus();
		return false;
	}
	else if(thisForm.pass.value.length < 6) {
		alert("Please enter a value for password at least six characters long");
		thisForm.pass.focus();
		return false;
	}

	return true;
} // end validateLogin()