function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   // alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}

//when the dom is ready
window.addEvent('domready', function() {
	  myMask = new Mask();
new SmoothScroll({ duration:700 }, window);
Sexy = new SexyAlertBox();
	/*
	var Tips3 = new Tips($$('.my_tip'), {
						initialize: function(){ 
							this.fx = new Fx.Style(this.toolTip,'opacity',{duration:500,wait:false}).set(0); },onShow: function(toolTip){ this.fx.start(1); }, onHide: function(toolTip) { this.fx.start(0); }});
	*/
		
	/*
	new MultiBox("mb", {
				descClassName:"multiBoxDesc",
				useOverlay:true			
				
	});
	*/
	
	
	

	
	var labelOpen='<img src="themes/natrodale/images/master_layout/product_range_open.png" width="242" height="48" border="0" />';
  	var labelClose='<img src="themes/natrodale/images/master_layout/product_range_close.png" width="242" height="48" border="0" />';
  
	  // Set slide and styles effects
	  //$('myPanel').style.display = 'block';  
	  if($('linkPanel').hasClass('openPanel')){
	  	var mySlide = new Fx.Slide('prd_range');
		$('linkPanel').set('html',labelClose)
	  }else{
		var mySlide = new Fx.Slide('prd_range').hide();
	  }
	  
	  var fx = new Fx.Morph($('linkPanel'), {duration:500, wait:false});
	  $('linkPanel').addEvent('click', function(e){
		mySlide.toggle();
		$('linkPanel').toggleClass('openPanel');
		fx.start({
		  'opacity': 0  
		}).chain(function(){
		  if($('linkPanel').hasClass('openPanel')) $('linkPanel').set('html',labelClose); 
		  else $('linkPanel').set('html',labelOpen); 
		  fx.start({'opacity': 1})
		});
	  });

	  //Product JS
	 var enq_form_html = '<div id="enq_form" style="display:none"><table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td colspan="2"><h2 style="padding-top:0px">Enquiry Form</h2></td></tr><tr><td>Name</td><td><input type="text" name="name" id="name"/></td></tr><tr><td>Email</td><td><input type="text" name="email" id="email"/></td></tr><tr><td>Notes</td><td><textarea rows="5" cols="30" name="notes" id="notes"></textarea></td></tr><tr><td colspan="2" align="right" style="padding-right:60px; padding-top:5px"><input type="button" id="enquire_send" value="Enquire"></td></tr></table></div>';

	 var friend_form_html = '<div id="send_form" style="display:none"><table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td colspan="2"><h2 style="padding-top:0px">Send to a Friend</h2></td></tr><tr><td>Name</td><td><input type="text" name="name" id="name"/></td></tr><tr><td>Email</td><td><input type="text" name="email" /id="email"></td></tr><tr><td>Recipient Email</td><td><input type="text" name="rec_email" id="rec_email"/></td></tr><tr><td>Notes</td><td><textarea rows="3" cols="25" name="notes" id="notes"></textarea></td></tr><tr><td align="right" style="padding-right:60px; padding-top:5px"><input type="button" id="enquire_send" value="Send"></td><td><a href="index.php?page_id=1?action=subscribe"><a href="index.php?page_id=2&action=subscribe#subscribe_wrapper"><img border="0" src="themes/natrodale/images/master_layout/mail_updates.jpg" width="182" height="37" alt="recieve email updates" /></a></td></tr></table></div>';
	 
	/*  this.overlay = new myOverlay({container: document.body}); */

	  prd_div = new Element('div',{
								'id':'prd_div',
								'styles':{
									'background-image':'url(themes/natrodale/images/master_layout/prd_box.png)',
									'background-repeat':'no-repeat',
									'height':'267px',
									'width':'407px',
									'opacity':'0',
									'display':'none',
									'z-index':9001,
									'position':'absolute',
									'visibility':'hidden',
									'padding':'20px'
								}
							}).injectInside(document.body);
	  var curr_prod = ''; 
	  if($$('.prd_enquire')){
		//console.log($$('.prd_enquire'));
		$$('.prd_enquire').each(function(item){
			item.addEvent('click',function(event){
				event.stop();			
				curr_prod = this.get('rel');
				//$('OverlayContainer').fade(0,0.7);			
					myMask.show();			
				var top = ((window.getHeight()/2)-(50/2)-document.body.getStyle('border').toInt())+window.getScroll().y-203;
				var left = ((window.getWidth()/2)-(50/2)-document.body.getStyle('border').toInt())-140;
				prd_div.setStyle('display','block');
				prd_div.setStyle('top',top+'px');
				prd_div.setStyle('left',left+'px');
				prd_div.fade(0,1);
				
				var myEffect = new Fx.Morph(prd_div, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});

				prd_div.set('html',enq_form_html);
				myEffect.start({
					'height': 267, //Morphs the 'height' style from 10px to 100px.
					'width': 407  //Morphs the 'width' style from 900px to 300px.
					//'left':((window.getWidth()/2)-(50/2)-document.body.getStyle('border').toInt())-140,
					//'top':  ((window.getHeight()/2)-(50/2)-document.body.getStyle('border').toInt())+window.getScroll().y-203
				});
				$('enq_form').fade(0);
				$('enq_form').setStyle('display','block');
				$('enq_form').fade(1);
				
				myMask.addEvent('click',function(event){
					//event.stop();
					myMask.hide();
					prd_div.fade(0);
					$('enq_form').fade(0);
					$('enq_form').dispose();
				});
				
				$('enquire_send').addEvent('click',function(){
					var name = $('name').get('value');
					var email = $('email').get('value');
					var notes = $('notes').get('value');
					var product = curr_prod;
					
					if(email == ''){
						Sexy.error('<h2>Invalid Email</h2><div>Please enter a valid email</div>');
					}else{
						if(echeck(email)){
							var req = new Request.HTML({  
								method: 'get',  
								url: 'snippets/prd_enquiries.php',  
								data: { 
									'do' : 'enq_send', 
									'name' : name,
									'email' : email,
									'notes' : notes,
									'product' : product
								},  
								onRequest: function() {
									prd_div.fade(0.7);
								},  
								onComplete: function(responseTree,responseElements,responseHTML){ 
									if(responseHTML == 'success'){
									myMask.hide();
										prd_div.fade(0);
										$('enq_form').fade(0);
										$('enq_form').dispose();
										Sexy.info('<h2>Status</h2><div>Your enquiry has been sent.</div>');
									}else{
										myMask.hide();
										prd_div.fade(0);
										$('enq_form').fade(0);
										$('enq_form').dispose();
										Sexy.error('<h2>Status</h2><div>Your enquiry could not be sent. Please try again.</div>');
									}
								}  
							}).send();
						}else{
							Sexy.error('<h2>Invalid Email</h2><div>Please enter a valid email</div>');
						}
					}
				});
				
			});
		});
						
	}
	
	 if($$('.prd_send')){
		//console.log($$('.prd_enquire'));
		$$('.prd_send').each(function(item){
			item.addEvent('click',function(event){
				event.stop();			
				curr_prod = this.get('rel');
				myMask.show();
								
				var top = ((window.getHeight()/2)-(50/2)-document.body.getStyle('border').toInt())+window.getScroll().y-203;
				var left = ((window.getWidth()/2)-(50/2)-document.body.getStyle('border').toInt())-140;
				prd_div.setStyle('display','block');
				prd_div.setStyle('top',top+'px');
				prd_div.setStyle('left',left+'px');
				prd_div.fade(0,1);
				
				var myEffect = new Fx.Morph(prd_div, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});

				prd_div.set('html',friend_form_html);
				myEffect.start({
					'height': 267, //Morphs the 'height' style from 10px to 100px.
					'width': 407  //Morphs the 'width' style from 900px to 300px.
					//'left':((window.getWidth()/2)-(50/2)-document.body.getStyle('border').toInt())-140,
					//'top':  ((window.getHeight()/2)-(50/2)-document.body.getStyle('border').toInt())+window.getScroll().y-203
				});
				$('send_form').fade(0);
				$('send_form').setStyle('display','block');
				$('send_form').fade(1);
				
				myMask.addEvent('click',function(event){
					//event.stop();
					myMask.hide();
					prd_div.fade(0);
					$('send_form').fade(0);
					$('send_form').dispose();
				});
				
				$('enquire_send').addEvent('click',function(){
					var name = $('name').get('value');
					var email = $('email').get('value');
					var rec_email = $('rec_email').get('value');
					var notes = $('notes').get('value');
					var product = curr_prod;
					
					if(rec_email == ''){
						Sexy.error('<h2>Invalid Email</h2><div>Please enter a valid friends email</div>');
					}else{
						if(echeck(rec_email)){
							if(email == ''){
								Sexy.error('<h2>Invalid Email</h2><div>Please enter a valid email</div>');
							}else{
								if(echeck(email)){
									var req = new Request.HTML({  
										method: 'get',  
										url: 'snippets/prd_enquiries.php',  
										data: { 
											'do' : 'friend_send', 
											'name' : name,
											'email' : email,
											'rec_email' : rec_email,
											'notes' : notes,
											'product' : product
										},  
										onRequest: function() {
											prd_div.fade(0.7);
										},  
										onComplete: function(responseTree,responseElements,responseHTML){ 
											if(responseHTML == 'success'){
											myMask.hide();
												prd_div.fade(0);
												$('send_form').fade(0);
												$('send_form').dispose();
												Sexy.info('<h2>Status</h2><div>Your message has been sent.</div>');
											}else{
												myMask.hide();
												prd_div.fade(0);
												$('send_form').fade(0);
												$('send_form').dispose();
												Sexy.error('<h2>Status</h2><div>Your message could not be sent. Please try again.</div>');
											}
										}  
									}).send();
								}else{
									Sexy.error('<h2>Invalid Email</h2><div>Please enter a valid email in bot email fields</div>');
								}
							}
						}else{
							Sexy.error('<h2>Invalid Email</h2><div>Please enter a valid friends email</div>');
						}
					}
					
					
				});
				
			});
		});
		
		
	}
	  


});
