/*
   icl.js
*/


// identify browers by object support
var gbNav4 = document.layers ? true : false
var gbNS6  = document.getElementById && !document.all? true : false
var gbFF1  = document.getElementById && !document.all? true : false
var gbIE4 = document.all && !document.getElementById ? true : false
var gbIE5 = document.all && document.getElementById ? true : false

var gbIE_browser = gbIE4 || gbIE5
var gbMZ_browser = gbNS6 || gbFF1

// carriage return/line feed pair
var gs_crlf = "\r\n";



//	trap mouse click; negate this condition if not desired.
if (false) //(true) 
{
	document.onmousedown = click;
}


//alert(navigator.userAgent);

function click(e) {
/*
	trap right mouse button click and display msg
*/
	var msg = GetCopyrightInfo();
	var ret_val = true;

	if (gbIE_browser)
	{
		if (event.button == 2)
		{
			alert(msg);
			ret_val = false;
		}

	}

	if (gbMZ_browser)
	{
		if (e.which == 3)
		{
			alert(msg);
			ret_val = false;
		}
	}

	return ret_val;
}
// eofct:


function GetCopyrightInfo() {
/*
	construct copyright statement	
*/
	var thisYear = GetThisYear();
	var sCopyrightSpan = "2003"
	
	if (thisYear != sCopyrightSpan)
		sCopyrightSpan += "-"  + thisYear;

	var msg = "Copyright " + sCopyrightSpan + " Investors Title Insurance Company" +
		 gs_crlf + "created by Rick Duke with contributions" + gs_crlf + 
		"provided by Gary Choma and Niles Mills";
	

	return msg;
}
// eofct:



function GetThisYear() {
/*
	get the current year
*/
	var now = new Date();
	var thisYear = y2k(now.getFullYear())
	return thisYear;
}
// eofct:


function verifyEmail(email) {
/*
	created by GCC; modified by ROD
	Validates email address; return true if valid
*/

	ret_val = false

	if(email.length > 7)
	{
		var at = email.indexOf("@");
		if((at > 1) && (at==email.lastIndexOf("@")))
		{
			var dot = email.lastIndexOf(".");
			if ((dot>4) && ((dot-at)>2) && ((email.length-dot)>2))
			{
				// return true; // valid!
				ret_val = true
			}
		}
	}
	

	if (email.length >= 0)
	{
		if (!ret_val)
		{
			alert("Invalid email address");
		}
		
	}
	
	
	return ret_val
}
// eofct:


function formatDateString(sdate){
/*
	format and return a date string with embedded slashes when absent
	example: 01012001 returns as 01/01/2001; 01-01-2001 returns as 01/01/2001
	06/27/02 ROD created
*/

	var slash = "/"

	// replace any hypen with backslash
	while (sdate.indexOf("-") != -1)
	{
		sdate = sdate.replace("-", "/")
	}
	
	/*
		if (sdate.substring(5,6) == slash && sdate.length == 8 )
		{
			sdate = sdate.substring(0,6) + "20" + sdate.substring(6,8)
		}
	*/

	// scan for slash
	var pos = sdate.indexOf(slash);
	if (pos < 0 && sdate.length == 8)
	{	
		// embed slashes in string
		sdate = sdate.substring(0,2) + slash + sdate.substring(2,4) + slash + sdate.substring(4,8)
	}

	// alert("formated date = " + sdate)
	return sdate

}
// eofct: formatDateString()


function y2k(number) {
/*
	Return y2k compliant year
	06/13/02 ROD created
*/
	return (number < 1000) ? number + 1900 : number; 
}
// eofct: y2k()

function verifyDate(sDate) {
/*
	validate a date string
    returns boolean: True for validated; False for invalidated
	ROD created 06/13/02: from GCC's eflite script
*/
	var date1 = "";
	var date2 = "";
	var month1 = "";
	var month2 = "";
	var year2 = "";
	var year1 = "";
	var sString1;
	var sString2;
	var slash = "/";

	sNewDate = "";
	if (sDate == "")
		return true;

	sString = sDate;
	var pos = sString.indexOf(slash);
	if (pos >= 0)
	{
		month1 = sString.substring(0,pos);
		sString = sString.substring(pos + 1, sString.length);
		//alert("pos = " + pos + crlf + "month = " + month + crlf + "sString = " + sString);

		pos = sString.indexOf(slash);
		if (pos >= 0)
		{
			date1 = sString.substring(0,pos);
			year1 = sString.substring(pos + 1, sString.length);
			//alert("pos = " + pos + crlf + "day = " + day + crlf + "year = " + year);
		}
	}
	if ((month1 > 0) && (month1 < 13) && (date1 > 0) && (date1 < 32) && (year1 > 1700) && (year1 < 2200))
	{
		var newDateObj = new Date();

		var d, s = "Today's date is: ";
		d = new Date();
		d.setFullYear(year1);
		//SET DATE TO ONE BEFORE SETTING MONTH TO AVOID INVALID DATE ERROR!
		d.setDate(1);
		d.setMonth(month1-1);
		d.setDate(date1);

		//newDateObj.setFullYear(year1);
		//newDateObj.setMonth(month1 - 1);
		//newDateObj.setDate(date1);
		if (date1.length == 1)
			date1 = "0" + date1;
		if (month1.length == 1)
			month1 = "0" + month1;
		sString1 = month1 + "/" + date1 + "/" + year1
		//alert("sString1=" + sString1);

		date2 = (d.getDate()) + "/";
		//alert("date2=" + date2);
		//day2 = getDate();

		month2 = (d.getMonth() + 1) + "/";
		//alert("month2=" + month2);
		//month2 = getMonth();


		s += (d.getMonth() + 1) + "/";
		s += d.getDate() + "/";
		s += d.getYear();
		//alert(s);


		if (date2.length == 2)
			date2 = "0" + date2;
		if (month2.length == 2)
			month2 = "0" + month2;
		sString2 = month2 + date2 + d.getFullYear();
		//alert("sString2=" + sString2);

		if (sString1 == sString2)
		{
			sNewDate = sString1;
			return true;
		}
		else
			return false;

	}
	else
		return false;
}
// eofct: verifyDate()


function StrToNum(uValue) {
/*
  Examines and converts string value to numeric; used for coverage amounts
  created 04/05/01 ROD
*/
	var nValue

	if (uValue != 0)
	{
		while (uValue.indexOf(",") != -1)
		{
			uValue = uValue.replace(",", "")
		}
				
		uValue = uValue * 1
	}

	if (uValue == "")
	{
		uValue = 0
	}

	nValue = uValue
	return nValue
}
// eofct: StrToNum()


function format (expr, decplaces)  {
/*
  embed decimal and comma(s) within numeric string
  created by DRH; modified by ROD for embedded comma support
*/

	var i
	var xstr
	var aseg = new Array()
	var newstr
	var str
	
	// convert expression to numeric; eliminates occassional error in formating
	expr = expr * 1

	str = "" +  Math.round(eval(expr) * Math.pow(10,decplaces))

	while(str.length <= decplaces)
		{
			str = "0" + str
		}
	var decpoint = str.length - decplaces

	// return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);

	// embed comma(s) within the string; borrowed from GCC e-flite
	xstr = str.substring(0,decpoint)

	// determine how many comma segments there are
	i = Math.ceil(xstr.length / 3) - 1
	while (xstr.length > 0)
	{
		// place each segment into array element
		aseg[i] = xstr.substring(xstr.length - 3, xstr.length)
		xstr = xstr.substring(0, xstr.length - 3)
		i--
	}
	
	//  join each array element with a comma and concatenate with decimal portion
	newstr = (aseg.join(",") + "." + str.substring(decpoint, str.length))

	if (gbNav4)
	{
		newstr = padl(newstr,14)
	}

	return newstr
}
// eofct: format()


function checkLogin(sLogin, sPassword) {
/*
	created by ROD
	Invalidats empty login or password
*/
	ret_val = true;
	if (sLogin.length == 0 || sPassword == 0 )
	{
		ret_val = false;
	}
	
	return ret_val;
}
// eofct:


function checkJsEnabled() {
/*
	set hidden value on icl login form
*/
	document.icl_login.jscheck.value = 1;
	//alert("js check = " + document.icl_login.jscheck.value );
	return;
	
}


function NavToDoc(sURL) {
	window.location.href = sURL;
}

function CancelGoBack() {
	history.back()
}

function ShowManual() {
/*
   open icl manual in its own browser window
*/
	var url = "icl_manual.pdf"

	// alert("url = " + url)

	if (gbNav4)
	{
		// need slightly differnt window parms for NS4
		open(url, "Manual", "scrollbars=1"  ).focus();
	}
	else
	{
		// remove third parameter (options) for full-blown browser; note, presence of one optional parameter forces all other settings OFF.
		open(url, "Manual", "toolbar=0, scrollbars=1").focus();
		
		// seems as if only way to resize brower is full-blown (no parameters)
		//open(url, "Manual", "").focus();
	}
		
} 

function iif(bExp, val1, val2) {
/*
	Simulate immediate if function; created ROD/GCC
*/
	var ret_val;

	if (bExp)
		ret_val = val1;
	else
		ret_val = val2;

	return ret_val;
}


// eof:
