
function isValidEmail(str) {

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
return true;
else{
return  false;
}
}

function validateNoOfBeds(fld, fldName)
    {
		
       var error = "";
       if (!isInteger(fld)) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
            fld.style.background = '#ffff99';
        }
        return error;
    }


 function validateIntWithLength(fld, fldName, length)
    {
        var error = "";
        var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

        if (!isInteger(fld)) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
            fld.style.background = '#ffff99';
        } else if (stripped > length) {
            error = "<br>The field "+fldName+" can have maximum value of 60 years.\n";
            fld.style.background = '#ffff99';
        }
        return error;
    }


   function validatePhone(fld, fld2, fldName,fldName2)
    {
		var error = "";
        if(fld.value== "" && fld2.value== ""){

            fld.style.background = '#ffff99';
            fld2.style.background = '#ffff99';
            return "<br>Enter either phone or mobile number.";
        }

        if(fld2.value!= ""){            
            var stripped2 = fld2.value.replace(/[\(\)\.\-\ ]/g, '');

            if (stripped2.length>0 && !isInteger(fld2)) {
                error = "<br>The "+fldName2+" number contains illegal characters.\n";
        } else if (!(stripped2.length == 11)) {
            error = "<br>The "+fldName2+" is of wrong length. Please provide a 11 digit number including 0.\n";
        }
        
        }  
        
       return error;
    }
        
        
   function validateIntWithLength(fld, fldName, length)
    {
        var error = "";
        var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

        if (!isInteger(fld)) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
            fld.style.background = '#ffff99';
        } else if (stripped > length) {
            error = "<br>The field "+fldName+" can have maximum value of 60 years.\n";
            fld.style.background = '#ffff99';
        }
        return error;
    }
    
	
function validateMobile(fld, length)
    {

        return true;
    }

function validateMobileValue(fldValue, length)
    {

        var stripped = fldValue.replace(/[\(\)\.\-\ ]/g, '');

        if (!(stripped.length == 10)) {
             return false;
        } else if (!isIntegerValue(fldValue) ) {
             return false;
        }

        return true;
    }


  function validateNoOfBeds(fld, fldName)
    {
		
       var error = "";
       if (!isInteger(fld)) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
            fld.style.background = '#ffff99';
        }
        return error;
    }


    
    function validateOperationalSince(fld,fldName,length)
    {
       	
       var error = "";
	   var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

       if (!isInteger(fld)) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
            fld.style.background = '#ffff99';
        }
        if (isNaN(parseInt(stripped)) && stripped.length >0  ) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
            fld.style.background = '#ffff99';
        } else if (!(stripped.length == 4) && stripped.length >0) {
            error = "<br>The field "+fldName+" shuld be "+length+" digit length.\n";
            fld.style.background = '#ffff99';
        }
        return error;
    }

function isAlphabet(elem){
  	var alphaExp = /^[a-zA-Z. ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}
	 return false;
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.value.length; i++)
    {   
        // Check that current character is number.
        var c = s.value.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function isIntegerValue(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}



function validateName(fld, fldName) {
        var error = "";

        if (fld.value== "") {

         return  "The "+fldName+" field has not been filled.\n";
         
        } else if(!isAlphabet(fld)) {
            error = "<br>The field "+fldName+" contains illegal characters.\n";
		  fld.style.background = '#ffff99';
        }
        return error;
}

function textCounter(field, maxlimit) {
	
    if (field.value.length > maxlimit) // if too long...trim it!
    {
        field.value = field.value.substring(0, maxlimit);
        return false;
    }
  
    return true;
}

function validateIntWithLength(fld, length)
{
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

    if (fld.value == "") {
        return false;
    } else if (isNaN(parseInt(stripped))) {
        return false;
    } else if (!(stripped.length == length)) {
        return false;
    }
    return true;
}

function validateInt(fld)
{
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

    if (fld.value == "") {
        return false;
    } else if (isNaN(parseInt(stripped))) {
        return false;
    }
    return true;
}

function validateNotNull(fld) {
    return !(fld==null || fld.value.length==0);
}

function confirmExit(eleNode,path,msg)
{
    var r = confirm(msg);
    if (r == true)
    {
        eleNode.href = path;
    }
}

function confirmExitFunction(functionName,param,msg){
    var r = confirm(msg);
    if (r == true)
    {
        functionName(param);
    }
}

function confirmExitFunctionWithoutParam(funcName,msg){
    var r = confirm(msg);
    if (r == true)
    {
        funcName();          
    }
}

function confirmExitFunctionWithParams(functionName, param1, param2,msg) {
    var r = confirm(msg);
    if (r == true)
    {
        functionName(param1,param2);
    }
}

