var reqDone;

if (jQuery) {
	
	jQuery(function () {
		
		jQuery('FORM.sectionForm').submit(function () {
			
			var res = validateForm(this, {FailClass : 'inputError'});
			return res;
			
		}); //jQuery each form
	
	}); //jQuery onLoad
	
	jQuery('.sendFriend').click(sendToFriend);
	jQuery('.printPage')
		.unbind('click')
		.click( function () {
		
		var rel = jQuery(this).attr('rel');
		
		if ( rel )
			PrintPage(rel);
		
		return false;
	}); //jQuery .printpage click 
	
} else {
/**/	
    $$('form').each( function (item) {
        item.observe('submit', function (event) {
            item.$$('.required').each (
                function (item) {
                    if (!item.value) {
                        item.setStyle( { backgroundColor: 'yellow' } );
                        Event.stop(event);
                        if (!reqDone) {
                            reqDone=true;
                            alert('Please complete the required fields [marked in yellow]');
                        }
                    }
                }
            );
        });
    });

    $$('.sendFriend').each( function (item) {
        item.observe('click', function (event) {
            window.open('/sendfriend/','sendToFriend','toolbar=0,status=0,width=320,height=400');
            event.cancel=true;
        });
    });

    $$('.printPage').each( function (item) {
        item.observe('click', function (event) {
            item=Event.element(event);
            rel=item.getAttribute('rel');
            win=window.open('#','printPage','toolbar=0,status=0,width=320,height=400');
            win.document.write($(rel).innerHTML);
            win.print();
            event.cancel=true;
        });
    });
    /**/
} 

/*--------------------------------------------------------------------------------*\
|	PrintPage
|----------------------------------------------------------------------------------
| Initiates "Print page" dialog.
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|	Params:
|		content	string	- Content element ID.
|	Return:
|			bool	- Always false.
\*--------------------------------------------------------------= by Mr.V!T =-----*/
function PrintPage(content) {
	
	var el = document.getElementById(content);
	if ( !el ) return false;
	
	var text = el.innerHTML;
	
	win=window.open('#','printPage','toolbar=0, status=0, width=320, height=400, scrollbars=1');
	win.document.write(text);
/**/	
	win.document.close();  
	win.focus();  
	win.window.print(); 
/*/
	win.print();
/**/
	return false;
} //FUNC PrintPage

/*--------------------------------------------------------------------------------*\
|	sendToFriend
|----------------------------------------------------------------------------------
| Initiates "Send to Friend" dialog.
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|	Params:
|		event	object	- Callback event object.
|	Return:
|			bool	- Always false.
\*--------------------------------------------------------------= by Mr.V!T =-----*/
function sendToFriend (event) {
	window.open('/sendfriend/','sendToFriend','toolbar=0,status=0,width=320,height=400');
	event.cancel=true;
	return false;
} //FUNC sendToFriend
