function showImage(file, h, w) {
	//alert(nr);
	path = "admin/popup.php?file="+file;
	window.open(path,"popup","height="+h+", width="+w);
}

function checkEmail(txtEmail)
{
	strMail = txtEmail.replace(/ /g,"");
	if (strMail.length == 0) {
		return false;
	}
		regex = 
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (regex.test(strMail)) {
			return true;
	}	else {
			return false;
	}
}


function isDigit (c) {
	return ((c >= "0") && (c <= "9"));
}


function isNumber(objText) {
	objText = objText.replace(/ /g, "");
	if(objText == "")
		return false;
	for (i = 0; i < objText.length; i++) {
		if (!isDigit(objText.charAt(i))) {
			return false;
		}
	}
	return true;
}


function doFormSubmit(objForm, strFormTarget, strFormAction) {
/*
Attributes needed on input/select fields:
mandatory=yes to have the object included in validation process
tip= ...  to force a certain validation process. (this defaults to text if attribute is missing or empty)
 -- valid tip attributes include: email, checkbox, text, number, select
errormsg= ... an error message to be displayed if the validation process for that field has failed

copy/paste this code into a "button" tag to use for submitting a form:
 -=  onClick="doFormSubmit(this.form)"  =-
*/
	arrValidation = Array();
	arrRejected = Array();
	txtErr = "";
	arrElements = objForm.elements;
	for(i=0;i<arrElements.length;i++) {
			obj = arrElements[i];
			if(obj.hasAttribute("mandatory") && (obj.getAttribute("mandatory") == "yes")) {
					arrValidation[arrValidation.length] = obj;
			}
	}

	for(i=0;i<arrValidation.length;i++) {
			obj = arrValidation[i];
			if(obj.hasAttribute("tip") && obj.getAttribute("tip").replace(/ /g,"") != "") {
				objValidationType = obj.getAttribute("tip");
			} else if(obj.hasAttribute("type")){
				objValidationType = obj.getAttribute("type");
			} else {
				objValidationType = "text";
			}
			strTmp = validateObjectByType(obj, objValidationType);
			if(strTmp != "") {
				txtErr += strTmp;
				arrRejected[arrRejected.length] = obj;
			}
	}

	if(txtErr != "") {
		alert(txtErr);
		arrRejected[0].focus();
	} else {
		if(strFormTarget.replace(/ /g,"") != "")
				objForm.setAttribute("target",strFormTarget.replace(/ /g,""));
		if(strFormAction.replace(/ /g,"") != "")
				objForm.setAttribute("action",strFormAction.replace(/ /g,""));
		objForm.submit();
	}

}

function validateObjectByType(obj, strType) {
		bErr = false;
		if(strType == "email") {
				objVal = obj.value;
				if(!checkEmail(objVal)) {
						bErr = true; 
				}
		} else if(strType == "text")  {
				objVal = obj.value;
				if(objVal.replace(/ /g,"") == "") {
						bErr = true; 
				}
		} else if(strType == "checkbox" || strType == "radio") {
				if(!obj.checked) {
						bErr = true;
				}
		}  else if(strType == "select")  {
				objVal = obj.value;
				if(objVal.replace(/ /g,"") == "" || parseInt(objVal.replace(/ /g,"")) == -1) {
						bErr = true; 
				}
		} else if(strType == "number")  {
				objVal = obj.value;
				if(!isNumber(objVal.replace(/ /g,""))) {
						bErr = true; 
				}
		} else if(strType == "password")  {
				objVal = obj.value;
				objID = obj.getAttribute("id") + "2";
				if(!document.getElementById(objID)) {
						bErr = true;
				} else if((objVal.replace(/ /g,"") == "") || (document.getElementById(objID).value.replace(/ /g,"") == "") || (document.getElementById(objID).value.replace(/ /g,"") != objVal.replace(/ /g,"")) ){
						bErr = true;
				}
		}

		if(bErr) {
			if(obj.hasAttribute("errormsg") && obj.getAttribute("errormsg").replace(/ /g,"") != "") {
				return obj.getAttribute("errormsg") + "\r\n";
			} else {
				return obj.getAttribute("name") + " has failed verification!\r\n";
			}
		}
		return "";
}
