
function mailIt(who,where) {
   emWin=window.open('mailto:'+who+'@'+where,'','');
}
// example of using MailIt
//<a href=javascript:void(0) onclick="mailIt('curtturner','comcast.net)>Curt Turner</a>

function scValidator(formName, validateEmail)
{
	//set error	message
	var	message='';
	var emailAddress = '';

	//loop through form	elements
	for(i=0;i<formName.elements.length;i++)
	{
		//set field	name
		var	formField=formName.elements[i];	

		if (formField.name == 'Email')
		{
			emailAddress = formField.value;
		}

		if(formField.required == 'yes')
		{
			switch(formField.type)
			{
				//text field
				case "password":
				case "text":
				case "select-one":
				case "select-multiple":
					//if empty
					if(formField.value == '')
					{
						//check	to see if message object exists
						if(formField.message)
						{	
							message=message + '\r\n    ' +	formField.message;
						}
						else
						{
							//display field	name if	message	object doesn't exists
							message=message	+ '\r\n    ' + formField.name;
						}
					}
				break; 

				//radio	button 
				case "radio":
					var radioField=formField;
					if (formField.checked == true)
					{
						var radioCheck=true
					}
					if(formField.required == "yes")
					{
						var	radioMessage; 
						var	radioRequired=true;	

						if(formField.message)
						{
							radioMessage = radioField.message;
						}
						else
						{
							radioMessage= formField.name;
						}
					}
					break;

				//check	box
				case "checkbox":
					//if empty
					if(formField.checked ==	false)
					{
						//check	to see if message object exists
						if(formField.message)
						{	
							message=message + '\r\n    ' + formField.message;
						}
						else
						{
							//display field	name if	message	object doesn't exist
							message=message	+ '\r\n    ' + formField.name;
						}
					}
				break;
			}
		}
	}

	//radio	button check addition
	if(radioCheck != true && radioRequired == true)
	{
		message	= message +	'\r\n    ' + radioMessage;
	}

	//display generic button 
	if(message != '')
	{
		message = 'Please fill in the following required fields:\r\n' + message;
		alert(message);
		return false;
	}
	else
	{
		if (validateEmail)
		{
			return eMailCheck(emailAddress);
		}
		return true;
	}
}

function eMailCheck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var error="Your e-mail address is invalid. Please verify that it is entered correctly"

	if (str.indexOf(at)==-1)
	{
	   alert(error)
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert(error)
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert(error)
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert(error)
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert(error)
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert(error)
		return false
	 }
		
	 if (str.indexOf(" ")!=-1){
		alert(error)
		return false
	 }

	 return true					
}

function MouseOver(ctrl, over)
{
	//var cname = type + (over ? '_over': '');
	//ctrl.className = cname;

	var cname = ctrl.className;
	var offset = cname.indexOf('_over');
	
	if (over && (offset == -1))
	{
	   ctrl.className = cname + '_over';
	}
	else
	{
		if (offset > 0)
		{
			ctrl.className = cname.substring(0, offset);
		}
	}
}

// Prevents the user from hitting submit multiple times
function preventMultiSubmit(ctrl)
{
	ctrl.value='Please wait...';ctrl.disabled = true;ctrl.form.submit();
}


// Input restriction functions

function restrictInput(evt, mask)
{
	var key = GetKeyCode(evt);
	if (key == 0)
	{
		// Ignore special keys such as backspace, delete, etc.
		return true;
	}
	return mask.indexOf(String.fromCharCode(key)) >= 0 ? true : false;
}

function restrictNumeric(evt, incSpace)
{
	return restrictInput(evt, incSpace == null || incSpace == true ? '0123456789 ' : '0123456789');
}

function restrictAlpha(evt, incSpace)
{
	var key = GetKeyCode(evt);
	if (key == 0)
	{
		// Ignore special keys such as backspace, delete, etc.
		return true;
	}

	var ch = String.fromCharCode(key);
	if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
	{
		return true;
	}
	
	return (incSpace == null || incSpace == true) && ch == ' ' ? true : false;
}

function restrictAlphaNumeric(evt, incSpace)
{
	return restrictAlpha(evt, incSpace) || restrictNumeric(evt, incSpace);
}
function IsDigit(e)
{
	return restrictInput(e, "0123456789");
}         

function RestrictNumeric2(e)
{
	return restrictInput(e, "0123456789-+.");
}

function IsDateChr(e)
{
	return restrictInput(e, "0123456789/");
}         

function IsDateTimeChr(e)
{
	return restrictInput(e, "0123456789/:amp ");
}         

function IsValidDate(d)
{
	return Date.parse(d) == NaN ? false : true;
}


// ------------------------
// mm/dd/yy Date Validation
// ------------------------

// Valid date character, minimum year and maximum year.
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s)
{
	for (var i = 0; i < s.length; i++)
	{   
		// Check current character is number.
		var c = s.charAt(i);
		if (c < "0" || c > "9")
		{
			return false;
		}
	}
	return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";

	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1)
		{
			returnString += c;
		}
	}
	return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i == 4 || i == 6 || i == 9 || i == 11)
		{
			this[i] = 30
		}
		if (i == 2)
		{
			this[i] = 29
		}
   } 

   return this
}

function IsValidMMDDYYYYDate(dtStr)
{
	var daysInMonth = DaysArray(12);
	var pos1 = dtStr.indexOf(dtCh);
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
	var strMonth = dtStr.substring(0, pos1);
	var strDay = dtStr.substring(pos1 + 1, pos2);
	var strYear = dtStr.substring(pos2 + 1);

	strYr = strYear;

	if (strDay.charAt(0)=="0" && strDay.length > 1)
	{
		strDay = strDay.substring(1);
	}
	if (strMonth.charAt(0)=="0" && strMonth.length > 1)
	{
		strMonth = strMonth.substring(1);
	}
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0) == "0" && strYr.length > 1)
		{
			strYr = strYr.substring(1);
		}
	}
	month = parseInt(strMonth);
	day = parseInt(strDay);
	year = parseInt(strYr);

	if (pos1 == -1 || pos2 == -1)
	{
		// The date format should be: 'mm/dd/yyyy'.
		return false;
	}
	if (strMonth.length < 1 || month < 1 || month > 12)
	{
		// Invalid month.
		return false;
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
	{
		// Invalid day.
		return false;
	}
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
	{
		// Invalid 4 digit year.
		return false;
	}
	if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false)
	{
		// Invalid date.
		return false;
	}

	return true;
}


// ----------------
// Cookie Functions
// ----------------

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {  
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) {    
		var j = i + alen;   
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);   
		i = document.cookie.indexOf(" ", i) + 1;   
		if (i == 0) break;  
	}  
	return null;
}

function setCookie (name, value) {  
	var argv = setCookie.arguments; 
	var argc = setCookie.arguments.length; 
	var expires = (argc > 2) ? argv[2] : null; 
	var path = (argc > 3) ? argv[3] : null; 
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false; 
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + paths)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function deleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function InitTitle(titletext)
{
	// Set title in parent window.
	var title = parent.document.getElementById("ttltext");
	if (title != null)
	{
		title.innerText = titletext;
	}
}

function SetPageTitle(titleTxt)
{
	// Set page title text in parent window.
	var title = parent.document.getElementById("ttltext");
	if (title != null)
	{
		title.innerText = titleTxt;
	}
}

function LoadPage(page)
{
    top.frames.cdMain.location.href = page;
}

function DetectPopupBlocker(e)
{
    if(!e)
        alert('We have detected that you are using popup blocking software. Please set your popup blocker to allow popups from our site.');

}
