var myHomeURL='http://www.embirddogdesigns.com';
var xmlhttp=false;
//************************************ database ******************************
var mnum=0;
var msel=[];
var mid=[];
var mname=[];
var mcomment=[];
var mclass=[];
var murlmin1=[];
var murlmin2=[];
var murlmin3=[];
var mbank=[];
var mcolinfo=[];
var mchangesnum=[];
var msize=[];
var msizecm=[];
var munit=[];
var mstitchnum=[];
var msupplier=[];
var mnew=[];
var mthumburl2=[];
var mthumburl3=[];
var mthumburl=[];
var mvernum=[];
//****************************************** doc **********************************
var dcol=[];
var dpnt=[];
var dmad=[];
var dsul=[];
var dcon=[];
var dred=[];
var dgrn=[];
var dblu=[];
var dnum=0;

var speclist=[];
var specn=0;
var speci=0;

var mbookmark="";
var mimgcnt=0;


//************************************* formats ************************************
var flist=new Array("DST","XXX","CSD","EXP","PEC","KSM","PCS","PCM","HUS","PES","SEW","JEF","VIP","EDR");
var fsel=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);

//*********************************** shop info ************************************
var composingcart=false;
var sord=[];  //sorted index array
var pgnum=0;
var sortcrit='time';
var thumbsz='large';
var dtamount='less';
var szunits='inches';
var baseidx=0;
var pgitems=35;
var pgitemheight=355;
var minpgitemwidth=230;

// **************************** constants ***************************************************
var l_pgitems=35;
var l_pgitemheight=355;
var l_minpgitemwidth=230;
var s_pgitems=35;
var s_pgitemheight=260;
var s_minpgitemwidth=180;

//*************************************** general variables ***************************
var items=1;
var suhlas=0;
var msugitems=0;


/*@cc_on @*/
 
/*@if (@_jscript_version >= 5)
 
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
 
@else
 
	xmlhttp = false;
 
@end @*/
 
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 
	try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {xmlhttp = false;}
 
}

//***************************************************************************************************************

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

//***************************************
function makeFile(fname,fcontent){
    fso = new ActiveXObject("Scripting.FileSystemObject");

    var TristateFalse = 0;
    var ForWriting = 2;
    thepage = fname;
    fso.CreateTextFile(thepage,true);
    a = fso.GetFile(thepage);
    b = a.OpenAsTextStream(ForWriting, TristateFalse);
    b.Write(fcontent);
    b.Close();
    return false;
}

//******************************************************
function getRSSdate()
  {
  var d="";
  var day_name=new Array(7);
  day_name[0]="Sun"
  day_name[1]="Mon"
  day_name[2]="Tue"
  day_name[3]="Wed"
  day_name[4]="Thu"
  day_name[5]="Fri"
  day_name[6]="Sat"
  
  var month_name=new Array(12);
  month_name[0]="Jan"
  month_name[1]="Feb"
  month_name[2]="Mar"
  month_name[3]="Apr"
  month_name[4]="May"
  month_name[5]="Jun"
  month_name[6]="Jul"
  month_name[7]="Aug"
  month_name[8]="Sep"
  month_name[9]="Oct"
  month_name[10]="Nov"
  month_name[11]="Dec"

  var mdate=new Date();
  d+=day_name[mdate.getDay()]+', ';
  d+=mdate.getDate()+' ';
  d+=month_name[mdate.getMonth()]+' ';
  d+=mdate.getFullYear()+' ';
  d+=mdate.getHours()+':';
  var min=mdate.getMinutes().toString();
  if (min.length<2) {min='0'+min};
  d+=min+':';
  var sec=mdate.getSeconds().toString();
  if (sec.length<2) {sec='0'+sec};
  d+=sec+' +0100';
  
  //var d2 = new Date()
  //var s=d2.toUTCString();

  //alert(d);
  return d;
  };

//*****************************************************
function rssHead(rssname)
{
var xitem='';
xitem+='<?xml version="1.0" ?>'+'\n';
xitem+='<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'+'\n';
xitem+='  <channel>'+'\n';
xitem+='    <atom:link href="'+myHomeURL+'/'+rssname+'" rel="self" type="application/rss+xml" />'+'\n';
xitem+='    <title>Embird Dog Designs</title>'+'\n';
xitem+='    <link>'+myHomeURL+'</link>'+'\n';
xitem+='    <description>Embird Dog Designs</description>'+'\n';
xitem+='    <lastBuildDate>'+getRSSdate()+'</lastBuildDate>'+'\n';
xitem+='    <language>en-us</language>'+'\n';
xitem+='    <copyright>Copyright BALARAD, s.r.o.</copyright>'+'\n';
xitem+='    <image>'+'\n';
xitem+='        <title>Embird Dog Designs</title>'+'\n';
xitem+='        <url>'+myHomeURL+'/grpx/embird.gif</url>'+'\n';
xitem+='        <link>'+myHomeURL+'</link>'+'\n';
xitem+='    </image>'+'\n';
//alert(xitem);
return xitem;
};

//*********************************************************
function rssEnd()
{
var xitem='';
xitem+='  </channel>'+'\n';
xitem+='</rss>'+'\n';
return xitem;
};

//*****************************************************
function rssItem(j)
{
var xitem="";
xitem+='          '+codeStr(mid[j]+'  '+'<a href="'+myHomeURL+'/index.htm"><img border="0" src="'+myHomeURL+'/newmin/'+murlmin1[j]+'.gif" alt="'+mname[j]+'"></a>'+'  '+mname[j]+'<br>');
xitem+='\n'; //end of line
return xitem;
};

//******************************************
function codeStr(s)
 {
 var q=s.replace(/</g,'&lt;');
 q=q.replace(/>/g,'&gt;');
 return q;
 };
 
//*************************************************
function pad(number, length) {
 var str = number.toString();
 while (str.length < length) {
       str = '0' + str;
       }
 return str;
}
 
//*****************************************************
function genHTML(mfolder)
{
var filename='';
var csvfname='';
var subfolder='';
var prevcolection='';
var actcolection='';

for (j=0; j<mnum; j++)
  {
  //-----------------
  actcolection=mbank[j].slice(0,4);
  //alert(actcolection);
  if (actcolection!=prevcolection)
    {
     prevcolection=actcolection;
     subfolder=actcolection+'/';
    }
  
   csvfname='../'+'threads/'+mid[j];
   if (mthumburl2[j].length>0 || mthumburl3[j].length>0)
     {
     csvfname+='a';
     };

   filename=mfolder+subfolder+pad(j+1,4)+'.html';
   //alert(filename);
   loadSpecPDF(csvfname+'.csv', j.toString(), mthumburl[j], filename);

   if (mthumburl2[j].length>0)
     {
     csvfname='../'+'threads/'+mid[j]+'b';
     filename=mfolder+subfolder+pad(j+1,4)+'b.html';
     loadSpecPDF(csvfname+'.csv', j.toString(), mthumburl2[j], filename);
     }

   if (mthumburl3[j].length>0)
     {
     csvfname='../'+'threads/'+mid[j]+'c';
     filename=mfolder+subfolder+pad(j+1,4)+'c.html';
     loadSpecPDF(csvfname+'.csv', j.toString(), mthumburl3[j], filename);
     };
   //-------
   

  }
alert('html pages stored in '+ mfolder);
}

//*****************************************************
function genRSS(rssname)
{
  var Hditem=rssHead(rssname);
  var Bditem='';
  Bditem+='    <item>'+'\n';
  Bditem+='       <title>New Embird Dog Designs</title>'+'\n';
  Bditem+='       <link>'+myHomeURL+'/index.htm</link>'+'\n';
  Bditem+='       <guid>'+myHomeURL+'/index.htm</guid>'+'\n';
  Bditem+='       <description>'+'\n';
  Bditem+='          '+codeStr('<div style="margin-left:32px; width:60%; text-align:left">')+'\n';
  Bditem+='          '+codeStr('<div style="text-align:center">');
  Bditem+='          '+codeStr('<b>Please visit our web site '+myHomeURL+' to see our latest designs</b>');
  Bditem+='          '+codeStr('</div>')+'\n';
  Bditem+='          '+codeStr('<div style="margin-left:25%;">')+'\n';
  for (j=0; j<mnum; j++)
   {
   if (mnew[j]=='N')
     {
     Bditem+=rssItem(j);
     };
   };
  Bditem+='          '+codeStr('</div>')+'\n';
  Bditem+='          '+codeStr('<p align="left">Our designs are programs (stitch files) for embroidery machines. We create our designs in <a href="http://www.embird.com" style="font-weight:bold;">Embird embroidery software</a>. Realistic fur effect was achieved with use of large number of manual stitches running at various angles. Therefore, these designs are not resizable in any larger scale. In contrast to plain-stitch fills, manual stitches are not homogenous and cannot be recalculated to a new size while preserving density at the same time. Therefore, most of designs are delivered in 3 sizes (cap size, left chest and larger left chest size). Delivery (e-mail) contains also picture documentation and list of recommended colors.</p>')+'\n';
  Bditem+='          '+codeStr('<p align="center">Copyright &#169; BALARAD, s.r.o. All Rights Reserved.</p>')+'\n';
  Bditem+='          '+codeStr('</div>')+'\n';
  Bditem+='       </description>'+'\n';
  Bditem+='       <pubDate>'+getRSSdate()+'</pubDate>'+'\n';
  Bditem+='    </item>'+'\n';
  var Editem=rssEnd();
  var fname='c:/'+rssname;
  makeFile(fname, Hditem+Bditem+Editem);
  alert('RSS feed is stored in '+fname);
};

//*****************************************************

function codeStr2(s)
 {
 return s;
 };

//*****************************************************

function blogItem(j)
{
var xitem="";
xitem+='          '+codeStr2(mid[j]+'  '+'<a href="'+myHomeURL+'/index.htm"><img border="0" src="'+myHomeURL+'/newmin/'+murlmin1[j]+'.gif" alt="'+mname[j]+'"></a>'+'  '+mname[j]+'<br>');
xitem+='\n'; //end of line
return xitem;
};

//*****************************************************

function genBlog(blogname)
{
  var Hditem='<html>';
  var Bditem='';
  Bditem+='  '+codeStr2('<div style="margin-left:32px; width:100%; text-align:left">')+'\n';
  Bditem+='  '+codeStr2('<div style="text-align:center">');
  Bditem+='  '+codeStr2('<b>Please visit our web site '+myHomeURL+' to see our latest designs</b>');
  Bditem+='  '+codeStr2('</div>')+'\n';
  Bditem+='  '+codeStr2('<div style="margin-left:25%;">')+'\n';
  for (j=0; j<mnum; j++)
   {
   if (mnew[j]=='N')
     {
     Bditem+=blogItem(j);
     };
   };
  Bditem+='  '+codeStr2('</div>')+'\n';
  Bditem+='  '+codeStr2('<p align="left">Our designs are programs (stitch files) for embroidery machines. We create our designs in <a href="http://www.embird.com" style="font-weight:bold;">Embird embroidery software</a>. Realistic fur effect was achieved with use of large number of manual stitches running at various angles. Therefore, these designs are not resizable in any larger scale. In contrast to plain-stitch fills, manual stitches are not homogenous and cannot be recalculated to a new size while preserving density at the same time. Therefore, most of designs are delivered in 3 sizes (cap size, left chest and larger left chest size). Delivery (e-mail) contains also picture documentation and list of recommended colors.</p>')+'\n';
  Bditem+='  '+codeStr2('<p align="center">Copyright &#169; BALARAD, s.r.o. All Rights Reserved.</p>')+'\n';
  Bditem+='  '+codeStr2('</div>')+'\n';
  var Editem='</html>';
  var fname='c:/'+blogname;
  makeFile(fname, Hditem+Bditem+Editem);
  alert('Blog is stored in '+fname);
};

//*****************************************************
function setBaseIdxAndShowShop(bidx,j)
{
  baseidx=bidx;
  mbookmark='bmk'+mid[j];
  storeShopInfo();
  window.location.assign("shop.htm");
};

//*****************************************************
function MinBreedItem(q,j,poradie)
{
var mbase=pgitems*Math.floor(q/pgitems);
var coltxt='rgb(0,0,0)';
var //xitem='<div class="breedit" style="margin-bottom:4px; font-size:xx-small; color:'+coltxt+'">';
    //xitem+='<a href="javascript:setBaseIdxAndShowShop('+mbase+')" style="text-decoration:none; font-weight:normal;">';
    xitem='<a href="breeds.htm" class="breedlink" style="font-weight:normal;">';
    xitem+=mname[j]; //+' '+mcomment[j];
    if (mclass[j].toLowerCase()=='cat')
      {
      xitem+=' (Cat)';
      }
    if (mclass[j].toLowerCase()=='horse')
      {
      xitem+=' (Horse)';
      }
    xitem+='</a><br>';
    //if (mnew[j]=='N')
    //  {xitem+='<span style="font-weight:bold; padding-left:32px; color:rgb(255,100,0);">'+'New!'+'</span>'};
    //xitem+='</div>';
 return xitem;
};

//******************************************************
function genMinBreedList(htmlname)
  {
  var Hditem='<html>'+'\n';
  Hditem+='<head>'+'\n';
  Hditem+='</head>'+'\n';
  Hditem+='<body>'+'\n';
  var Bditem='';
  
    //sort names
    var idxa=[];
    for (j=0; j<mnum; j++)
          {idxa[j]=mname[j].toLowerCase()+mcomment[j].toLowerCase()+'*'+j;};
          quick_sort(idxa);

    //doglist
    var prevch='_';
    var newch='_';
    var prevbreed='_';
    var newbreed='';
    var poradie=0;
    for (j=0; j<mnum; j++)
      {
      var txt=idxa[j].split("*");
      var ix=txt[1];
      //if (mclass[ix].toLowerCase()!='cat' && mclass[ix].toLowerCase()!='horse')
      //  {
        if (sortcrit=='name')
          {
          var newitem=MinBreedItem(j,ix,poradie);
          }
         else
          {
          var newitem=MinBreedItem(mnum-1-ix,ix,poradie);
          };
        newbreed=mname[ix];
        if (newbreed!=prevbreed)
          {
          prevbreed=newbreed;
          Bditem+=newitem+'\n';
          };
        //newch=mname[ix].charAt(0);
        //alert(newch);
        //if (newch!=prevch)
        // {
        // prevch=newch;
        // poradie=0;
        // var newletter=letterItem(newch);
        // AddItem(xid, xid+'end', newletter);
        // }
        //} else {poradie++};
      }; //for j
  var Editem='</body>'+'\n';
  Editem+='</html>'+'\n';
  var fname='c:/'+htmlname;
  makeFile(fname, Hditem+Bditem+Editem);
  alert('Blog is stored in '+fname);
};
  
//*****************************************************
function breedItem(q,j,poradie)
{
var mbase=pgitems*Math.floor(q/pgitems);
var coltxt='rgb(0,0,0)';
var xitem='<div class="breedit" style="margin-bottom:4px; color:'+coltxt+'">';
    xitem+='<a href="javascript:setBaseIdxAndShowShop('+mbase+','+j+')">';
    xitem+=mname[j]+' '+mcomment[j]+'<span style="font-weight:normal; font-size:x-small;"> ~ '+mid[j]+'   ~   collection '+mbank[j]+'</span>';
    xitem+='</a>';
    if (mnew[j]=='N')
      {xitem+='<span style="font-weight:bold; padding-left:32px; color:rgb(255,100,0);">'+'New!'+'</span>'};
    xitem+='</div>';
 return xitem;
};

//*****************************************************
function letterItem(L)
{
var xitem='<div style="margin-top:16px; font-weight:bold; color:rgb(150,70,0); font-size:medium; ">';
    xitem+=L;
    xitem+='</div>';
 return xitem;
};

//*****************************************************
function insertLikeButtons()
{
var xid='like';
var me=document.getElementById(xid);
if (me)
  {
//var xitem='<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.embirddogdesigns.com/index.htm" data-text="New dog embroidery designs" data-count="vertical">Tweet</a>'+'\n';
var xitem='';
    //xitem='<a href="http://twitter.com/share?url=http%3A%2F%2Fwww.embirddogdesigns.com%2Findex.htm&amp;text=New dog embroidery designs&amp;count=vertical" class="twitter-share-button" rel="nofollow">Tweet</a>'+'\n';
    //xitem+='&nbsp;&nbsp;'+'\n';
	//xitem+='<fb:like href="http://www.embirddogdesigns.com/index.htm" layout="box_count"></fb:like>'+'\n';
   xitem+='<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.embirddogdesigns.com%2Findex.htm&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px; height:60px;" allowTransparency="true"></iframe>'+'\n';
  me.innerHTML=xitem;
  //document.getElementById(xid).innerHTML='<div id="'+xid+'end"></div>';
  //AddItem(xid, xid+'end', xitem);
  //alert(xitem);
  }
}

//*****************************************************
function composeBreedList()
{
//clear all lists
var xid='doglist';
var me=document.getElementById(xid);
if (me)
  {
    document.getElementById(xid).innerHTML='<div id="'+xid+'end"></div>';
    xid='catlist';
    document.getElementById(xid).innerHTML='<div id="'+xid+'end"></div>';
    xid='horselist';
    document.getElementById(xid).innerHTML='<div id="'+xid+'end"></div>';

    //sort names
    var idxa=[];
    for (j=0; j<mnum; j++)
          {idxa[j]=mname[j].toLowerCase()+mcomment[j].toLowerCase()+'*'+j;};
          quick_sort(idxa);
          //alert(idxa);

    //doglist
    var prevch='_';
    var newch='_';
    var poradie=0;
    for (j=0; j<mnum; j++)
      {
      var txt=idxa[j].split("*");
      var ix=txt[1];
      if (mclass[ix].toLowerCase()!='cat' && mclass[ix].toLowerCase()!='horse')
        {
        if (sortcrit=='name')
          {
          var newitem=breedItem(j,ix,poradie);
          }
         else
          {
          var newitem=breedItem(mnum-1-ix,ix,poradie);
          };
        newch=mname[ix].charAt(0);
        //alert(newch);
        if (newch!=prevch)
         {
         prevch=newch;
         poradie=0;
         var newletter=letterItem(newch);
         AddItem('doglist', 'doglistend', newletter);
         }
        AddItem('doglist', 'doglistend', newitem);
        } else {poradie++};
      }; //for j

    //catlist
    var prevch='_';
    var newch='_';
    for (j=0; j<mnum; j++)
      {
      var txt=idxa[j].split("*");
      var ix=txt[1];
      if (mclass[ix].toLowerCase()=='cat')
        {
        if (sortcrit=='name')
          {
          var newitem=breedItem(j,ix,poradie);
          }
         else
          {
          var newitem=breedItem(mnum-1-ix,ix,poradie);
          };
        newch=mname[ix].charAt(0);
        //alert(newch);
        if (newch!=prevch)
         {
         prevch=newch;
         poradie=0;
         var newletter=letterItem(newch);
         AddItem('catlist', 'catlistend', newletter);
         }
        AddItem('catlist', 'catlistend', newitem);
        } {poradie++};

      }; //for j


    //horselist
    var prevch='_';
    var newch='_';
    for (j=0; j<mnum; j++)
      {
      var txt=idxa[j].split("*");
      var ix=txt[1];
      if (mclass[ix].toLowerCase()=='horse')
        {
        if (sortcrit=='name')
          {
          var newitem=breedItem(j,ix,poradie);
          }
         else
          {
          var newitem=breedItem(mnum-1-ix,ix,poradie);
          };
        newch=mname[ix].charAt(0);
        //alert(newch);
        if (newch!=prevch)
         {
         prevch=newch;
         poradie=0;
         var newletter=letterItem(newch);
         AddItem('horselist', 'horselistend', newletter);
         }
        AddItem('horselist', 'horselistend', newitem);
        } {poradie++};

      }; //for j
  }; // if me
};

//***************************************************
function selSort(crit)
{
 //alert(crit+' '+sortcrit);
if (sortcrit!=crit)
 {
  sortcrit=crit;
  //alert(crit);
  baseidx=0;
  storeShopInfo();
  genShopInfo();
  composeShop(baseidx);
  composeBreedList();
 };
};

//***********************************

function setThumbSize(xsize)
 {
if (thumbsz!=xsize)
 {
 thumbsz=xsize;
 storeShopInfo();
 genShopInfo();
 composeShop(baseidx);
 };
};

//***************************************************

function setInfo(xamount)
{
  if (dtamount!=xamount)
   {
   dtamount=xamount;
   storeShopInfo();
   genShopInfo();
   composeShop(baseidx);
   };
};

//***************************************************

function setUnits(xunits)
{
  //alert('setunits');
  if (szunits!=xunits)
   {
   szunits=xunits;
   storeShopInfo();
   genShopInfo();
   composeShop(baseidx);
   };
};

//***************************************************
function storeShopInfo(){
var txt="";
txt=baseidx+'*'+sortcrit+'*'+thumbsz+'*'+dtamount+'*'+szunits+'*'+mbookmark;
//fsel.join("*");
msetCookie("EbrdShp",txt);
};

//***************************************************
function genShopInfo(){
   pgnum=Math.ceil(mnum/pgitems);
   

    if (thumbsz=='large')
     {
      pgitems=l_pgitems;
      pgitemheight=l_pgitemheight;
      minpgitemwidth=l_minpgitemwidth;
     }
    else
     {
     pgitems=s_pgitems;
     pgitemheight=s_pgitemheight;
     minpgitemwidth=s_minpgitemwidth;
     };

   if (dtamount=='less') pgitemheight-=50;

   if (sortcrit=='name')
     {
      //order - name
      for (j=0; j<mnum; j++)
      {
      sord[j]=mname[j].toLowerCase()+mcomment[j].toLowerCase()+'*'+j;
      };
      quick_sort(sord);
      //alert(sord);
      for (j=0; j<mnum; j++)
      {
      var txt=sord[j].split("*");
      sord[j]=txt[1];
      };
      //alert(sord);
     }
    else
     {
      //basic order - time
      for (j=0; j<mnum; j++)
      {
      sord[j]=mnum-1-j;
      };
     };


   //disp selected params

   var q=document.getElementById('sortcr');
   if (q)
     {
     for (var i=0; i<q.options.length; i++)
       {
       if (q.options[i].value==sortcrit) {q.options[i].selected=true} else {q.options[i].selected=false};
       }
     };

   var q=document.getElementById('thsize');
   if (q)
     {
     for (var i=0; i<q.options.length; i++)
       {
       if (q.options[i].value==thumbsz) {q.options[i].selected=true} else {q.options[i].selected=false};
       }
     };

   var q=document.getElementById('dtamount');
   if (q)
     {
     for (var i=0; i<q.options.length; i++)
       {
       if (q.options[i].value==dtamount) {q.options[i].selected=true} else {q.options[i].selected=false};
       }
     };

   var q=document.getElementById('szunit');
   if (q)
     {
     for (var i=0; i<q.options.length; i++)
       {
       if (q.options[i].value==szunits) {q.options[i].selected=true} else {q.options[i].selected=false};
       }
     };

};

//****************************************************
function tryBookmark()
{
if (mbookmark!='')
  {
  //alert('found bookmark '+mbookmark);
  //var newurl='shop.htm#'+mbookmark;
  var oldbookmark=mbookmark;
  mbookmark='';
  storeShopInfo();
  window.location.assign('#'+oldbookmark);
  //window.location.assign(newurl);
  };
};

//***************************************************
function restoreShopInfo(){
//alert(document.referrer);

var cs=mgetCookie("EbrdShp");
 if (cs)  {
    var txt=cs.split("*");
    if (txt.length>0)
      {
      baseidx=Number(txt[0]);
      sortcrit=txt[1];
      thumbsz=txt[2];
      dtamount=txt[3];
      szunits=txt[4];
      mbookmark=txt[5];
      //alert('restore shop '+baseidx);
      //alert (baseidx+ ' '+sortcrit);
      };
  } //if cs

  genShopInfo();
};



//**********************************************************
function createDesignCell(j,mwidth)
{
var cellid='q'+mid[j];
;
var cell='<div id="' + 'w'+mid[j] +'" class="cellwrap" style="float:left; display:inline; width:'+ mwidth + 'px; height:'+pgitemheight+'px; padding-left:7px; padding-right:7px; margin-left:7px; margin-right:7px; margin-bottom:10px; margin-top:4px; border:solid 1px rgb(220,220,220);">';

cell+='<div id="' + cellid +'" align="center">';

  cell+='<div id="'+cellid+'end"></div>';

  //cell+='Design: '+mid[j];
  cell+='<div style="text-align:center;">';
    cell+='<input type="checkbox" id="' + mid[j] + '"value="ON" ';
    cell+='style="width:32px; height:32px; margin-top:5px;" onClick="makeSel()"';
    cell+='>';
  cell+='</div>';

cell+='</div>';
cell+='</div>';

//alert(cell);
return[cellid,cell];
}

//**********************************************************

function getThumbFontSize(msz)
{
var mlarge="medium";
var mnorm="small";
var msmall="x-small";
var mchbox=28;

if (msz=='small')
  {
  mlarge="small";
  mnorm="x-small";
  msmall="xx-small";
  mchbox=20;
  };
  
if (msz=='large')
  {
  mlarge="large";
  mnorm="medium";
  msmall="small";
  mchbox=28;
  };
  
if (msz=='xlarge')
  {
  mlarge="x-large";
  mnorm="large";
  msmall="medium";
  mchbox=32;
  };
  
return [mlarge,mnorm,msmall,mchbox];
};


//**********************************************************
function createDesignCell2(j,mwidth)
{
var fntsz=getThumbFontSize(thumbsz);
var cellid='q'+mid[j];

var cell='';


cell+='<div id="' + 'w'+mid[j] +'" class="cellwrap" style="float:left; text-align:center; display:inline; width:'+ mwidth + 'px; height:'+pgitemheight+'px; margin-bottom:10px; margin-top:4px; margin-left:7px; margin-right:7px; background-color:rgb(255,255,255);  border:solid 1px rgb(220,220,220);">';

cell+='<div>';
cell+='<a name="'+'bmk'+mid[j]+'">';
cell+='</a>';
cell+='</div>';


var pomh=pgitemheight-20;
var pomw=mwidth-20;
cell+='<div style="width:100%;">';

cell+='<div style="float:left; margin-left:7px; margin-top:7px;">';
  cell+='<input type="checkbox" id="' + mid[j] + '"value="ON" ';
  cell+='style="width:'+Number(fntsz[3])+'px; height:'+Number(fntsz[3])+'px; vertical-align:middle;" onClick="makeSel()"';
  cell+='>';
  cell+='<span style="font-weight:bold; font-size:'+fntsz[0]+'; vertical-align:middle;">'+' '+mid[j]+'</span>';
cell+='</div>';

cell+='<div style="float:right; margin-top:7px; margin-right:7px;">';
  if (mnew[j]=='N') {cell+='<span style="font-size:'+fntsz[0]+'; font-weight:bold; color:rgb(255,100,0);">'+'New!'+'</span>'}
   else
     {
      if (dtamount=='more')
        {
         cell+='<span style="font-size:'+fntsz[2]+'; ">'+'Collection '+mbank[j]+'</span>';
         };
     };
cell+='</div>';



cell+='<div style="clear:both;">';
  cell+='<div id="' + cellid +'">';
  cell+='<div id="'+cellid+'end"></div>';
  cell+='</div>';
cell+='</div>'




cell+='<div id="' + cellid +'x'+'" style="padding-left:7px; padding-right:7px;">';
cell+='<div id="'+cellid+'x'+'end"></div>';
cell+='</div>';



cell+='</div>';

cell+='</div>';

//alert(cell);
return[cellid,cell];
}


//**********************************************************************************
function selDesignsPage(mybaseidx)
{
//alert(baseidx);
baseidx=mybaseidx;
storeShopInfo();
composeShop(baseidx);
};


//**********************************************************************************

function saveImageAs (imgOrURL,fname) {
if (typeof imgOrURL == 'object')
imgOrURL = imgOrURL.src;
window.win = open (imgOrURL);
setTimeout('win.document.execCommand("SaveAs")', 500);
}

function ImgOnLoad(xid) {

//alert(xid);
var me=document.getElementById('w'+xid);
if (me) 
  {
  idx=mid.indexOf(xid);
  mw1=document.getElementById('y'+xid).width;
  mw2=mw1;
  if (!mthumburl2[idx]=='') mw2=mw2+mw1;
  if (!mthumburl3[idx]=='') mw2=mw2+mw1;
  if (mw2<minpgitemwidth) mw2=minpgitemwidth;
  me.style.overflow='hidden';
  me.style.width=mw2+35;
  me.style.overflow='auto';
  
  //po nahrati posledneho img sa pokusim uplatnit bookmark
  if (mimgcnt>=1)
    {
     mimgcnt=mimgcnt-1;
     if (mimgcnt==0) {tryBookmark();};
    }
  
  //var fname='x'+mid[idx]+'.jpg';
  //saveImageAs(document.getElementById('y'+xid), fname);
  
  //var fname='x'+mid[idx]+'.jpg';
  //alert(fname);
  //var qe=document.getElementById('y'+xid);
  //qe.document.execCommand("SaveAs");

  };
}


//****************************************************************

function composeShop(bidx)
{
//clear shop
//alert(baseidx);

var xid='ishop';
var me=document.getElementById(xid);
if (me)
 {
 me.style.display='none';
 me.innerHTML='<div id="'+xid+'end"></div>';

 var newImg=[];
 
 mimgcnt=pgitems;

 for (j=0; j<pgitems; j++)
       {
       sidx=bidx+j; //index to sorted
       //alert('sidx'+sidx);
       if (sidx<mnum)
          {
           var idx=sord[sidx];
    
           var mcell=createDesignCell2(idx, minpgitemwidth);
           AddItem(xid, xid+'end',mcell[1]);  //vlozenie bunky do shopu
           var newitem=thumbItem(idx,false,thumbsz,dtamount,szunits);
           //newitem+=sidx+'/'+mnum;
           //var newitem=mid[idx];
           AddItem(mcell[0],mcell[0]+'end', newitem[0]); //vlozenie img do bunky
           AddItem(mcell[0]+'x',mcell[0]+'xend', newitem[1]); //vlozenie textu do bunky
          }
       };


 //clear page select
 pid="pgselect";
 document.getElementById(pid).innerHTML='<div id="'+pid+'end"></div>';

 var pgline="";
 for (j=0; j<pgnum; j++)
  {
  var txt=j+1;
  
  var mbase=j*pgitems;
  //pgline+='<input type="button" value="'+txt+'" style="width:30px; height:32px; margin-left:2px; margin-right:2px; margin-bottom:4px;';
  //if (baseidx>=mbase && baseidx<mbase+pgitems) {pgline+='font-weight:bold; background-color:rgb(255,255,100);';}
  //   else {pgline+='background-color:rgb(245,230,245);';};
  //pgline+='" onClick="selDesignsPage('+ mbase +')">';

  pgline+='<a href="javascript:selDesignsPage('+ mbase +')" style="margin:2px; padding:3px; height:30px; font-size:medium; text-decoration:none; ';
  if (baseidx>=mbase && baseidx<mbase+pgitems) {pgline+='color:rgb(240,120,0); border:1px solid rgb(255,210,200);';}
     else {pgline+='color:rgb(100,100,100);';};
  pgline+='">'+txt+'</a>';

  } 
  //alert(pgline);
  AddItem(pid, pid+'end',pgline);  //vlozenie pgselect

  dispCheckboxes();
  dispCart();
  
  me.style.display='block';
  };//if me
};



//******************************************************************************

function CorrectData()
  { 
    var res="n";
    var sum=sumAll();
    
    if (sum[1]+sum[2]>0)     //pocet+pocetlinedraw
    {
      if (sum[3]>0)  //pocet formatov
      {
        if (CheckEmailAddress(document.getElementById('DMAIL').value)) 
          {
             res="y";
          } else {alert("E-mail address is not correct!")};
      } else {alert("Please select embroidery file format.")};
    } else {alert("Shopping cart is empty")};

   return res;
  }


//*************************************
function storePayData(adresa,tovar,cena)
 {
 var txt="";
 txt=adresa+'*'+tovar+'*'+cena;
 msetCookie("EbrdPay",txt);
 };
 
//*************************************
function restorePayData()
 {
 var adresa="Undefined";
 var tovar="Undefined";
 var cena=0;
 var cs=mgetCookie("EbrdPay");
 if (cs)  {
    var txt=cs.split("*");
    if (txt.length>0)
      {
      adresa=txt[0];
      tovar=unescape(txt[1]);
      cena=Number(txt[2]);
      };
   } else {alert('Payment is not possible. Please enable cookies in your browser.')};
  return [adresa,tovar,cena];
 };

//****************************************************************************
function enableOrder()
   {
   suhlas=0;

      if (CorrectData()=="y")
        {
        suhlas=1;
        var q=document.getElementById("mysendemail");
        if (q)
          {
           var sum=makeSummary();
           var adresa=document.getElementById('DMAIL').value;
           document.getElementById("emailadresa").value=adresa;
           document.getElementById("emailtovar").value=sum[0];
           storePayData(adresa,sum[0],sum[1])
           q.action=myHomeURL+"/sendemail.php";
           q.submit();
          };
       };
  };
  
//*****************************************************************************
// Read a page's GET URL variables and return them as an associative array
 function getUrlVars()
  {
  var map = {};
  var parts = window.location.search.replace(/[?&]+([^=&]+)(=[^&]*)?/gi, function(m,key,value) { map[key] = (value === undefined) ? true : value.substring(1); });
  return map;
 }


//***************************************************************************************************************
function makeSummary(){
var d="";
var sum=sumAll();
var cena=sum[0];

for (j=0; j<msel.length; j++) 
  {
  if (msel[j]=='y'){d+=mid[j]+', ';};
  }
for (j=0; j<fsel.length; j++) 
  {
  if (fsel[j]==1){d+=flist[j]+', ';};
  }
//alert('designs: '+d);
//alert('cena: '+cena);
return [d,cena];
};


//***************************************************************************************************************
function selFormat() {
for (j=0; j<flist.length; j++) {
  var me=document.getElementById(flist[j]);
  //alert(flist[j]+'  '+me.id);
  if(me.getAttribute('type')=='checkbox'){
    if (me.checked==true)
    {fsel[j]=1;}
    else
    {fsel[j]=0;};
    };
  };

StoreFormats();
//composeCartPage();
updateCart();
};


//***************************************************
function dispFormats(){
      for (j=0; j<fsel.length; j++) 
      {
      var me=document.getElementById(flist[j]);
      if(me.getAttribute('type')=='checkbox')
        {
        if (fsel[j]==1){me.checked=true;} else {me.checked=false;};
        };
      };
      //alert('transferred');
};


//***************************************************
function StoreFormats(){
msetCookie("EbrdFr",fsel.join("*"));
};


//***************************************************
function RestoreFormats(){
//alert(document.referrer);
var cs=mgetCookie("EbrdFr");
 if (cs)  {
    var pom=cs.split("*");
    if (pom.length>=fsel.length) {
      for (j=0; j<fsel.length; j++) 
      {
      fsel[j]=pom[j];
      };
    };
  }
};

//***************************************************************************************************************
function enableButtons(place){
if(place=='shop')
  {
   me=document.getElementById('iButtonClearAll');
   me.style.display="inline";
   me=document.getElementById('iButtonRecalcCart');
   me.style.display="none";
   me=document.getElementById('pgselect');
   me.style.display="inline";  
  }
else
 {
  if (place=='cart')
   {
    me=document.getElementById('iButtonClearAll');
    me.style.display="inline";
    me=document.getElementById('iButtonRecalcCart');
    me.style.display="inline";
    me=document.getElementById('pgselect');
    me.style.display="none";  
   }
  else
     {
      me=document.getElementById('iButtonClearAll');
      if (me)
        {
          me.style.display="none";
          me=document.getElementById('iButtonRecalcCart');
          me.style.display="none";
          me=document.getElementById('pgselect');
          me.style.display="none";
        };
     };

 };
};



//***************************************************************************************************************
 

function AddItem(xid,xidend,newitem) {
 //div=document.getElementById(xid);
 miesto=document.getElementById(xidend);
 if (miesto){
 items++;
 
 newnode=document.createElement("div");
 newnode.innerHTML=newitem;
 //div.insertBefore(newnode,miesto);
 miesto.parentNode.insertBefore(newnode,miesto);
 };
}


//***************************************************************************************************************
function makeSelInCart_noUpdate(){
if (!composingcart)
{
makeSel();
dispDeliveryContent();
};
};

//***************************************************************************************************************
function makeSelInCart(){
if (!composingcart)
{
makeSel();
composeCartPage();
};
};

//***************************************************************************************************************

function loadSpec() {
   speci++;
   if (speci<=specn)
     {
       var txt=speclist[speci].split('*');
       //alert(txt[0]+'/'+txt[1]+'/'+txt[2]);
       if (xmlhttp)
         {
           xmlhttp.open("GET", txt[0].toLowerCase(),true);
           xmlhttp.onreadystatechange=function()
             {
                if (xmlhttp.readyState==4)
                   {
                      //alert(xmlhttp.responseText);
                      DecodeSpecCSV(xmlhttp.responseText,Number(txt[1]),txt[2]);
                	}
             }
             xmlhttp.send(null)
        }
    }
}

//********************************************************************
function thumbItemDocPDF(j,thumburl)
{
var xitem="";
var qitem="";
var fntsz=getThumbFontSize("large");


var thfolder='../newmid/';

  //xitem+='<a href="' + docurl + '" title="'+mname[j]+'">';
  //var xid='y'+mid[j];

  xitem+='<img border="0" alt="'+mname[j]+'" src="' + thfolder + thumburl +'.jpg">'+'\n';


qitem+='<h2>';

 qitem+=mid[j]+' - ';

qitem+=mname[j] + '  ' + mcomment[j];
qitem+='</h2>'+'\n';

if (mcolinfo[j].length>0)
{
if (Number(mcolinfo[j])==1)
 {
 qitem+=mcolinfo[j]+' color';
 }
 else
 {
 qitem+=mcolinfo[j]+' colors / '+mchangesnum[j]+' thread changes';
 };
qitem+='<br>'+'\n';
};

if (msize[j].length>0)
{
qitem+='Sizes (inches): '+msize[j]; qitem+=' "';
if (munit[j]=='w') {qitem+=' width'} else {qitem+=' height'};
qitem+='<br>'+'\n';

qitem+='Sizes (cm): '+msizecm[j]; qitem+=' cm';
if (munit[j]=='w') {qitem+=' width'} else {qitem+=' height'};
qitem+='<br>'+'\n';
};

if (mstitchnum[j].length>0)
{
qitem+='Stitches: '+mstitchnum[j]+'<br>'+'\n';
};

if (msupplier[j].length>0)
{
qitem+='Photo supplied by '+msupplier[j]+'<br>'+'\n';
};

  qitem+='Collection: '+mbank[j]+'\n';


//alert(xitem);

return [xitem,qitem];
}


//***************************************************************************************************************


function loadSpecPDF(fname,dnum,turl,savepath) {
   var Hditem='';
   var Bditem='';
   var Editem='';
   if (xmlhttp)
     {
       //alert(txt[0].toLowerCase());
       xmlhttp.open("GET", fname.toLowerCase(),true);
       xmlhttp.onreadystatechange=function()
         {
            if (xmlhttp.readyState==4)
               {
                  Hditem='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'+'\n';
                  Hditem+='<html>'+'\n';
                  Hditem+='<head>'+'\n';
                  Hditem+='<title>'+mname[dnum]+','+mcomment[dnum]+'</title>'+'\n';
                  Hditem+='</head>'+'\n';

                  Hditem+='<body>'+'\n';
                  //alert(xmlhttp.responseText);
                  var sitem=genSpecItemsPDF(xmlhttp.responseText,Number(dnum),turl);
                  //alert(sitem);
                  Bditem+='<div style="margin-bottom:0px; padding-bottom:16px; border-bottom: 1px solid rgb(0,0,0);">' + '\n';
                  Bditem+='<img id="logo" border="0" alt="embird logo" src="../embirdlogo.gif">'+'\n';
                    //Bditem+='<div style="font-size:large;">'+'\n';
                    //Bditem+='Embird Embroidery Dog Designs'+'\n';
                    //Bditem+='</div>'+'\n';
                    Bditem+='<div style="font-size:normal;">'+'\n';
                    Bditem+='www.embirddogdesigns.com'+'<br>'+'\n';
                    Bditem+='© BALARAD, s.r.o. All Rights Reserved.'+'<br>'+'\n';
                    Bditem+='</div>'+'\n';
                  Bditem+='</div>'+'\n';
                  Bditem+='<div style="margin-bottom:32px; padding-bottom:16px; border-bottom: 1px solid rgb(0,0,0);">' + '\n';
                  Bditem+='<center>'+'\n';
                  Bditem+='<table cellpadding="5" cellspacing="5" width="100%">'+'\n';
                  Bditem+='<tr>'+'\n';
                  Bditem+='<td width="25%" align="right">'+sitem[0]+'</td>'+'\n';
                  Bditem+='<td width="75%">'+sitem[1]+'</td>'+'\n';
                  Bditem+='</tr>'+'\n';
                  Bditem+='</table>'+'\n';
                  Bditem+='</center>'+'\n';
                  Bditem+='</div>'+'\n';
                  Bditem+=sitem[2];
                  
                  Bditem+='<div style="clear:both; padding-top:16px; margin-top:16px; margin-bottom:32px; text-align:center;">'+'\n';
                  Bditem+='Disclaimer: above thread colors are for information only. BALARAD, s.r.o. does not quarantee their accuracy and correctness. Reference source for colors selection was Madeira thread catalog. Other color codes were found with use of conversion tables.'+'\n';
                  Bditem+='</div>'+'\n';

                  Editem+='</body>'+'\n';
                  Editem+='</html>'+'\n';

                  //alert(filename);
                  makeFile(savepath, Hditem+Bditem+Editem);

            	}
         }
         xmlhttp.send(null)
    }
}



//**********************************************

function rgb_to_hex(red,green,blue)
 {
 var rgb = blue | (green << 8) | (red << 16);
 return '#' + rgb.toString(16);
 }

//***************************************************

function genSpecItemsPDF(ds,j,thumburl) {

  var newitem=thumbItemDocPDF(j,thumburl);

  var dgs="";


  var allTextLines = [];

  allTextLines = ds.split(/\r\n|\n/);
  //alert(allTextLines.length);

   dnum=0;
   for(i=0; i<allTextLines.length; i++) {
      dgs=allTextLines[i].split(',');
      dcol[dnum]=dgs[1];
      dpnt[dnum]=dgs[2];
      dmad[dnum]=dgs[3];
      dsul[dnum]=dgs[4];
      dcon[dnum]=dgs[5];
      dred[dnum]=dgs[6];
      dgrn[dnum]=dgs[7];
      dblu[dnum]=dgs[8];
      if (dgs[0]) dnum++;
     }
    //alert('# '+dnum);


    var qitem='';
    qitem+='<center>'+'\n';
    //qitem+='<font size="2">'+'\n';
    //cellpadding="3" cellspacing="3"
    qitem+='<table border="0" cellspacing="3" width="100%">'+'\n';
    qitem+='<tr>'+'\n';
    qitem+='<td width="6%" align="center"><b>No.</b></td>'+'\n';
    qitem+='<td width="10%"><b>Color</b></td>'+'\n';
    qitem+='<td width="24%"><b>Name</b></td>'+'\n';
    qitem+='<td width="15%" align="center"><b>Pantone</b></td>'+'\n';
    qitem+='<td width="12%" align="center"><b>Madeira</b></td>'+'\n';
    qitem+='<td width="10%" align="center"><b>Sulky</b></td>'+'\n';
    qitem+='<td width="23%" align="center"><b>Consumption</b></td>'+'\n';
    qitem+='</tr>'+'\n';

    var num=0;
    for(i=0; i<dnum; i++) {
       num=i+1;
       qitem+='<tr>'+'\n';
         qitem+='<td width="6%" align="center"><b>'+num+'.'+'</b></td>'+'\n';
         //qitem+='<td width="10%"'+' '+'bgcolor='+'"'+rgb_to_hex(dred[i],dgrn[i],dblu[i])+'"'+'>'+'&nbsp;'+'</td>'+'\n';
         if (dnum<13)
           {
            qitem+='<td width="10%"><div style="border:solid 1px rgb(0,0,0); '+'color:rgb(0,0,0); '+'background-color:rgb('+dred[i]+','+dgrn[i]+','+dblu[i]+');'+' width:80px; height:32px; ">'+'&nbsp; '+'</div></td>'+'\n';
           }
          else
           {
            qitem+='<td width="10%"><div style="border:solid 1px rgb(0,0,0); '+'color:rgb(0,0,0); '+'background-color:rgb('+dred[i]+','+dgrn[i]+','+dblu[i]+');'+' width:80px; height:24px; ">'+'&nbsp; '+'</div></td>'+'\n';
           };
         qitem+='<td width="24%"><div style="background-color:rgb(255,255,255);">'+dcol[i]+'</div></td>'+'\n';
         qitem+='<td width="15%" align="center">'+dpnt[i]+'</td>'+'\n';
         qitem+='<td width="12%" align="center">'+dmad[i]+'</td>'+'\n';
         qitem+='<td width="10%" align="center">'+dsul[i]+'</td>'+'\n';
         qitem+='<td width="23%" align="center">'+dcon[i]+'</td>'+'\n';
       qitem+='</tr>'+'\n';
       }

    qitem+='</table>'+'\n';
    //qitem+='</font>'+'\n';
    qitem+='</center>'+'\n';

    //alert(newitem[0]);
    //alert(newitem[1]);
    //alert(qitem);
    return [newitem[0],newitem[1],qitem];
}

//***************************************************

function genSpecItems(ds,j,thumburl) {

  var newitem=thumbItemDoc(j,thumburl,'xlarge','more',szunits);

  var dgs="";


  var allTextLines = [];

  allTextLines = ds.split(/\r\n|\n/);
  //alert(allTextLines.length);

   dnum=0;
   for(i=0; i<allTextLines.length; i++) {
      dgs=allTextLines[i].split(',');
      dcol[dnum]=dgs[1];
      dpnt[dnum]=dgs[2];
      dmad[dnum]=dgs[3];
      dsul[dnum]=dgs[4];
      dcon[dnum]=dgs[5];
      dred[dnum]=dgs[6];
      dgrn[dnum]=dgs[7];
      dblu[dnum]=dgs[8];
      if (dgs[0]) dnum++;
     }
    //alert('# '+dnum);


    var qitem='<div style="margin-top:32px; margin-bottom:32px;">';

    qitem+='<div style="clear:both; width:90%; font-weight:bold; text-align:left; padding-top:3px; margin-bottom:7px;">';
      qitem+='<div style="float:left; width:6%; text-align:right; padding-right:10px;">No.';
      qitem+='</div>';
      qitem+='<div style="float:left; width:10%;">Color';
      qitem+='</div>';
      qitem+='<div style="float:left; width:23%; padding-left:15px;">Name';
      qitem+='</div>';
      qitem+='<div style="float:left; width:12%;">Pantone';
      qitem+='</div>';
      qitem+='<div style="float:left; width:12%;">Madeira';
      qitem+='</div>';
      qitem+='<div style="float:left; width:12%;">Sulky';
      qitem+='</div>';
      qitem+='<div style="float:left; width:22%;">Consumption';
      qitem+='</div>';
    qitem+='</div>';

    qitem+='<div style="clear:both; height:3px; width:90%; padding:0; margin:0; border-top:2px solid rgb(0,0,0);"></div>';

    var num=0;
    for(i=0; i<dnum; i++) {
    num=i+1;
    qitem+='<div style="clear:both; width:90%; text-align:left; padding-top:3px; padding-bottom:3px;">';
      qitem+='<div style="float:left; width:6%; text-align:right; padding-right:10px;">'+num+'.';
      qitem+='</div>';
      qitem+='<div style="float:left; width:10%; height:30px; border:2px solid rgb(0,0,0); background-color:rgb('+dred[i]+','+dgrn[i]+','+dblu[i]+')">';
      qitem+='</div>';
      qitem+='<div style="float:left; width:23%; padding-left:15px;">'+dcol[i];
      qitem+='</div>';
      qitem+='<div style="float:left; width:12%;">'+dpnt[i];
      qitem+='</div>';
      qitem+='<div style="float:left; width:12%;">'+dmad[i];
      qitem+='</div>';
      qitem+='<div style="float:left; width:12%;">'+dsul[i];
      qitem+='</div>';
      qitem+='<div style="float:left; width:22%; font-size:x-small;">'+dcon[i];
      qitem+='</div>';
    qitem+='</div>';
    }
    qitem+='</div>';
    
    //alert(newitem[0]);
    //alert(newitem[1]);
    //alert(qitem);
    return [newitem[0],newitem[1],qitem];
}


//***************************************************

function DecodeSpecCSV(ds,j,thumburl) {

  var xid='dgwrap';
  
  var qitem='';
  var sit=genSpecItems(ds,j,thumburl);

  AddItem(xid, xid+'end', sit[0]);
  AddItem(xid, xid+'end', sit[1]);
  AddItem(xid, xid+'end', sit[2]);
  
    //alert (dcol[i]+' = '+dpnt[i]+ ' = '+dmad[i] + ' = '+dsul[i]);
   if (speci<specn)
      {
       loadSpec();
      }
     else
      {
      qitem='<div style="clear:both; padding-top:16px; margin-top:16px; margin-bottom:32px; text-align:center;">';
      qitem+='Disclaimer: above thread colors are for information only. BALARAD, s.r.o. does not quarantee their accuracy and correctness. Reference source for colors selection was Madeira thread catalog. Other color codes were found with use of conversion tables.';
      qitem+='</div>';
      AddItem(xid, xid+'end', qitem);
      }
}

//********************************************************************
function designDoc(j)
  {
  var txt=j.toString();
  msetCookie("EbrdDoc",txt);
  //alert('set '+txt);
  window.location="spec.htm";
  };
  
//********************************************************************
function dispDoc()
  {
  var j=-1;
  
  var cs=mgetCookie("EbrdDoc");
  if (cs)  {
    //alert(cs);
    var txt=cs.split("*");
    if (txt.length>0)
      {
      j=Number(txt[0]);
      };
   } //if cs

  if (j>=0)
    {
     var xid='dgwrap';
     var me=document.getElementById(xid);
     if (me)
       {
       me.innerHTML='<div id="'+xid+'end"></div>';

       specn=0;
       speci=0;

       var fname='threads/'+mid[j];

       //alert('doc '+j+' '+fname+' '+mnum);

       if (mthumburl2[j].length>0 || mthumburl3[j].length>0)
         {
         fname+='a';
         };

       specn++;
       speclist[specn]=fname+'.csv'+'*'+j.toString()+'*'+mthumburl[j];
       
       if (mthumburl2[j].length>0)
         {
         fname='threads/'+mid[j]+'b';
         specn++;
         speclist[specn]=fname+'.csv'+'*'+j.toString()+'*'+mthumburl2[j];
         }

       if (mthumburl3[j].length>0)
         {
         fname='threads/'+mid[j]+'c';
         specn++;
         speclist[specn]=fname+'.csv'+'*'+j.toString()+'*'+mthumburl3[j];
         };
         

       loadSpec();
      }
    }
  };
  
//********************************************************************
function thumbItemDoc(j,thumburl,msz,mamount,mszunits)
{
var xitem="";
var qitem="";
var fntsz=getThumbFontSize(msz);

xitem+='<div class="thumbimg" style="text-align:center;">';

var thfolder='newmax/';
if (msz=='small' && inclcode==false) thfolder='newmid/';

xitem+='<span class="thumb" style="text-align:center;">';
  //xitem+='<a href="' + docurl + '" title="'+mname[j]+'">';
  xitem+='<a href="javascript:designDoc('+j+')" title="'+mname[j]+'">';
  var xid='y'+mid[j];
  xitem+='<img id="'+xid+'" border="0" alt="'+mname[j]+'" onLoad="ImgOnLoad(\''+mid[j]+'\')" src="' + thfolder + thumburl +'.jpg">';
  xitem+='</a>';
xitem+='</span>';

xitem+='</div>'



qitem+='<div class="thumbname" style="text-align:center; font-weight:bold; font-size:'+fntsz[1]+'; margin-top:5px; margin-bottom:5px;">';

 qitem+=mid[j]+' - ';

qitem+=mname[j] + '  ' + mcomment[j];
qitem+='</div>';

if (mcolinfo[j].length>0 && mamount=='more')
{
qitem+='<div class="thumcolinfo" style="text-align:center; font-size:'+fntsz[2]+';">';
if (Number(mcolinfo[j])==1)
 {
 qitem+=mcolinfo[j]+' color';
 }
 else
 {
 qitem+=mcolinfo[j]+' colors / '+mchangesnum[j]+' thread changes';
 };
qitem+='</div>';
};

if (msize[j].length>0 && mamount=='more')
{
qitem+='<div class="thumsize" style="text-align:center; font-size:'+fntsz[2]+';">';
if (mszunits=='inches') {qitem+='Sizes: '+msize[j]; qitem+=' "'} else {qitem+='Sizes: '+msizecm[j]; qitem+=' cm'};
if (munit[j]=='w') {qitem+=' width'} else {qitem+=' height'};
qitem+='</div>';
};

if (mstitchnum[j].length>0 && mamount=='more')
{
qitem+='<div class="thumbstitches" style="text-align:center; font-size:'+fntsz[2]+';">';
qitem+='Stitches: '+mstitchnum[j];
qitem+='</div>';
};

if (msupplier[j].length>0 && mamount=='more')
{
qitem+='<div class="thumbsupplier" style="text-align:center; font-size:'+fntsz[2]+';">';
qitem+='Photo supplied by '+msupplier[j];
qitem+='</div>';
};

  qitem+='<div class="thumbstitches" style="text-align:center; font-size:'+fntsz[2]+';">';
  qitem+='Collection: '+mbank[j];
  qitem+='</div>';


//alert(xitem);

return [xitem,qitem];
}

//********************************************************************
function thumbItem(j,inclcode,msz,mamount,mszunits)
{
var xitem="";
var qitem="";
var fntsz=getThumbFontSize(msz);



//alert(xitem);

xitem+='<div class="thumbimg" style="text-align:center;">';

var thfolder='newmax/';
if (msz=='small' && inclcode==false) thfolder='newmid/';

xitem+='<span class="thumb" style="text-align:center;">';
  //xitem+='<a href="' + docurl + '" title="'+mname[j]+'">';
  xitem+='<a href="javascript:designDoc('+j+')" title="'+mname[j]+'">';
  var xid='y'+mid[j];
  xitem+='<img id="'+xid+'" border="0" alt="'+mname[j]+'" onLoad="ImgOnLoad(\''+mid[j]+'\')" src="' + thfolder + mthumburl[j] +'.jpg">';
  xitem+='</a>';
xitem+='</span>';

if (!mthumburl2[j]=='')
{
xitem+='<span class="thumb" style="text-align:center;">';
  //xitem+='<a href="' + docurl + '" title="'+mname[j]+'">';
  xitem+='<a href="javascript:designDoc('+j+')" title="'+mname[j]+'">';
  xitem+='<img border="0"  alt="'+mid[j]+'b" src="' + thfolder + mthumburl2[j] +'.jpg">';
  xitem+='</a>';
xitem+='</span>';
};

if (!mthumburl3[j]=='')
{
xitem+='<span class="thumb" style="text-align:center;">';
  //xitem+='<a href="' + docurl + '" title="'+mname[j]+'">';
  xitem+='<a href="javascript:designDoc('+j+')" title="'+mname[j]+'">';
  xitem+='<img border="0"  alt="'+mid[j]+'c" src="' + thfolder + mthumburl3[j] +'.jpg">';
  xitem+='</a>';
xitem+='</span>';
};

xitem+='</div>'



qitem+='<div class="thumbname" style="text-align:center; font-weight:bold; font-size:'+fntsz[1]+'; margin-top:5px; margin-bottom:5px;">';
if (inclcode==true)
 {
 qitem+=mid[j]+' - ';
 }
qitem+=mname[j] + '  ' + mcomment[j];
qitem+='</div>';

if (mcolinfo[j].length>0 && mamount=='more')
{
qitem+='<div class="thumcolinfo" style="text-align:center; font-size:'+fntsz[2]+';">';
if (Number(mcolinfo[j])==1)
 {
 qitem+=mcolinfo[j]+' color';
 }
 else
 {
 qitem+=mcolinfo[j]+' colors / '+mchangesnum[j]+' thread changes';
 };
qitem+='</div>';
};

if (msize[j].length>0 && mamount=='more')
{
qitem+='<div class="thumsize" style="text-align:center; font-size:'+fntsz[2]+';">';
if (mszunits=='inches') {qitem+='Sizes: '+msize[j]; qitem+=' "'} else {qitem+='Sizes: '+msizecm[j]; qitem+=' cm'};
if (munit[j]=='w') {qitem+=' width'} else {qitem+=' height'};
qitem+='</div>';
};

if (mstitchnum[j].length>0 && mamount=='more')
{
qitem+='<div class="thumbstitches" style="text-align:center; font-size:'+fntsz[2]+';">';
qitem+='Stitches: '+mstitchnum[j];
qitem+='</div>';
};

if (msupplier[j].length>0 && mamount=='more')
{
qitem+='<div class="thumbsupplier" style="text-align:center; font-size:'+fntsz[2]+';">';
qitem+='Photo supplied by '+msupplier[j];
qitem+='</div>';
};


if (inclcode==true)
 {
  qitem+='<div class="thumbstitches" style="text-align:center; font-size:'+fntsz[2]+';">';
  qitem+='Collection: '+mbank[j];
  qitem+='</div>';
 };



//alert(xitem);

return [xitem,qitem];
}

//**********************************************************************************************************
function dispDogThumb(xid, j)
{
document.getElementById(xid).innerHTML='<div id="'+xid+'end"></div>';
var newitem=thumbItem(j,true,thumbsz,dtamount,szunits);
AddItem(xid, xid+'end', newitem[0]);
AddItem(xid, xid+'end', newitem[1]);
};

//***************************************************************************************************************

function countSugImg()
  {
  //alert(msugitems);
  msugitems=msugitems-1;
  if (msugitems==0)
    {
    me=document.getElementById('sugtab');
    me.style.display="block";
    
    newitem='<p align="left" style="font-weight:bold;">Customers who bought above designs also bought</p>';
    AddItem('isughead', 'isugheadend', newitem);
    }
  };

//***********************************************************

function dogItem(j,fixed){

//var lnk="";
var xitem="";

xitem+='<div class="dogitem"';
xitem+=' onmouseover="dispDogThumb(\'izoom\',' + j + ')"';

//alert(xitem);

if (fixed=='y')
 {xitem+=' style="clear:both; margin-left:32px; height:40px; display:block; font-size:small;">';
 }
else
 {xitem+=' style="clear:both; margin-left:8px; height:40px; display:block; font-size:x-small;">';
 };

xitem+='<table border="0" cellpadding="0" cellspacing="0" align="left">';
xitem+='<tr>';

xitem+='<td style="height:40px; width:10px; vertical-align:middle; ">';
xitem+='</td>';

xitem+='<td valign="middle"  style="vertical-align:middle; ">';
  xitem+='<input type="checkbox" id="' + mid[j] + '"value="ON" ';
  if (fixed=='y'){xitem+='style="width:32px; height:32px;" onClick="makeSelInCart_noUpdate()"'} else {xitem+='onClick="makeSelInCart()"'};
  xitem+='>';
xitem+='</td>';

xitem+='<td valign="middle" class="minimg" style="padding-left:7px; vertical-align:middle; text-align:center;  ">';
//  xitem+='<a href="' + lnk + '">';
  xitem+='<img border="0" alt="'+mid[j]+'"';
  if (fixed!='y')
    {xitem+=' onload="countSugImg()"';
    };
  xitem+=' src="newmin/' + murlmin1[j] +'.gif">';
//  xitem+='</a>';
xitem+='</td>';
//alert(xitem);

if (!murlmin2[j]=="")
{
xitem+='<td valign="middle" class="minimg2" style="vertical-align:middle; text-align:center;  ">';
//  xitem+='<a href="' + lnk + '">';
  xitem+='<img border="0" alt="'+mid[j]+'b" src="newmin/' + murlmin2[j] +'.gif">';
//  xitem+='</a>';
xitem+='</td>';
};

if (!murlmin3[j]=="")
{
xitem+='<td valign="middle" class="minimg3" style="vertical-align:middle; text-align:center; ">';
//  xitem+='<a href="' + lnk + '">';
  xitem+='<img border="0" alt="'+mid[j]+'c" src="newmin/' + murlmin3[j] +'.gif">';
//  xitem+='</a>';
xitem+='</td>';
};


  xitem+='<td valign="middle" class="dogid" style="vertical-align:middle; font-weight:bold; font-size:small; padding-left:7px;">';
    xitem+=mid[j];
  xitem+='</td>';

  xitem+='<td valign="middle" class="dogname" style="vertical-align:middle; font-weight:normal; font-size:small; ">';
    xitem+= ' - ' + mname[j] + '  ' + mcomment[j]; // + '  ('+mbank[j]+')';
  xitem+='</td>';

xitem+='</tr>';
xitem+='</table>';

xitem+='</div>';

//alert(xitem);

return xitem;
}

//***********************************************************

function dogItem2(j,fixed){

//var lnk="";
var xitem="";
  xitem+='<img border="0" alt="'+mid[j]+'"';
  xitem+=' src="newmin/' + murlmin1[j] +'.gif">';
return xitem;
}

//*******************************************************************
function updateCart(){
composeCartPage();

//if (frmtnum==0) {document.getElementById("APPROVE").disabled=true}
//else {document.getElementById("APPROVE").disabled=false};
//document.getElementById("buttonPP").disabled=true;
//document.getElementById("buttonVanCart").disabled=true;
}


//***************************************************************************************************************
 function dispDeliveryContent(){
 document.getElementById('delivery').innerHTML='<div id="deliveryend"></div>'; 

  var me=document.getElementById('delivery');
  me.style.display="block";
  var pom=makeSummary();

 newitem='<p>' + pom[0] + '</p>';
 AddItem('delivery', 'deliveryend', newitem); 
 
}


//***************************************************************************************************************
 
function composeCartPage() {
if (!composingcart) {

//alert('cart page');

composingcart=true

//clear fields
document.getElementById('icart').innerHTML='<div id="icartend"></div>'; 
document.getElementById('isughead').innerHTML='<div id="isugheadend"></div>'; 
document.getElementById('isuggest').innerHTML='<div id="isuggestend"></div>'; 
document.getElementById('izoom').innerHTML='<div id="izoomend"></div>'; 
document.getElementById('message').innerHTML=''; 

var sum=sumAll();

if (sum[1]+sum[2]==0)  //pocet+pocetlinedraw
  {
  document.getElementById('message').innerHTML="<h2>Shopping cart is empty</h2>";
  document.getElementById('step1').style.display="none";
  document.getElementById('step2').style.display="none";
  document.getElementById('step3').style.display="none";
  document.getElementById('step4').style.display="none";
  //document.getElementById('step5').style.display="none";
  }
else
  {
  document.getElementById('step1').style.display="block";
  document.getElementById('step2').style.display="block";
  document.getElementById('step3').style.display="block";
  document.getElementById('step4').style.display="block";
  //document.getElementById('step5').style.display="block";

	//display cart content
	for(var j=0; j<mnum; j++){
	 if (msel[j]=='y')
	  {
	  newitem=dogItem(j,'y');
	  //alert(newitem);
	  AddItem('icart', 'icartend', newitem);
 	 };
 	};

	// find suggested designs
	var sug=[];
	var breed="";
 	var sugn=0;
 	me=document.getElementById('sugtab');
    me.style.display="none";

 	for(var j=0; j<mnum; j++){sug[j]=msel[j]};

	 for(var j=0; j<mnum; j++){
	   if (msel[j]=='y') {
 	    breed=mclass[j];
   	  for(var k=0; k<mnum; k++){
   	    if (sug[k]=='n' && mclass[k]==breed) {
   	     sug[k]='s';
   	     sugn++;
  	      };
  	   }; //for k
  	  }; //if msel
	  }; //for j

	 //alert('suggested '+sugn);


    msugitems=sugn;
	//display suggested items
	if (sugn>0) {
 	 me=document.getElementById('isughead');
 	 me.style.display="block";
 	 me=document.getElementById('isuggest');
 	 me.style.display="block";


 	 for(var j=0; j<mnum; j++)
      {
  	  if (sug[j]=='s')
   	   {
  	    var newit2=dogItem(j,'n');
  	    AddItem('isuggest', 'isuggestend', newit2);
 	   };
 	  };
 	  


	 }
	else
	 {
	 }; //if sgn

     //display delivery content
     dispDeliveryContent();
 };  //if sum


// check checkboxes
dispCheckboxes();
dispCart();
dispFormats();

};//ifcomposing

composingcart=false;
//alert('end');
};

//***************************************************************************************************************


function loadDesigns(sender){
loadDoc('designs.csv',sender);
};

function loadDesigns2(sender){
loadDoc('../designs.csv',sender);
};

//***************************************************************************************************************
 
function loadDoc(docname,sender) {

   if (xmlhttp) 
     {
       xmlhttp.open("GET", docname,true);
       xmlhttp.onreadystatechange=function() 
         {
            if (xmlhttp.readyState==4) 
               {
                  //alert(xmlhttp.responseText);
                  DecodeDogsCSV(xmlhttp.responseText);
                  RestoreSel(); 
                  RestoreFormats(); 
                  restoreShopInfo();

                  if (sender=='shop')
                     {
                     var map=getUrlVars();
                     if (map)
                       {
                        if (map['clear']=='yes')
                           {
                            clearCart();
                            storePayData('','',0);
                           };
                       };
                     composeShop(baseidx);
                     enableButtons(sender);
                     //alert('bookmark '+mbookmark);
                     //tryBookmark();
                     }
                  else
                    {
                     if (sender=='cart')
                       {                       
                       enableButtons(sender);  
                       composeCartPage();
                       }
                      else
                       {
                       if (sender=='breed')
                         {
                         enableButtons(sender);
                         composeBreedList();
                         }
                        else
                         {
                          if (sender=='spec')
                           {
                           //alert('spec');
                           enableButtons(sender);
                           dispDoc();
                           dispCart();
                           }
                           else
                            {
                             enableButtons(sender);
                             dispCart();
                            };
                         }



                       };
                    };

	}
         }
         xmlhttp.send(null)
 
    }
 
}

//***************************************************

function DecodeDogsCSV(ds) {
var dgs="";
  var allTextLines = [];

  allTextLines = ds.split(/\r\n|\n/);     
  //alert(allTextLines.length);
                
   mnum=0;
   for(i=0; i<allTextLines.length; i++) {
      dgs=allTextLines[i].split(',');
      mid[mnum]=dgs[0];
      mname[mnum]=dgs[1];
      mcomment[mnum]=dgs[2];
      mclass[mnum]=dgs[3];
      mbank[mnum]=dgs[4];
      mcolinfo[mnum]=dgs[5];
      mchangesnum[mnum]=dgs[6];
      msize[mnum]=dgs[7];
      msizecm[mnum]=dgs[8];
      munit[mnum]=dgs[9];
      mstitchnum[mnum]=dgs[10];
      msupplier[mnum]=dgs[11];
      mnew[mnum]=dgs[12];
      mvernum[mnum]=Number(dgs[13]);

      msel[mnum]='n';
      murlmin1[mnum]=mid[mnum].toLowerCase();
      murlmin2[mnum]='';
      murlmin3[mnum]='';
      if (mvernum[mnum]>1) {murlmin1[mnum]=mid[mnum].toLowerCase()+'a';
                            murlmin2[mnum]=mid[mnum].toLowerCase()+'b';}
      if (mvernum[mnum]>2) {murlmin3[mnum]=mid[mnum].toLowerCase()+'c';}
      mthumburl[mnum]=mid[mnum].toLowerCase();
      mthumburl2[mnum]='';
      mthumburl3[mnum]='';
      if (mvernum[mnum]>1) {mthumburl[mnum]=mid[mnum].toLowerCase()+'a';
                            mthumburl2[mnum]=mid[mnum].toLowerCase()+'b';}
      if (mvernum[mnum]>2) {mthumburl3[mnum]=mid[mnum].toLowerCase()+'c';}

      if (dgs[0]) mnum++;
     }           
    //alert('mnum '+mnum);
    //for(i=mnum; i<1; i++) {
   // alert (mid[i]+' = '+mname[i]+ ' = '+mbank[i] + ' = '+mcolinfo[i]+ ' = '+msize[i]); 
   // }     
}

//***************************************************
function RestoreSel(){
//alert(document.referrer);
var cs=mgetCookie("EbrdDg");
 if (cs)  {
    var pom=cs.split("*");
    //alert(pom.length);
    if (pom.length>=mnum) {
      for (j=0; j<mnum; j++) {msel[j]=pom[j]};
      //alert('transferred');
    };
  }
};

//***************************************************
function StoreSel(){
msetCookie("EbrdDg",msel.join("*"));
};

//***************************************************
function clearCart()
 {
 //alert('clear cart');
 if (mnum>0){
  for(var j=0; j<mnum; j++){msel[j]='n';}
  };
 msetCookie("EbrdDg","");
 };

//***************************************************
function sumAll(){
var cena=0.0;
var pocet=0;
var pocetlinedraw=0;

// count selected
for(var j=0; j<mnum; j++){
  if (msel[j]=='y') {
   if (mid[j]=='LD1'){pocetlinedraw++;}
    else if (mid[j]=='LD2'){pocetlinedraw++;}
     else if (mid[j]=='LH1'){pocetlinedraw++;}
      else {pocet++;}
   };
  }

 var maxprice=12.0;
 var midprice=8.0;
 var farprice=6.0;
 var minprice=5.0;
 var mbeg=1; //zaciatok klesania - do tohto poctu je max price
 var mmid=10; //koniec prudkeho poklesu a zaciatok mierneho. V tomto bode je mid price
 var mfar=30; //koniec klesania - od tohto poctu je min price
 var mend=120; //koniec klesania - od tohto poctu je min price
 var itprice=maxprice;
 if (pocet>=mbeg && pocet<mmid) {itprice=maxprice + ((pocet-mbeg)/(mmid-mbeg))*(midprice-maxprice)};
 if (pocet>=mmid && pocet<mfar) {itprice=midprice + ((pocet-mmid)/(mfar-mmid))*(farprice-midprice)};
 if (pocet>=mfar && pocet<mend) {itprice=farprice + ((pocet-mfar)/(mend-mfar))*(minprice-farprice)};
 if (pocet>=mend){itprice=minprice};

 cena=pocet*itprice + pocetlinedraw*3;
// alert(pocet);

 cena=Math.ceil(10*cena)/10;

 //zisti, ci je vybrany aspon jeden format
    EF=0;
    for (j=0; j<fsel.length; j++) 
    {
     if (fsel[j]==1) 
      {
       if (flist[j]!='EDR') {EF++;};
      };
    };

 return [cena, pocet, pocetlinedraw,EF];
}


//***************************************************
function dispCart() {
var sum=sumAll();
var cena=sum[0];
var selnum=sum[1]+sum[2]; //pocet+pocetlinedraw

me=document.getElementById("carttab");
if (me)
  {
  me.style.display="block";
  };

me=document.getElementById("icartcontent");
if (me)
  {
    me.innerHTML ="US$ "+cena;

    var txt="";
    if (selnum==0){}
      else if (selnum==1){txt = selnum+" item";}
       else {
         txt = selnum+" items";
         var cena2=Math.ceil(100*cena/selnum)/100;
         txt+='  (US$ '+cena2+' per item)';
        };
    document.getElementById("icartnum").innerHTML = txt;
  };
};

//***************************************************


function dispCheckboxes() {

//var inputs = document.getElementsByTagName('input');
//for(var j=0; j<inputs.length; j++){
// if(inputs[j].getAttribute('type')=='checkbox'){inputs[j].checked=false;}
//}

var chbox;

for(var j=0; j<mnum; j++){
chbox=document.getElementById(mid[j]);
if (chbox) {
 //alert(chbox.id); 
 if (msel[j]=='y'){chbox.checked=true;} else {chbox.checked=false;};  
 }
}

}

//***************************************************

function findDogIdx(actid) {
var mres=-1;
var j=0;
while (j<mnum) {
 if (actid==mid[j]) {mres=j; j=mnum;}
j++;
}
return mres;
}

//***************************************************

function selPage() {
if (mnum){
var inputs = document.getElementsByTagName('input');
var actid="";
var actidx=-1;

for(var j=0; j<inputs.length; j++){
if(inputs[j].getAttribute('type')=='checkbox'){
 actid=inputs[j].getAttribute('id');
 if (!actid==""){
 actidx=findDogIdx(actid);
 //alert(actidx);
 if (actidx>=0 && actidx<mnum)
   {
   //alert('select '+actidx);
   msel[actidx]='y';
   }
 }
 }
}
StoreSel();
dispCheckboxes();
dispCart();
}// if mnum
}

//***************************************************

function clearPage() {
if (mnum){
var inputs = document.getElementsByTagName('input');
var actid="";
var actidx=-1;

for(var j=0; j<inputs.length; j++){
if(inputs[j].getAttribute('type')=='checkbox'){
 actid=inputs[j].getAttribute('id');
 if (!actid==""){
 actidx=findDogIdx(actid);
 //alert(actidx);
 if (actidx>=0 && actidx<mnum)
   {
   //alert('select '+actidx);
   msel[actidx]='n';
   }
 }
 }
}
StoreSel();
dispCheckboxes();
dispCart();
}// if mnum
}



//***************************************************

function clearAllPages() {

clearCart();
if (mnum>0){

me=document.getElementById('icart');
if (me) 
  {
  composeCartPage();
  }
else
  {
  dispCheckboxes();
  };
dispCart();
}// if mnum
}

//***************************************************

function makeSel(){
var inputs = document.getElementsByTagName('input');
var idx=-1;

for(var j=0; j<inputs.length; j++){
if(inputs[j].getAttribute('type')=='checkbox'){
 idx=findDogIdx(inputs[j].id);
 if (idx>=0 && idx<mnum) {
 if (inputs[j].checked==true) {msel[idx]='y'} 
                                  else {msel[idx]='n'};
  }  //if idx
  }  //if chbox
}  //for

StoreSel();
dispCart();
}


//***************************************************

function MyGetViewportSize()
{
 var viewportwidth=100;
 var viewportheight=100;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth;
      viewportheight = window.innerHeight;
     //alert('a '+viewportwidth);
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth;
       viewportheight = document.documentElement.clientHeight;
      //alert('b '+viewportwidth);
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
       viewportheight = document.getElementsByTagName('body')[0].clientHeight;
      //alert('c '+viewportwidth +' x '+ document.documentElement.clientWidth);
 }
 return [viewportwidth, viewportheight];
}; 

//****************************************************

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

//************************************************************************************

function MySizePanels()
{ 
  var sz=MyGetViewportSize();
  //var sz=[];
  //sz[0]=f_clientWidth();
  //sz[1]=f_clientHeight();
  
  //alert ('scroll '+f_scrollLeft());

  var me=document.getElementById('icontent');

 if (me.id=='icontent')
  {
   
   me.style.width=sz[0]-200-4;
   me.style.height=sz[1]-87-4;

   me=document.getElementById('ihead'); 
   me.style.width=sz[0]-4;

   var lheight=sz[1]-87-4

   me=document.getElementById('ileft');
   me.style.height=lheight;
   

   me=document.getElementById('mbreedlist');
   if (me)
     {
      var mrsize=lheight-320;
      if (mrsize<10) {mrsize=10};
      me.style.height=mrsize;
   
      me=document.getElementById('mbreedlisthd');
      me.style.height=mrsize+32;
     }
 };
}

//*********************************

function msetCookie(c_name,value)
{
var expiredays=10;
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

//*********************************

function mgetCookie(name)
{
//alert(document.cookie);
var nameEQ = name + "=";
var ca = document.cookie.split(';');
//alert(name+' ~ '+ca);
for(var i=0;i < ca.length;i++) {
  var c = ca[i]; 
  while (c.charAt(0)==' ') {c = c.substring(1,c.length);};
  if (c.indexOf(nameEQ) == 0) {
     var res=c.substring(nameEQ.length,c.length);
     //alert('return '+res); 
     return res;
     }
}
//return null;



//if (document.cookie.length>0)
//  {
//  c_start=document.cookie.indexOf(c_name + "=");
//  if (c_start!=-1)
//    {
//    c_start=c_start + c_name.length+1;
//    c_end=document.cookie.indexOf(";",c_start);
//    if (c_end==-1) c_end=document.cookie.length;
//    return unescape(document.cookie.substring(c_start,c_end));
//    }
//  }
//return "";
}

//**************************************************************************

// Funkcia na kontrolu emailu
      function CheckEmailAddress(adresa) 
      {
        
         
        // Pozicia posledneho znaku
        var LastChar=adresa.length - 1;


        // Pozicia @ - nesmie byt ani na prvom,
        // ani na poslednom mieste
        var CharPos=adresa.indexOf("@");
        if ((CharPos<1)||(CharPos==LastChar)) return false;

        // Pozicia prvej bodky
        var CharPos=adresa.indexOf(".");
        if (CharPos<1) return false;

        // Pozicia poslednej bodky
        var CharPos=adresa.lastIndexOf(".");
        if (CharPos==LastChar) return false;

        //V adrese sa nesmie nachadzat ciarka
        var CharPos=adresa.indexOf(",");
        if (CharPos>=0) return false;

        //V adrese sa nesmie nachadzat medzera
        var CharPos=adresa.indexOf(" ");
        if (CharPos>=0) return false;

        //V adrese sa nesmu nachadzat dve bodky za sebou
        var CharPos=adresa.indexOf("..");
        if (CharPos>=0) return false;


        //V adrese sa nesmie vyskytovat www.
        var CharPos=adresa.indexOf("www.");
        if (CharPos>=0) return false;

        //V adrese sa nesmie vyskytovat http
        var CharPos=adresa.indexOf("http");
        if (CharPos>=0) return false;


        //V adrese sa nesmie vyskytovat /
        var CharPos=adresa.indexOf("/");
        if (CharPos>=0) return false;



        return true;  
        
      }

//************************** QUICK SORT ==============================================


Array.prototype.swap=function(a, b)
{
	var tmp=this[a];
	this[a]=this[b];
	this[b]=tmp;
}


function partition(array, begin, end, pivot)
{
	var piv=array[pivot];
	array.swap(pivot, end-1);
	var store=begin;
	var ix;
	for(ix=begin; ix<end-1; ++ix) {
		if(array[ix]<=piv) {
			array.swap(store, ix);
			++store;
		}
	}
	array.swap(end-1, store);

	return store;
}


function qsort(array, begin, end)
{
	if(end-1>begin) {
		var pivot=begin+Math.floor(Math.random()*(end-begin));

		pivot=partition(array, begin, end, pivot);

		qsort(array, begin, pivot);
		qsort(array, pivot+1, end);
	}
}


function quick_sort(array)
{
	qsort(array, 0, array.length);
}


