function enlargeImage(prodId, width, height, directory) {
	
	var bodyTag=document.getElementsByTagName("body");
	
	//FIND WIDTH OF BODY	
	for(var i=0; i<bodyTag.length; i++) {
		var bodywidth=bodyTag[i].offsetWidth;
	}
	
	//FIND CENTER FOR WINDOW
	var centre=(bodywidth/2)-(width/2);
	//SHOW WINDOW
	var newWin=window.open('pages/product_enlarge.inc.php?prodId='+prodId+'&directory='+directory+'', 'image', 'width='+width+', height='+height+', scrollbars=no, left='+centre+',top=200');
	newWin;
	
	return false;
}

function validateUpdate(qty) {
	var updateField=document.getElementById(qty);
	var error=document.getElementById("error");
	
	if((updateField.value=="")||(updateField.value==0)||(updateField.value=="\S")) {
		error.style.display="block";
		updateField.value=1;
		return false;
	}else{
		return true;
	}
	
}

//VALIDATE FORMS
function validateForm(formName) {
	var emptyFields=0;
	
	//CHECK FORM FOR REQUIRED INPUTS
	var inputs = document.forms[formName].getElementsByTagName("input");
	var texareas = document.forms[formName].getElementsByTagName("textarea");
	var selects = document.forms[formName].getElementsByTagName("select");
	
	//LOOP THROUGH INPUTS
	for(var i=0; i<inputs.length; i++) {
			//FIND THE CLASS NAME
			if(inputs[i].className=="mand") {
				//IS THE MANDATORY FIELD EMPTY
				if((inputs[i].value=="")||(inputs[i].value=='0.00')) {
					//ADD EMPTY FIELD NAME TO VAR
					emptyFields++;
					inputs[i].style.border="1px solid #cb0000";
					inputs[i].style.backgroundColor="#f5d4d4";
				}
			}
	}
	
	//LOOP THROUGH TEXTAREAS
	for(var i=0; i<texareas.length; i++) {
			//FIND THE CLASS NAME
			if(texareas[i].className=="mand") {
				//IS THE MANDATORY FIELD EMPTY
				if(texareas[i].value=="") {
					//ADD EMPTY FIELD NAME TO VAR
					emptyFields++;
					texareas[i].style.border="1px solid #cb0000";
					texareas[i].style.backgroundColor="#f5d4d4";
				}
			}
	}
	
	//LOOP THROUGH SELECTS
	for(var i=0; i<selects.length; i++) {
			//FIND THE CLASS NAME
			if(selects[i].className=="mand") {
				//IS THE MANDATORY FIELD EMPTY
				if(selects[i].value=="0") {
					//ADD EMPTY FIELD NAME TO VAR
					emptyFields++;
					selects[i].style.border="1px solid #cb0000";
					selects[i].style.backgroundColor="#f5d4d4";
				}
			}
	}
	
	//PLUG IN FOR OVER 18 DISCLAIMER
	if(document.getElementById("Y")) {
		var yes=document.getElementById("Y");
		var no=document.getElementById("N");
		if((yes.checked==false)&&(no.checked==false)) {
			emptyFields++;
			if(yes.checked==false) {
				yes.parentNode.style.border="1px solid #cb0000";
				yes.parentNode.style.backgroundColor="#f5d4d4";
			}
			if(no.checked==false) {
				no.parentNode.style.border="1px solid #cb0000";
				no.parentNode.style.backgroundColor="#f5d4d4";
			}
		}
	}
	
	//ALERT EMPTY FIELDS
	if(emptyFields) {
		document.getElementById("error").style.display='block';
		return false;
	}else{
		return true;
	}
	
}

function displayDelivery() {
	var deliveryBox=document.getElementById("delivery_show");

	deliveryBox.onclick=function() {
		var delivery_info=document.getElementById("delivery_info");
		if(deliveryBox.checked==true) {
			delivery_info.style.display="block";
		}else{
			delivery_info.style.display="none";
		}
	}
}

function clearLogin() {
	var user=document.getElementById("username");
	var password=document.getElementById("password");
	var comp=document.getElementById("comp_email");
	if(comp) {
		comp.onfocus=function() {
			this.value="";
		}
	}
	
	user.onfocus=function() {
		user.value="";
	}
	
	password.onfocus=function() {
		password.value="";
	}
	
}

function loadFunctions() {
	if(document.getElementById("delivery")) {
		displayDelivery();
	}
	if((document.getElementById("username"))&&(document.getElementById("password"))) {
		clearLogin();
	}
}

window.onload = function() {
	loadFunctions();
}