//Browser check JS include

function BrowserCheck () {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b
	this.v = parseInt(navigator.appVersion);
	this.ns = (this.b=="ns" && this.v >= 4);
	this.ns4 = (this.b=="ns" && this.v == 4);
	this.ns5 = (this.b=="ns" && this.v == 5);
	this.ie = (this.b=="ie" && this.v >= 4);
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	if (this.ie5) this.v=5;
	this.min = (this.ns || this.ie);
}

//Open a new window
function openArticle(locURL) {

	if (window.articleWin && !window.articleWin.closed)
	{
		window.articleWin.location.href = locURL;
		if (!is.ie4)
		{
			window.articleWin.focus();
		}
	}
	else
	{
		window.articleWin = window.open(locURL,'articleWin',"toolbar=no,menubar=yes,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,height=350,innerheight=350,width=500,innerwidth=500,screenx=125,left=125,screeny=150,top=150");
		if (!is.ie4)
		{
			window.articleWin.focus();
		}
	}
}


//Close the article window
function closeArticle(){
	if (window.articleWin && !window.articleWin.closed)
	{
		window.articleWin.close();
	}

}


function trim(st) {
var len = st.length
var begin = 0, end = len - 1;
while (st.charAt(begin) == " " && begin < len) {
begin++;
}
while (st.charAt(end) == " " && begin < end) {
end--;
}
return st.substring(begin, end+1);
}

function RemoveCommas(str) {
		var new_str="";
		for(i=0;i<str.length;i++)
		{
			if (str.charAt(i)!=',')
				new_str +=str.charAt(i);
		}
			return new_str;
	}
	
	function StringCompare(string1,string2){
		if (string1.length != string2.length)
			return false;
		for(i=0;i<string1.length;i++){
			if(string1.charAt(i) != string2.charAt(i))
				return false; 
		}
		return true;
		
	}

	function RemoveLineBreaks(str){
		var new_str = '';
		for( i =0; i < str.length; i++){
			if ((str.charAt(i)!='\r') && (str.charAt(i)!='\n') && (str.charAt(i)!='\t') && (str.charAt(i)!='\f') && (str.charAt(i)!='\b'))
				new_str += str.charAt(i);
			}
		return new_str;
	}

	function RemoveSpace(bob){
		var new_bob = '';
		for( i =0; i < bob.length; i++){
			if (bob.charAt(i)!=' ')
				new_bob += bob.charAt(i);
			}
		return new_bob;
	}

	function EmailCheck(bob) {
		if (bob.indexOf("@")<3){
			alert("The email address entered seems wrong. Please check the prefix and '@' sign.");
			return false;
		}
		if ((bob.indexOf(".com")<5) && (bob.indexOf(".org")<5) && (bob.indexOf(".gov")<5) && (bob.indexOf(".net")<5) && (bob.indexOf(".mil")<5) && (bob.indexOf(".edu")<5)){
			alert("I'm sorry. This email address seems wrong. Please check the suffix for accuracy. (It should include a .com, .edu, .net, .org, .gov or .mil)");
			return false;
		   }
		return true;
	}

	function CheckEmpty(str)
	{
	  if (str.length == 0)
	    return true;
	  else
		return false;
	}

	function CheckDate(str)
	{
		//this is routine will work 98.08% of the time (seriously)
		//will fix later
		//must be mm/dd/yyyy format
		//     or mm/d/yyyy
		//     or m/dd/yyyy
		//     or m/d/yyyy
		//must include two "/"'s
		//four digit year
		//year above 1900 and below 2100
		//month 1-12
		//day 1-31
		var nogood = false;
		if (str.length == 8)
		{
			if (str.charAt(1) == '/' && str.charAt(3) == '/')
			{
				var month, day, year;
				
				month = str.charAt(0);
				day = str.charAt(2);
				year = str.charAt(4) + str.charAt(5) + str.charAt(6) + str.charAt(7);
				
				if ((month > 0 && month < 13) && (day > 0 && day < 32) && (year > 1900 && year < 2100))
					return true;
				else
					nogood=true;				
			} else
				nogood = true;
		}
		else if (str.length == 9)
		{
			if (str.charAt(1) == '/' && str.charAt(4) == '/')
			{
				var month, day, year;
				
				month = str.charAt(0);
				day = str.charAt(2) + str.charAt(3);
				year = str.charAt(5) + str.charAt(6) + str.charAt(7)+ str.charAt(8);
				
				if ((month > 0 && month < 13) && (day > 0 && day < 32) && (year > 1900 && year < 2100))
					return true;
				else
					nogood=true;					
			}
			else if (str.charAt(2) == '/' && str.charAt(4) == '/')
			{
				var month, day, year;
				
				month = str.charAt(0) + str.charAt(1);
				day = str.charAt(3);
				year = str.charAt(5) + str.charAt(6) + str.charAt(7)+ str.charAt(8);
				
				if ((month > 0 && month < 13) && (day > 0 && day < 32) && (year > 1900 && year < 2100))
					return true;
				else
					nogood=true;				
			
			} else
				nogood=true;
		}
		else if (str.length == 10)
		{
			if (str.charAt(2) == '/' && str.charAt(5) == '/')
			{
				var month, day,year;

				month = str.charAt(0) + str.charAt(1);
				day = str.charAt(3) + str.charAt(4);
				year = str.charAt(6) + str.charAt(7) + str.charAt(8) + str.charAt(9);
				
				if ((month > 0 && month < 13) && (day > 0 && day < 32) && (year > 1900 && year < 2100))
					return true;
				else
					nogood=true;
			}
			else
				nogood=true;
		}
		else
			nogood=true;
			
		if (nogood)
		{
			alert("All date fields must follow this format: MM/DD/YYYY");
			return false;
		}
		return true;
	}
	
	function CheckNumeric(str)
	{
		//alert(str);
		strLength = str.length;
	
		error = false;
		var i = 0;
		for (i; i < strLength; i++)
		{
			if ( (str.charAt(i) < '0') || (str.charAt(i) > '9') )
			{
				if ( i == 0)
				{
					if ((str.charAt(i) != '-') && (str.charAt(i) != '.'))
					{
						error = true;
						break;
					}	
				}
				else
				{
					error = true;
					break;
				}
			}
		}

		return !error;
	}

	function CheckPhone(str){
		//11/10 digets only
		var x = 0;
		if ((CheckNumeric(str.charAt(0))) && ((str.charAt(1) == '-') || (str.charAt(1) == '.')))
			{
			x=2;
			}
		if (!((str.charAt(x+3) == '-')&&(str.charAt(x+3) == '.')) && !((str.charAt(x+7) == '-')||(str.charAt(x+7) == '.')))
			return false;
		strLength = str.length;
		error = false;
		if (strLength < 12)
			return false;
		for (i=x; i < strLength; i++)
		{
			if ( (str.charAt(i) < '0') || (str.charAt(i) > '9') )
			{
				if (!((i  == (x + 3)) || (i  == (x + 7))))
				{
					error = true;
					break;
				}
			}
		}

		return !error;
	}


	function CheckZip(str)
	{
		if (str.length < 5)
			return false;
		if(!checkNumeric(str.charAt(0) + str.charAt(1) + str.charAt(2) + str.charAt(3) + str.charAt(4)))
				return false;
		if(str.length == 5)
				return true;
		if((str.charAt(5) != '-') || (str.length != 10))
				return false;
		if(!checkNumeric(str.charAt(6) + str.charAt(7) + str.charAt(8) + str.charAt(9)))
			return false;
		return true; 
	}



function CheckTime(str){
	var i=0;
	if (!checkNumeric(str.charAt(0)))
		return false;
	if (str.charAt(1) == ":")
		i=1;
	else if (!checkNumeric(str.charAt(1)))
		return false;
	else if ((i!=1) && (str.charAt(2) == ":"))
		i=2;
	else if(!checkNumeric(str.charAt(2)))
		return false;
	if ((i==2) && (str.charAt(0) != "1"))
		return false;
	if (!checkNumeric(str.charAt(i+1)))
		return false;
	if (!checkNumeric(str.charAt(i+2)))
		return false;
	if (str.charAt(i+3) != " ")
		return false;
	if ((str.charAt(i+4).toUpperCase() != "A") && (str.charAt(i+4) != "P"))
		return false;
	if(str.charAt(i+5).toUpperCase() != "M"	)
		return false;
	return true;		
}

function isLeapYear(intYear)
{
if ((((intYear % 4) == 0) && ((intYear % 100) != 0)) || (((intYear % 100) == 0) && ((intYear % 400) == 0)))
	{
      return true;
	}
else {
      return false;
   }
}

function NotEmpty(str)
{
	if (str.value.length == 0)
	{		
		alert("You cannot leave any fields blank.");
		return false;
	}
	else
		return true;
}

function replace(argvalue, x, y) {

  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
    errmessage = "replace function error: \n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.\n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;
  }
    
  while (argvalue.indexOf(x) != -1) {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;
  }

  return argvalue;

}

// automatically create the "is" object
is = new BrowserCheck()

