/* Strip whitespace from the beginning and end of a string. Input : a string */
function trim(str){	return str.replace(/^\s+|\s+$/g,'');}
/*Make sure that textBox only contain number*/
function checkNumber(textBox){
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {textBox.value = 0;
	} else {textBox.value = parseInt(textBox.value);}*/
}
/* Check if a form element is empty. If it is display an alert box and focus on the element */
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	return _isEmpty;
}
/* Set one value in combo box as the selected value */
function setSelect(listElement, listValue){
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue){listElement.selectedIndex = i;}
	}
}
// Order
function viewOrder(){
	statusList = window.document.frmOrderList.cboOrderStatus;
	status     = statusList.options[statusList.selectedIndex].value;	
	if (status != '') {
		window.location.href = 'index.php?status=' + status;
	} else {window.location.href = 'index.php';	}
}
function modifyOrderStatus(orderId){
	statusList = window.document.frmOrder.cboOrderStatus;
	status     = statusList.options[statusList.selectedIndex].value;
	window.location.href = 'processOrder.php?action=modify&oid=' + orderId + '&status=' + status;
}
function deleteOrder(orderId){}
window.onload = initAll;
window.onload = initLinks;
var currImg = 0;
var captiontext = new Array("beautiful photo1","beautiful photo2","beautiful photo3")
var myPix = new Array("scaffold_images/index_page_images/ladders.JPG", "scaffold_images/index_page_images/letter.JPG","scaffold_images/index_page_images/planks.JPG","scaffold_images/index_page_images/shoring.JPG");
var thisPic = 0;
function initLinks(){
	document.getElementById("prevLink").onclick = processProvious;
	document.getElementById("nextLink").onclick = processNext;
}
function initAll(){
	document.getElementById("imgText").innerHTML = captionText[0];
	document.getElementById("prevLink").onclick = processProvious;
	document.getElementById("nextLink").onclick = processNext;
}
function processPrevious(){
	newSlide(-1);
}
function processNext(){
	newSlide(1);
}
function newSlide() {
	var imgCt = currImg + direction;
	if(currImg < 0){
		currImg = imgCt-1;
	}
	if(currImg == imgCt){
		currImg = 0;
	}
	document.getElementById("slideshow").src = "scaffold_images/index_page_images/ladders" + currImg + ".JPG";
	document.getElementById("imgText").innerHTML = captionText[currImg];
}
	
/*function processPrevious(){
	if(thisPic == 0){
		thisPic = myPic.length;
	}
	thisPic--;
	document.getElementById("myPicture").src = myPic[thisPic];
	return false;
}
function processNext(){
	thisPic++;
	if(thisPic == myPic.length){
		thisPic = 0;
	}
	document.getElementById("myPicture").src = myPic[thisPic];
	return false;
}*/
function writeMessage(){	
	document.getElementById("helloMessage").innerHTML = "Hello world from external javascript with php";
}