siteurl='http://www.togga.co.uk/';
function email(str) {
	    var error = "";
  var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){  
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){  
	document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		       error = "Invalid E-mail\n";
		   return error;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		document.getElementById("email").style.backgroundColor = '#FFDFE3';
		
		     error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){	 
	document.getElementById("email").style.backgroundColor = '#FFDFE3';
	
		      error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){	
		document.getElementById("email").style.backgroundColor = '#FFDFE3';
		
		   error = "Invalid E-mail\n";
		   return error;
		 }
		
		 if (str.indexOf(" ")!=-1){
		     error = "Invalid E-mail\n";
		document.getElementById("email").style.backgroundColor = '#FFDFE3';
		   return error;
		 }

		   return error; 
}
 

function fetchinfo (str,div)
 	{
		document.getElementById(div).style.display = 'block';
		new Ajax.Updater(div,siteurl+str,{asynchronous: true});	  
		
}
function openinfo (div)
 	{
	
		new Effect.BlindDown(div);

		
}
 function dochange(str,prodid)
{  
   	new Ajax.Updater("selectsize",siteurl+"prt.grabsizes.php?type="+str+"&prodid="+prodid,{asynchronous: true});
	new Ajax.Updater("productthumbnails",siteurl+"prt.changethumb.php?type="+str+"&prodid="+prodid,{asynchronous: true});	 
	new Ajax.Updater("productimage",siteurl+"prt.changemainpic.php?type="+str+"&prodid="+prodid,{asynchronous: true}); 
	new Ajax.Updater("altcontainer",siteurl+"prt.changealt.php?type="+str+"&prodid="+prodid,{asynchronous: true});
	
}
function closediv(div){

   document.getElementById(div).style.display = 'none';

   }

     function getsizes(str)
    { 
	 var url=siteurl+'prt.grabsizes.php';	   
		 url=url+"?type="+str	 
	var div='selectsize';
	   new Ajax.Updater(div,url,{asynchronous: true});
    }
      function getqty(str)
    { 
	 var url=siteurl+'prt.grabstock.php';	   
		 url=url+"?type="+str	 
	var div='qty';
  new Ajax.Updater(div,url,{asynchronous: true});	
  new Ajax.Updater("price",siteurl+"prt.changeprice.php?type="+str,{asynchronous: true});
    }
 
 function comments()
    {
	 var errors=0; 
	
	if (document.blogcomments.name.value.length < 2 )
    {
        alert ( "Please add your name");
        errors ++;
		document.blogcomments.getElementById("name").style.backgroundColor = '#FFDFE3';
    }
	else
	document.getElementById("name").style.backgroundColor = 'white'; 
	
	/*var emailID=document.blogcomments.email
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false;
	}
	else
	document.blogcomments.getElementById("email").style.backgroundColor = 'white';	
	*/ 
   	 if (document.blogcomments.comment.value.length < 10 )
    {
        alert ( "Please add your comments (min 10 chars)");
        errors ++;
		document.blogcomments.getElementById("comment").style.backgroundColor = '#FFDFE3';
    }
	else
	document.blogcomments.getElementById("comment").style.backgroundColor = 'white';	 
	
     if(!errors)
   {

  
	var str=document.blogcomments.n.value;
	var name=document.blogcomments.name.value;
	var email=document.blogcomments.email.value;
	var comment=escape(encodeURI(document.blogcomments.comment.value));
	var div='comments';
	var url=siteurl+'prt.comments.php';
	 	url=url+"?n="+str+"&name="+name+"&email="+email+"&comment="+comment;
    new Ajax.Updater(div,url,{asynchronous: true});

   }

 } 
function validate_product() {
var reason = "";

  	reason += validatechoice();
  	reason += validatesize();
	reason += validateqty();

  
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
else
{  
   document.addtobasket.action=siteurl+'cartcontrol/';
   document.addtobasket.submit();
   }
}
function validatechoice() {
    var error = "";
 
    if (document.addtobasket.ppid.value == "") 
	{	
		document.getElementById("ppid").style.backgroundColor = '#FFDFE3';
        error = "Please select your colour choice.\n";
    } 
    return error;  
}
function validatesize() {
    var error = "";
 
    if (document.addtobasket.typea.value == "") 
	{  
		document.getElementById("typea").style.backgroundColor = '#FFDFE3';
        error = "Please select your size.\n";
    } 
    return error;  
}
function validateqty() {
    var error = "";
 
    if (document.addtobasket.quantity.value == "") 
	{  
		document.getElementById("quantity").style.backgroundColor = '#FFDFE3';
        error = "Please select quantity required.\n";
    } 
    return error;  
}
function validate_feedback( )  	 
{
 var errors=0;

    if ( document.feedback.name.value == "" )
    {
        alert ( "Pleae enter your name to leave feedback." );
        errors ++;
    }
 
    if ( document.feedback.feedback.value.length < 10)
    {
        alert ( "Your feedback must be more than 10 characters long." );
        errors ++;
    } 
	

     if(!errors)
   {
   	var pid=document.feedback.pid.value;
	var phone=document.feedback.phone.value;
	var name=document.feedback.name.value;
	var email=document.feedback.email.value;
	var comment=escape(encodeURI(document.feedback.feedback.value));
	var div='review';
	var url=siteurl+'prt.addfeedback.php';
	 	url=url+"?pid="+pid+"phone="+phone+"&name="+name+"&email="+email+"&feedback="+comment;
    new Ajax.Updater(div,url,{asynchronous: true});


   }
 }