function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isArray(com) {
	if (typeof(com.length) == "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function isArraySelectBox(com) {
	if (typeof(com[0].length) == "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function trim(str) {
	var strTrim = "";
	var i, j;
	
	if (isEmpty(str)) return strTrim;
	
	for (i=0; i<str.length; i++) {
		if (str.charAt(i) != " ") break;
	}
	for (j=str.length-1; j>=0; j--) {
		if (str.charAt(j) != " ") break;
	}
	
	strTrim = str.substr(i, j-i+1);
	return strTrim;
}

function isEmpty(str) {
	return ((str==null) || (str.length==0));
}

function isWhiteSpace(str) {
	return isEmpty(trim(str));
}

function isDigit(d) {
	return ((d >= "0") && (d <= "9"));
}

function isLetter(c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));
}

function isNumeric(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isDigit(chr)) {
			return false;
		}
	}
	return true;
}
function isInteger(s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isFloat(s){
  var i;
  var seenDecimalPoint = false;
  if (isEmpty(s)) 
    if (isFloat.arguments.length == 1) return false;
    else return (isFloat.arguments[1] == true);
  if (s == '.') return false;
  for (i = 0; i < s.length; i++){   
    var c = s.charAt(i);
    if ((c == '.') && !seenDecimalPoint) 
	  seenDecimalPoint = true;
    else if (!isDigit(c)) return false;
  }
  return true;
}

function isDate (year,month,day) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) )
        return true;
    else
        return false
}


function isAlphaNumeric(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isDigit(chr) && !isLetter(chr)) {
			return false;
		}
	}
	return true;
}

function isAlphaOnly(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isLetter(chr)) {
			return false;
		}
	}
	return true;
}

function isRange(formObj, min, max)
{
	if(formObj.length < min || formObj.length > max)
	{
		return false;
	}
	return true;
}


function isEmail(s)
{   
	
	//alert(s); 
   	// is s whitespace?
    //if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++;
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else
	return true;
}

//Function to check whether the string is a valid integer
//Function to check whether the zipcode is a valid US zip code
function isZIPCode(field) 
{
	var valid = "0123456789";
	var hyphencount = 0;
	
	if (field.length!=5) {
	alert("Please enter your 5 digit zip code.");
	return false;
	}
	for (var i=0; i < field.length; i++) {
	temp = "" + field.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
	alert("Invalid characters in your zip code.  Please try again.");
	return false;
	}

	}
	return true;
}

function isMoney(str) 
{
	var valid = "0123456789.-"
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			//ok = "no";
			return false;
	}
	return true;
}

function isPhoneNumber(str) 
{
	var valid = "0123456789()-"
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			//ok = "no";
			return false;
	}
	return true;
}

function isCheckedRadio(objRadio) {
	checked = false;
	if (objRadio) {
		count = objRadio.length;
		if(typeof(count) == 'undefined') {
			checked = objRadio.checked;
		} 
		else {
			for(var i=0; i<count; i++) {
				if(objRadio[i].checked) {
					checked = true;
				}
			}
		}
	}
	return checked;
}

function getRadioVal(objRadio) {
	checked = false;
	if (objRadio) {
		count = objRadio.length;
		if(typeof(count) == 'undefined') {
			checked = objRadio.value;
		} 
		else {
			for(var i=0; i<count; i++) {
				if(objRadio[i].checked) {
					checked = objRadio[i].value;
				}
			}
		}
	}
	return checked;
}


function isSelected(frmObjSelect)
{
	if (frmObjSelect.value == -1) {
		return false;
	}
	else {
		return true;
	}
}


function popupNameWindow(page_url,name, width, height, opt) {
	temp= window.open(page_url,name,'width='+width+',height='+height+','+opt);
	temp.focus();
	
}

function popupWindow(page_url, width, height, opt) {
	window.open(page_url,'popup_window','width='+width+',height='+height+','+opt);
}

function nameWindow(page_url,name, width, height, opt) {
	temp = window.open(page_url,name,'width='+width+',height='+height+','+opt);
	temp.focus();
}

function printWindow(page_url,width,height) {
	temp = window.open(page_url,'popup_window','width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=1,menubar=0,scrollbars=1');
	temp.focus();
	
}


function imgView(img_obj) {
	if(window.popup != undefined) window.popup.close();
	if (typeof(img_obj) == 'string') {
		var win_scrollbars = 'no';
		var width_plus = 0;
		var img_name = img_obj;
	} else if (img_obj.height > 400) {
		var win_scrollbars = 'yes';
		var width_plus = 20;
		var img_name = img_obj.src;
	} else {
		var win_scrollbars = 'no';
		var width_plus = 0;
		var img_name = img_obj.src;
	}
	popup = window.open('about:blank','imgView','width=10,height=10, toolbar=0,menubar=0,resizable=yes,scrollbars='+win_scrollbars+', top=50, left=50');
	popup.document.writeln('<html><title>Photo Viewer</title>'
		+ '<body topmargin="0" rightmargin="0" leftmargin="0" bgcolor="#FFFFFF">'
		+ '<sc'+'ript>function reSize() { if(document.all("pre_img").width > 0) resizeTo(((document.all("pre_img").width > 800)?800:document.all("pre_img").width) + 10 + '+width_plus+',((document.all("pre_img").height > 900)?900:document.all("pre_img").height) + 80);} </scr'+'ipt>'
		+ '<img src=' + encodeURI(img_name) + ' border=0 onclick=self.close() style="cursor:hand" name=pre_img id=pre_img onload="reSize()">'
		+ '');
}

function mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + location.href; 
location.href = mail_str;
}