function openPopUp ( url, width, height )
{
	w = !width ? 650 : width;
	h = !height ? 750 : height;
	l = parseInt( screen.width/2 - w/2 );
	t = parseInt( screen.height/2 - h/2 );
	winID = url.replace(/[\/\.=?\&]/gi, "");
	window.open(url, winID, "left=" + l + ",top=" + t + ",width=" + w + ",height=" + h + ",resizable=yes,status=no,scrollbars=yes,dependent=no");	
}

// row highlighting
var prevClassName = "";
function omv ( row, className )
{
	if ( !className ) className = "rS";
	prevClassName = row.className;
	row.className = className;
}
function omu ( row, className )
{
	if ( !className ) className = prevClassName;
	row.className = className;
	prevClassName = "";
}

// icon highlighting
function swapIcon ( icoObj, icoPath , icoActive )
{
	icoObj.src = icoPath + ( icoActive ? "_a" : "" ) + ".gif";
}

// form fields validation
function fieldExists ( entryForm, fieldName )
{
	if (!entryForm[fieldName]) return false;
	else return true;
}

function validateSelect ( themessage, form, fieldName, ifError, isMandatory )
{
	if ( form[fieldName] && isMandatory ) {
		if ( form[fieldName].value == "0" || form[fieldName].value == "" ) themessage += " - " + ifError + "\n";
	}
	return themessage;
}

function validateText ( themessage, form, fieldName, ifError, isMandatory )
{
	if ( form[fieldName] && isMandatory ) {
		if ( form[fieldName].length )
		{
			for ( i=0; i<form[fieldName].length; i++ )
				if ( form[fieldName][i].value == "" )
				{
					themessage += " - " + ifError + "\n";
					break;
				}
		} else if ( form[fieldName].value == "" ) themessage += " - " + ifError + "\n";		
	}
	return themessage;
}

function validateConfirmation ( themessage, form, fieldName1, fieldName2, ifError )
{
	if ( form[fieldName1] && form[fieldName2] )
	{
		if ( form[fieldName1] != form[fieldName2] )
		{
			if ( form[fieldName1].value != form[fieldName2].value ) themessage += " - " + ifError + "\n";
		} else themessage += " DEVERROR: you are trying to confirm field " + fieldName1.toUpperCase() + " with " + fieldName2.toUpperCase() + "\n";
	} else themessage += " DEVERROR: field " + fieldName1.toUpperCase() + " or " + fieldName2.toUpperCase() + " doesn't exists in form " + form.name.toUpperCase() + "\n";
	return themessage;
}

function validateURL ( themessage, form, fieldName, ifError, isMandatory )
{
	if ( form[fieldName] )
	{
//		var filter = /^(http|https)+:\/\/(([a-zA-Z0-9\-\_])+\.)+(([a-zA-Z0-9]{2,4}).)+(\/+([a-zA-Z0-9\-\_]))*/;
		var filter = /(([a-zA-Z0-9\-\_])+\.)+(\/+([a-zA-Z0-9\-\_]))*/;
		if ((isMandatory && form[fieldName].value == "") || (form[fieldName].value != "" && !filter.test(form[fieldName].value))) themessage += " - " + ifError + "\n";
	}
	return themessage;
}

function validateEmail ( themessage, form, fieldName, ifError, isMandatory )
{
	if ( form[fieldName] )
	{
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
		if ((isMandatory && form[fieldName].value == "") || (form[fieldName].value != "" && !filter.test(form[fieldName].value))) themessage += " - " + ifError + "\n";
	}
	return themessage;
}

function validateBox ( themessage, form, fieldName, ifError, isMandatory )
{
	if ( form[fieldName] && isMandatory )
	{
		var orgmessage = themessage;
		// var isBox = true;
		var isChecked = false;
		
		/*
		// removed due to safari bug 24/04/2007
		if (!form[fieldName].length) {
			if (form[fieldName].type != "radio" && form[fieldName].type != "checkbox") isBox = false;
		} else if (form[fieldName][0].type != "radio" && form[fieldName][0].type != "checkbox") {
			isBox = false;
			alert(form[fieldName][0].type);
			alert(form[fieldName].length);
		}
		
		if (!isBox) themessage += " DEVERROR: field " + fieldName.toUpperCase() + " isn't a RADIO or CHECKBOX fieldtype\n";
		*/
		
		if (themessage == orgmessage) {
			if (!form[fieldName].length) {
				if(form[fieldName].checked) isChecked = true;
			} else {
				for (i=0; i<form[fieldName].length; i++) {
					if(form[fieldName][i].checked || (form[fieldName][i].type == "text" && form[fieldName][i].value != "")) { 
						isChecked = true;
						break;
					}
				}
			}
			if (!isChecked) themessage += " - " + ifError + "\n";
		}
	}
	return themessage;
}

function validateDate ( themessage, mm, dd, yyyy, ifError )
{
	var d = new Date(mm + "/" + dd + "/" + yyyy);
	if ( !(d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy) )  themessage += " - " + ifError + "\n";
	return themessage;
}

function validateNumeric ( themessage, form, fieldName, ifError, isMandatory )
{
	if ( form[fieldName] )
	{
		var filter = /^([0-9]*)+([\.\:]{0,1})+([0-9]*)$/;
		if ((isMandatory && form[fieldName].value == "") || (form[fieldName].value != "" && !filter.test(form[fieldName].value))) themessage += " - " + ifError + "\n";
	}
	return themessage;
}

function validateLengthInWords ( themessage, form, fieldName, ifError, isMandatory, maxWords )
{
	if ( form[fieldName] )
	{
		if ((isMandatory && form[fieldName].value == "") || (form[fieldName].value.split(/\s+/g).length > maxWords)) themessage += " - " + ifError + "\n";
	}
	return themessage;
}