<!--

function signUp(f)
{
	if(f.email.value=="" || f.name.value=="")
	{
		alert("Please fill in all fields.");
	}
	else
	{
		if(!validateEmail(f.email.value))
		{
			alert("Invalid email address. Please re-enter email.");
		}
		else
		{
			f.submit();
		}
	}
}

/*
 * validate email address, check for illegal characters, check there is one
 * @ sign and at least one . after it. return true or false
 */
function validateEmail(tempEmail)
{

   var valid = true;
   len = tempEmail.length;

   if(len==0){
        valid = false;
   }


   spaces = tempEmail.indexOf(' ');
        // check for spaces
        if(spaces != -1)
                valid = false;

   ampers = tempEmail.indexOf('&');
        // check for ampersands
        if(ampers != -1)
                valid = false;

   at = tempEmail.indexOf('@');
        // check there is a at sign
        if(at == -1)
                valid = false;

   atmore = tempEmail.indexOf('@',(at+1));
        // check for more at signs
        if(atmore != -1)
                valid = false;

   dot = tempEmail.indexOf('.',at);
        // check for a dot after the at sign
        if(dot== -1)
                valid = false;

   if((at == 0)||(at== len))
   {
        // check where the at sign is
        valid = false;
   }

   return valid;
}

function changeDelivery(url,s)
{
	var nxt_day = s[s.selectedIndex].value;
	url += "?change_del_type="  +  nxt_day;
	
	document.location.href=url;
}

function openWindow(url,name,width,height)
{
	props = "width=" + width + ",height=" + height + ",scrollbars";
	window.open(url,name,props);
}

function showGalleryImage(gallery_id)
{
	url = "showgalleryimage.php?gallery_id=" + gallery_id;
  	var win = openWindow(url,"gallery",450,450);
}

function sendToFriend(f)
{
  var friends_email = f.friends_email.value;
  var my_email = f.my_email.value;
  var product_id = f.product_id.value;

	if(!(friends_email==" Friend's e-mail..." || my_email==" Your e-mail...."))
	{
  		var url = "sendtofriend.php?friends_email=" + friends_email + "&amp;my_email=" + my_email + "&amp;product_id=" + product_id;
  		var win = openWindow(url,"friend",300,115);
  	}
  	else
  	{
  		alert("Please fill in both email addresses");
  	}
}

old_textbox_value = "";

function clearBox(t,original)
{
	if(t.value == original)
	{
		old_textbox_value = t.value;
		t.value = "";
	}
}

function restoreBox(t)
{
	if(t.value == "")
	{
		t.value = old_textbox_value;
		old_textbox_value = "";
	}
}

colourImages = new Array();

function switchColours(sel)
{
	var selNum = sel.selectedIndex;
	var newimage = colourImages[selNum];
	if(newimage!="")
	{
		document.images['large_image'].src = "upload_files/" + newimage;
	}
	
}

function checkCustomerDetails(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- contact_name must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }
 
    if (f.password.value == "" || f.passwordc.value == "")
    {
         errors += "- password and password confirmation must be completed.\n";
         valid = false;
    }
    else
    {
		if (f.password.value != f.passwordc.value)
		{
        	 errors += "- password and password confirmation do not match.\n";
			valid = false;
		}    
    }
    
    if (f.billing_line1.value == "")
    {
        errors += "- billing_line1 must be completed.\n";
        valid = false;
    }
    
    if (f.billing_town.value == "")
    {
        errors += "- billing_town must be completed.\n";
        valid = false;
    }
    
    if (f.billing_county.value == "")
    {
        errors += "- billing_county must be completed.\n";
        valid = false;
    }
      
    if (f.billing_country_id[f.billing_country_id.selectedIndex].value == "")
    {
        errors += "- billing_country must be completed.\n";
        valid = false;
    }
    
    if (f.billing_postcode.value == "")
    {
        errors += "- billing_postcode must be completed.\n";
        valid = false;
    }

    if (f.tel.value == "")
    {
        errors += "- telephone must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_line1.value == "")
    {
        errors += "- shipping_line1 must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_town.value == "")
    {
        errors += "- shipping_town must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_county.value == "")
    {
        errors += "- shipping_county must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_country_id[f.shipping_country_id.selectedIndex].value == "")
    {
        errors += "- shipping_country must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_postcode.value == "")
    {
        errors += "- shipping_postcode must be completed.\n";
        valid = false;
    }
       
    if(!f.agree_terms.checked)
    {
        errors += "- terms and conditions must be read and agreed to.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}


function checkNewsletterDetails(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- contact_name must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }

    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function checkLogin(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.email.value == "")
    {
        errors += "- email must be completed.\n";
        valid = false;
    }

    if (f.password.value == "")
    {
        errors += "- password must be completed.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function checkGalleryUpload(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- contact name must be completed.\n";
        valid = false;
    }

    if (f.contact_email.value == "")
    {
        errors += "- contact email must be completed.\n";
        valid = false;
    }
  
      if (f.description.value == "")
      {
          errors += "- photo description must be completed.\n";
          valid = false;
    }
    
    
    
       if (f.submitted_image.value == "")
       {
           errors += "- image must be uploaded.\n";
           valid = false;
    }
    
    
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function checkEmailFriend(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.name_of_recipient.value == "")
    {
        errors += "- Recipient Name must be completed.\n";
        valid = false;
    }

    if (f.email_of_recipient.value == "")
    {
        errors += "- Recipient Email must be completed.\n";
        valid = false;
    }
    
    if (f.your_name.value == "")
    {
        errors += "- Your Name must be completed.\n";
        valid = false;
    }
    
    if (f.your_email.value == "")
    {
        errors += "- Your Email must be completed.\n";
        valid = false;
    }
    
   if (f.msg.value == "")
   {
	   errors += "- Message must be completed.\n";
	   valid = false;
	}
   
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function checkQuestionaire(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.name.value == "")
    {
        errors += "- Your Name must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- Your Email must be completed.\n";
        valid = false;
    }
    
    if (f.speed[f.speed.selectedIndex].value == "")
    {
        errors += "- How did you rate the speed with which our website downloaded?\n";
        valid = false;
    }

    if (f.navigate[f.navigate.selectedIndex].value == "")
    {
        errors += "- How easy did you find our website to navigate?\n";
        valid = false;
    }
    
    if (f.design[f.design.selectedIndex].value == "")
    {
        errors += "- What do you think about the design of the site?\n";
        valid = false;
    }

    if (f.competition[f.competition.selectedIndex].value == "")
    {
        errors += "- How important are the competitions/bonus scheme to you?\n";
        valid = false;
    }
    
     if (f.range[f.range.selectedIndex].value == "")
     {
         errors += "- What did you think of the size of the product range?\n";
         valid = false;
    }
    
    if (f.productinfo[f.productinfo.selectedIndex].value == "")
    {
        errors += "- How do you rate the product information provided by our website?\n";
        valid = false;
    }
    
     if (f.overall[f.overall.selectedIndex].value == "")
     {
         errors += "- How do you rate your overall experience with Justteeshirts?\n";
         valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    
    return valid;
}

function checkForgotPass(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.forgot_email.value == "")
    {
        errors += "- Email address must be completed.\n";
        valid = false;
    }
   
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

function copyAddress(f)
{
		f.shipping_line1.value = f.billing_line1.value;
		f.shipping_line2.value = f.billing_line2.value;
		f.shipping_line3.value = f.billing_line3.value;
		f.shipping_town.value = f.billing_town.value;
		f.shipping_county.value = f.billing_county.value;
		f.shipping_country_id.value = f.billing_country_id.value;
		f.shipping_postcode.value = f.billing_postcode.value;
}

function checkPromo(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.promo_code.value == "")
    {
        errors += "- promotion code must be completed.\n";
        valid = false;
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }
    else
    {
    	f.submit();
    }
}

//-->