<!--

var myAgent = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie = ((myAgent.indexOf("msie") != -1) 
         && (myAgent.indexOf("opera") == -1));
var is_nav = ((myAgent.indexOf('mozilla')!=-1) 
           && (myAgent.indexOf('spoofer')==-1) 
           && (myAgent.indexOf('compatible') == -1) 
           && (myAgent.indexOf('opera')==-1)
           && (myAgent.indexOf('webtv') ==-1) 
           && (myAgent.indexOf('hotjava')==-1));

var is_win = ((myAgent.indexOf("win")!=-1) 
           || (myAgent.indexOf("16bit")!=-1));

var is_mac = (myAgent.indexOf("mac")!=-1);

/**
 *
 * ieSpell API JavaScript
 * Copyright (C) 2002-2004 Red Egg Software. 
 * All rights reserved. 
 *
 * @author Sidney Chong
 * @version $Revision: 1.1 $ $Date: 2004/11/19 16:06:03 $
 * @srcpath $Source: e:/coderepo/iespell/src/app/api/ieSpell.js,v $
 *
 **/

var iespell_url = 'http://www.iespell.com/download.php';
var iespell_spelling_checked_flag = false;

//this function will dynamically determine if ieSpell is installed.
//If YES, a button with the text "Check Spelling" will be shown to the user.
//if NO, a button with the text "Get ieSpell" will be shown instead.
function spellcheckbutton() {
//  try {
//    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
    document.write("<input type='button' name='iespell_check_spelling_button' value='Check Spelling' class='iespell' id='check_spelling_button' onclick='checkdocspelling()'>");
//  } catch(exception) {
//    if (is_ie&&is_win) {
//      document.write("<input type='button' name='btnSpell' value='Get ieSpell' class='forminput' onclick='checkdocspelling()'>");
//    }
//  }
}


//this function will invoke ieSpell on the ENTIRE document.
function checkdocspelling() {
  try {
    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
    tmpis.CheckAllLinkedDocuments(document);
	iespell_spelling_checked_flag = true;
	return true;
  } catch(exception) {
    if (is_ie&&is_win) {
      	//window.open("http://www.iespell.com/download.php","Download");
		alert('You must have ieSpell installed.\nPlease have your system administrator install it.\n It can be downloaded at "' + iespell_url + '".');
		return false;
    }
  }
}

//this function will invoke ieSpell on the specified node. The rest of the document is 
//not touched
function checknodespelling(node) {
  try {
    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
    tmpis.CheckDocumentNode(node);
	iespell_spelling_checked_flag = true;
	return true;
  } catch(exception) {
    if (is_ie&&is_win) {
      	//window.open("http://www.iespell.com/download.php","Download");
		alert('You must have ieSpell installed.\nPlease have your system administrator install it.\n It can be downloaded at "' + iespell_url + '".');
		return false;
    }
  }
}

//this function uses the more advanced document spell check method that does not
//prompts the user with the "Spell Check Completed" message as well as returning a
//FALSE if the user cancels the spell check.
function checkdocspelling2() {
  try {
    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
	iespell_spelling_checked_flag = true;
    return tmpis.CheckAllLinkedDocuments2(document, true);
  } catch(exception) {
    if (is_ie&&is_win) {
      	//window.open("http://www.iespell.com/download.php","Download");
		alert('You must have ieSpell installed.\nPlease have your system administrator install it.\n It can be downloaded at "' + iespell_url + '".');
		return false;
    }
  }
}

//this function uses the more advanced node spell check method that does not
//prompts the user with the "Spell Check Completed" message as well as returning a
//FALSE if the user cancels the spell check.
function checknodespelling2(node) {
  try {
    var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
	iespell_spelling_checked_flag = true;
    return tmpis.CheckDocumentNode2(node, true);
  } catch(exception) {
    if (is_ie&&is_win) {
      	//window.open("http://www.iespell.com/download.php","Download");
		alert('You must have ieSpell installed.\nPlease have your system administrator install it.\n It can be downloaded at "' + iespell_url + '".');
		return false;
    }
  }
}

function check_iespell_complete() {

	if (!iespell_spelling_checked_flag) {
		//checkdocspelling();
	}
	if (!iespell_spelling_checked_flag) {
		alert('You must check the spelling before you can submit this story.');
		return false;
	}
	return true;
	
}


/**
 * End Spell Check Functions
 **/

function check_password(pw,pw_min,pw_max) {
	pw = pw.value;
	var alpha = /[A-Za-z]/;
	var num = /[0-9]/;
	var special = /[!@#$%^&]/;
	if (!pw_min) pw_min = 6;
	if (!pw_max) pw_max = 20;
	var msg = 'Your password must:\n';
	var flag = true;
	if(pw.length < pw_min) {
    	msg += '* be minimum of ' + pw_min + ' characters in length\n';
    	flag = false;
	}
	if(pw.length > pw_max) {
    	msg += '* be maximum of ' + pw_max + ' characters in length\n';
    	flag = false;
	}
	if(!alpha.test(pw)) {
		msg += '* contain at least one alphabetical letter\n';
		flag = false;
	}
	if(!num.test(pw)) {
		msg += '* contain at least one number\n';
		flag = false;
	} 
	if(!special.test(pw)) {
		msg += '* have at least one special character (' + special + ')\n';
		flag = false;
	}
	if(!flag) alert(msg);
	return flag;
}

function show_hide_div(div, state){
	var obj = (document.all) ? document.all[div] : document.getElementById(div);
	obj.style.display = state ? 'inline' : 'none';
}


function confirm_it(num,msg) {
	var flag = 1;
	if (!msg) msg = 'Are you sure you want to do this?';
	if(!confirm(msg)) flag = 0;
	if (num > 1) {
		if(!confirm('Are you really sure you want to do this?')) flag = 0;
	}
	if (num > 2) {
		if(!confirm('Just one more time for good measures!')) flag = 0;
	}
	return flag;
}

function compile_email_link(u,d,s) {
	var js_email = window.open("mailto:" + u + "@" + d + "?subject=" + s);
	js_email.close();
	return true;
}


function check_phone(pn,req,name) 
{
	pn = pn.value;
	if (!name) name = 'phone number';
	if (!pn) {
		if (req) {
			alert("The " + name + " appears to be blank.");
			return false;	
		}
		return true;
	}
	
	var message = "";
	repm = new RegExp(/^^(\([1-9]\d{2}\) |[1-9]\d{2}\-)\d{3}\-\d{4}$$/);
	if (!repm.test(pn)) {
		alert("Then " + name + " must be entered in one of the following formats:\n555-555-1234\n(555) 555-1234");
		return false
	}
	return true;
}

//  check if a text input field has content.
function check_form_text_size(ss,min_len,max_len,name) {
	ss = ss.value;
	var msg = '\'' + name + '\' must:\n';
	if (!min_len) min_len = 1;
	var flag = true;
	if (ss.length < min_len) {
		msg += '* be minimum of ' + min_len + ' characters in length\n';
		flag = false;
	}
	if (max_len && ss.length > max_len) {
		msg += '* be maximum of ' + max_len + ' characters in length\n';
		flag = false;
	}
	if (name && !flag) alert(msg);
	return flag;
}

// check if none of a set of text input field have content.
function none_without_content(ss,name)
 {
	for(var i = 0; i < ss.length; i++)
	{
		if(ss[i].value.length > 0) return false;
	 }
	return true;
 }

// check if the single radio button or checkbox is checked
function check_form_checkbox_checked(ss,msg) {
	var flag = true;
	if(!ss.checked) {
		if (msg) alert(msg);
		flag = false;
	}
	return flag;
 }

// // check set radio buttons or checkboxes for number checked. Defaults to 1.
function check_form_checkbox_set_for_number_checked(ss,min_count,max_count,msg)
 {
	var flag = true;
	var count = 0;
	if (!min_count) min_count = 1;
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].checked) {
			count++;
		}
	}
	if ((count < min_count) || (max_count && count > max_count)) {
		if (msg) alert(msg);
		flag = false;
	}
	return flag;
 }

// check if selected drop-down list or select box for number checked. Defaults to 1.
function form_check_select_for_number_selected(ss,min_count,max_count,msg) {
	var debugmode = false;
	var flag = true;
	var count = 0;
	if (!min_count) min_count = 1;
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].selected) {
			if (debugmode) alert(ss[i].value.length);
			//if(ss[i].value.length > 0) {
				count++;
			//}
		}
	}
	if ((count < min_count) || (max_count && count > max_count)) {
		if (msg) alert(msg);
		flag = false;
	}
	return flag;
}

// check if flag makes required

function check_required(req) {
	var debugmode = false;
	if (req) {
		if (debugmode) alert("required");
		return true;
	}
	if (debugmode) alert("not required");
	return false;
}


function check_email(emailStr,req,name) {

	//emailStr = emailStr.value;
	emailStr = emailStr.toLowerCase();

	if (!name) name = 'email';
	if (!req) req = 1;
	var msg = "Your " + name + " appears to be invalid. ";
	
	//alert('Email is:' + emailStr);
	
	if (!emailStr) {
		if (req) {
			alert(msg + "Email appears to be blank.");
			return false;
		}
		return true;
	}

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@#,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		alert(msg + "Check @ and .'s");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert(msg + "The username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert(msg + "The domain name contains invalid characters.");
			return false;
		}
	}
	
	// See if "user" is valid 
	
	if (user.match(userPat)==null) {
		// user is not valid
		alert(msg + "The username doesn't seem to be valid.");
		return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert(msg + "Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert(msg + "The domain name does not seem to be valid.");
			return false;
		   }
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert(msg + "The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
		alert(msg + "This address is missing a hostname!");
		return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}

function cancel_and_go_back() {
	if(confirm_it(1,'Are you sure you want to cancel?')) {
		history.go(-1);
		return true;
	}
	else {
		return false;
	}
}

function enable_disable_element(v) {
	if (v.disable) {
		v.disabled = false;
	}
	else {
		v.disabled = true;
	}
	return true;
}

function disable_button_on_submit(v,msg) {
	var e = document.getElementById(v);
	if (msg) {
		e.value = msg;
	}
	e.disabled = true;
}


-->