<!-- hide me

function delCookie(cookieName)
{
  if (document.cookie != "")
  {
    thisCookie = document.cookie.split("; ")
    for (i=0; i<thisCookie.length; i++)
    {
      if(cookieName == thisCookie[i].split("=")[0])
      {
        expireDate = new Date
        expireDate.setDate(expireDate.getDate()-1)
        document.cookie = cookieName+ "=;expires=" + expireDate.toGMTString()
      }
    }
  }
}

function setCookie(cookieName, cookieValue, liveMin)
{
  var expireDate = new Date
  expireDate.setMinutes(expireDate.getMinutes()+liveMin)
  document.cookie = cookieName + "=" + cookieValue + ";expires=" + expireDate.toGMTString()
}

function AddrRequest(myObject,dbid,action,idx)
{
//a = document.YWAddress.Addr1.style.backgroundColor.value
//alert(a)
//  document.YWAddress.Addr1.focus()
  myObject.addr_id.value = dbid
  myObject.act_req.value = action
  myObject.idx.value = idx
  setCookie('db_update',action,180)
  myObject.submit();
  return false;
}

function limitText(textArea, length, action)
{
  if (action == 'down')
  {
    chklength = length - 1
  }
  else
  {
    var chklength = length
  }
  if (textArea.value.length > length)
  {
    textArea.value = textArea.value.substr(0, chklength);
    alert('Please enter at most ' + length + ' chars');
    textArea.focus();
  }
}

function validateItemEntry(validString, the_thing, myform) {
  var thisLength = validString.length;
  if(!validateNumberEntry(validString, the_thing, thisLength))
  {
    the_thing.focus();
    the_thing.select();
    the_thing.value = "1";
  }
  
  if (validString.length == 0)
  {
    the_thing.value = "1";
  }
}

function removeNonDigits(textStr) {
  //old code removed, didn't work with FireFox v1.5
  //var tempStr = textStr + "";
  //return tempStr.replace(/\D/g, "");

  var tempStr = "";  
  for (i = 0; i < textStr.length; i++)
  {   
    // Check that current character is number.
    var c = textStr.charAt(i);
    if (((c >= "0") && (c <= "9")))
      tempStr += c;
  }

  return tempStr;
}


var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
  var i;
  for (i = 0; i < s.length; i++){   
    // Check that current character is number.
    var c = s.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  // All characters are numbers.
  return true;
}

function stripCharsInBag(s, bag){
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++){   
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

function daysInFebruary (year){
  // February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
  for (var i = 1; i <= n; i++) {
    this[i] = 31
    if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
    if (i==2) {this[i] = 29}
  } 
   return this
}

function validateDateTimeEntry(scheduleDate, scheduleTime)
{
  // Time must not be within 1.5 hours of current time
  elapsedSeconds = 5400;
  scheduleDateTime = new Date( Date.parse(scheduleDate+" "+scheduleTime) )

  elapsedSeconds*=1000;
  var now=new Date();
	
  if (scheduleDateTime - now <= 0)
  {
    alert("Date specified is in the past");
    return false;
  }
  else if( (scheduleDateTime - now) <= elapsedSeconds )
  {
    alert("Pick-up or Delivery must be scheduled at least 1.5 hours in advance");
    return false;
  }
  return true;
}

function validateDateEntry(dtStr, minDays) {

  var mydate=new Date()
  var todayyear=mydate.getYear()
    
  if (todayyear < 1000)
      todayyear+=1900
    
  var todayday=mydate.getDate()
  var todaymonth=mydate.getMonth()+1
    
  if (todaymonth<10)
      todaymonth="0"+todaymonth

  var daysInMonth = DaysArray(12)
  var pos1=dtStr.indexOf(dtCh)
  var pos2=dtStr.indexOf(dtCh,pos1+1)
  var strMonth=dtStr.substring(0,pos1)
  var strDay=dtStr.substring(pos1+1,pos2)
  var strYear=dtStr.substring(pos2+1)
  strYr=strYear
  if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
  if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
  for (var i = 1; i <= 3; i++) {
    if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
  }
  month=parseInt(strMonth)
  day=parseInt(strDay)
  year=parseInt(strYr)
  if (pos1==-1 || pos2==-1){
    //alert("The date format should be : mm/dd/yyyy")
    return false
  }
  if (strMonth.length<1 || month<1 || month>12){
    //alert("Please enter a valid month")
    return false
  }
  if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
    //alert("Please enter a valid day")
    return false
  }
  if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
    //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
    return false
  }
  if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
    //alert("Please enter a valid Advanced Order date")
    return false
  }

  var todayDate = new Date ();
  var orderDate = new Date ();
  
  orderDate.setYear(year);
  orderDate.setMonth(month-1);
  orderDate.setDate(day);

  if (todayDate > orderDate)
  {
    alert("Advanced Order date can not be in the past");
    return false;
  }
 
  todayDate.setDate (todayDate.getDate() + minDays);
  if (todayDate > orderDate)
  {
    alert("Order must be ordered " + minDays + " days in advanced.");
    return false;
  }
  
  return true
}

/**********************************************************************
*                                                                     *
*  Function    - validateNumberEntry                                  *
*  Parameters  - validString                                          *
*  Description - This function checks if the argument string is a     *
*                valid phone number, and displays an alert dialog     *
*                if it is not.                                        *
*  Called By   - onChange event handler                               *
*                                                                     *
**********************************************************************/
function validateNumberEntry(validString, the_thing, minLength) {

   //  This variable is true if the string contains valid numbers,
   //  and false otherwise.
   var isNumValid = true;
   var numLength = 0;
   //  Loop thtough each of the characters in the string argument.
   for (i=0 ; i < validString.length ; i++) {

     // check if the number is valid
     if (validateNumber(validString.charAt(i)) == false) {
       isNumValid = false;
       i=validString.length;
     }
     else
     {
       if (validString.charAt(i) != '-') {
         numLength += 1;
       }
     }
   }

   //
   //  If the string contains any non-valid numbers,
   //  display an alert dialog.
   //
   if (isNumValid == false) {
     the_thing.focus();
     the_thing.select();
     alert("Must be numeric.");
      the_thing.value = "0";
     return false;
   }
   else
   { if (numLength < minLength)
     {
     	 the_thing.focus();
       the_thing.select();
       alert("Number entered has too few digits.");
       the_thing.value = "";
       return false;
     }
     else
     {
       return true;
     }
   }
}
/**********************************************************************
*                                                                     *
*  Function    - validateNumber                                       *
*  Parameters  - character                                            *
*  Description - This function returns a value of true if the         *
*                character argument, is a number or dash.             *
*  Called By   - validateNumberEntry Function                         *
*                                                                     *
**********************************************************************/
function validateNumber(character) {

   //  Return true if valid, false otherwise.
   if ((character >= '0' && character <= '9')
        || ( character == '-'))
     return true;
   else
     return false;
}
/**********************************************************************
*                                                                     *
*  Function    - validateSimpleNumber                                 *
*  Parameters  - character                                            *
*  Description - This function returns a value of true if the         *
*                character argument, is a number                      *
*  Called By   - validateNumberEntry Function                         *
*                                                                     *
**********************************************************************/
function validateSimpleNumber(character) {

   //  Return true if valid, false otherwise.
   if ((character >= '0' && character <= '9'))
     return true;
   else
     return false;
}

var vCatClicked = 0;
var vRegionClicked = 0;

function swapCatOptions(the_target,the_id)
{
  setCatOptionText(the_target, the_id);
}

function maySwapCatOptions(the_target,the_id)
{
  if (!vCatClicked)
    setCatOptionText(the_target, the_id);
}

function setCatOptionText(the_select, the_id)
{
  var i = 0;
  var loop = 0;

  // first, assume max of length, or else will fail the script
  the_select.options.length = TotCat;
  for (loop=0; loop < TotCat; loop++)
  {
    if( the_id == arCatParentID[loop] )
    {
      the_select.options[i].text = arCatDesc[loop]  //+the_id; DEBUG
      the_select.options[i].value = arCatID[loop];
      i++;
    }
  }
  the_select.options.length = i;
}

function swapRegionOptions(the_target,the_id)
{
  setRegionOptionText(the_target, the_id);
}

function maySwapRegionOptions(the_target,the_id)
{
  if (!vRegionClicked)
    setRegionOptionText(the_target, the_id);
}

function setRegionOptionText(the_select, the_id)
{
  var i = 0;
  var loop = 0;

  // first, assume max of length, or else will fail the script
  the_select.options.length = TotRegion;
  for (loop=0; loop < TotRegion; loop++)
  {
    if( the_id == arRegionParentID[loop] )
    {
      the_select.options[i].text = arRegionDesc[loop]  //+the_id; DEBUG
      the_select.options[i].value = arRegionID[loop];
      i++;
    }
  }
  the_select.options.length = i;
}

function ValidateContactInfo(myform,action,act_req)
{
  var valid_info = true;      // init to true
  var buf = "Please correct the following:\n";

  if(myform.advanced_order_flag[1].checked == true)
  {
    if (myform.advanced_order_date.value == "")
    {
      valid_info = false;
      buf += "\nMissing Advanced Order Date";
    }
    else if (!validateDateEntry(myform.advanced_order_date.value, parseInt(myform.advanced_order_days.value)))
    {
      valid_info = false;
      buf += "\nInvalid Advanced Order Date";
    }

    if (myform.advanced_order_time.value == "")
    {
      valid_info = false;
      buf += "\nMissing Advanced Order Time";
    }
    
    if (valid_info)
    {
      if (!validateDateTimeEntry(myform.advanced_order_date.value, myform.advanced_order_time.value))
      {
        valid_info = false;
        buf += "\nInvalid Advanced Order Date Time";
      }
    }
  }

  if(myform.payment_method != null && myform.payment_method.value == "")
  {
    valid_info = false;
    buf += "\nMissing Payment Method";
  }

  if(myform.terms != null && !myform.terms.checked)
  {
    valid_info = false;
    buf += "\nPlease read and accept terms and conditions";
  }
      
  if(myform.cust_fname.value == "")
  {
    valid_info = false;
    buf += "\nMissing First Name";
  }
  if(myform.cust_lname.value == "")
  {
    valid_info = false;
    buf += "\nMissing Last Name";
  }
  
  if(myform.cust_phone.value == "")
  {
    valid_info = false;
    buf += "\nMissing Phone";
  }
  else 
  {
	tempStr = removeNonDigits(myform.cust_phone.value);
	if (tempStr.length != 10) {
		valid_info = false;
		buf += "\nInvalid Phone number.";
	}
  }

  if (myform.cust_email.value == "")
  {
    valid_info = false;
    buf += "\nMissing Email Address";
  }
  else if (!isEmailValid(myform.cust_email.value))
  {
    valid_info = false;
    buf += "\nInvalid Email Address format";
  }
 
  if (myform.zip_code != null)
  {
    if (myform.zip_code.value == "")
    {
      valid_info = false;
      buf += "\nMissing Postal Code";
    }
    else if (!isValidPostalcode(myform.zip_code.value))
    {
      valid_info = false;
      buf += "\nInvalid Postal Code";
    }
  }

  // For delivery, needs address information as well
  if(myform.pickup_delivery.value == "D")
  {
    if(myform.street_address != null && myform.street_address.value == "")
    {
      valid_info = false;
      buf += "\nMissing Street Address";
    }
    if(myform.city != null && myform.city.value == "")
    {
      valid_info = false;
      buf += "\nMissing City";
    }
  }
  if(myform.state_prov != null && myform.state_prov.value == "")
  {
    valid_info = false;
    buf += "\nMissing Province";
  }

  tempStr = removeNonDigits(myform.cust_phone_extn.value);
  if (tempStr < myform.cust_phone_extn.value.length) {
    valid_info = false;
    buf += "\nInvalid Phone Extension.";
  }

  // Any problems???
  if(valid_info == false)
  {
    alert(buf);
  }
  else
  {
    if (action == 'my_ywlogin.php')
    {
      aWindow = window.open('my_ywlogin.php',"ywLogin","width=510,height=280,left=300,top=200");
      myform.act_req.value = act_req;
    }
    else
    {
      //format the phone number to xxx-xxxx
      tempStr = removeNonDigits(myform.cust_phone.value);

      setCookie('db_update',act_req,180)
      myform.action = action;
      myform.act_req.value = act_req;
      myform.submit();
    }
  }
}


function displayWarning(myform, warning, mode)
{
  var found_it

  for (var i=0; i<myform.pickup_delivery.length; i++)  {
    if (myform.pickup_delivery[i].checked)  {
      found_it = myform.pickup_delivery[i].value
    } 
  }
		
  if ((warning != "") && ((found_it == mode) || (mode == "A")))
  {
    alert(warning);
  }
  else
  {
    myform.submit();
  }
}

function ValidateSearchInfo(myform)
{
  var valid_info = true;      // init to true
  var buf = "Missing the following search information:";

  if(myform.city.value == "")
  {
    valid_info = false;
    buf += "\nCity";
  }
  if(myform.sub_category.value == "")
  {
    valid_info = false;
    buf += "\nCuisine Type";
  }
  if(myform.service_type.value == "")
  {
    valid_info = false;
    buf += "\nService Type";
  }

  // Any problems???
  if(valid_info == false)
  {
    alert(buf);
  }
  else
  {
    myform.submit();
  }
}

/* Once selected an item, make decision about if we need to satify any
   requirements about additional category of stuff need to be filled in
*/
function submit_select(myform)
{
  //alert("Called 2.5");
  var buf = "Testing ";
  var num_of_items = 0;

  //parent.show_shopping_cart_frame.location.href = "index.php";
  //parent.show_shopping_cart_frame.location.href = "show_shopping_cart.php";
  //window.location.href = "a.php";
  //parent.LEFT_FM.location.href = "show_menu_item.php";
  //myform.submit();

  //alert(myform.my_action.value);

  for (var i=0; i<myform.elements.length; i++)
  {
     if (myform.elements[i].name.indexOf("yw_aiid") != -1)
     {
     buf += "Addn_Ing: ";
     buf += myform.elements[i].name;
     buf += " ";
     }
     if (myform.elements[i].name.indexOf("miq_") != -1)
     {
     buf += "Item: ";
     buf += myform.elements[i].name;
     buf += " ";
     num_of_items += myform.elements[i].value;
     }
     if (myform.elements[i].name.indexOf("MenuItemQty_") != -1)
     {
     buf += "Item x: ";
     buf += myform.elements[i].name;
     buf += " ";
     buf += myform.elements[i].value;
     num_of_items += myform.elements[i].value;
     }
     if (myform.elements[i].name.indexOf("choice_") != -1)
     {
     buf += "Choice: ";
     buf += myform.elements[i].name;
     buf += " ";
     }
     if (myform.elements[i].name.indexOf("misselect_") != -1)
     {
     buf += "SizeSelect ";
     buf += myform.elements[i].name;
     buf += " ";
     buf += myform.elements[i].value;
       if (myform.elements[i].checked)
       {
        buf += " CHECKED ";
       }
     }
  }
  //alert(buf);

  if(num_of_items <= 0)
  {
     alert("At least one item must be selected");
     return false;
  }
  else
  {

    myform.sub_button.value = "Y";
    myform.submit();
    return true;
  }
}

function BackButtonPressed(myObject)
{
    myObject.back_button.value = "Y";
    myObject.submit();
}

//
// The following function is taken from the Web to resize a pop-up image
//
function openPopup (imageURL, caption) {

/*
This routine creates a pop-up window, and ensures that it takes focus. It is
intended to be called from an anchor tag. The new window will resize itself to
the optimum size, so we make it as large as the largest required window to
overcome bugs in various manifestations of various browsers.

Author:   John Gardner
Written:  8th November 2003
Updated:  27th January 2004

Calling sequence: <a href="a.jpg" onClick="return openLargeImage('a.jpg','Caption');">

The first parameter is the URL of the image to be opened, and the second
parameter is the caption for the image which is displayed in the window title
and in the alt property of the image tag.

Note that the calling sequence will simply open the image in the main window if
JavaScript isn't enabled.

*/

  // Constants - change these to suit your requirements Note that the defaultWidth
  // and defaultHeight variables should be set to more than your largest image to
  // overcome a bug in Mozilla (at least up to Firefox 0.9).

  var windowTop = 100;                // Top position of popup
  var windowLeft = 100                // Left position of popup
  var defaultWidth = 730;             // Default width (for browsers that cannot resize)
  var defaultHeight = 532;            // Default height (for browsers that cannot resize)
  var onLoseFocusExit = true;         // Set if window to exit when it loses focus
  var undefined;

  // Set up the window open options
  var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft + ",resizable"

  // Now write the HTML markup to the new window, ensuring that we insert the
  // parameter URL of the image and the parameter description of the image in
  // the right place.
  var myScript = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
    "<html>\n" +
    "<head>\n" +
    "<title>" + caption + "\</title>\n" +
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n" +
    "<meta http-equiv=\"Content-Language\" content=\"en-gb\">\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
    "  var width = document.myimage.width;\n" +
    "  var height = document.myimage.height;\n";

  // Netscape
  if (navigator.appName.indexOf("Netscape") != -1) {
    myScript = myScript +  "  window.innerHeight = height;\n  window.innerWidth = width;\n"
  }

  // Opera - was 12, 31
  else if (navigator.appName.indexOf("Opera") != -1) {
    myScript = myScript +  "  window.resizeTo (width+14, height+34);\n"
  }

  // Microsoft - was 12, 31
  else if (navigator.appName.indexOf("Microsoft") != -1) {
    myScript = myScript + "  window.resizeTo (width+14, height+34);\n"
  }

  // Assume a frig factor for any other browsers
  else {
    myScript = myScript + "  window.resizeTo (width+14, height+34);\n"
  }

  myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";

  // If the window is required to close when it loses focus.
  if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}

  myScript = myScript + "style=\"margin: 0px; padding: 0px;\">\n" +
    "<img src=\"" + imageURL + "\" alt=\"" + caption + "\" title=\"" + caption + "\" name=\"myimage\">\n" +
    "</body>\n" +  "</html>\n";

  // Diagnostic - uncomment the next line if you wish to see the script generated.
  //alert (myScript);

  // Create the popup window
  var imageWindow = window.open ("","imageWin",Options);
  imageWindow.document.write (myScript)
  imageWindow.document.close ();
  if (window.focus) imageWindow.focus();
  return false;
}


// Contributors
// Ilkka Huotari at http://www.editsite.net
// Mathieu 'p01' HENRI at http://www.p01.org/
// http://seky.nahory.net/2005/04/rounded-corners/
// Steven Wittens at http://www.acko.net/anti-aliased-nifty-corners
// Original Nifty Corners by Alessandro Fulciniti at http://pro.html.it/esempio/nifty/
function NiftyCheck() {
  if(!document.getElementById || !document.createElement) {
    return false;
  }
  var b = navigator.userAgent.toLowerCase();
  if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1) {
    return false;
  }
  return true;
}

function Rounded(className, sizex, sizey, sizex_b, sizey_b) {
	var bk;
	if (!NiftyCheck()) return;
	if (typeof(sizex_b) == 'undefined')
		sizex_b = sizex;
	if (typeof(sizey_b) == 'undefined')
		sizey_b = sizey;
	var v = getElements(className);
	var l = v.length;
	for (var i = 0; i < l; i++) {
		color = get_current_style(v[i],"background-color","transparent");
		bk = get_current_style(v[i].parentNode,"background-color","transparent");
		AddRounded(v[i], bk, color, sizex, sizey, true);
		AddRounded(v[i], bk, color, sizex_b, sizey_b, false);
	}
}

Math.sqr = function (x) {
  return x*x;
};

function Blend(a, b, alpha) {

  var ca = Array(
    parseInt('0x' + a.substring(1, 3)),
    parseInt('0x' + a.substring(3, 5)),
    parseInt('0x' + a.substring(5, 7))
  );
  var cb = Array(
    parseInt('0x' + b.substring(1, 3)),
    parseInt('0x' + b.substring(3, 5)),
    parseInt('0x' + b.substring(5, 7))
  );
  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);

  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);
}

function AddRounded(el, bk, color, sizex, sizey, top) {
  if (!sizex && !sizey)
	return;
  var i, j;
  var d = document.createElement("div");
  d.style.backgroundColor = bk;
  var lastarc = 0;
  for (i = 1; i <= sizey; i++) {
    var coverage, arc2, arc3;
    // Find intersection of arc with bottom of pixel row
    arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;
    // Calculate how many pixels are bg, fg and blended.
    var n_bg = sizex - Math.ceil(arc);
    var n_fg = Math.floor(lastarc);
    var n_aa = sizex - n_bg - n_fg;
    // Create pixel row wrapper
    var x = document.createElement("div");
    var y = d;
    x.style.margin = "0px " + n_bg + "px";
	x.style.height='1px';
	x.style.overflow='hidden';
    // Make a wrapper per anti-aliased pixel (at least one)
    for (j = 1; j <= n_aa; j++) {
      // Calculate coverage per pixel
      // (approximates circle by a line within the pixel)
      if (j == 1) {
        if (j == n_aa) {
          // Single pixel
          coverage = ((arc + lastarc) * .5) - n_fg;
        }
        else {
          // First in a run
          arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
          coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;
          // Coverage is incorrect. Why?
          coverage = 0;
        }
      }
      else if (j == n_aa) {
        // Last in a run
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;
      }
      else {
        // Middle of a run
        arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = ((arc2 + arc3) * .5) - (sizey - i);
      }

      x.style.backgroundColor = Blend(bk, color, coverage);
	  if (top)
	      y.appendChild(x);
      else
	      y.insertBefore(x, y.firstChild);
      y = x;
      var x = document.createElement("div");
		x.style.height='1px';
		x.style.overflow='hidden';
      x.style.margin = "0px 1px";
    }
    x.style.backgroundColor = color;
    if (top)
	    y.appendChild(x);
    else
		y.insertBefore(x, y.firstChild);
    lastarc = arc;
  }
  if (top)
	  el.insertBefore(d, el.firstChild);
  else
	  el.appendChild(d);
}

function getElements(className) {
	var elements = [];
	var el = document.getElementsByTagName('DIV');
	var regexp=new RegExp("\\b"+className+"\\b");
	for (var i = 0; i < el.length; i++)
	{
		if (regexp.test(el[i].className))
			elements.push(el[i]);
	}
	return elements;
}

function get_current_style(element,property,not_accepted)
{
  var ee,i,val,apr;
  try
  {
    var cs=document.defaultView.getComputedStyle(element,'');
    val=cs.getPropertyValue(property);
  }
  catch(ee)
  {
    if(element.currentStyle)
  	{
	    apr=property.split("-");
	    for(i=1;i<apr.length;i++) apr[i]=apr[i].toUpperCase();
	    apr=apr.join("");
	    val=element.currentStyle.getAttribute(apr);
   }
  }
  if((val.indexOf("rgba") > -1 || val==not_accepted) && element.parentNode)
  {
	 if(element.parentNode != document)
		 val=get_current_style(element.parentNode,property,not_accepted);
	 else
		 val = '#FFFFFF';
  }
  if (val.indexOf("rgb") > -1 && val.indexOf("rgba") == -1)
	  val = rgb2hex(val);
  if (val.length == 4)
	  val = '#'+val.substring(1,1)+val.substring(1,1)+val.substring(2,1)+val.substring(2,1)+val.substring(3,1)+val.substring(3,1);
  return val;
}

function rgb2hex(value)
{
	var x = 255;
	var hex = '';
	var i;
	var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
	var array=regexp.exec(value);
	for(i=1;i<4;i++) hex += ('0'+parseInt(array[i]).toString(16)).slice(-2);
	return '#'+hex;
}

function isEmailValid(emailAddr)
{
 return emailAddr.match("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$");
}

function removeNonDigits(textStr) {
  var tempStr = textStr + "";
  return tempStr.replace(/\D/g, "");
}

function trim(aTextString)
{
  return aTextString.replace(/^\s+|\s+$/g, '');
}

function isEmpty(aTextField) {
   if ((aTextField == null) || (aTextField.length == 0)) {
      return true;
   }
   else { return false; }
} 

function isValidZipcode(zipcode) {
   if (!(zipcode.length == 5)) return false;
   if (!isNumeric(zipcode)) return false;
   return true;
}

function isValidPostalcode(postalcode) {
      if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
      else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z](-|\s)\d[a-zA-Z]\d$/) != -1) return true;
      else return false;
   return true;
}

function ShowDiv(divName) {
   document.getElementById(divName).style.display = 'block';		
}

function HideDiv(divName) {
   document.getElementById(divName).style.display = 'none';		
}

/* Nifty corners */

function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

function Rounded(selector,wich,bk,color,opt){
var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;

if(color=="transparent"){
    cn=cn+"x";
    ecolor=bk;
    bk="transparent";
    }
else if(opt && opt.indexOf("border")>=0){
    var optar=opt.split(" ");
    for(i=0;i<optar.length;i++)
        if(optar[i].indexOf("#")>=0) ecolor=optar[i];
    if(ecolor=="") ecolor="#666";
    cn+="e";
    edges=true;
    }
else if(opt && opt.indexOf("smooth")>=0){
    cn+="a";
    ecolor=Mix(bk,color);
    }
if(opt && opt.indexOf("small")>=0) cn+="s";
prefixt=cn;
prefixb=cn;
if(wich.indexOf("all")>=0){t=true;b=true}
else if(wich.indexOf("top")>=0) t="true";
else if(wich.indexOf("tl")>=0){
    t="true";
    if(wich.indexOf("tr")<0) prefixt+="l";
    }
else if(wich.indexOf("tr")>=0){
    t="true";
    prefixt+="r";
    }
if(wich.indexOf("bottom")>=0) b=true;
else if(wich.indexOf("bl")>=0){
    b="true";
    if(wich.indexOf("br")<0) prefixb+="l";
    }
else if(wich.indexOf("br")>=0){
    b="true";
    prefixb+="r";
    }
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    if(edges) AddBorder(v[i],ecolor);
    if(t) AddTop(v[i],bk,color,ecolor,prefixt);
    if(b) AddBottom(v[i],bk,color,ecolor,prefixb);
    }
}

function AddBorder(el,bc){
var i;
if(!el.passed){
    if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){
        var t=el.firstChild.nodeValue;
        el.removeChild(el.lastChild);
        var d=CreateEl("span");
        d.style.display="block";
        d.appendChild(document.createTextNode(t));
        el.appendChild(d);
        }
    for(i=0;i<el.childNodes.length;i++){
        if(el.childNodes[i].nodeType==1){
            el.childNodes[i].style.borderLeft="1px solid "+bc;
            el.childNodes[i].style.borderRight="1px solid "+bc;
            }
        }
    }
el.passed=true;
}

function AddTop(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingTop=0;
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateEl(x){
if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x));
else return(document.createElement(x));
}

function getElementsBySelector(selector){
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];

if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    f=document.getElementById(fs[1]);
    if(f) return(f.getElementsByTagName(s[1]));
    return(objlist);
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    f=document.getElementById(selid);
    if(f) objlist.push(f);
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className.indexOf(selclass)>=0){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    }
return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));
}


window.onload=function(){
if(!NiftyCheck())
    return;
Rounded("div#featured div","all","#FFF","#FFE07A","smooth");
}

function HideDiv(divName) {
   document.getElementById(divName).style.display = 'none';		
}

//-->
