function emptyField(obj) {

	switch(obj.type){
		case "text" :
			if (obj.value.length == 0) return true;
			for (var j=0; j<obj.value.length; ++j) {
				var ch = obj.value.charAt(j);
				if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n') return false;
			}
			return true;
			break;
		case "textarea" :
			if (obj.value.length == 0) return true;
			for (var j=0; j<obj.value.length; ++j) {
				var ch = obj.value.charAt(j);
				if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n') return false;
			}
			return true;
			break;
		case "select-one" :
			return (obj[obj.selectedIndex].value.length == 0);
			break;
		default : 
			return true;
	}
}

function CString(number) {
	number += "";
	return number;
}

function ltrimjs(str) {
	while('' + str.charAt(0) == ' ')
		str = str.substring(1,str.length);
	return str;
}

function rtrimjs(str) {
	while('' + str.charAt(str.length-1) == ' ')
		str = str.substring(0,str.length-1);
	return str;
}

function xtrimjs(str) {
	return ltrimjs(rtrimjs(str));
}

function trimstring(str) {
	return xtrimjs(str.value);
}

function hourpart(mytime) {
var colonpos=(mytime.indexOf(':'));
if ((colonpos!=1) && (colonpos!=2)) {
	colonpos=(mytime.indexOf('.'));
}
if ((colonpos!=1) && (colonpos!=2)) {
		return false;
	}
	else {
		if (colonpos==1) 
			return mytime.substring(0,1);
		else
			return mytime.substring(0,2);
	}	
}

function minutepart(mytime) {
var colonpos=(mytime.indexOf(':'));
if ((colonpos!=1) && (colonpos!=2)) {
	colonpos=(mytime.indexOf('.'));
}
if ((colonpos!=1) && (colonpos!=2)) {
	return false;
} else {
	if (colonpos==1) 
		return mytime.substring(2,4);
	else
		return mytime.substring(3,5);
}
}

function invalidtime(mytime) {
	if (mytime.length == 0) {
		return false;
	} else if ((mytime.length!=4) && (mytime.length!=5)) {
		return true;
	} else {
		var colonpos=(mytime.indexOf(':'));
		if ((colonpos!=1) && (colonpos!=2)) {
			colonpos=(mytime.indexOf('.'));
		}
		if ((colonpos!=1) && (colonpos!=2)) {
			return true;
		} else {
			var hh, mm;
			if (colonpos==1) {
				hh = mytime.substring(0,1);
				mm = mytime.substring(2,4);
			} else {
				hh = mytime.substring(0,2);
				mm = mytime.substring(3,5);
			} 
			if (isNaN(hh)) {
				return true;
			}
			if ((parseInt(hh)<0) || (parseInt(hh)>23)) {
				return true;
			}
			if (isNaN(mm)) {
				return true;
			}
			if ((parseInt(mm)<0) || (parseInt(mm)>59) || (mm.length!=2)) {
				return true;
			}
			
		}
		return false;
	}
}

function sbar(text) {
    window.status=text;
    return true
    }
    
function nolink()
	{ alert("This link would normally take you to a further page of information, but has been disabled within this free tour."); }
    
function advpopup(URL, title, x, y) {
	var windowprops='location=yes,scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes,left=100,top=100,width='+x+',height='+y+';'
	popup1=window.open(URL,title,windowprops);
	popup1.focus()
    }
    
function popup(URL, x, y) {
	var windowprops='location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,left=100,top=100,width='+x+',height='+y+';'
	popup1=window.open(URL,'popup',windowprops);
	popup1.focus()
    }
    
function rclick() {
    if (document.images) {
    	for(i=0;i<document.images.length;i++) {
		    if (document.images[i].name=='protect') {
		        document.images[i].onmousedown = click;
                }			    
		    }
	    }
    }
    
function click(e) {

    // blocks right-click but not left (in MSIE & Netscape). Adapted from http://www.rgagnon.com/jsdetails/js-0061.html
    
    if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
        alert("Sorry, this image is protected");
        return false;
        }
    else {
        if (navigator.appName == 'Netscape' && e.which == 3) {
            alert("Sorry, this image is protected");
            return false;
            }
        }            
   return true;
}

function nospam(user, domain, name) {
    document.write('<a href=\"mailto:' + user + '@' + domain + '\">');
    document.write(name + '</a>');
    }
    
function MM_preloadImages() { //v1.2 Nykris
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    var theIndex = 0;
    if (document.preloadArray == null)
      document.preloadArray = new Array();
    theIndex = document.preloadArray.length;
    for (var i=0; i<imgFiles.length; i++) {
      document.preloadArray[theIndex] = new Image;
      document.preloadArray[theIndex].src = imgFiles[i];
      theIndex++;
    }
  }
}

function MM_swapImage() { //v1.2
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}

function MM_swapImgRestore() { //v1.2
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function ExpandControl(flag,controller,body) {
    if(flag=='show') {
        var rep = new RegExp("show","gi"); //regular expression - replace all instances, case-insensitive
        document.getElementById(body).style.display="";
        document.getElementById(controller).innerHTML=document.getElementById(controller).innerHTML.replace(rep,"hide")
        }
    else {
        var rep = new RegExp("hide","gi"); //regular expression - replace all instances, case-insensitive
        document.getElementById(body).style.display="none";
        document.getElementById(controller).innerHTML=document.getElementById(controller).innerHTML.replace(rep,"show")
    }    
}

function jumptosection(anchor,collapsiblesectionid) {
    ExpandControl('show','control' + collapsiblesectionid,'collapse' + collapsiblesectionid)
    window.location.hash=anchor; 
}

function GetXmlHttpObject()
{
var xmlHttp = null;
try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
    }
catch (e)
    {
    // Internet Explorer
    try
        {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
    catch (e)
        {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
return xmlHttp;
}

function poll(mode, frm, adest)
{
    var d = new Date();
    var chosen = "";
    //get selected option(s)
    var len = frm.polloptionid.length;
    for (var i = 0; i <len; i++) {
        if (frm.polloptionid[i].checked) {
            chosen = chosen + frm.polloptionid[i].value + ',';
        }
    }
    new Ajax.Updater(adest, '../common/ajax/poll.asp', { 
        method: 'get',
        parameters: {mode: mode, p: frm.pollid.value, o: chosen, timestamp: d.getTime() }
    });
}

function pollresults(id,adest)
{
    var d = new Date();
    new Ajax.Updater(adest, '../common/ajax/poll.asp', { 
        method: 'get',
        parameters: {mode: 'results', p: id, timestamp: d.getTime() }
    });
}

function validatepoll(frm)
{
    var chosen = '';
    //get selected option
    var len = frm.polloptionid.length;
    for (var i = 0; i <len; i++) {
        if (frm.polloptionid[i].checked) {
            chosen = frm.polloptionid[i].value;
        }
    }    
    if(chosen=='') alert('Please select an option before clicking the Vote button!');                    
    return (chosen!='');
}

//startList = function() {
//if (document.all&&document.getElementById) {
        //navRoot = document.getElementById("dropdownmenu");
        //if(navRoot) {
            //for (i=0; i<navRoot.childNodes.length; i++) {
                //node = navRoot.childNodes[i];
                //if (node.nodeName=="LI") {
                    //node.onmouseover=function() {
                        //this.className+=" over";
                    //}
                    //node.onmouseout=function() {
                        //this.className=this.className.replace(" over", "");
                    //}
                //}
            //}
        //}
    //}
//}
//window.onload=startList;

function selectable(option,sel) 
{
    var chosen = 0;
    var len = option.form.polloptionid.length;
    //how many options are selected?
    for (var i = 0; i <len; i++) {
        if (option.form.polloptionid[i].checked) {
            chosen++;
        }
    }
    if (option.checked) {
        if (chosen>=sel) {
            // disable any unchecked options
            for (var i = 0; i <len; i++) {
                if (!option.form.polloptionid[i].checked) {
                    option.form.polloptionid[i].disabled=true;
                }
            }
        }
    }        
    else {
        if (chosen<sel) {
            // enable any disabled options
            for (var i = 0; i <len; i++) {
                if (option.form.polloptionid[i].disabled) {
                    option.form.polloptionid[i].disabled=false;
                }
            }
        }
    }    
}   
    
function cancel(adest)
{
    $(adest).innerHTML = '';
    $(adest).style.display = 'none';
}

function get_check_value(obj)
{
if (obj.checked)
    {
      return obj.value;
    }
else
    {
      return false;
    }
}

function get_select_value(obj)
{
	switch(obj.type){
		case "select-one" :
			return (obj[obj.selectedIndex].value);
            break;
        case "text" :
			return (obj.value);
            break;
        case "textarea" :
			return (obj.value);
            break;
        default:
            return null;
    }
}            

function selecttext(obj)
{
	switch(obj.type){
		case "text" :
			obj.focus();
			obj.select();
			break;
		case "textarea" :
			obj.focus();
			obj.select();
			break;
	}
}

function isUpperCase(string) {
    // considers a string to be upper-case if it contains no lower-case letters (regardless of what other characters appear). 
    // e.g. isUpperCase('123') returns True, but isUpperCase('ABCDEf') returns False. isUpperCase('') returns False.
    return /^[^a-z]+$/.test(string) 
}

function togglecase(obj,initialcap)
{
	if(obj.type=='text'|obj.type=='textarea'){
	    if(isUpperCase(obj.value)) 
	        if(initialcap)
	            obj.value = obj.value.charAt(0).toUpperCase() + obj.value.substr(1).toLowerCase()
            else
                obj.value = obj.value.toLowerCase()
        else	        
	        obj.value = obj.value.toUpperCase()
	}
}

function waiting(dest) {
    $(dest).innerHTML = '<img src="/i/gen/ajax-loader.gif" width="16" height="16" alt="waiting" />'
}
