function getParameter (parameterName ,def)
{
	var queryString = window.top.location.search.substring (1);
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if (queryString.length > 0 )
	{
		// Find the beginning of the string
		begin = queryString.indexOf (parameterName);
		// If the parameter name is not found, skip it, otherwise return the value
		if (begin != - 1 )
		{
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ("&" , begin );
			if (end == - 1 )
			{
				end = queryString.length
			}
			// Return the string
			return unescape (queryString.substring (begin, end ));
		}
		// Return "null" if no parameter has been found
		if ( typeof(def) == 'undefined' )
			return null;
		else 
			return def;
	}
}
//
function vP (param){
	if (getParameter(param) != null && getParameter(param).length != 0){
		return true;
	}
	return false;
}
//
function getPagename (){
		var pathname = window.top.location.pathname;
		return pathname.substring(pathname.lastIndexOf('/')+1,pathname.length);
}
//
var required;
function decode(str) {
     return unescape(str.replace(/\+/g, " "));
}
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function onFormSubmit(form)
{
	filter(form);
	if  (!checkRequired(form)){
		return false;
	}
	if (!validation (form)){
		return false;
	}
	return true;
}
function filter (form){
//make sure no special characters entered
	for(var i = 0; i<form.length; i++)
	{
		if(form.elements[i].type == "text" )
		{
			var txt = form.elements[i].value.trim();
			txt = txt.replace("\"" ,"&quot;").replace('\'', "&#39;");
			form.elements[i].value = txt;
		}
	}
}
function validationPassword (pwd ,confpwd ){
	return  confpwd.value == pwd.value;
}
function validationEmail(email) {
   return (email.value.indexOf(".") > 2) && (email.value.indexOf("@") > 0);
}
function validation (form){
	if (typeof (form.validation) == 'undefined' )
		return true;
	else 
		return form.validation();
}
function checkRequired (form){
	if (typeof (form.required) == 'undefined' )
			return true;	
	var inputs = Form.getElements(form);
	var showMessage = '';
	inputs.each (function(node){
		if (typeof(form.required[node.name]) != 'undefined'){
			if (node.value == null || node.value.length == 0){
				showMessage += form.required[node.name][1] + "\n";
			}
		}
	});

	if (showMessage.length != 0 ){
		alert (showMessage);
		return false;
	}else {
		return true;
	}
	
}




