



/*
****************************************************************************************
	2 Function below: popupWindow and ResizeImgWindow are used in conjunction to dynamically
	resize an image on a page.
****************************************************************************************
*/
	//	Function used at placement of the image and calling this function for new popup window
function popupWindow(url) 
{	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

	//	Called in the Body tag of the page to dynamically resize the image to the window size
function ResizeImgWindow() 
{	var i=0;
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0]) window.resizeTo(document.images[0].width +25, document.images[0].height+110-i);
}
/*
****************************************************************************************
	End of 2 Functions used in conjunction to dynamically	resize an image on a page.
****************************************************************************************
*/





function isInteger(sVal)  
{	var i;
  for (i = 0; i < sVal.length; i++)
  {		// Check that the current char is numeric
    var c = sVal.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
		// All the chars are numeric
  return true;
}



/*
****************************************************************************************
	Checking for whitespace or emtpy field related functions
****************************************************************************************
*/


var whitespace = " \t\n\r";

function IsWhitespace (val, msg)
{	var sInput = new String(val.value);
	var i;

	if (IsEmpty(sInput)) return true;

	for (i = 0; i < sInput.length; i++)
	{		// Check that current character isn't whitespace.
		var c = sInput.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}

		// All characters are whitespace.
	alert(msg);
	return true;
}


function IsEmpty(val)
{ var sInput = new String(val.value);
	return ((sInput == null) || (sInput.length == 0))
}





/*
****************************************************************************************
	Email validation related functions
****************************************************************************************
*/

var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

function IsValidEmail(val, msg)
{	var sInput = new String(val.value);
	
	if (re.test(sInput))	
	{	return true
	}
	alert(msg);
	return false;
}








/*
****************************************************************************************
	Date related functions
****************************************************************************************
*/

	// Declaring valid date character, minimum year and maximum year
var sDateChar = "/";
var iMinYear = 1900;
var iMaxYear = 2100;


function isDate(sDate)  
{	var iDaysInMonth = DaysArray(12)
	var iPos1 = sDate.indexOf(sDateChar)
	var iPos2 = sDate.indexOf(sDateChar, iPos1 + 1)
	var iMonth = sDate.substring(0, iPos1)
	var iDay = sDate.substring(iPos1 + 1, iPos2)
	var iYear = sDate.substring(iPos2 + 1)
	strYr = iYear
	if (iDay.charAt(0) == "0" && iDay.length > 1) iDay = iDay.substring(1)
	if (iMonth.charAt(0) == "0" && iMonth.length > 1) iMonth = iMonth.substring(1)
	for (var i = 1; i <= 3; i++) 
	{	if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
	}
	month = parseInt(iMonth)
	day = parseInt(iDay)
	year = parseInt(strYr)
	if (iPos1 == -1 || iPos2 == -1)
	{	alert("The date format should be: MM/DD/YYYY")
		return false
	}
	if (month < 1 || month > 12)  {
		alert("Please enter a valid month")
		return false
	}
	if (day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > iDaysInMonth[month])
	{	alert("Please enter a valid day")
		return false
	}
	if (iYear.length != 4 || year==0 || year < iMinYear || year > iMaxYear)
	{	alert("Please enter a valid 4 digit year between "+iMinYear+" and "+iMaxYear)
		return false
	}
	if (sDate.indexOf(sDateChar, iPos2 + 1) != -1 || isInteger(stripCharsInBag(sDate, dtCh)) == false)
	{	alert("Please enter a valid date")
		return false
	}
	return true
}

function stripCharsInBag(sVal, bag)  
{	var i;
  var returnString = "";
		// Search through the characters one by one and if the char is not in bag then append to returnString
  for (i = 0; i < sVal.length; i++)
  {	var c = sVal.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

