function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {oldonload();}
      func();
    }
  }
}



wf.showAlertOnError = false;
wf.functionName_formValidation = "myCustomValidation";

function myCustomValidation (evt) {
	
	var formElement = wf.utilities.getSrcElement(evt); 
	
	if(wf.formValidation(evt)) {
		if(formElement.id == "frmSendPage") {
			new Ajax.Updater('result', 'http://www.citylit.ac.uk/business/sendpage.php',{

			onLoading:function(request){sendpage()},
			onComplete:function(request){handelrequest()},parameters:Form.serialize(document.forms['frmSendPage']), insertion:Insertion.Bottom, asynchronous:true});
			return wf.utilities.XBrowserPreventEventDefault(evt);
		}
		
		/*if(formElement.id == "comment_form") {
					// grab the comment form default action
					var com_action = $('comment_form').action;

					new Ajax.Request(com_action,{

					onLoading:function(request){sendcomment()},
					onSuccess:function(request){handelcomrequest()},parameters:Form.serialize(document.forms['comment_form']), asynchronous:true});
					return wf.utilities.XBrowserPreventEventDefault(evt);
				}
				
				if(formElement.id == "frm_mailing") {
					new Ajax.Updater('result', '/send_mailing_list.php',{

					onLoading:function(request){sendmail()},
					onComplete:function(request){handelmailing()},parameters:Form.serialize(document.forms['frm_mailing']), insertion:Insertion.Bottom, asynchronous:true});
					return wf.utilities.XBrowserPreventEventDefault(evt);
				}*/
}	
}

function sendpage() {
	new Effect.Appear('progress');
}

function handelrequest() {
	new Effect.Fade('progress', {delay: 3.0});
	new Effect.BlindUp('stfWrap', {delay: 0.0});
	new Effect.Appear('result', {delay: 4.0});
	
	$$('#form_switch').each ( function(element) {
			
			// set a click event on the links
			Event.observe(element, 'click', function(event) {
				Event.stop(event);
				resetForm();
            }); // event observe
		}
	);
	
function resetForm() {
$('frmSendPage').enable();
$('frmSendPage').reset();

$('result').update('');
new Effect.Fade('result');
new Effect.BlindDown('stfWrap');

if ($('hide_form')) {
$('hide_form').show();
}
}
	
}


function prepareLinks(){
		
$$('div#imageGallery a').each ( function(element) {
	
	// set a click event on the links
	Event.observe(element, 'mouseover', function(event) {
	Event.stop(event);
					
	$$('#imageGallery a').each ( function(element) { element.removeClassName('active'); });

	/*$('img_preview').src = this;*/
    element.className = "active";
	var theImage = element.href;
	var altAttr = element.title;

	$('imgPreview').src = theImage; 
	$('imgPreview').alt = altAttr; 
	
	}); // event observe
	
	// set a click event on the links
	Event.observe(element, 'click', function(event) {
	Event.stop(event);
	}); // event observe

});


$$('a#printPage').each ( function(element) {
	
	// set a click event on the links
	Event.observe(element, 'click', function(event) {
	Event.stop(event);
					
	window.print();
	
	}); // event observe

});

$$('a#emailPage').each ( function(element) {
	
	// set a click event on the links
	Event.observe(element, 'click', function(event) {
	Event.stop(event);
					
	new Effect.toggle('stfWrap', 'slide');
	$('result').hide();
	/*$('frm_yname').focus();*/
	
	}); // event observe

});

$$('a#stfCancel').each ( function(element) {
	
	// set a click event on the links
	Event.observe(element, 'click', function(event) {
	Event.stop(event);
					
	new Effect.toggle('stfWrap', 'slide');
	
	}); // event observe

});




		
}	
	
addLoadEvent(prepareLinks);
