﻿
document.write('<script type="text/javascript" src="/admin/js/validateFormFields.dic.js"></script>');
function checkEmail(email){
	re = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/
	if (re.test(email) == true)
		return true 
	else {
		return (validateEmail(email))
	}
}

function validateEmail(email){
	var atPos = email.indexOf("@",1)
	var invalidChars = " /:;,"
//alert(clientDic.EMPTY_EMAIL)
	
	if(isnull(email)){ //email cannot be empty
//alert(clientDic.IN_EMAIL)
		return("clientDic.EMPTY_EMAIL");
	}
	for(var i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i)
		if(email.indexOf(badChar,0) != -1){ //email cannot be invalid chars
			return (clientDic.BAD_CHAR+" "+badChar+" "+clientDic.IN_EMAIL );
		}
	}
	if((email.indexOf("@")) != (email.lastIndexOf("@"))){ //email must be one "@" symbol
		return(clientDic.MORE_THEN_1_AT);
	}
	if(email.indexOf("@") == -1){ //check if there is "@" symbol in the email
		return(clientDic.ADD_AT);
	}
	if((email.indexOf("@")) == 0){ //check if the "@" symbol is in the first place
		return(clientDic.WRONG_AT_POSITION);
	}
	if((email.indexOf(".")) == -1){ //check if there is "." symbol in the email
		return(clientDic.ADD_POINT)
	}
	if((email.indexOf(".")) < atPos){ // check if the "." before the "@" symbol
		return(clientDic.WRONG_POINT_POSITION);
	}
	if((email.indexOf(".")) == atPos+1){ // check if the "." before the "@" symbol
		return(clientDic.WRONG_POINT_POSITION);
	}
	if(email.lastIndexOf(".") == (email.length -1)){ //check if the "." is the last in the email
		return(clientDic.ADD_VALUE_AFTER_POINT);
	}
	var dotCount = 0;
	for(var j=0; j<email.length; j++){
		if(email.substring(j,j+1) == ".") dotCount ++ // check if there isn't more then two dots
		if (dotCount > 2)	{
			return(clientDic.MORE_THEN_2_POINT);
		}
	}
	if(email.substring(email.indexOf(".")+1,email.length).length > 3)
		return(clientDic.MORE_THEN_3_CARACTER_AFTER_LAST_POINT);
		
	if(email.indexOf("..") != -1){ // check if the isn't two dots in 
		return(clientDic.TWO_POINT_IN_SERIAL);
	}
	return true;
}

//*******************************************************************
// Tests whether the given argument is empty or null
//function isnull(arg) {
///	if(typeof(arg) == "object")
//		return false;
//	arg = arg+'';
//	return (arg == '' || arg == 'null' || arg == 'undefined');
//}

//*******************************************************************
function numberOk(str){
	var numOk="0123456789"
	for(i=0; i<str.length; i++){
		if(numOk.indexOf(str.substring(i,i+1))==-1){
			return false;
		}
	}
	return true;
}
//*******************************************************************
function trim(str){
	try {
		return str.replace(/^\s+|\s+$/g,'');
	}
	catch (e) {
		return str;
	}
}

function onlyChars(str){
	var re = /\d+/gi;
	if (re.test(str) == false)
		return true
	else 
		return false
}

function charOk(myStr){
	var re = new RegExp("[A-Za-z\\s\\d\\/\\'\\,\\.\\?\\!\\;\\:\\[\\]\\{\\}\\-\\_\\(\\)\\+\\=\\@\\$\\&\\*\\^\\#]", "g");
	result = myStr.replace(re, "")
	return result
}




