// Developer:  Imad Atallah
//***********************************************************

function art_ext(obj)
{
	var lclAt, lclValue="", a=1;

	lclValue = eval(obj + '.value');

	for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
		if (lclValue.substring(lclAt,lclAt+1) == '.') a = lclAt;

	if (lclValue.substring(a+1,a+4) != "JPG")
	if (lclValue.substring(a+1,a+4) != "jpg")
	if (lclValue.substring(a+1,a+4) != "GIF")
	if (lclValue.substring(a+1,a+4) != "gif")
		a = 0;

	if (a == 0)
		{
			alert("Message: Invalid file extension.");
			eval(obj + ".focus()");
			return false;
		}

	return true;
}
//***********************************************************
function text_ext(obj)
{
	var lclAt, lclValue="", a=1;

	lclValue = eval(obj + '.value');

	for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
		if (lclValue.substring(lclAt,lclAt+1) == '.') a = lclAt;

	if (lclValue.substring(a+1,a+4) != "HTM")
	if (lclValue.substring(a+1,a+4) != "htm")
	if (lclValue.substring(a+1,a+4) != "TXT")
	if (lclValue.substring(a+1,a+4) != "txt")
	if (lclValue.substring(a+1,a+4) != "DOC")
	if (lclValue.substring(a+1,a+4) != "doc")
		a = 0;

	if (a == 0)
		{
			alert("Message: Invalid file extension.");
			eval(obj + ".focus()");
			return false;
		}

	return true;
}

//***********************************************

function SingleLine(obj)
{
	var lclAt, lclValue="", a=0;

	lclValue = eval(obj + '.value');

	for (lclAt=0; lclAt < lclValue.length; lclAt++)
		if ((lclValue.charCodeAt(lclAt) == 13) || (lclValue.charCodeAt(lclAt) == 10)) a = 1;

	if (a == 1)
		{
			alert("Message: In the brief description of 1 to 3 phrases, do not hit the \"RETURN\" or \"ENTER\" key.");
			eval(obj + ".focus()");
			return false;
		}

	return true;
}

//***********************************************************

function ValidFileName(obj)
{
	var lclAt, lclValue="", a=1;

	lclValue = eval(obj + '.value');

	for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
		if (lclValue.substring(lclAt,lclAt+1) == "\\") a = lclAt;

	lclValue = lclValue.substring(a,lclValue.length);

	a = 0;
	for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
		if (lclValue.substring(lclAt,lclAt+1) == ' ') a = lclAt;

	if (a != 0)
		{
			alert("Message: Spaces are not allowed in the file name.  Please rename the file by removing any spaces before uploading.");
			eval(obj + ".focus()");
			return false;
		}

	return true;
}

//***********************************************************

function email(obj)
{
	var lclAt, lclValue="", a=0;

	lclValue = eval(obj + '.value');

	for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
		if (lclValue.substring(lclAt,lclAt+1) == '@') ++a;

	if (a == 0 || a > 1)
		{
			alert("Message: Invalid email address.");
			eval(obj + ".focus()");
			return false;
		}

	return true;
}

//***********************************************************
function notmarked(obj, msg)
{
	if(eval(obj+".checked"))
	{
		alert("Message: Please tell us " + msg + ".");
		return true ;
	}
	else
		return false ;
}

//***********************************************************

function notchecked(obj, msg)
{
var atLeastOne = 0; len=0; val="";

len = eval(obj+".length");

for (var i=0; i < len; i++)
{
	val = eval(obj+"[" + i + "].checked");
	if (val) atLeastOne = 1;
}

if (atLeastOne == 0)
	{
	alert("Message: Please tell us " + msg + ".");
	return true ;
	}
	
return false ;
}

//***********************************************************

function notselected(obj, msg)
{
var lclValue=""

if (eval(obj + ".value") == "")
	{
	alert("Message: Please tell us " + msg + ".");
	eval(obj + ".focus()") ;
	return true ;
	}
	
return false ;
}
//***********************************************************
function isblank(obj, msg)
{
var lclAt=0, lclValue="" , lclFiltered="";

if(eval(obj+".type") == 'select-one')
{
	var si=eval(obj+".selectedIndex");
	lclValue = eval(obj + ".options[si].text") ;
}
else
	lclValue = eval(obj + ".value") ;

for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
	{
	if (lclValue.substring(lclAt,lclAt+1) != " ")
		lclFiltered = lclFiltered + lclValue.substring(lclAt,lclAt+1) ;
	}

if (lclFiltered == "")
	{
	alert("Message: Please tell us " + msg + ".");
	eval(obj + ".focus()") ;
	return true ;
	}
	
return false ;
}

//***********************************************************

function hasspace(obj, msg)
{
var lclValue="" , lclSecond="", lclTemp="";

lclValue = eval(obj + ".value") ;

if ((lclValue.indexOf(" ") >0 ) || (lclValue.substring(0,1) == " "))
	{
	lclSecond=lclValue.substring(lclValue.indexOf(" "), lclValue.length);

	for (lclAt=0; lclAt < lclSecond.length+1; lclAt++)
		{
		lclTemp=lclSecond.substring(lclAt,lclAt+1);
		if (lclTemp != " ")
			{
			alert("Message: The " + msg + " cannot contain blank spaces.");
			eval(obj + ".focus()");
			return true ;
			}
		}
	}
return false ;
}

//***********************************************************

function checkEmail(obj)
{
	var lclValue=eval(obj + ".value");
	
	if((lclValue.indexOf("@") == -1) || (lclValue.indexOf(".") == -1))
	{
		alert("Message: The Email id is invalid");
		return true;
	}
	return false;
}

/*function filter(obj, msg)
{
	var lclAt, lclValue="", a=0;

//		if (lclValue.substring(lclAt,lclAt+1) != '/')
//		if (lclValue.substring(lclAt,lclAt+1) != '+')
//		if (lclValue.substring(lclAt,lclAt+1) != '(')
//		if (lclValue.substring(lclAt,lclAt+1) != ')')
//		if (lclValue.substring(lclAt,lclAt+1) != '%')
//		if (lclValue.substring(lclAt,lclAt+1) != '$')
//		if (lclValue.substring(lclAt,lclAt+1) != '#')
//		if (lclValue.substring(lclAt,lclAt+1) != '!')
//		if (lclValue.substring(lclAt,lclAt+1) != '~')
//		if (lclValue.substring(lclAt,lclAt+1) != "=")
//		if (lclValue.substring(lclAt,lclAt+1) != "'")
//		if (lclValue.substring(lclAt,lclAt+1) != '"')

	lclValue = eval(obj + '.value');

//	for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
//	{
//		a = 0;
//		if (lclValue.substring(lclAt,lclAt+1) != '>')
//		if (lclValue.substring(lclAt,lclAt+1) != '<')
//		if (lclValue.substring(lclAt,lclAt+1) != '&')
//		if (lclValue.substring(lclAt,lclAt+1) != '|')
//			a = 1;
//	
	if(lclValue.indexOf('>') != -1)
	{	
		a=0;
	}
		if (a == 0)
		{
			alert("Message: The " + msg + " cannot contain any of the following characters:" + 
				'       > < & | ');
			eval(obj + ".focus()");
			return true;
		}
	//}
	return false;
}
*/
//***********************************************************

function match(obj1, obj2, msg)
{
	if (eval(obj1 + '.value') != eval(obj2 + '.value'))
	{
		alert("Message: " + msg);
		eval(obj2 + ".focus()");	
		return false;
	}
	return true;
}

//***********************************************************

function CheckMonths()
{
  var fr  =  document.member.fromdate.value.substring(0,2);
  var t   =  document.member.todate.value.substring(0,2);	
 
  var y1  =  document.member.from_year.value;
  var y2  =  document.member.to_year.value;
  var temp = y2 - y1;
  var ok = false;
  
  if(y1 < y2  && temp == 1)
  {
    ok = true;        
  }

  if(t != '')
  {
    if(t < fr)
    {
      if(!ok)
      {	
        document.member.todate.selectedIndex = 0;
        alert("Month selected is less that the starting month");	
      }  
    }  
  }
}	

function CheckYear()
{
  var f1  =  document.member.from_year.value;
  var t1  =  document.member.to_year.value;

  if(t1 < f1)
  {
    alert("The Year you selected is less than the starting year in the period");
    document.member.to_year.selectedIndex = 0;
  }
  else
  { 
    if(f1 > t1) 
    {
      alert("The Year you selected is greater than the ending year in the period");
      document.member.from_year.selectedIndex = 0;	
    }
  }		
  //CheckMonth();	 	
} 


function CheckPeriod(list)
{
  var fmonth = list.options[list.selectedIndex].value.substring(0,2);
  //var yr     = list.options[list.selectedIndex].value.substring(6);
  //var sel =  list.options[list.selectedIndex].value.substring(0,6);
  //list.options[list.selectedIndex].value = sel+document.member.from_year.value;
  //alert("This is the year :"+list.options[list.selectedIndex].value+' '+document.member.from_year.value);

  var y1  =  document.member.from_year.value;
  var y2  =  document.member.to_year.value;
 
  var now = new Date();
  var month = now.getMonth();
  var year = now.getYear();
  month = month + 1;
  
  if(month < 10)
  {
     month = "0"+month; 
  }	
  
  var temp = y2 - y1;
  var ok = false;
  
  if(y1 < y2  && temp == 1)
  {
    ok = true;        
  }

  if(fmonth > month)
  {
    if(!ok)
    {
      alert("You can't select a future Review period"); 	
      list.selectedIndex = 0;
    }  
  }  
}	

//***********************************************************

function ch_ssn(lclObject, lclMessage)
{
	var lclAt, lclValue="", lclMask;
	lclValue = eval('document.member.' + lclObject + '.value');
	lclMask = "999-99-9999";
	if (lclMask.length != lclValue.length)
	{
		if (lclValue.length != 0)
		{
			alert("AACPMAS Message\n\nThe " + lclMessage + " doesn't match to mask");
			eval('document.member.' + lclObject + ".focus()");
			return true;
		}
	}	
	else
	{
		var count=0;
		var t=lclValue.substring(0,1);
		for (lclAt=0; lclAt < lclValue.length+1; lclAt++)
		{
			var lclVal=lclValue.substring(lclAt,lclAt+1);
			if(lclVal == t && lclVal != '-' && lclVal != '')
				count++;
				
			if (lclMask.substring(lclAt,lclAt+1) == '9')
			{
				if ((lclValue.substring(lclAt,lclAt+1) > '9') || (lclValue.substring(lclAt,lclAt+1) < '0'))
				{
					alert("AACPMAS Message\n\nThe " + lclMessage + " doesn't match to mask");
					eval('document.member.' + lclObject + ".focus()");
					return true;
				}
			}
			else
			{
				if (lclValue.substring(lclAt,lclAt+1) != lclMask.substring(lclAt,lclAt+1))
				{
					alert("AACPMAS Message\n\nThe " + lclMessage + " doesn't match to mask");
					eval('document.member.' + lclObject + ".focus()");
					return true;				
				}
			}
		}
		if(count>=9)
		{
			alert("AACPMAS Message\n\nThe " + lclMessage + " is not valid.");
			eval('document.member.' + lclObject + ".focus()");
			return true;				
		}
	}
	return false;
}