// u=url ,n = name, h = height, w = width, sb scrollbars
function openWindow(u, n, h, w, sb) {
	if (puWinID != null) {
		puWinID.close();
	}
	//center the window opening 
	if (h==0) { h=450; } else { h=h +20; }
	if (w==0) { w=750; } else { w=w +20; }
	// if the window is to be opened bigger than the screen then reduce it 80px less than the screen, 
	// move it up 15 px and add a scrollbar and increase the width by 10 px
	if (h>(screen.height-80)) { hp=5; h= screen.height - 80; w+=10; sb="yes";} else {hp=(screen.height-h)/2;} 
	if(w>(screen.width-20)) { hw=5; w= screen.width - 20; sb="yes";} else {hw=(screen.width-w)/2;} 
	puWinID =  window.open(u, n,'toolbar=no,status=yes,menubar=no,location=no,scrollbars='+sb+',resizable=yes,height='+h+',width='+w+',top='+hp+',left='+hw+',screenY='+hp+',screenX='+hw+'');
	if (puWinID.opener == null) {
		puWinID.opener = self; // this is here to make sure that the particular frame cell is referenced as the opener of this window
	}
	try {
		puWinID.focus();
	} catch(e) {
		alert("The correct control or window is not displaying.\nThe problem may be caused by a 'popup blocker', or the window you wish to view may be behind the active window.\nPlease turn off all popup blockers (including blockers in security software) and try again,\nor locate the correct window behind the active window."); 
	}
}

function openWindow2(u,n,h,w,sb) {
	openWindow(u, n, h, w, sb);
}

function openWindow3(u,n,h,w,sb) {
	openWindow(u, n, h, w, sb);
}

function openWindow4(u,n,h,w,sb) {
	openWindow(u, n, h, w, sb);
}

function openWindow5(u,n,h,w,sb){
	openWindow(u, n, h, w, sb);
}

function openSubmitWindow(n) {
	openWindow('', n, 150, 300, 'no');
	return true;
}

function validateNonZeroNumber(textFieldObj, maxValue) {
	if (maxValue === undefined || maxValue == "" || maxValue == null || maxValue == 0) {
		maxValue = 99999999;
	}
	if (!textFieldObj.value.match(/^[0-9]+$/g) || textFieldObj.value == 0 || textFieldObj.value.match(/^0+[1-9][0-9]*$/g) || textFieldObj.value > maxValue) {
		alert('The quantity is not valid. Please enter a valid quantity.');
		textFieldObj.focus();
		textFieldObj.value = 1;
	}
}

function validateNumber(textFieldObj, maxValue) {
	if (maxValue === undefined || maxValue == "" || maxValue == null || maxValue == 0) {
		maxValue = 99999999;
	}
	if (!textFieldObj.value.match(/^[0-9]+$/g) || textFieldObj.value == 0 || textFieldObj.value > maxValue) {
		alert('The quantity is not valid. Please enter a valid quantity.');
		textFieldObj.focus();
		textFieldObj.value = 1;
	}
}
