//-------------------
function Is_IE() {
 var tag;
 var path = "";
 
 if (window.location.href.indexOf("main")>0) path = "../../";
 
 if(navigator.userAgent.indexOf("Firefox") != -1){
 tag = "<link rel='stylesheet' type='text/css' href='" + path + "lib/ffox.css'> ";
 } else {
  tag = "<link rel='stylesheet' type='text/css' href='" + path + "lib/ie.css'> ";
 }
 document.write(tag); 
}

//-------------------
function SetLang(sNew) {   
  var sSelLang = GetTheCookie("Lang");
  if (!sNew) {  
    if (!sSelLang) { 
      sNew = "en";			
      SetTheCookie("Lang", sNew, 30);	    
    }
  } else {
    if (sNew != sSelLang) {
      SetTheCookie("Lang", sNew, 30);
      window.location.href = "products.php";
    }
  }
}

//===================
function ShowCont() {
  var email, tel;
  
  var addr = "info@kowatec.com";
  var contact = "<td valign='center' align='right'>\n"
   + "<a class='toc' href='mailto:"  + addr + "'><b>\n";
  if (navigator.userAgent.indexOf("Firefox") != -1){
//  if (navigator.userAgent.indexOf("IE") == 27){ 
     email = "Email: " + addr;
     tel = " | Tel: &nbsp;";
   } else {
     email = "<span class='ico'>+</span>&nbsp;" + addr  + "</a>";
     tel = " | <span class='ico'>(</span>&nbsp;";
  }

  contact += email + "&nbsp;\n" + tel + "1-408-451-9779&nbsp;|&nbsp;</b></td>\n";  
 
  document.write(contact);

}


/*========================
 navigation
=========================*/ 
//-----------------------
function over() {
 var item = event.srcElement;
  var curAns = document.getElementById("a" + item.id.substr(1, 2));
 if ((curAns.style.display == "") || (curAns.style.display == "none")) {
   item.style.color = "blue"; 
   item.style.cursor = "pointer";
   item.style.fontWeight = "bold";
 }
}

//---------------------
function out() {
 var curId = event.srcElement.id;
 var curAns =document.getElementById("a" + curId.substr(1, 2));
 if ((curAns.style.display == "") || (curAns.style.display == "none")) {
   event.srcElement.style.color = "black";
   event.srcElement.style.fontWeight = "normal";
 }
}

//-----------------------
function MnuOver(elem) {
 elem.className = "mnuOver";  
}

//-----------------------
function MnuOut(elem) { 
  elem.className = "menubox"  
}

//--------------------
function GoToPage(url) {
  document.location.href = url; 
}

//--------------------
function MseOver() {
 event.srcElement.style.cursor = "pointer";
}


//---------------------
function Zoom(sfile) {  
    window.open(sfile,null,"height=100,width=120,status=no,toolbar=no,menubar=no,location=no");
}


//---------------------
function ZoomImg(url) {
  window.open(url, 'KowatecZoom', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=549,height=549,left=0,top=0');
	return (true);
}


//---------------------
function ShowDemo(sfile, prod) {
   
   if (prod == "ws") {
     size = "width='600' height='350'";
     
   } else {
     size = "width='145' height='145'";
   }
    
   sTag = "<embed src='" + sfile + "' " + size + " type='application/x-shockwave-flash'" 
     +  " allowscriptaccess='always' allowfullscreen='false'></embed>";
     
   document.getElementById("divDemo").innerHTML = sTag;   
}


//-------------------------
var prevTab = 0;

function tbClick(evt) {  
  var rHd = document.getElementById("rHead");
  var rDt = document.getElementById("rDet");
  var tot = rHd.cells.length;   
 
  var Elem =(typeof event!=='undefined')? event.srcElement : evt.target;
  for (var i=0; i< tot; i++) {
    var theCell = rHd.cells[i];
 
    if (prevTab != i) {
 		 
      if (theCell == Elem) {
         Elem.style.backgroundColor = "lightblue";
         Elem.style.fontWeight="bold";
       
         rDt.cells[i].style.display = "block";
         rDt.cells[prevTab].style.display = "none";
			 
         rHd.cells[prevTab].style.backgroundColor = "white";
         rHd.cells[prevTab].style.fontWeight= "normal";
         prevTab = i;
      }    
    }    
  }  
}


//--------------------
// check which main categ was selected
function ShowCat(elem) {
  var url = document.location.href;
  var iPos = url.indexOf("id=");
  if (iPos > 0) {
    id = url.substr(iPos + 3, 1);
  } else {
    if (id == undefined) id = 0;
    if (prevCat == undefined) prevCat = 0;
  }
  // hidden cell that holds the id passed by qry
  var catItem = document.getElementById("tdCatId");
  
  var catId = catItem.innerText;
  if (id != prevCat) {    
    var prev = document.getElementById("div" + prevCat);
    prev.style.display = "none";
  
    var newCat =  document.getElementById("div" + catId);    
    newCat.style.display = "block";    
    var newItem = newCat.children(0);
    SelItem(newItem);
    prevCat = id;
  }
}

//-----------------------
// toggle display with selected item highlighted;
// prevItem is set in the calling htm as:
// var prevItem = "div0";
// sel item id = "00", toggle item id = "div00";
// where 00 can be any number and matching in both ids;
//
function SelItem(item) {
  var prevId, prev;

   // toggle the highlight  
  var prev = document.getElementById(prevItem); 
  var id = item.id;
  var newId = "div" + id.substr(1, 2);

  if (prevItem != newId) {
    prev.style.display = "none";
//    prev.className = "non";
  }
  
  document.getElementById(newId).style.display = "block";
  //document.getElementById(id).className ="sel";
  prevId = item.id;
  prevItem = newId;
}

//-----------------------
// expand or collapse ans based on selected question;
// prevAns is set in the calling htm as:
// var prevAns = "a0";
// quest id = "q1", ans id = "a1";
//
function SelFaq(item) {
  var prev = document.getElementById(prevAns); 
  if (prevAns != "a0") {
    prev.style.display = "none";
    var prevQ = document.getElementById("q" + prevAns.substr(1, 2));
    prevQ.style.color = "black";
    prevQ.style.fontWeight = "normal";
//    prevQ.style.marginTop = "0pt";
  }
  
  var id = item.id;
  var newId = "a" + id.substr(1, 2);
  document.getElementById(newId).style.display = "block";
 // document.getElementById(newId).style.marginBottom = "10pt";
  prevAns = newId;
  
  var curQ = document.getElementById("q" + id.substr(1, 2))
  curQ.style.color = "black";
 // curQ.style.marginTop = "10pt";
}

//-------------------
// move around the table
// call from a table with onmouse functions
function SelRow(sAction) {  
  var row = event.srcElement;
  
  switch (sAction) {
    case "over" :
    case "up" :
     row.style.backgroundColor = "lightgrey";
     break;
    case "dwn" : row.style.backgroundColor = "white"; break;
    case "out" : row.style.backgroundColor = "pink"; break;
  }
}



/*=======================
 Ads
=========================*/
function ShowAds() {
  var sTag, filepath, imgName;
  
  var url = document.location.href;
  var iPos = url.indexOf("x=");
  
  if (iPos > 0) {
   var iVal = url.substr(url.length -1, 1);
   if (iVal <= 1) {
     var namePos = url.indexOf("n=") + 2; 
     filepath = url.substr(namePos, (iPos - 1) - namePos);   
     imgName = filepath.substr(0, filepath.length - 4);
     sTag = "<center><img width='135' id='imgList' src='img/prod/" + filepath + "'></center><br>";
     document.write(sTag);
     document.getElementById("imgList").title = imgName; //+ " - " + fIndex;   
   } 
  } else { 
    var fIndex = Math.round(Math.random() * imgFiles.length - 1);
    if (fIndex < 0) fIndex = 0;
    filepath = imgFiles[fIndex];
   if (filepath.substr(0, 2) == "fd") {
       sTag = "<center><img id='imgList' class='img5' src='img/prod/" + filepath + "'></center><br>";
    } else {
       sTag = "<center><img width='130' height='100' id='imgList' src='img/prod/" + filepath + "'></center><br>";
   } 
   document.write(sTag);
    AdBanner();
  }
}

//----------------------
function AdBanner() {
  var fIndex = Math.round(Math.random() * imgFiles.length -1);
  if (fIndex <= 0) fIndex++;
  var filepath = imgFiles[fIndex];
  var imgName = filepath.substr(0, filepath.length - 4);
 
  if (filepath.substr(0, 2) == "fd") imgName = filepath.substr(3, filepath.length - 7);
   document.getElementById("imgList").title = imgName; //+ " - " + fIndex;
  document.getElementById("imgList").src = "img/prod/" + filepath;
  thetimer = setTimeout("AdBanner()",3000);
}


//-------------------------
function HideDemo() {
  var url = document.location.href;
  if (url.indexOf("a-") >= 1) {
     divDemo.style.display = "none";
     tbAcc.style.display = "block";
  }
  else {
     divDemo.style.display = "block";
     tbAcc.style.display = "none";
  }
}


/*========================
 Timesout
=========================*/ 
//---------------------
function GetDate() {
  var item = event.srcElement;
  oDate = new Date();
  iMon = oDate.getMonth() + 2;
  iDay = oDate.getDate();
  iYear = oDate.getFullYear();
  sDate = iMon + "/" + iDay + "/" + iYear;
  return sDate; 
}

/*========================
 Cookies
=========================*/ 
//----------------------
function SetTheCookie(sName, sValue, iExpire, sPath, sDomain, bSecure) {  
  // sExpire is the number of days the cookie will expired.  
  // default to expire in 30 days
   
  var iSec = 60*60*24;
  if (!iExpire) 
    iExpire = iSec * 30;
  else
    iExpire = iSec * iExpire;
 
  var oDate = new Date();
  oDate.setTime(oDate.getTime() + iExpire);
  
  var sCookie = sName + "=" + sValue
    + ((iExpire) ? "; expires=" + oDate.toGMTString() : "")
    + ((sPath) ? "; path=" + sPath : "") 
    + ((sDomain) ? "; domain=" + sDomain : "")
    + ((bSecure) ? "; secure" : "");   
 
  document.cookie = sCookie;
}

//----------------------------
function GetTheCookie (sName) {
  var sArg = sName + "=";
  var iLen = sArg.length;
  var iCookLen = document.cookie.length;
  var iPos = 0;
  while (iPos < iCookLen) {
    var iCurPos = iPos + iLen;
    if (document.cookie.substring(iPos, iCurPos) == sArg) { 
       var iEnd = document.cookie.indexOf(";", iCurPos);
       if (iEnd == -1)
       iEnd = document.cookie.length;
       return unescape(document.cookie.substring(iCurPos, iEnd));
    }  
    iPos = document.cookie.indexOf(" ", iPos) + 1;
    if (iPos == 0) break; 
  }
  return null;
}


//--------------------
function DeleteTheCookie (sName) {
  if (GetCookie(sName)) {
    document.cookie = sName + "=" +
//      ((path) ? "; path=" + path : "") +
//      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


//--------------------
function CountDown() {
  Today = new Date();
  Future = new Date(2009, 5, 12); //february is 1; 
  /*
var newDate=new Date(), 11, 25) //Month is 0-11 in JavaScript
if (today.getMonth()==11 && today.getDate()>25) //if newdate has passed already
newDAte.setFullYear(newDate.getFullYear()+1) //calculate next year's 
*/
//Set 1 day in milliseconds
var one_day=1000*60*60*24;

//Calculate difference btw the two dates, and convert to days
document.write(Math.ceil((Future.getTime()-Today.getTime())/(one_day)));
}

//----------------
function Whatisnew() {
var newimage='<img src="news.gif">';
var today=new Date();

var expire=new Date(yr,mon,day);
if (today.getTime()<=expire.getTime()) document.write(newimage);
}

