var win;
var doc;
var frm;

function init() {
    win = window;
    doc = document;
    frm = document.forms[0];
    
    chgCursor();
    
}

function getSelected(pFld) {

    obj = doc.getElementById(pFld);
    if (obj) {
        return obj.options[obj.selectedIndex].value;
    }
}

function validateNewEvent() {
    var sMsg = "";

    //Check a proper category has been selected
    obj = doc.getElementById('fldcategory');
    if (obj.options[obj.selectedIndex].value == "%") {sMsg += "\nSelect event type.";}
    
    //Check other fields have been completed
    if (doc.getElementById('flddate').value == "") {sMsg += "\nEnter a date.";}
    if (doc.getElementById('fldshortdescription').value == "") {sMsg += "\nenter a short description.";}
    
    if (sMsg == "") {
        return true;
    } else {
        alert("Please correct the following issues:\n" + sMsg);
        return false;
    }
}

function validateForm(pstrFld, pstrLbl) {
    var sMsg = "";
    var arrFld = new Array();
    var arrLbl = new Array();
    
    //Put passed strings into arrays
    arrFld = pstrFld.split(", ");
    arrLbl = pstrLbl.split(", ");
    
    //check fields have a value
    for (intLoop=0; intLoop<arrFld.length; intLoop++) {
        obj = doc.getElementById(arrFld[intLoop]);
        if (obj) {
            if(obj.value == "") {
                if (sMsg == "") {
                    sMsg = arrLbl[intLoop]; 
                } else {
                    sMsg += ", " + arrLbl[intLoop];
                }
            } else {
                if (arrFld[intLoop].indexOf("email") > -1) {
                    if (validateEmail(arrFld[intLoop]) == false) {
                        if (sMsg == "") {
                            sMsg = "Valid email address";
                        } else {
                            sMsg += ", valid email address";
                        }
                    }
                }
            }
        }
    }
    
    if (sMsg == "") {
        return true;
    } else {
        alert("Please correct the following details:\n\n"+sMsg+".");
        return false;
    }
}

//Validate an email address
function validateEmail(pstrFld) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var sEmail = doc.getElementById(pstrFld).value;
   if(reg.test(sEmail) == false) {return false;} else {return true;}
}

//Function to set all buttons with a mouseover event
function mouseover() {
    this.style.cursor = 'pointer';
    this.style.textDecorationUnderline = true;
}
function mouseout() {
    this.style.textDecorationUnderline = false;
}
function chgCursor() {
    var btns = doc.getElementsByTagName("input");
    for (intLoop=0; intLoop<btns.length; intLoop++) {
        if (btns[intLoop].className == "btn"){
            btns[intLoop].onmouseover = mouseover;
            btns[intLoop].onmouseout = mouseout;
        }
    }
    
    var tds = doc.getElementsByTagName("td");
    for (intLoop=0; intLoop<tds.length; intLoop++) {
        if (tds[intLoop].name == "minievent"){
            tds[intLoop].onmouseover = mouseover;
            tds[intLoop].onmouseout = mouseout;
        }
    }
    
    
}

function chgCategory(obj) {
    frm.submit();
}

window.onload = function()
  {
	init();

      /*
      The new 'validTags' setting is optional and allows
      you to specify other HTML elements that curvyCorners
      can attempt to round.

      The value is comma separated list of html elements
      in lowercase.

      validTags: ["div", "table"]

      The above example would enable curvyCorners on FORM elements.
      */

      settings = {
          tl: { radius: 5 },
          tr: { radius: 5 },
          bl: { radius: 0 },
          br: { radius: 0 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }

      var myBoxObject = new curvyCorners(settings, "myBox");
      myBoxObject.applyCornersToAll();
  }

  function changeAlbumPicture(pic) {
    pic = pic.replace("#", "'");
    document.getElementById('bigdiv').style.display='inline'; 
    document.getElementById('bigpicture').src=pic;
  }
  
  function showPic(url)
{
  url = url.replace("#", "'");
  if (window.showModalDialog)
  {
    winval = window.showModalDialog(url, null, "dialogWidth:800px; dialogHeight:600px; center:yes; scroll:no; status:no;");
  }
  else
  {
    window.top.captureEvents (Event.CLICK|Event.FOCUS);
    window.top.onfocus=HandleFocus;
    winval = window.open (url,"", "width=800px; height=400px; toolbar=no; status=no; scrollbars=no;resizable=no;");
    winModalWindow.focus();
  }
  
}

 
function HandleFocus()
{
  if (winModalWindow)
  {
    if (!winModalWindow.closed)
    {
      winModalWindow.focus();
    }
    else
    {
      window.top.releaseEvents (Event.CLICK|Event.FOCUS);
      window.top.onclick = "";
    }
  }
  return false
}

function hidestatus(){
	window.status='';
	return true;
}
if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
document.onmouseover=hidestatus
document.onmouseout=hidestatus
