var reqDone;

if (jQuery) {
	
	jQuery('.sendFriend').click(sendToFriend);
	jQuery('.printPage').click(PrintPage);
	
} 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:
|		event	object	- Callback even object.
|	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');
	win.document.write(text);
	win.print();
	return false;
} //FUNC PrintPage

/*--------------------------------------------------------------------------------*\
|	sendToFriend
|----------------------------------------------------------------------------------
| Initiates "Send to Friend" dialog.
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|	Params:
|		event	object	- Callback even 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