messageObj = new DHTML_modalMessage();	// We only create one object of this class
messageObj.setShadowOffset(3);	// 5=Large shadow

// Form validation
function validateEmpty(fld, strMsg, minLen, intValMin) {
	var error = "";

	if (fld.value.length < minLen || (intValMin > 0 && fld.value < intValMin)) {
		fld.style.background = 'Yellow'; 
		error = "- Specify " + strMsg + ' (Min of ' + minLen + ' characters)\n'
	} else {
		fld.style.background = 'White';
	}
	return error;  
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function confirmThis(what, url)
{
	if (confirm("Are you sure you want to " + what + "?"))
	{
		location = url;
	}
}
function openSmilies() {
	smileyWin = window.open('emoticons.asp','emoticons','width=400,height=300,scrollbars=yes')
}
function addemoticon(text) {
	var tarea = document.newmsg.body;
	if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
		start = tarea.selectionStart;
		end = tarea.selectionEnd;
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
		tarea.selectionEnd = start + text.length;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}

function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

function displayStaticMessage(messageContent,cssClass,w,h)
{
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(w,h);
	messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
}

function displayOkMessage(messageContent,w,h)
{
	messageContent = messageContent + '<br /><br /><div align=center><div style=\'width:60px;\'><a class=\'roundbutton\' onclick=\'this.blur(); closeMessage()\'><span>Ok</span></a></div>'
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(w,h);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
}

function displayStaticYesNo(messageContent,cssClass,w,h)
{
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(w,h);
	messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
}

function closeMessage()
{
	messageObj.close();	
}

function forumSearch() {
	var frm = document.getElementById("forumsearch");
	var q = document.getElementById("q").value;
	if (q == "" || q == "Search topics") {
		alert("Please enter something to search for in the search input box.");
	} else {
		frm.submit();
	}
	return false;
}

function translatePage() {
	var frm = document.getElementById("frmTranslate");
	var q = document.getElementById("langpair").value;
	if (q == "" || q == "help") {
		displayStaticMessage("Please select a language to translate this page to.<p>Note that this feature will not work on pages which require you to be logged in.</p><p><a href=\'#\' onclick=\'closeMessage();return false\'>Close</a></p>", false, 400, 125);
//		alert("Please select a language to translate this page to.\n\nPlease note that this feature will not work on pages which require you to be logged in.");
	} else {
		frm.submit();
	}
	return false;
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

// getSelectedRadioValue(document.forms['frm1'].fieldName)
function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

// Used for FLOW+ and photos
function flowIbox(url) {
	document.getElementById('flash').style.visibility = "hidden";

	showIbox(url,'','')
	showBG();
	window.onscroll = maintPos;
	window.onresize = maintPos;
}