function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


var submitcount=0;

function checkSubmit(){
  if(submitcount == 0){
	  submitcount++;
	  document.Surv.submit();
  }
}

function textCounter(field, countfield, maxlimit) {
  if(field.value.length > maxlimit){
      field.value = field.value.substring(0, maxlimit);
  }else{
  	  countfield.value = maxlimit - field.value.length;
  }
}

function countText(val, field) {
  field.value = val.length;
}

function checkrequired(which) {

var pass = true;
var num_chars = 9;

if (document.images) {

	for (i = 0; i < which.length; i ++) {
	var tempobj = which.elements[i];

		if (tempobj.name.substring(0,num_chars) == "required_") {
			if (((tempobj.type == "text" || tempobj.type == "textarea") &&
				tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" &&
				tempobj.selectedIndex == 0)) {
				pass = false;
				break;
      }
    }
  }
}

if (!pass) {
	shortFieldName = tempobj.name.substring(num_chars,30).toUpperCase();
	alert("Please enter a value in the " + shortFieldName + " field.");
	return false;
}
else
	return true;
}

// java pane window
function tips(){
open('tips.php','help', 'toolbar=no,menubar=no,scrollbars=1,width=450,height=400,resizable=no,screenX=690,screenY=350')
}

function adminhelp(){
open('admin-help.php','help','toolbar=no,menubar=no,scrollbars=1,width=650,height=600,resizable=no,screenX=690,screenY=350')
}

function insertcode(tag, desc)
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our open tag
    var open = "<" + tag + ">";

    // our close tag
    var close = "</" + tag + ">";

    if(!textarea.setSelectionRange)
    {
        var selected = document.selection.createRange().text;
        if(selected.length <= 0)
        {
            // no text was selected so prompt the user for some text
            textarea.value += open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }
        else
        {
            // put the code around the selected text
            document.selection.createRange().text = open + selected + close;
        }

    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the selected text with tags before and after
        var codetext = open + textarea.value.substring(textarea.selectionStart, textarea.selectionEnd) + close;

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // check if there was a selection
        if(codetext == open + close)
        {
            //prompt the user
            codetext = open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }

        // update the text field
        textarea.value = pretext + codetext + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts an image by prompting the user for the url
function insertimage()
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our image
    var image = "<img src='" + prompt("Please enter the url", "http://") + "' />";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the image to the end
            textarea.value += image;
        }
        else
        {
            // replace the selection with the image
            document.selection.createRange().text = image;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + image + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts a link by prompting the user for a url
function insertlink()
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our link
    var url = prompt("Please enter the url", "http://");
    var link = "<a href=" + url + ">" + url + "<\/a>";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the link to the end
            textarea.value += link;
        }
        else
        {
            // replace the selection with the link
            document.selection.createRange().text = link;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + link + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}

// inserts a mailto by prompting the user for a url
function insertmail()
{
    // our textfield
    var textarea = document.getElementById("required_content");

    // our link
    var url = prompt("Please enter the email address", "mailto:");
    var link = "<a href=" + url + ">" + url + "<\/a>";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text;

        if(selected.length <= 0)
        {
            // no text was selected so add the link to the end
            textarea.value += link;
        }
        else
        {
            // replace the selection with the link
            document.selection.createRange().text = link;
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length)

        // update the text field
        textarea.value = pretext + link + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}