
function eCheckEMail(sn){
    s= sn.value;
    if (s.indexOf("@") == -1) return false;
    if (s.indexOf(".") == -1) return false;
    at=false;
    dot=false;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                if (ch == "@"){
                  if (at) return false;
                  else at=true;
                }
                if ((ch==".") && at)
                   dot=true;
        }
        else return false;
    }
   return dot;
}

function checkEmail(theForm,fname){
	check=true;
		if(eval("theForm."+fname+".value")=='')
		{
			check=true; 
		}
        else if (!eCheckEMail(eval("theForm."+fname))){
           alert("Ongeldig E-mail adres");
            check=false; 
            eval("theForm."+fname+".focus()");
        }
 }

//to check Url 
//@ f name of form
//@ fname name of field
function checkUrl(f,fname)
{
	check=true;
	var value=eval("f."+fname+".value");
	if(value!="" && value.length>0)
	{
		var ind_h=value.indexOf("http://");
		var ind_dot=value.indexOf(".");
		
		
		if(ind_h==-1 || ind_dot==-1)
		{
			check=false;
			alert(invalid_url);
			eval("f."+fname+".focus()");
		}
	}
}
//Used to format the no of decimal in given text value
//@ field name 
//@ no of digit after dot
function formatDecimal(f,fname,no)
{
		check=true;
		var value=eval("f."+fname+".value");
		if(checkNumber(value))
		{
			check=true;
		}
		else
		{
			alert(not_a_number);
			check=false;
			//eval("f."+fname+".value=''");
			eval("f."+fname+".focus()");
		}
		
}
function checkInt(f,fname)
{
	var value=eval("f."+fname+".value");
	check=false;
	if(checkNumber(value))
	{
		if(value.indexOf(".")==-1 && value.indexOf(",")==-1)
		{
			check=true;
		}
	}
	if(check==false)
	{
		alert(not_a_number);
	}
}
//To check whether the given value is nubmer or not
//@ text value
function checkNumber(val,extra)
{
	var check=true;
	for(i=0;i<val.length;i++)
	{
		var c=val.charAt(i);
		//alert(c);
		if(!((c>='0' && c<='9')||(c==".")||(c==",")))
		{
			check=false;
			break;
		}
	}
	return check;
}
//Function to check the date format
//@ f form name
//@ fname field name
function checkDate(f,fname)
{
	check=true;
	var value=eval("f."+fname+".value");
	if(checkNumber(value,"-"))
	{
		if(value!="" && value.length>0)
		{
			var beforeindex=value.indexOf("-");
			var afterval=value.substring(value.indexOf("-")+1,value.length);
			var afterindex=afterval.indexOf("-");
			if(beforeindex!=4 || afterindex!=2)
			{
				alert(invalid_date_format);
				check=false;
			}
		}
	}
	else
	{
		alert(invalid_date_format);
		check=false;
	}
}
