//alert("TEST!!! 1");


//BASE 64
  var origkeyStr = "ABCDEFGHIJKLMNOP" + 
                   "QRSTUVWXYZabcdef" + 
                   "ghijklmnopqrstuv" + 
                   "wxyz0123456789+/" + 
                   "="; 

  var keyStr = "ABCDEFGHIJKLMNOP" + 
               "QRSTUVWXYZabcdef" + 
               "ghijklmnopqrstuv" + 
               "wxyz0123456789-/" + 
               "_"; 

  
  function encode64(finput) { 
     var bt,input;
     //input = escape(input); 
     bt =  Base64_utf8_encode(finput);
     if ( bt.length == finput.length )
     {
	//already UTF8 encoded.
	input = finput;
     }else{
	input = bt;
     }
    

     var output = ""; 
     var chr1, chr2, chr3 = ""; 
     var enc1, enc2, enc3, enc4 = ""; 
     var i = 0; 
  
     do { 
        chr1 = input.charCodeAt(i++); 
        chr2 = input.charCodeAt(i++); 
        chr3 = input.charCodeAt(i++); 
  
        enc1 = chr1 >> 2; 
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 
        enc4 = chr3 & 63; 
   
        if (isNaN(chr2)) { 
           enc3 = enc4 = 64; 
        } else if (isNaN(chr3)) { 
           enc4 = 64; 
        } 
  
        output = output + 
           keyStr.charAt(enc1) + 
           keyStr.charAt(enc2) + 
           keyStr.charAt(enc3) + 
           keyStr.charAt(enc4); 
        chr1 = chr2 = chr3 = ""; 
        enc1 = enc2 = enc3 = enc4 = ""; 
     } while (i < input.length); 

	output = escape(output);
     return output; 
  } 
  
  function decode64(input) { 
     var output = ""; 
     var chr1, chr2, chr3 = ""; 
     var enc1, enc2, enc3, enc4 = ""; 
     var i = 0; 
  
     // remove all characters that are not A-Z, a-z, 0-9, +, /, or = 
     //var base64test = /[^A-Za-z0-9\+\/\=]/g;
     var base64test = /[^A-Za-z0-9\-\/\_]/g; 
     if (base64test.exec(input)) { 
        alert("There were invalid base64 characters in the input text.\n" + 
              "Valid base64 characters are A-Z, a-z, 0-9, '-', '/',and '_'\n" + 
              "Expect errors in decoding."); 
     } 
     //input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 
     input = input.replace(/[^A-Za-z0-9\-\/\_]/g, ""); 
  
     do { 
        enc1 = keyStr.indexOf(input.charAt(i++)); 
        enc2 = keyStr.indexOf(input.charAt(i++)); 
        enc3 = keyStr.indexOf(input.charAt(i++)); 
        enc4 = keyStr.indexOf(input.charAt(i++)); 
  
        chr1 = (enc1 << 2) | (enc2 >> 4); 
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 
        chr3 = ((enc3 & 3) << 6) | enc4; 
  
        output = output + String.fromCharCode(chr1); 
  
        if (enc3 != 64) { 
           output = output + String.fromCharCode(chr2); 
        } 
        if (enc4 != 64) { 
           output = output + String.fromCharCode(chr3); 
        } 
  
        chr1 = chr2 = chr3 = ""; 
        enc1 = enc2 = enc3 = enc4 = ""; 
  
     } while (i < input.length); 
  
     return Base64_utf8_decode(output); 
  } 

  function Base64_utf8_encode(string) { 
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);
		//alert(c);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {

		//alert("C2! = " + c );
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
		//alert("C3! = " + c );
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }
        return utftext;
    }


  function Base64_utf8_decode(utftext) { 
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }


//BASE 64

function decryptXOR(CodeKey, DataIn)
{
	var strDataOut = "";
	var codechar = "";
	for(ii=0;ii<DataIn.length;ii++)
	{
		//codechar = CodeKey.charCodeAt((ii%CodeKey.length));
		codechar = CodeKey.charCodeAt(((ii+1)%CodeKey.length));
		strDataOut+=String.fromCharCode(codechar^DataIn.charCodeAt(ii));
	}
        return strDataOut;
}

////////////////////////////////////////////////////////////////////////

function htmlentities (hestr, quote_style) {
    // Convert all applicable characters to HTML entities
    tmp_str = "";

    for (var hei=0;hei<hestr.length;hei++)
    {
	hech = hestr.substr(hei, 1);
        //hecv = hestr.charCodeAt(hei);
        hecv = hech.charCodeAt(0);
	if (  (hecv < 48) || ((hecv > 57) && (hecv < 65)) || (hecv > 122)  )
	{
		tmp_str = tmp_str + '&#' + hecv.toString(10) + ';';
	}else{
		tmp_str = tmp_str + hech;
	}
    }
    //alert(tmp_str + ' == ' + tmp_str.length );
    return tmp_str;
}


////////////////////////////////////////////////////////////////////////
//borrowed from http://isohunt.com/js/functions.js
////////////////////////////////////////////////////////////////////////
var smooth_timer;

function getBrowser(){
var BrowserDetect = {
  init: function () {
    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    this.version = this.searchVersion(navigator.userAgent)
            || this.searchVersion(navigator.appVersion)
            || "an unknown version";
    this.OS = this.searchString(this.dataOS) || "an unknown OS";
  },
  searchString: function (data) {
    for (var i=0;i<data.length;i++) {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
          return data[i].identity;
      }
      else if (dataProp)
      return data[i].identity;
    }
  },
  searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  },
  dataBrowser: [
          {       string: navigator.userAgent,
                  subString: "OmniWeb",
                  versionSearch: "OmniWeb/",
                  identity: "OmniWeb"
          },
          {
                  string: navigator.vendor,
                  subString: "Apple",
                  identity: "Safari"
          },
          {
                  prop: window.opera,
                  identity: "Opera"
          },
          {
                  string: navigator.vendor,
                  subString: "iCab",
                  identity: "iCab"
          },
          {
                  string: navigator.vendor,
                  subString: "KDE",
                  identity: "Konqueror"
          },
          {
                  string: navigator.userAgent,
                  subString: "Firefox",
                  identity: "Firefox"
          },
          {
                  string: navigator.vendor,
                  subString: "Camino",
                  identity: "Camino"
          },
          {               // for newer Netscapes (6+)
                  string: navigator.userAgent,
                  subString: "Netscape",
                  identity: "Netscape"
          },
          {
                  string: navigator.userAgent,
                  subString: "MSIE",
                  identity: "Explorer",
                  versionSearch: "MSIE"
          },
          {
                  string: navigator.userAgent,
                  subString: "Gecko",
                  identity: "Mozilla",
                  versionSearch: "rv"
          },
          {               // for older Netscapes (4-)
                  string: navigator.userAgent,
                  subString: "Mozilla",
                  identity: "Netscape",
                  versionSearch: "Mozilla"
          }
  ],
  dataOS : [
          {
                  string: navigator.platform,
                  subString: "Win",
                  identity: "Windows"
          },
          {
                  string: navigator.platform,
                  subString: "Mac",
                  identity: "Mac"
          },
          {
                  string: navigator.platform,
                  subString: "Linux",
                  identity: "Linux"
          }
  ]
};
  BrowserDetect.init();
  //return BrowserDetect.browser;
  return BrowserDetect;
}






////////////////////////////////////////////////////////////////////////
//	http://isohunt.com/js/functions.js
function servOC(spid, href, nColor, triangleI) {

  var trObj = (document.getElementById) ? document.getElementById('ihtr_' + spid) : eval("document.all['ihtr_" + spid + "']");
  var nameObj = (document.getElementById) ? document.getElementById('name_' + spid) : eval("document.all['name_" + spid + "']");
  //--var ifObj = (document.getElementById) ? document.getElementById('ihif_' + spid) : eval("document.all['ihif_" + spid + "']");

  var browserobj = getBrowser(); 
  var browser = browserobj.browser; 
 
 if (browser == "Firefox" || browser == "Mozilla" || browser == "Netscape" || browser == "Gecko" || browser == "Seamonkey"){
    //ageID.addEventListener("click", stopEvent, false);
    trObj.addEventListener("click", stopEvent, false);
    nameObj.addEventListener("click", stopEvent, false);
    nameObj.addEventListener("click", stopEvent, false);
  }
  else {
    window.event.cancelBubble = true;
  }; 

  //alert(trObj.id + nameObj.id + ifObj.id);
 
 if (trObj != null) {
    if (trObj.style.display=="none") {
      //--ifObj.style.height = "0px";
      trObj.style.display="";

      //nameObj.style.background="#ECECD9";
      nameObj.style.background="#000099";

      if (browser == "Safari" || browser == "Konquerors")
      {
         setTimeout("toggleDownUp('triangle_"+spid+"','down');",1);
      }   else {
        toggleDownUp('triangle_'+spid,'down');
      }
      //--if (!ifObj.src) {
	//--if (href.length > 1)
	//--{ ifObj.src = href; }
      //--}
      //--smoothHeight('ihif_' + spid, 0, 240, 60, 'o');
      smoothHeight('ihtr_' + spid, 0, 240, 60, 'o');

    }
    else {     
      nameObj.style.background=nColor;
      //--smoothHeight('ihif_' + spid, 240, 0, 60, 'ihtr_' + spid);
      smoothHeight('ihtr_' + spid, 240, 0, 60, 'ihtr_' + spid);
      if (browser == "Safari" || browser == "Konquerors")
      {
	setTimeout("toggleDownUp('triangle_"+spid+"','up');",1);
      } else {
        toggleDownUp('triangle_'+spid,'up');
      }
     /* triangleID.setAttribute('src', '/img/serp-toggle-up.gif');*/
    }
  }
}


function toggleDownUp(ele,pos)
{
	var ele = document.getElementById(ele);
	if (ele)
	{
		ele.setAttribute('src', '/images/serp-toggle-'+pos+'.gif');
	}
}


function smoothHeight(id, curH, targetH, stepH, mode)
{
  diff = targetH - curH;
  if (diff != 0)
  {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 16 );
  }
  else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}


function stopEvent(ev) {
  // this ought to keep t-daddy from getting the click.
  ev.stopPropagation();
//return false;
// alert("event propagation halted.");
//  ev.cancelBubble = true;
}


//------------------------------------Not Used------------------------------
function servOCorig(i, href, nColor, triangleID) {
  var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
  var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
  var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");

  var ageID = document.getElementById('row_6_' + i);
  var browser = getBrowser(); 

  if (browser == "Firefox" || browser == "Mozilla" || browser == "Netscape" || browser == "Gecko" || browser == "Seamonkey"){
    ageID.addEventListener("click", stopEvent, false);
    trObj.addEventListener("click", stopEvent, false);
    nameObj.addEventListener("click", stopEvent, false);
    nameObj.addEventListener("click", stopEvent, false);
  }
  else {
    window.event.cancelBubble = true;
  }; 
 if (trObj != null) {
    if (trObj.style.display=="none") {
      ifObj.style.height = "0px";
      trObj.style.display="";
      nameObj.style.background="#ECECD9";
      if (browser == "Safari" || browser == "Konquerors"){
         setTimeout("toggleDownUp('triangle_"+i+"','down');",1);
      }   else {
        toggleDownUp('triangle_'+i,'down');
      }
      if (!ifObj.src) ifObj.src = href;
      smoothHeight('ihif' + i, 0, 210, 42, 'o');

    }
    else {     
      nameObj.style.background=nColor;
      smoothHeight('ihif' + i, 210, 0, 42, 'ihtr' + i);
      if (browser == "Safari" || browser == "Konquerors"){
      setTimeout("toggleDownUp('triangle_"+i+"','up');",1);
      } else {
        toggleDownUp('triangle_'+i,'up');
      }
     /* triangleID.setAttribute('src', '/img/serp-toggle-up.gif');*/
    }
  }
}



///// http://blog.firetree.net/2005/07/04/javascript-find-position/
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosYOld(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function findPosY(obj) {
	yPos = obj.offsetTop;
	tempEl = obj.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}



////////////////////// Swap-a-roo /////////////////
function swapimg (theimg, theonum, thennum) {
	var swaptmp;

	if ( (theimg) && (theimg.src) )
	{
		swaptmp = theimg.src;
		//alert("No - " + theonum + "/" + thennum + "..." + swaptmp);
		theimg.src = swaptmp.replace(theonum + ".png", thennum + ".png");
	}else{

	}
}


function swapback(theimg, theonum, thennum) {
	//alert("No2");
	var swaptmp;

	if ( (theimg) && (theimg.style) && (theimg.style.background)  )
	{
		swaptmp = theimg.style.background;
		//alert("No - " + theonum + "/" + thennum + "..." + swaptmp);
		theimg.style.background=swaptmp.replace(theonum + ".png", thennum + ".png");
	}else{

	}
}

function swapcache (theclass) {
	if ( (theimg) && (theimg.style) && (theimg.style.background) && (theimg.style.background.length > 1) && (theimg.style.background != "blank.gif") )
	{
		theimg.style.background=theimg.style.background.replace(theonum + ".png", thennum + ".png");
	}
}



///// Check for missing images ... Preload SWAP images for "xxxx_single1.png" //////////
function failsafeImg(){
	var badImg = new Image();
	badImg.src = 'blank.gif';
	var imageArray1=new Array();
	var imageArray2=new Array();
	var imgtot;

	imgtot = document.images.length;
	imgtot = -1;

	for(var fi=0;fi<imgtot;fi++)
	{
		if ( document.images[fi].src.indexOf("app") > 0 )
		{
			imageArray1[fi]=new Image();
			imageArray1[fi].src = document.images[fi].src;
		}else if ( ( document.images[fi].src.indexOf("ingle1") > 0 ) || ( document.images[fi].src.indexOf("utton") > 0 ) )
		{

			imageArray2[fi] = new Image();
			imageArray2[fi].src = document.images[fi].src.replace("1.png", "2.png");
			//alert (imageArray2[fi].src + " =-= " + imageArray2[fi].width );
		}
	}
	for(var fi=0;fi<imgtot;fi++)
	{
	    //if (imageArray1[fi].complete) 
	    if ( document.images[fi].src.indexOf("app") > 0 )
	    {
		//alert(document.images[fi].src + " / " + cpyImg.width);
		if ( (!imageArray1[fi].width) ||  (imageArray1[fi].width < 1 ) || (imageArray1[fi].width == 28 ) ) //IE's red X is 28px.
		{
			//alert(document.images[fi].src + " -- " + imageArray1[fi].width);
			document.images[fi].src = badImg.src;
		}
	    }
	}
}


function IsImageOk(img) {

    if ( img.src.indexOf("app3") > 0 )
    {
	//alert(" ... " + img.src + " .... " + img.type + " .... " + img.width );
	//alert(" ... " + img.src + " .... " + img.width );
    }

    //IE's red X is 28px. IE7 is 38px. Chrome is 18px
    if ( (!img.width) ||  (img.width < 1 ) || (img.width == 38 ) || (img.width == 28 ) || (img.width == 18 ) )
    {
        return false;
    }

    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    try
    {
    	if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
	        return false;
	    }
    }
	catch (e)
	{
		idontcare = true;
	}

    // No other way of checking: assume it's ok.
    return true;
}


function failsafeImg2()
{
	if (document.domain.indexOf("store.") >= 1) return;
	if (document.domain.indexOf("secure.") >= 1) return;

	//  alert("failsafeImg2");
	var badImg = new Image();
	badImg.src = 'blank.gif';
	for (var fi = 0; fi < document.images.length; fi++)
	{
        	if ( !IsImageOk(document.images[fi]) )
		{
		    //alert(" ... " + document.images[fi].src + " .... " + document.images[fi].width );
		    document.images[fi].title = "X";
		    document.images[fi].src = badImg.src;
	            document.images[fi].style.visibility = "hidden";
	            document.images[fi].style.display = "none";
	        }
	}
}


function Wait4it(){

}


function moveSZimg(){
	//Move Sizechart IMG
	//if( (thise = document.getElementById("sizechart")) && (thisi = document.getElementById("sizeimg")) )




	if( (thise = document.getElementById("SZCHARTID")) && (thisi = document.getElementById("sizeimg")) )
	{
   		 setTimeout("moveSZimg2(thise,thisi)",100 );
   		 setTimeout("moveSZimg2(thise,thisi)",1000 );
  		 setTimeout("moveSZimg2(thise,thisi)",5000 );
	}

}

function moveSZimg2(thise,thisi){
	//alert("YES!");
	//thise = document.getElementById("SZCHARTID");
	//thisi = document.getElementById("sizeimg");
	thisy = findPosY(thise);
	if (thisy >= 150)
	{
		if ((thisi.width) && (thisi.width >= 40))
		{
			movelft = (thisi.width + 45);
			movelft = movelft + "";
		}else{
			movelft = "195";
		}

		thisyt = (thisy - 165) ;
		if( document.getElementById("IE6MSG")  )
		{
			if (thisyt < 1000) { thisyt = 1000; }
		}

		if (thisyt < 750) { thisyt = 730; }
		thisyt = thisyt + "px";
		//thisyt = (thisy - 155) + "px";
		//thisyt = (thisy) + "px";

		thisi.style.top = thisyt;
		thisi.style.left = "-" + movelft + "px";

	}
}

////////////////////// C is 4 cookie /////////////////
function createCookie(name,value,days) {
	try
	{

		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	catch (e)
	{
		idontcare = true;
	}
}

function readCookie(name) {
	try
	{
		var nameEQ = name + "=";
		//alert(document.cookie);
		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) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	catch (e)
	{
		idontcare = true;
		return null;
	}
}

function eraseCookie(name) {
	createCookie(name,"",-1);

}

function cookNav(cnlevel, cnlink, cntext, cncode) {

	var maxlev = 6;
	var myLevels=new Array();
	var cntarget = "navspace";
	var cnoutput = "";

	if (document.domain.indexOf("store.") >= 1) return;
	if (document.domain.indexOf("secure.") >= 1) return;


	if ( cncode === undefined ) {
		cncode = 'XXXX';
	}


	//make Home Page level 0...
	if (cnlink == "/")
	{
		cnlevel = 0;
	}

	//Erase cookies below
	for(var i=cnlevel;i <= maxlev;i++)
	{
		cntmp = "level" + i;
		eraseCookie(cntmp);
		myLevels[i] = "";
	}
	//Read cookies above
	for(var i=cnlevel;i >= 0;i--)
	{
		cntmp = "level" + i;
		myLevels[i] = readCookie(cntmp);
	}

	//Set Current
	cnlevel += "";		//Explicit conversion to string.
	cntmp = "level" + cnlevel;
	cnlevel =  parseInt(cnlevel);		//Explicit conversion to numeric.
	//myLevels[cnlevel] = cntext + "||" + cnlink;
	myLevels[cnlevel] = "b64x" + encode64(cntext + "||" + cnlink + "||" + cncode);
	createCookie(cntmp, myLevels[cnlevel],2);


	//Draw nav HTML
	if (cnlevel >= 0)
	{
		navcnt = 0;
		for(var i=0;i <= maxlev;i++)
		{

			if (  (myLevels[i]) && (myLevels[i].length > 2) )
			{
				if (cnoutput.length > 1)
				{ 
					cnoutput += " &raquo; ";
				}
				cntemp = myLevels[i];
				if ((cntemp.length > 4) && (cntemp.substring(0,4) == "b64x"))
				{
					cntemp = decode64( cntemp.substring(4) );
				}
				cnparts = cntemp.split("||"); 


				cnoutput += " <a href='" + cnparts[1] + "'>" + cnparts[0] + "</a> ";
				navcnt++;
			}
		}
		if (navcnt > 1)
		{
			var ele = document.getElementById(cntarget);
			if (ele)
			{
				ele.innerHTML = cnoutput;
			}else{
				//alert(" ?!@#*! ");
			}
		}
	}

	//return true;
}


//////////////////////////////////////////////////////

