﻿// JScript File

function escString(searchString)
{
	//var newString = searchString.replace(/\+/g,"%2B");
	var newString = escape(searchString);
	return newString;
}

function siteSearch(searchString)
{
 
	if (searchString != "")
	{
	    if (document.all) {
	        window.location='http://quilting-fabric.connectingthreads.com/search?w=' + escString(searchString);
	    } else if (document.getElementById) {
	        location.href='http://quilting-fabric.connectingthreads.com/search?w=' + escString(searchString);
	    }		
	
	}
	
	return false;
}

function fyarnline(yarnid)
{
 
	if (yarnid != "")
	{
	    if (document.all) {
	        window.location='/yarns/yarn_list.aspx?id=' + yarnid;
	    } else if (document.getElementById) {
	        location.href='/yarns/yarn_list.aspx?id=' + yarnid;
	    }
	
	}else {
	    alert("Please select a Yarn from the list.");
	}
	
	return false;
}

function addCartItem(itemID)
{
    var loc = '/cart/add2cart.asp?SKU_0=' + escString(itemID) + '&QTY_0=1';
    if (document.all) {
        window.location = loc;
    } else if (document.getElementById) {
        location.href = loc;
    }


}

//
//If Email field is invalid (minimally "a@b.c")
//then return true.
//Otherwise, return false.
//
function InvalidEmail(email)
{
   var offset1
   var offset2
   
   if (email.length < 5)
   {
      alert("Sorry, the Email address you entered is not valid.")
      return false;
   }else
   {  //
      offset1 = email.indexOf("@", 1)
      offset2 = email.lastIndexOf(".")
      
	  if ((offset1 == -1) ||
	      (offset2 == -1))
	  {
         alert("Sorry, the Email address you entered is not valid.")
         return false;
	  }else
	  {
	     if (offset2 < offset1+2)
	     {
            alert("Sorry, the Email address you entered is not valid.")
            return false;
	     }else
	     {
            return true;
	     }
	  }
   }
}

