

function getCookieVal (offset)
 {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
   { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
 }

function GetCookie (name)
 {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
     {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
       { return getCookieVal (j); }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) { break; }
     }
    return null;
 }

function SetCookie (name, value)
 {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
  }

function DeleteCookie (name)
 {
  SetCookie (name, '');
 }

/////////////////////////////////////////////

function check_in()
 {
  var f = prompt ("If you are registered VIP customer, please enter your email address as registered.","")

  if (f == null) { return; }
  if (f == '')   { return; }

  var thenewdate = new Date ();

  thenewdate.setTime (thenewdate.getTime() + (365 * 24 * 3600 * 1000));

  if (isEmail (f) == false)
   {
    alert ('The email address you entered is invalid.');
    SetCookie ('email_address', '', thenewdate, "/");
   }
  else
   {
    // check with CGI if this is valid login (ajax stuff)
    check_vip_login (f);
   }
 }

/////////////////////////////////////////////

function check_in_fr()
 {
  var f = prompt ("Si vous êtes déjà un client privilégié, veuillez entrer l’adresse e-mail que vous avez enregistrée.","")
  var thenewdate = new Date ();
  thenewdate.setTime (thenewdate.getTime() + (365 * 24 * 3600 * 1000));
  SetCookie ('email_address',f, thenewdate, "/");
  window.location.reload();
 }

/////////////////////////////////////////////

function validate_registration()
{
 if ((reg.Name.value == '') ||
     (reg.Address1.value == '') ||
     (reg.City.value == '') ||
     (reg.State.value == '') ||
     (reg.ZIP.value == '') ||
//     (reg.Referred.value == '') ||
     (reg.Country.value == '') ||
     (reg.Country.value == 'not_selected') ||
     (reg.Email.value == '') ||
     (isEmail (reg.Email.value) == false) ||
     (reg.Phone.value == ''))

  {
   alert ('One of the required fields is empty or email address is invalid. You have to provide valid email address to receive email from us');
   event.returnValue = false;
   return false;
 }
 event.returnValue = true;
 return true;
}


////////////////////////////////////////

var clickmessage = "This image is copyrighted by Austin Hamilton Inc.";

function disableclick (e)
{
 if (document.all)
  {
   if (event.button==2||event.button==3)
    {
     if (event.srcElement.tagName=="IMG")
      {
       alert(clickmessage);
       return false;
      }
    }
  }
 else if (document.layers)
  {
   if (e.which == 3)
    {
     alert(clickmessage);
     return false;
    }
  }
else if (document.getElementById)
 {
  if (e.which==3&&e.target.tagName=="IMG")
   {
    alert (clickmessage);
    return false
   }
 }
}

//////////////////

function associateimages()
{
 for (i=0; i < document.images.length; i++)
  document.images[i].onmousedown=disableclick;
}

/////////////////////////////////////////////

/////////////////////////////////////////////

function validate_referal_form()
{
 if ((reg.Name.value == '') ||
     (reg.Email.value == '') ||
     (reg.FriendName.value == '') ||
     (reg.FriendEmail.value == ''))

  {
   alert ("One of the required fields is empty.");
   event.returnValue = false;
   return false;
  }

 if (reg.Email.value == reg.FriendEmail.value)
  {
   alert ("You can not refer yourself.");
   event.returnValue = false;
   return false;
  }

 event.returnValue = true;

 return true;
}

/////////////////////////////////////////////

function validate_email_form()
{
 if (email_friend.recipient.value == '')
  {
   alert ("One of the required fields is empty.");
   event.returnValue = false;
   return false;
  }

 if (email_friend.recipient.value.indexOf ('@') < 0)
  {
   alert ("This is not a valid email address.");
   event.returnValue = false;
   return false;
  }

 if (email_friend.recipient.value.indexOf ('.') < 0)
  {
   alert ("This is not a valid email address.");
   event.returnValue = false;
   return false;
  }

 event.returnValue = true;
 return true;
}


/////////////////////////////////////////


function popUp (URL)
{
 day = new Date();
 id = day.getTime();
 eval ("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,height=720,width=800,resizable=1');");

///// eval ("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=400,left = 340,top = 112');");
}



////////////////////////////////////////
// used by HTML order form

function addRow (id)
{
 var INPUT_NAME_PREFIX1 = 'item';
 var INPUT_NAME_PREFIX2 = 'quant';
 var tbl = document.getElementById(id);
 var nextRow = tbl.rows.length;
 var iteration = nextRow + parseInt(1);
 var txtInp;

 var tbody = document.getElementById(id).getElementsByTagName("TBODY")[0];
 var row = document.createElement("TR");

 var td1 = document.createElement("TD");
 td1.appendChild(document.createTextNode(iteration + ")"));

 var td2 = document.createElement("TD");
 td2.appendChild (document.createTextNode("Item Id: "));

 var td3 = document.createElement("TD");
 txtInp = document.createElement('input');
 txtInp.setAttribute('type', 'text');
 txtInp.setAttribute('name', INPUT_NAME_PREFIX1 + iteration);
 txtInp.setAttribute('size', '8');
 txtInp.setAttribute('maxlength', '8');
 txtInp.setAttribute('value', '');
 td3.appendChild (txtInp);

 var td4 = document.createElement("TD");
 td4.appendChild (document.createTextNode(" "));

 var td5 = document.createElement("TD");
 td5.appendChild (document.createTextNode(" Quantity : "));

 var td6 = document.createElement("TD");
 txtInp = document.createElement('input');
 txtInp.setAttribute('type', 'text');
 txtInp.setAttribute('name', INPUT_NAME_PREFIX2 + iteration);
 txtInp.setAttribute('size', '8');
 txtInp.setAttribute('maxlength', '8');
 txtInp.setAttribute('value', '');
 td6.appendChild (txtInp);

 row.appendChild(td1);
 row.appendChild(td2);
 row.appendChild(td3);
 row.appendChild(td4);
 row.appendChild(td5);
 row.appendChild(td6);
 tbody.appendChild(row);
}

//////////////////////////////////////////////

function validate_wsapp()
{
 if ((ws_application.Name.value == '') ||
     (ws_application.Address1.value == '') ||
     (ws_application.City.value == '') ||
     (ws_application.State.value == '') ||
     (ws_application.ZIP.value == '') ||
     (ws_application.Referred.value == 'not_selected') ||
     (ws_application.Country.value == 'not_selected') ||
     (isEmail (ws_application.Email.value) == false) ||
     (ws_application.Phone.value == '') ||
     (ws_application.pass1.value == '') ||
     (ws_application.pass2.value == ''))
  {
   alert ('One of the required fields is empty.');
   event.returnValue = false;
   return false;
 }

 if (ws_application.pass1.value != ws_application.pass2.value)
  {
   alert ('Passwords do not match.');
   event.returnValue = false;
   return false;
  }

 event.returnValue = true;
 return true;
}

/////////////////////////////////////////////


function validate_blapp()
{
 if ((bl_application.Name.value == '') ||
     (bl_application.Address1.value == '') ||
     (bl_application.City.value == '') ||
     (bl_application.State.value == '') ||
     (bl_application.ZIP.value == '') ||
     (bl_application.Country.value == '  ') ||
     (isEmail (bl_application.Email.value) == false) ||
     (bl_application.Phone.value == '') ||
     (bl_application.Notes.value == '') ||
     (bl_application.pass1.value == '') ||
     (bl_application.pass2.value == '') ||
     (bl_application.pass1.value != bl_application.pass2.value))

  {
   alert ('One of the required fields is empty, or passwords do not match.');
   event.returnValue = false;
   return false;
 }
 event.returnValue = true;
 return true;
}

/////////////////////////////////////////////


function validate_bunny()
{
 if ((beading_bunny.Name.value == '') ||
     (beading_bunny.Address1.value == '') ||
     (beading_bunny.City.value == '') ||
     (beading_bunny.State.value == '') ||
     (beading_bunny.ZIP.value == '') ||
     (beading_bunny.Country.value == '  ') ||
     (beading_bunny.Bunny.value == ' ') ||
     (isEmail (beading_bunny.Email.value) == false) ||
     (beading_bunny.Phone.value == ''))

  {
   alert ('One of the required fields is empty.');
   event.returnValue = false;
   return false;
 }
 event.returnValue = true;
 return true;
}

///////////////////////////////////////////////

function isEmail (str)
{
 // alert (str);
 if (str == 'dolisting') return true;
 if (str == '')          return false;

 //// return (email_address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);

 var at = "@"
 var dot = "."
 var lat = str.indexOf (at)
 var lstr = str.length
 var ldot = str.indexOf (dot)

 if (str.indexOf(at)==-1)
  {
   return false
  }
 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
  {
   return false
  }
 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
  {
   return false
  }
 if (str.indexOf(at,(lat+1))!=-1)
  {
   return false
  }
 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
  {
   return false
  }
 if (str.indexOf(dot,(lat+2))==-1)
  {
   return false
  }
 if (str.indexOf(" ")!=-1)
  {
   return false
  }

 return true					
}

////////////////////////////////////////////////

function validate_order()
{
 if ((checkout_form.Name.value == '') ||
     (checkout_form.Address1.value == '') ||
     (checkout_form.City.value == '') ||
     (checkout_form.State.value == '') ||
     (checkout_form.ZIP.value == '') ||
     (checkout_form.Country.value == '  ') ||
     (isEmail (checkout_form.Email.value) == false) ||
     (checkout_form.Phone.value == ''))

  {
   alert ('One of the required fields is empty.');
   event.returnValue = false;
   return false;
 }
 event.returnValue = true;
 return true;
}

///////////////////////////////////////////////

function isNumeric (val)
{
 return (parseFloat(val,10) == (val*1));
}

///////////////////////////////////////////////

function validate_giftcert()
{
 var gamount = 0;
 var cookie = '';
 var thenewdate = new Date ();
 thenewdate.setTime (thenewdate.getTime() + (1200 * 1000));

 if (isNumeric (gift_cert_form.Amount.value) == true)
  {
   gamount = 1 * gift_cert_form.Amount.value;
  }

 if ((gift_cert_form.Amount.value == '') ||
     (isNumeric (gift_cert_form.Amount.value) == false) ||
     (gamount < 20) ||
     (gamount > 5000) ||
     (gift_cert_form.To.value == '') ||
     (gift_cert_form.From.value == '') ||
     (isEmail (gift_cert_form.Email1.value) == false) ||
     (isEmail (gift_cert_form.Email2.value) == false) ||
     (gift_cert_form.Email1.value != gift_cert_form.Email2.value))
  {
   alert ('One of the required fields is empty or incorrect.');

   event.returnValue = false;
   return false;
  }

 cookie = gift_cert_form.Amount.value + "|" + gift_cert_form.To.value + "|" +
          gift_cert_form.From.value + "|" + gift_cert_form.Email1.value + "|" +
          gift_cert_form.Message.value;
 SetCookie ('gift_cert', cookie, thenewdate, "/");

 event.returnValue = true;
 return true;
}

///////////////////////////////////////////////

function validate_wlogin()
{
 if ((whole_login.email.value == '') ||
     (whole_login.password.value == '') ||
     (isEmail (whole_login.email.value) == false))
  {
   alert ('One of the required fields is empty or invalid.');
   event.returnValue = false;
   return false;
  }

 event.returnValue = true;
 return true;
}

////////////////////////////////////////////


function validate_puppy()
{
 if ((beading_puppy.Name.value == '') ||
     (beading_puppy.Address1.value == '') ||
     (beading_puppy.City.value == '') ||
     (beading_puppy.State.value == '') ||
     (beading_puppy.ZIP.value == '') ||
     (beading_puppy.Country.value == '  ') ||
     (beading_puppy.Puppy.value == ' ') ||
     (isEmail (beading_puppy.Email.value) == false) ||
     (beading_puppy.Phone.value == ''))

  {
   alert ('One of the required fields is empty.');
   event.returnValue = false;
   return false;
 }
 event.returnValue = true;
 return true;
}


////////////////////////


function logout()
{
 DeleteCookie ('email_address');
 DeleteCookie ('ws_email');
 window.location.reload();
}


////////////////////////////////////////////


function validate_remove()
{
 if (isEmail (unsubscribe.email.value) == false)

  {
   alert ('Invalid email address.');
   event.returnValue = false;
   return false;
 }
 event.returnValue = true;
 return true;
}


////////////////////////////////////////////
function addbookmark()
{
var bookmarkurl=window.location.href.substr(0, window.location.href.indexOf('/', 8) + 1) + '';
if (document.title) { var bookmarktitle=document.title; }
else { var bookmarktitle="";}
var bookmarktext="Bookmark Us"
if (navigator.appName == "Netscape") {
 bookmarktext="Bookmark Us (CTRL+D)";
}
else if (navigator.appName == "Opera") {
bookmarktext="Bookmark Us (CTRL+T)";
}
 if (window.sidebar) {
 window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}
 else if (window.external) {
window.external.AddFavorite(bookmarkurl, bookmarktitle);
}
}

