function showMenu(obj) {
	$(obj).setStyle({
		visibility: 'visible'
	});
	
}

function hideMenu(obj) {
	$(obj).setStyle({
		visibility:'hidden'
	})
}

function showBox() {
        $('friend').setStyle({
		visibility: 'visible'
	});
}

function hideBox() {
	$('friend').setStyle({
		visibility:'hidden'
	})
}

/****
function used by sliders in product page
****/

function setPage(){
 var p='';
 for (var x = 1; x <= mPanel; x++){
  if(x==cPanel){ p=p + '<b>'; }
  p=p + x + ' ';
  if(x==cPanel){ p=p + '</b>'; }
 }
 //document.getElementById('page_counter').innerHTML=p;
}

function setArrows(){
 if(pPanel>0){
   document.getElementById('lt_arrow').innerHTML='<a href="javascript:;" onclick="click_arrow(\'lt\');" title="Click to scroll"><img src="/assets/images/left_arrow.jpg" border="0"></a>';
 }else{
  document.getElementById('lt_arrow').innerHTML='';
 }
 if(nPanel<=mPanel){
  document.getElementById('rt_arrow').innerHTML='<a href="javascript:;" onclick="click_arrow(\'rt\');" title="Click to scroll"><img src="/assets/images/rt_arrow.jpg" border="0"></a>';
 }else{
  document.getElementById('rt_arrow').innerHTML='';
 }
}

function click_arrow(dir){
 if(dir=='rt'){
  pPanel=pPanel+1;
  cPanel=cPanel+1;
  nPanel=nPanel+1;
  new Effect.MoveBy('wn', 0, scr_amt_bk , {duration: 0.4,  transition: Effect.Transitions.sinoidal});
 }else{
  pPanel=pPanel-1;
  cPanel=cPanel-1;
  nPanel=nPanel-1;
  new Effect.MoveBy('wn', 0, scr_amt_fwd , {duration: 0.4,  transition: Effect.Transitions.sinoidal});
 }
 setArrows();
 setPage();
}

/****
function to interact with product page and change cart link and price accordingly.
****/
function setColor(id,name,color,price,weight)
{
	document.getElementById('cartButton').innerHTML='<input type="hidden" name="name" value="'+name+'" /><input type="hidden" name="price" value="'+price+'" /><input type="hidden" name="code" value="'+id+'" /><input type="hidden" name="color" value="'+color+'" /><input type="hidden" name="weight" value="'+weight+'" /><input type="submit" value="BUY" class="buybutton">';

	if(color==''){
		dispcolor='';
	}else{
	 	dispcolor=' (color: '+color+')';
	}

	document.getElementById('price').innerHTML='<b>$'+price+'</b>'+dispcolor;
	
}

/****
Code to interact with tell a friend page and process the request.
****/

	//var email = new LiveValidation('email');
	//email.add(Validate.Email);
 /*
 if(document.getElementById('tell_a_friend'))
 {
       $('tell_a_friend').onsubmit = function(){
	 var valid, msg = $('msg')
	 // are both fields present?
	 var email = $('email');
	 var emailTemp = document.getElementById('email').value;
	 
	 valid = $(this.name).present() && $(this.email).present() && $(this.femail).present() &&  $(this.msg).present() && checkemail(emailTemp);
	 if(valid)
	 {
		document.getElementById('wait').style.visibility = "visible";
		 new Ajax.Request('/assets/snippets/tellAFriend.php',  
			 {     
			       method:'post',  
			       parameters: $('tell_a_friend').serialize(true) ,
			       onSuccess: function(transport){
				       
			       var response = transport.responseText || "no response text";       
				       document.getElementById('thanks').style.visibility = "visible";
				       document.getElementById('wait').style.visibility = "hidden";
				       document.getElementById('friend').style.visibility = "hidden";
				       setTimeout('document.getElementById("thanks").style.visibility = "hidden";',5000);
       
			       },     
			       onFailure: function(){
				       //alert('Something went wrong...') 
				}    
			       }); 
       
       
	       
	 } else {
	   msg.update('Please fill out all the fields.').style.color = 'red'
	       return false;
       
	 }
	return false;
   }
 }
 */ 
/****
function to interact with mailing list 
****/
function showlist() {
	
	//document.getElementById('mailing_list').innerHTML='<form name="join" id="join" style="margin:0px" method="post" action="/assets/snippets/mailingList.php"><input type="text" name="addr" style="font-size:11px; width:130px" id="addr"> <input type="submit" value="Join" style="font-size:10px"><span class="validation_message"></span><br><div align="right"><a href="#" onclick="showForm();" style="color:gray; text-decoration:none">X</a></div></form>';
	document.getElementById('mailing_list').innerHTML='<form name="join" id="join" style="margin:0px" method="post" action="/assets/snippets/mailingList.php">' +
	    '<table><tr><td>first name</td><td><input type="text" name="fn" style="font-size:11px; width:120px" id="fn"></td></tr>' +
	    '<tr><td>last name</td><td><input type="text" name="ln" style="font-size:11px; width:120px" id="ln"></td></tr>' +
	    '<tr><td>email</td><td><input type="text" name="addr" style="font-size:11px; width:120px" id="addr"></td></tr>' +
	    '<tr><td></td><td><input type="submit" value="Join" style="font-size:10px"><img src="assets/images/spacer.gif" width="74" height="1" />' +
	    '<a href="#" onclick="showForm();" style="color:gray; text-decoration:none">X</a></td></tr></table></form>';
	
	document.forms['join'].addr.focus();
	// Validate Email  //
	
	var addr = new LiveValidation('addr');
	addr.add(Validate.Email);
	
	// Submit Form //
	$('join').onsubmit = function(	 ) {
		var addrTemp = document.getElementById('addr').value;
		checkemail(addr);
		alert(addrTemp);


   //var valid, msg = $('mailing_list')
  // Is email address field present?
  // var valid = $(this.addr).present() && checkemail(addrTemp);
   //if(valid)
   // {
	 // new Ajax.Request('/assets/snippets/mailingList.php',  
	//	  {     
	//		method:'post',  
	//		parameters: $('join').serialize(true) ,
	//		onSuccess: function(transport){
	//			
	//		var response = transport.responseText || "no response text"; 
	//			 document.getElementById('mailing_list').innerHTML='THANK YOU FOR JOINING OUR MAILING LIST<br><div align="right"><a href="#" onclick="showForm();" style="color:red; text-decoration:none">X</a></div>';
	//		},     
	//		onFailure: function(){
	//			//alert('Something went wrong...') 
	//		 }    
	//		}); 
   //} 
    //else 
    //{
		//document.getElementById('mailing_list').innerHTML='<a href="" onclick="return showlist();" style="color:red; text-decoration:none">VALID EMAIL ADDRESS REQUIRED</a>';
		//return false
    //}
	return false;
  }
  
}
function showForm()
{
	document.getElementById('mailing_list').innerHTML = '<a href="#" onclick="showlist()"><img src="/assets/images/list_add.jpg" border="0"></a>';
}
function checkemail(pVal){
	var str=pVal
	//alert(pVal);
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
	else{
	//alert("Please input a valid email address!")
	testresults=false
	}
	return (testresults)
}
