function confirmDelete(type) {
	var message = "";
	if (type == 'address') {
		message = "Are you sure you want to delete this address? Click OK to delete.";
	} else if (type == 'item') {
		message = "Are you sure you want to delete this menu item? Click OK to delete.";
	} else {
		message = "Are you sure you want to delete this credit card? Click OK to delete.";
	}
	confirm(message);
}

function logout() {
	var message = "Are you sure you want to logout? Your order has not been placed yet.";
	if (confirm(message)) {
		document.location.href="login.jsp";
	}
}

function stripWhitespace(item) {
	var tmp = "";
	var item_length = item.value.length;
	var item_length_minus_1 = item.value.length - 1;
	for (index = 0; index < item_length; index++) {
		if (item.value.charAt(index) != ' ') {
			tmp += item.value.charAt(index);
		} else {
			if (tmp.length > 0) {
				if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1) {
					tmp += item.value.charAt(index);
				}
			}
		}
	}
	return tmp;
}

function capitalize(formObject) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = formObject.value;
	//tmpStr = formObject.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
				}
			else {
				tmpChar = tmpStr.substring(index, index+1);
				if ( (tmpChar == " " || tmpChar =="'" || tmpChar =="-") && index < (strLen-1) )  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
					}
				}
			}
		}
	formObject.value = tmpStr;
}

function validatePN(value) { 
	if ((value.length!=12) || (value.charAt(3)!="-") || (value.charAt(7)!="-")) {
		return false;
	} else {
		for (i=0;i<=11;i++) {
			if (i!=3 && i!=7) {
			var test=parseInt(value.charAt(i))
				if (isNaN(test)) {
					return false;
				}
			}
		}
	return true;
	}
}

function formatPhone(field) {
	var ov = field.value;
	var v = "";
	var x = -1;
	var n = 0;
	if ('1' == ov.charAt(0)) {
		ov = ov.substring(1, ov.length);
	}
	for (i = 0; i < ov.length; i++) {
		var ch = ov.charAt(i);
		if (ch >= '0' && ch <= '9') {
			if (n == 3) v += "-";
			else if (n == 6) v += "-";
			v += ch;
			n++;
		}
	}
	if (n == 10) {
		field.value = v;
	}
}

var nWin;var name;var config;
function newWindow(win,winName,winConfig) {
	if(winName == null || winName == "") {
		name = "NewWindow";
	} else {
		name = winName;
	}
	if(winConfig == null || winConfig == "") {
		config = "status=no,toolbar=no,menubar=no,top=0,left=50,location=no,scrollbars=yes,resizable=no,width=450,height=500";
	} else {
		config = winConfig;
	}
	nWin = window.open(win, name, config);
	nWin.focus();
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		alert('You have reached the maximum ' + maxlimit + ' characters limit for this field.');
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function checkIndustry(form,pharmaCode){
	var industryValue = form.industry.value;
	var normalOptOutLayer = window.document.getElementById("normalOptOut");
	var rxOptOutLayer = window.document.getElementById("rxOptOut");
	if(industryValue == pharmaCode){
		normalOptOutLayer.style.display = 'none';
		rxOptOutLayer.style.display = '';
	}else{
		normalOptOutLayer.style.display = '';
		rxOptOutLayer.style.display = 'none';
	}
}

function checkUserType(form,busCode){
	var userType = form.userType.value;
	var normalReqLayerCompany = window.document.getElementById("normalReqCompany");
	var busCodeReqLayerCompany = window.document.getElementById("busCodeReqCompany");
	var normalReqLayerIndustry = window.document.getElementById("normalReqIndustry");
	var busCodeReqLayerIndustry = window.document.getElementById("busCodeReqIndustry");
	if(userType == busCode){
		normalReqLayerCompany.style.display = 'none';
		busCodeReqLayerCompany.style.display = '';
		normalReqLayerIndustry.style.display = 'none';
		busCodeReqLayerIndustry.style.display = '';
	}else{
		normalReqLayerCompany.style.display = '';
		busCodeReqLayerCompany.style.display = 'none';
		normalReqLayerIndustry.style.display = '';
		busCodeReqLayerIndustry.style.display = 'none';
	}
}
