// JavaScript Document
function submitTo(url)
{
	//alert(url);
	var x=document.forms.form1;
	x.action= url;
	document.forms.form1.submit();
}
function checkstock(value1, value2, value3){
  if(Number(value1)>Number(value2)){
	alert("Invalid Input! Quantity order ("+value1+") is greater than quantity available ("+value2+")");
	myobj = document.form1.qty[value3];
	myobj.value=0;
	myobj.focus();
	return false;
  }
}
function checkstock1(value1, value2, value3, value4){
  if(Number(value1)>Number(value2)){
	alert("Invalid Input! Quantity order ("+value1+") is greater than quantity available ("+value2+")");
	myobj = document.getElementById(value4);
	myobj.value=0;
	myobj.focus();
	return false;
  }
}
//checking if the delivery company is select and go to the next fields.
function checkaddresstype(value){
	if(value=="0"){
	myobj = document.getElementById("deladdress1");
	}
	else{
	myobj = document.getElementById("businesscomp");
	}
	myobj.focus();
}
//check if user select business address then business name is compulsary
function menuOn(imagename){
	findDOM("menu").src = "dimage/" + imagename;
}
function menuOff(){
	findDOM("menu").src = "dimage/spacer.gif";
}
function confirmSubmit()
{
	var agree=confirm("Are you sure you wish to continue?");
	if (agree)
		return true ;
	else
		return false ;
}

//check if user select business address then business name is compulsary
function previewImage(imagename){
	window.open('zoomin.asp?imgname=' + imagename, 'preview', 'width=500, height=500, scrollbars=1, resizable=1');
}
function checkNumeric(theInput)
{
	if(isNaN(theInput.value)&&theInput.value!="")
	{
		theInput.value = "";
		alert("Please enter a number");
		theInput.focus();
		return false;
	}
	return true;
}
function validate(item, type, notice, maxlen, evalString){ // negative for N/A, 0 for no limit but not blank, positive for maxlength
	valid = true;
	errormsg = notice;
	if(type == "String"){
		if(isBlank(item.value)){
			valid = false;
		}
	}
	if(type == "Number"){
		if(isNaN(item.value)){
			valid = false;
		}
	}
	if(type == "Custom"){
		if(!eval(evalString)){
			valid = false;
		}
	}
	if(type == "Email"){
		if(isBlank(item.value) || !checkEmail(item.value)){
			valid = false;
		}
	}
	if(type == "TextArea"){
		if(isBlank(item.innerHTML))
			valid = false;
	}
	if(!valid){
		alert(errormsg);
		item.focus();
	}
	return valid;
}

function confirmSubmit(){
	return confirm("Are you sure you wish to continue?");
}
function isBlank(item){
	temp1 = String(item);
	temp1 = temp1.replace(/\s/g,"");
	if (temp1.length == 0)
		return true;
	return false;
}
function disableDropDown(item, orgValue, departID, exceptionIDStr, msg){
	var exceptionIDStr = exceptionIDStr.replace(/\s/, "");
	var excDepartArry = exceptionIDStr.split(",");
	var disabledCheck = true;

	for (var i=0; i<excDepartArry.length; i++){
		if (String(departID) == String(excDepartArry[i])){
			disabledCheck = false;
			break;
		}
	}
	if (disabledCheck && item.value != orgValue){
		if (blank(msg) != "")
			alert(msg);
		item.value = orgValue;
	}
}
