var myHomeURL='http://www.mapwel.net';
var xmlhttp=false;
var mcustomer='';
var mcost=0;
var mnum=0;
var mID=[];

/*@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;}

}

//*****************************************************
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+='<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.mapwel.net%2Fdown.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>';
  me.innerHTML=xitem;
  //document.getElementById(xid).innerHTML='<div id="'+xid+'end"></div>';
  //AddItem(xid, xid+'end', xitem);
  //alert(xitem);
  }
}

//*************************************************************************
function genMapwelRSS(rssname,ds)
  {
  var Hditem=rssHead(rssname);
  var Bditem='';
  var scan=false;
  
  Bditem+='    <item>'+'\n';
  Bditem+='       <title>New Version Released</title>'+'\n';
  Bditem+='       <link>'+myHomeURL+'/index.htm</link>'+'\n';
  Bditem+='       <guid>'+myHomeURL+'/index.htm</guid>'+'\n';
  Bditem+='       <description>'+'\n';
  Bditem+='          '+codeStr('<div style="width:80%; margin-left:32px; text-align:left">')+'\n';
  Bditem+='          '+codeStr('<div style="margin-left:0;">')+'\n';

  var items=ds.split('\n');
  for(i=0; i<items.length; i++)
  {

  if (items[i].indexOf('</body')>=0) {scan=false};
  if (scan==true) {
   Bditem+=codeStr(items[i]);
   };
  if (items[i].indexOf('<body')>=0) {scan=true};
   
  }

  Bditem+='          '+codeStr('</div>')+'\n';
  Bditem+='          '+codeStr('<p align="center">Copyright &#169; BALARAD, s.r.o. All Rights Reserved.</p>')+'\n';
  
  //Bditem+='          '+codeStr('<a href="http://api.tweetmeme.com/share?url=www.mapwel.net"><img src="http://api.tweetmeme.com/imagebutton.gif?url=www.mapwel.net" height="61" width="51" /></a>');
  
  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);

  writeConsole(Hditem+Bditem+Editem);
  };
  
//***************************************************************************************************************


function writeConsole(content) {
 top.consoleRef=window.open('','myconsole',
  'width=350,height=250'
   +',menubar=0'
   +',toolbar=1'
   +',status=0'
   +',scrollbars=1'
   +',resizable=1')
 top.consoleRef.document.writeln(
  '<html><head><title>Console</title></head>'
   +'<body bgcolor=white onLoad="self.focus()">'
   +content
   +'</body></html>'
 )
 top.consoleRef.document.close()
}
//***************************************************************************************************************

function HTMLtoRSS(fname,rssname){
loadHTMLspec(fname,rssname);
};

//***************************************************************************************************************

function loadHTMLspec(docname,rssname) {

   if (xmlhttp)
     {
       xmlhttp.open("GET", docname,true);
       xmlhttp.onreadystatechange=function()
         {
            if (xmlhttp.readyState==4)
               {
                  //alert(xmlhttp.responseText);
                  genMapwelRSS(rssname,xmlhttp.responseText);
               }
         }
         xmlhttp.send(null)
    }
}
  
//*****************************************************
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>Mapwel GPS Mapping Software</title>'+'\n';
xitem+='    <link>'+myHomeURL+'</link>'+'\n';
xitem+='    <description>Turn-by-turn navigation, earth sciences, geospatial data processing, forestry, electrical engineering, cartography, geology, geodesy, mineralogy, petroleum geology, aviation, real estate, geocaching, hiking, snow mobiling</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>Mapwel GPS Mapping Software</title>'+'\n';
xitem+='        <url>'+myHomeURL+'/manual/grpx/logo.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 codeStr(s)
 {
 var q=s.replace(/</g,'&lt;');
 q=q.replace(/>/g,'&gt;');
 return q;
 };

//******************************************************
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 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 load_inclHTML(docname,divid) {
   if (xmlhttp)
     {
       xmlhttp.open("GET", docname,true);
       xmlhttp.onreadystatechange=function()
         {
            if (xmlhttp.readyState==4)
               {
                  //alert(xmlhttp.responseText);
                  putHTMLtoDIV(divid,xmlhttp.responseText);
               }
         }
         xmlhttp.send(null)
    }
}

//*************************************************************************
function putHTMLtoDIV(divid,ds)
  {
  var Bditem='';
  var scan=false;

  var items=ds.split('\n');
  for(i=0; i<items.length; i++)
  {
  if (items[i].indexOf('</body')>=0) {scan=false};
  if (scan==true) {
   Bditem+=items[i];
   };
  if (items[i].indexOf('<body')>=0) {scan=true};
  }
  
  //alert(Bditem);
  
  var me=document.getElementById(divid);
  if (me)
    {
     me.innerHTML=Bditem;
     me.style.display='block';
     //alert('included');
    };
  };
  
//***************************************************************************************************************

function load_inclHTML2(curdir,newdir,docpath,divid) {
   if (xmlhttp)
     {
       xmlhttp.open("GET", docpath,true);
       xmlhttp.onreadystatechange=function()
         {
            if (xmlhttp.readyState==4)
               {
                  //alert(xmlhttp.responseText);
                  putHTMLtoDIV2(curdir,newdir,divid,xmlhttp.responseText);
               }
         }
         xmlhttp.send(null)
    }
}

//*************************************************************************

String.prototype.replaceLast = function (what, replacement)
 {
 return this.split('/').reverse().join('/').replace(new RegExp(what), replacement).split('/').reverse().join('/');
 };
function putHTMLtoDIV2(curdir,newdir,divid,ds)
  {
  var Bditem='';
  var scan=false;

  var items=ds.split('\n');
  for(i=0; i<items.length; i++)
  {
  if (items[i].indexOf('</body')>=0) {scan=false};
  if (scan==true) {
   Bditem+=items[i];
   };
  if (items[i].indexOf('<body')>=0) {scan=true};
  }

  //alert(Bditem);

  var me=document.getElementById(divid);
  if (me)
    {
     me.innerHTML=Bditem;
     me.style.display='block';
     //alert('included');

     var imgs = document.getElementById(divid).getElementsByTagName("img");
     for (var j = 0; j < imgs.length; j++)
     {
     imgs[j].src =imgs[j].src.replace(curdir+'grpx',newdir+'grpx');
     //alert(imgs[j].src);
     }
     
     if (!curdir=='')
     {
     var links = document.getElementById(divid).getElementsByTagName("a");
     for (var j = 0; j < links.length; j++)
     {
     links[j].href =links[j].href.replaceLast(curdir,newdir);
     //alert(links[j].href);
     };
     };

    };

  };


//*****************************************************************************
// 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 loadFile(fname){
loadspec(fname);
};

//***************************************************************************************************************

function loadspec(docname) {

   if (xmlhttp)
     {
       xmlhttp.open("GET", docname,true);
       xmlhttp.onreadystatechange=function()
         {
            if (xmlhttp.readyState==4)
               {
                  //alert(xmlhttp.responseText);
                  DecodeFile(xmlhttp.responseText);

               }
         }
         xmlhttp.send(null)

    }

}

//***************************************************

function DecodeFile(ds) {
  var items="";
  var allTextLines = [];

  //allTextLines = ds.split(/\r\n|\n/);
  //alert(allTextLines.length);

  items=ds.split(',');
  mcustomer=items[0];
  mcost=items[1];
  mnum=0;
  for(i=2; i<items.length; i++)
  {
  mID[mnum]=items[i];
  mnum++;
  }
  
  dispIDs();
  if (mcost>0)
      {
       document.getElementById("buttonPP").disabled=false;
       document.getElementById("buttonVanCart").disabled=false;
      };
  //alert (mcost+' '+mnum);
}

//*********************************

function dispIDs()
{
var me=document.getElementById('units');
if (me)
  {
  me.innerHTML='<div id="unitsend"></div>';
  for(i=0; i<mnum; i++)
    {
    var newitem='<div>'+mID[i]+'</div>';
    AddItem('units','unitsend',newitem);
    }
  };

var me=document.getElementById('cost');
if (me)
  {
  me.innerHTML='<div id="costend"></div>';
  var newitem='<div>'+'US $ '+mcost+'</div>';
  AddItem('cost','costend',newitem);
  }

var me=document.getElementById('cust');
if (me)
  {
  me.innerHTML='<div id="custend"></div>';
  var newitem='<div>'+mcustomer+'</div>';
  AddItem('cust','custend',newitem);
  }

};

//*********************************

function AddItem(xid,xidend,newitem) {
 //div=document.getElementById(xid);
 miesto=document.getElementById(xidend);
 if (miesto){
 newnode=document.createElement("div");
 newnode.innerHTML=newitem;
 //div.insertBefore(newnode,miesto);
 miesto.parentNode.insertBefore(newnode,miesto);
 };
}


//*********************************

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(';');
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 "";
}

//****************************************************************************
function checkmail()
 {
 var q=document.getElementById("mysendemail");
 if (q)
   {
    document.getElementById("emailadresa").value='tech@mapwel.net';
    document.getElementById("emailtovar").value=mcustomer+' '+mcost;
    q.action=myHomeURL+"/sendemail.php";
    q.submit();
   };
  };

//***************************************************

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];
};


