function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
   test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}

function fnUpdate() {
	var dblPrice = document.getElementById("hdnPrice").value;
	var intPlaces = document.getElementById("sltPlaces").value;
	
	document.getElementById("hdnTotalPrice").value = (intPlaces * dblPrice).toFixed(2);
	document.getElementById("priceUpdate").innerHTML = (intPlaces * dblPrice).toFixed(2);
} //fnUpdate

var Site = {
    init: function() {
        Site.editor();
        Site.preview();
    },

    editor: function() {
        if ($('content') || $('events')) {
            tinyMCE.init({
                mode: "textareas",
                editor_selector: "textareaLarge",
                theme: "advanced",
                theme_advanced_buttons1: "undo,redo,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,link,unlink",
                theme_advanced_buttons2: "formatselect,fontsizeselect,forecolor,|,image,charmap,|,spellchecker",
                theme_advanced_buttons3: "",
                theme_advanced_blockformats: "p,h1,h2,h3",
                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                theme_advanced_resizing: true,
                theme_advanced_resize_horizontal: false,
                theme_advanced_statusbar_location: "bottom",
                cleanup_on_startup: true,
		paste_auto_cleanup_on_paste: true, 
                plugins : "inlinepopups,spellchecker,contextmenu"
            });
        }
    },

    preview: function() {
        if ($('formPreview')) {
            $('previewSubmit').addEvent('click', function() {
                var message = '';
                if ($('title').value == '') message += 'Please enter in a title\n';
                if (tinyMCE.get('content').getContent() == '') message += 'Please enter in a page content\n';
                if ($('images[1]').value == '0') message += 'Please select image (top)\n';
                if ($('images[2]').value == '0') message += 'Please select image (side)\n';

                if (message == '') {
                    $('previewTitle').value = $('title').value;
                    $('previewContent').value = tinyMCE.get('content').getContent();
                    $('previewImage1').value = $('images[1]').value;
                    $('previewImage2').value = $('images[2]').value;
                    $('formPreview').submit();
                } else {
                    alert('Please correct the folowing error(s):\n\n' + message);
                }
            });
        }
    }
};

window.addEvent('domready', Site.init);

