function checknumber(object_value)
    {

    if (object_value.length == 0)
        return false;
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;


	check_char = start_format.indexOf(object_value.charAt(0))

	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        

	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)	
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	

    return true
}


function CheckFormItems(theForm)
{
	var ok = true;
	if (theForm.ForumChck && theForm.ForumChck.value == 2)
	{
		theForm.ForumChck.value = "mod";
	}

	pwd1Defined = false;
	pwd2Defined = false;
	pwd1="";
	pwd2="";

	
	for (var i = 0; i < theForm.elements.length; i++) 
	{
			var e = theForm.elements[i];
			
			//START of password check
			if(e.name == "Password")
			{
				pwd1 = e.value;
				pwd1Defined = true;
			}

			if(e.name == "Password2")
			{
				pwd2 = e.value;
				pwd2Defined = true;
			}
			
			if(pwd1 != pwd2 && pwd1Defined && pwd2Defined)
			{
				alert("Check the passwords!");
				e.focus();
				return false;
			}

			//END of password check			


			if (!(e.name.indexOf('def_')>= 0))
			
			{

				if ( !(typeof(eval('theForm.elements["dfs_' + e.name + '"]')) == "undefined") )			
					{
					defselval = eval('theForm.elements["dfs_' + e.name + '"].value');
					selvalues = defselval.split('_');
					selrequired = selvalues[0];
					selalert = selvalues[1];
					if (selrequired == 'req')
						{
						sreq = true;
						}
					else
						sreq = false;
						
					if (sreq && e.value == 'null')
						{
						alert(selalert);
						return false;
						}
					
					}

			
				if ( !(typeof(eval('theForm.elements["def_' + e.name + '"]')) == "undefined") )
					{
					defval = eval('theForm.elements["def_' + e.name + '"].value');
					
					values = defval.split('_');
					datatype = values[0];
					required = values[1];
					alertmessage = values[2];
					alertmessage2 = values[3];
				
					if (required == 'req')
						req = true;
					else
						req = false;
					
					if (datatype == 'int' || datatype == 'float')
						{
						needN = true;
						}
					else
						needN = false;
						
						
					if (req && e.value == '')
						{
						alert(alertmessage);
						if (e.type!='hidden'){
							e.focus();
						};
						return(false);
						}
						
					if (!checknumber(e.value) && needN)
						{
						alert(alertmessage2);
						if (e.type!='hidden'){
							e.focus();
						};
						return(false);
						}

					}
			}
	}

	return (true);

}

// function for delete button
function AskToDelete(form_object, question) {
	if(confirm(question)) {
		form_object.elements['ActionType'].value = 'DELETE';
		return true;
	}
	else
		return false;
}

function CheckEmail (EmailObject, theAlert){

	if(EmailObject.value.length >= 0 && EmailObject.value.length < 8){
		alert(theAlert);
		EmailObject.focus();
		return false;
	}


	if ( EmailObject.value.length > 0 )
	{
		for(var i = 0, j = 0; i < EmailObject.value.length; i++)
			if(EmailObject.value.charAt(i) == '@') 
				j++;

		if(j!=1)
		{
			alert(theAlert);
			EmailObject.focus();
			return false;
		}

	}

	return true;
}

	function OpenWindow4Print(URL) {
		var newWin
		newWin = window.open(URL, "Window_Address", "resizable=no,scrollbars=yes,status=0,menubar=1,width=800,height=500");
		newWin.focus();
		return (false);
	}
	
	function OpenWindow4Mail(URL) {
		newWin = window.open(URL, "Window_Address", "resizable=no,scrollbars=no,status=0,menubar=0,width=410,height=380");
		newWin.focus();
		return (false);
	}

	function doPopup(URL,width,height) {
		winprop = "resizable=no, scrollbars=no, status=0, menubar=0, width=" + width + ", height=" + height
		newWin = window.open(URL,"void",winprop);
		newWin.focus();
		return (false);

	}

	function HideReactions(vIndex,vSetting){
		theObject = new Object()

		if (vSetting == 'block'){
			theObject = document.getElementById("HideMessage" + vIndex)
			theObject.style.visibility = 'visible';
			theObject = document.getElementById("ShowMessage" + vIndex)
			theObject.style.visibility = 'hidden';
		}
		else{
			theObject = document.getElementById("ShowMessage" + vIndex)
			theObject.style.visibility = 'visible';
			theObject = document.getElementById("HideMessage" + vIndex)
			theObject.style.visibility = 'hidden';
		}

		theObject = document.getElementById("MessageBox" + (vIndex + 1))
		while (theObject.style.marginLeft.substr(0,theObject.style.marginLeft.length-2) > 10){
			theObject.style.display = vSetting;
			vIndex++
			theObject = document.getElementById("MessageBox" + (vIndex + 1))
		}
	}

	function FillForm(ParentID, vTitle){
		vForm = document.forms.ForumForm
		vForm.ParentForumMessageID.value = ParentID
		vForm.ForumMessageTitle.value = vTitle
	}

function CheckRegistration(theForm) {
	if ( CheckFormItems(theForm) )
	{
		if (theForm.ActionType.value == "UPDATE")
			return (true)
		
		if (!CheckEmail (theForm.Email, theForm.WrongEmailAlert.value) )
			return (false)

		if (theForm.Password.value != theForm.Password2.value){
			alert (theForm.def_Password2.value);
			return(false)
		}

		return (true)
	}
	else
		return(false)
}