function popup(url, windowName, height, width) {
	newwindow=window.open(url,windowName,'height=' + height + ',width=' + width +', location=0,menubar=0,directories=0,toolbar=1,scrollbars=1,resizable=1');
	if (window.focus) {newwindow.focus()}
}

var printWindowReference;
function openAndPrintWindow(url){
	printwindow = window.open(url,"printWindow", 300, 800 );
	printwindow.print();
}

function sortRows(rowId, columnIdx, skipCharIndex) {

var stIsIE = /*@cc_on!@*/false;

var row = document.getElementById(rowId);


	if (!row || row.tagName != "TR") {
		alert('row not recd in sortRows()')
		return
	}
	
	if (skipCharIndex == undefined)
		skipCharIndex=0;
	
	// if (row.cells[columnIdx].attributes['skipCharIndex'] != undefined && row.cells[columnIdx].attributes['skipCharIndex'] != null)
	//	skipCharIndex = row.cells[columnIdx].attributes['skipCharIndex'].nodeValue;
	
	// alert("skip "+skipCharIndex);
	// alert("th content "+row.cells[columnIdx].innerHTML);
	//alert("class : "+row.cells[columnIdx].class);
	var c = row.parentNode.childNodes;
	var tobeSorted = new Array();
	for (var i=0, tmp; tmp=c[i]; i++) {
		if (tmp != row && tmp.tagName == "TR") {
			var cellContent = new Array();
			
			for (var j=0, jc; jc=tmp.cells[j]; j++)
				cellContent.push(jc.innerHTML);
				
			tobeSorted.push({'row':cellContent, 'col': tmp.cells[columnIdx].innerHTML, 'idx':i, 'skipCharIndex':skipCharIndex} );
			// alert('found row');
		}
	}
	
	// alert('array len: '+tobeSorted.length);
	

	// determine sort order
	if (row.cells[columnIdx].sortOrder == 0)
		row.cells[columnIdx].sortOrder = 1;
	else
		row.cells[columnIdx].sortOrder = 0;
		
	
	tobeSorted.sort(row.cells[columnIdx].sortOrder == 0 ? sortFn : reverseSortFn);
	
	for (var i=0, j=0, tmp; tmp=c[i]; i++) {
		if (tmp != row && tmp.tagName == "TR") {
			for (var k=0, newCell; newCell=tmp.cells[k]; k++)
				newCell.innerHTML = tobeSorted[j].row[k];
			j++;
		}
	}

	// apply sort order mark
	
	var sortMark = document.getElementById("sortMarkId");
	if (sortMark)
		sortMark.parentNode.removeChild(sortMark);
	else {
		sortMark = document.createElement("span");
		sortMark.id = "sortMarkId";
	}
	
	if (row.cells[columnIdx].sortOrder == 0)
		sortMark.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
	else
		sortMark.innerHTML = stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;';
	
	
	row.cells[columnIdx].appendChild(sortMark);	
}

function reverseSortFn(a, b) {
	return -sortFn(a, b);
}


function sortFn(a, b) {

	var c1 = a.col; //.row.cells[a.idx].innerHTML;
	var c2 = b.col; //.row.cells[b.idx].innerHTML;
	
	// alert('a style: '+a.skipCharIndex+' b style: '+b.skipCharIndex);
	// alert("skip "+a.skipCharIndex+" before "+c1+" len "+c1.length);
	
	// skip chars if indicated
	if (a.skipCharIndex < 0) {
		c1 = c1.substr(0, c1.length+a.skipCharIndex);
	} else {
		c1 = c1.substr(a.skipCharIndex);
	}
	
	// alert("after "+c1+" len "+c1.length);
		
	if (b.skipCharIndex < 0) {
		c2 = c2.substr(0, c2.length+b.skipCharIndex);
	} else {
		c2 = c2.substr(b.skipCharIndex);
	}
	
	// try date
	var d1 = Date.parse(c1), d2 = Date.parse(c2);
	if (!isNaN(d1) && !isNaN(d2)) {
		// fix for 2 digit years that JS considers to be 19YY
		// add 100 years! including leap years
		if (d1 < 0) {
			// alert('d1 before '+d1);
			d1 += (100*365 +25)*24*60*60*1000;
			// alert('d1 after '+d1);
		} // else
			// alert('d1 NO fix '+d1);
		
			
		if (d2 < 0) {
			// alert('d2 before '+d2);
			d2 += (100*365 +25)*24*60*60*1000;
			// alert('d2 after '+d2);
		} // else
			// alert('d2 NO fix '+d2);
		
		
		if (d1 < d2)
			return -1;
		else if (d1 > d2)
				return 1;
			else
				return 0;
	}
	
	// try float
	var n1 = new Number(c1), n2 = new Number(c2);
	
	if (!isNaN(n1) && !isNaN(n2)) {
		if (n1 < n2)
			return -1;
		else	if (n1 > n2)
					return 1;
				else
					return 0;
	}
	
	// try currency by checking the first char for $
	var currnRe = /^\$\s*(.+)/;
	
	n1=n2=null;
	var match=c1.match(currnRe);
	if (match != null)
		n1 = new Number(match[1]);
	match=c2.match(currnRe);
	if (match != null)
		n2 = new Number(match[1]);
	
	if (n1 != null && n2 != null && !isNaN(n1) && !isNaN(n2)) {
		if (n1 < n2)
			return -1;
		else	if (n1 > n2)
					return 1;
				else
					return 0;
	}	

	// finally do a character sort
	if (c1.toUpperCase() < c2.toUpperCase())
		return -1;
	else	if (c1.toUpperCase() > c2.toUpperCase())
				return 1;
			else
				return 0;
	
	}
	 
function emailCheckRFC(emailStr) {
	/* 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("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    alert("The part of your email address before the '@' 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("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Part of your email address after the '@' doesn't seem to be valid")
	    return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>6 || IsNumeric(domArr[domArr.length-1])) {
	   // the address must end in a two letter or other TLD including museum
	   alert("The address must end in a top level domain (e.g. .com), or two letter country.")
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   alert(errStr)
	   return false
	}

	// If we've got this far, everything's valid!
	return true;
	}

	 
	function emailCheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address! Please re-enter.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address! Please re-enter.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address! Please re-enter.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address! Please re-enter.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address! Please re-enter.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address! Please re-enter.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address! Please re-enter.")
		    return false
		 }

 		 return true					
	}
	function IsNumeric(sText)
	{
   	//var ValidChars = "0123456789";
   	//var IsNumber=true;
      //var Char;

      var check = true;
      var i = 0;
      var tempChar
 
      for (i = 0; i < sText.length; ++i) {
         tempChar = sText.charAt(i); //cycle through characters
         if(((tempChar < "0") || (tempChar > "9")) && !(tempChar == "")){
            check = false;
            break;
         }
       }
       return check;
   /*
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
      
     return IsNumber;
   */
   }
	
	Date.prototype.format = function(format) {
		var returnStr = '';
		var replace = Date.replaceChars;
		for (var i = 0; i < format.length; i++) {
			var curChar = format.charAt(i);
			if (replace[curChar]) {
				returnStr += replace[curChar].call(this);
			} else {
				returnStr += curChar;
			}
		}
		return returnStr;
	};
	Date.replaceChars = {
		shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
		longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
		shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
		longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
		
		// Day
		d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
		D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
		j: function() { return this.getDate(); },
		l: function() { return Date.replaceChars.longDays[this.getDay()]; },
		N: function() { return this.getDay() + 1; },
		S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
		w: function() { return this.getDay(); },
		z: function() { return "Not Yet Supported"; },
		// Week
		W: function() { return "Not Yet Supported"; },
		// Month
		F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
		m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
		M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
		n: function() { return this.getMonth() + 1; },
		t: function() { return "Not Yet Supported"; },
		// Year
		L: function() { return (((this.getFullYear()%4==0)&&(this.getFullYear()%100 != 0)) || (this.getFullYear()%400==0)) ? '1' : '0'; },
		o: function() { return "Not Supported"; },
		Y: function() { return this.getFullYear(); },
		y: function() { return ('' + this.getFullYear()).substr(2); },
		// Time
		a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
		A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
		B: function() { return "Not Yet Supported"; },
		g: function() { return this.getHours() % 12 || 12; },
		G: function() { return this.getHours(); },
		h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
		H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
		i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
		s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
		// Timezone
		e: function() { return "Not Yet Supported"; },
		I: function() { return "Not Supported"; },
		O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; },
		P: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':' + (Math.abs(this.getTimezoneOffset() % 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() % 60)); },
		T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result;},
		Z: function() { return -this.getTimezoneOffset() * 60; },
		// Full Date/Time
		c: function() { return this.format("Y-m-d") + "T" + this.format("H:i:sP"); },
		r: function() { return this.toString(); },
		U: function() { return this.getTime() / 1000; }
	};	
		
	 