﻿// JScript File

// function to trim the string
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

//function to validate the Email.
function chkEmailIds(obj, msg){
	var regex = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var strEmail = obj.value;
	strEmail = strEmail.replace(/;/g,",");
	var strMailId = "";		
	if(strEmail.indexOf(",") != -1){
		var splitEmail = strEmail.split(",");
		for (var x=0; x<splitEmail.length; x++){
			strMailId = splitEmail[x];
			strMailId = strMailId.replace( /^\s+/g,'').replace(/\s+$/g,'');
			
			for (var z=x+1; z<splitEmail.length; z++){
				if(strMailId == splitEmail[z].replace( /^\s+/g,'').replace(/\s+$/g,''))
				{
					if(msg =="E-Mail") alert("Email address " + strMailId + " is already entered. \nPlease enter a different email address.");
					else alert("Email address " + strMailId + " is already entered. \nPlease enter a different " + msg + " email address.");
					obj.focus();
					return false;
				}
			}
			
			if(!regex.test(strMailId)){
					alert("Please enter a valid " + msg + " email address.");
					obj.focus();
					return false;
				}
			var strEmailDomain = splitEmail[x].split("@");
			strEmailDomain = strEmailDomain[1].split(".");
				
			/*for (var z=1; z < strEmailDomain.length; z++)
			{
				strEmailDomain[z] = strEmailDomain[z].replace( /^\s+/g,'').replace(/\s+$/g,'');
				if ((strEmailDomain[z].length < 2) || (strEmailDomain[z].length > 3))
				{
					alert("Please enter a valid " + msg + " email address.");		
					obj.focus();
					return false;
				}
			}*/
				
		} 				
	}
	else if(obj.value.length > 0 )
	{	
		strMailId = strEmail.replace( /^\s+/g,'').replace(/\s+$/g,'');
		if(!regex.test(strMailId)){
				alert("Please enter a valid " + msg + " email address.");		
				obj.focus();
				return false;
			}
		var strEmailDomain = strEmail.split("@");
		
		strEmailDomain = strEmailDomain[1].split(".");
		/*for (var y=1; y <strEmailDomain.length; y++)
			{	
				strEmailDomain[y] = strEmailDomain[y].replace( /^\s+/g,'').replace(/\s+$/g,'');
				
				if ((strEmailDomain[y].length < 2) || (strEmailDomain[y].length > 3))
				{
					alert("Please enter a valid " + msg + " email address.");		
					obj.focus();
					return false;
				}
				
			}*/
	}
	return true;
}
function funReset(pSearch,pStatus)
{
    document.getElementById(pSearch).value = "";
    //document.getElementById(pStatus).value = "";
    document.getElementById(pStatus).selectedIndex = 0;   
    return false;
}