function popWin (winURL, winName, winWidth, winHeight, winFeatures){
	var scrW = screen.width;
	var scrH = screen.height;
	winFeatures = !winFeatures ? "toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizeable=0" : winFeatures;
	winFeatures = 'width=' + winWidth + ',height=' + winHeight + ',' + winFeatures + ',left=' +(scrW-winWidth)/2 + ',top=' + (scrH - winHeight - 40)/2;
	var hWin = window.open(winURL, winName, winFeatures);
	hWin.focus();
}

function GetCookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function SetCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "") + ";";
}

function ValidateNumbers(objInput, critName, chkEmpty){
	var chkValue = objInput.value;
	if (chkEmpty){
		if ((chkEmpty && chkValue != '') && (chkValue/chkValue == 1 || chkValue == 0))
			return true;
	} else {
		if (chkValue/chkValue == 1 || chkValue == 0)
			return true;
	}
	alert ("Please enter a valid numeric value for the '" + critName + "' field.");
	objInput.focus();
	objInput.select();
	return false;
}

function ValidateText(objInput, critName){
	if (objInput.value != '')
		return true;
	alert ("Please enter a valid value for the '" + critName + "' field.");
	objInput.focus();
	objInput.select();
	return false;
}

function validateText(objInput, critName){
	if (objInput.value != '')
		return false;
	alert ("Please enter a valid value for the '" + critName + "' field.");
	objInput.focus();
	objInput.select();
	return true;
}

function validateSel(obj, fieldName, ind){
	if (obj.selectedIndex > ind)
		return false;
	alert ("Please select a valid value for the '" + fieldName + "' field.");
	obj.focus();
	return true;
}

function StrRepl(str1, str2, str3){
	var nPos;
	var cTemp = str1;

	while ((nPos = cTemp.indexOf(str2)) >= 0){
	    cTemp = cTemp.substring(0, nPos) + str3 + cTemp.substring(nPos+str2.length, cTemp.length);
	}
	return cTemp;
}

function IsEmail(objInput, allowEmpty){
    if (allowEmpty && objInput.value == "")
        return true;
    if(objInput.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		objInput.focus();
		alert("Invalid email address!");
        return false;
    } else {
        return true;
    }
}

function ClearForm(){
    if (confirm("Clear this form?"))
        document.forms[0].reset();
    return false;
}
