/* 
Browser sniffer. Written by PerlScriptsJavaScripts.com
Copyright http://www.perlscriptsjavascripts.com 
Free and commercial Perl and JavaScripts     
*/

var v3 = false;
var op = false;
var ie  = false;
var ie4  = false;
var ie5 = false;
var nn = false;
var nn4 = false;
var nn6 = false;
var isMac = false;
var aol = false;
var moz = false;

if(document.images){
 if(navigator.userAgent.indexOf("Opera") != -1){
  op = true;
 } else {
  if(navigator.userAgent.indexOf("Gecko") != -1){
	 moz = true;
	} else {
   if(navigator.userAgent.indexOf("AOL") != -1){
	  aol = true;
	 } else {
	  ie4 = (document.all && !document.getElementById);
		nn4 = (document.layers);
		ie5 = (document.all && document.getElementById);
		nn6 = (document.addEventListener);
	 }
  }
 }
} else {
 v3 = true;
}

if(navigator.userAgent.indexOf("Mac") != -1){
 isMac = true;
}

ie = (ie4 || ie5);
nn = (nn4 || nn6);

/*
 Find the absolute Left position of an object
*/
function absoluteX( obj)
{
 var curleft = 0;
 if (obj.offsetParent) {
  while (obj.offsetParent) {
   if ( obj.clientWidth > 0) {
    curleft += obj.offsetLeft;
 	  curleft -= obj.scrollLeft;
   }
	  obj = obj.offsetParent;
	  if ( ie && obj.offsetParent && isNum(obj.currentStyle.borderLeftWidth)) {
    curleft += parseInt(obj.currentStyle.borderLeftWidth);
	  }
	 }
 }
 else if (obj.x) curleft += obj.x;
 return curleft;
}
function positionLeft(obj)
{
 return( absoluteX( obj));

 var curleft = 0;
 if (obj.offsetParent) {
  while (obj.offsetParent) {
   curleft += obj.offsetLeft;
   curleft -= obj.scrollLeft;
 	 obj = obj.offsetParent;
 	}
 }
 else if (obj.x) 
  curleft += obj.x;
 return curleft;
}
/*
 Find the absolute Top position of an object
*/
function absoluteY( obj)
{
 var curtop = 0			;
 if (obj.offsetParent) {
  while (obj.offsetParent) {
	  curtop += obj.offsetTop;
	  curtop -= obj.scrollTop;
	  obj = obj.offsetParent;
	  if ( ie && obj.offsetParent && isNum(obj.currentStyle.borderTopWidth)) {
    curtop += parseInt(obj.currentStyle.borderTopWidth);
	  }
	 }
 }
 else if (obj.y) curtop += obj.y;
 return curtop;
}
function positionTop(obj)
{
 return( absoluteY( obj));

 var curtop = 0;
 if (obj.offsetParent) {
  while (obj.offsetParent) {
 	 curtop += obj.offsetTop;
 	 curtop -= obj.scrollTop;
 	 obj = obj.offsetParent;
  }
 }
 else if (obj.y)
  curtop += obj.y;
 return curtop;
}

XMLHTTPSupport = false;
var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")},
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++)
	{
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

function getServerHtmlData( url, targetObject, furtherAction)
{
 var req = createXMLHTTPObject();
 if (!req) return( false);
 XMLHTTPSupport = true;

 req.open("GET",url,true);
//	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
 req.onreadystatechange = function () {

	 if (req.readyState != 4) return;

	 if (req.status != 200 && req.status != 304) {
   if ( req.status == 499) {
    // Customized TEXT error
    alert("ERROR: " + req.responseText);
   }
   else {
    if ( req.status == 498) {
     // Customized JAVASCRIPT error
     eval(req.responseText);
    }
    else {
     if ( req.status == 299) {
      // Customized TEXT message
      alert(req.responseText);
     }
     else {
		   alert('HTTP error : '+req.status+' requesting URL ['+url+']');
     }
    }
   }
		 return;
	 }
  if ( req.responseText.indexOf('498 Custom Javascript') >= 0) {
   eval(req.responseText);
   targetObject = null;
  }
  if ( targetObject) {
   newvalue = req.responseText;
   targetObject.setAttribute("oldValue", targetObject.getAttribute("value"));
   targetObject.setAttribute("value", newvalue);
  }
  if (furtherAction) {
   furtherAction();
  }
 }
 req.send(null);
}

function getServerHtml( url, targetObject, furtherAction)
{
 var req = createXMLHTTPObject();
 if (!req) return( false);
 XMLHTTPSupport = true;

 req.open("GET",url,true);
//	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
 req.onreadystatechange = function () {

	 if (req.readyState != 4) return;

	 if (req.status != 200 && req.status != 304) {
   if ( req.status == 499) {
    // Customized TEXT error
    alert("ERROR: " + req.responseText);
   }
   else {
    if ( req.status == 498) {
     // Customized JAVASCRIPT error
     eval(req.responseText);
    }
    else {
     if ( req.status == 299) {
      // Customized TEXT message
      alert(req.responseText);
     }
     else {
		   alert('HTTP error : '+req.status+' requesting URL ['+url+']');
     }
    }
   }
		return;
	 }
  if ( req.responseText.indexOf('498 Custom Javascript') >= 0) {
   eval(req.responseText);
   targetObject = null;
  }
  if ( targetObject) {
   HTML = req.responseText;
   targetObject.innerHTML = HTML;
  }
  if (furtherAction) {
   furtherAction();
  }
 }
 req.send(null);
}

function trim( str)
{
 if ( str) {
  return str.replace(/^\s*|\s*$/g,"");
 } else {
  return("");
 }
}

function notify( obj)
{
 if ( !obj.getAttribute('notification')) return;

 div = document.createElement( 'DIV');
 div.style.position = "absolute";
 t = eval( positionTop( obj) + obj.offsetHeight + 15);
 div.style.top = t+"px";
 l = eval( positionLeft( obj) + 5);
 div.style.left = l+"px";
 div.style.padding = "3px";
 div.style.border = "1px solid navy";
 div.style.backgroundColor = "rgb(255,255,200)";
 div.style.lineHeight = "12px";
 div.style.fontSize = "10px";
 div.style.fontFamily = "sans-serif";
 div.style.zIndex = 9999;
 div.style.textAlign = "justify";
 div.opacity = 0.9;
 div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=98)";
 div.innerHTML = obj.getAttribute('notification');
 div.setAttribute('notificationbox',true);
 document.body.appendChild( div);

 if ( div.offsetWidth > 200) {
  div.style.width = "200px";
 }
 obj.noteObject = div;
 obj.onmouseout = function() {
  if ( this.noteObject) {
   try {
    document.body.removeChild( this.noteObject);
   }
   catch (e) {
   }
   this.noteObject = null;
  }
 }
}
function removenotifies()
{
 divs = document.getElementsByTagName('DIV');
 for (var i=0;i<divs.length;i++) {
  if ( divs[i].getAttribute('notificationbox')) {
   document.body.removeChild( divs[i]);
  }
 }
}

function setnotifications()
{
 divs = document.getElementsByTagName('*');
 for (var i=0;i<divs.length;i++) {
  if ( divs[i].getAttribute('notification')) {
	 divs[i].onmouseover = function() {
	  notify( this);
	 }
	 divs[i].onmouseoout = function() {
	  removenotifies();
	 }
  }
 }
}


/*********** IMAGE SWAPPING ***********/
// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 4000

// Duration of crossfade (seconds)
var crossFadeDuration = 1

// Specify the image files
// =======================================
// Duplicate This Part For New Slice

var Pic = new Array() // don't touch this

Pic[0] = 'images/01.jpg'
Pic[1] = 'images/02.jpg'
Pic[2] = 'images/03.jpg'
Pic[3] = 'images/04.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
 preLoad[i] = new Image()
 preLoad[i].src = Pic[i]
}

function runSlideShow()
{
 if (document.all){
  document.SlideShow.style.filter="blendTrans(duration=2)"
  document.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
  document.SlideShow.filters.blendTrans.Apply()
 }
 document.SlideShow.src = preLoad[j].src
 if (document.all){
  document.SlideShow.filters.blendTrans.Play()
 }
 j = j + 1
 if (j > (p-1)) j=0
 t = setTimeout('runSlideShow()', slideShowSpeed)
}


/**** PRODUCT RELATED FUNCTIONS ****/
function iHTML()
{
}
function loadProductImages( productID)
{
 if ( productID) {
  url = "productImages.php?random="+Math.random()+"&productID="+productID;
 } else {
  url = "productImages.php?random="+Math.random()+"&productID=0";
 }
 getServerHtml( url, document.getElementById('productImages'), iHTML); 
}

function displayImage( obj)
{
 img = obj.parentNode.parentNode.style.backgroundImage;
 if ( img != "") {
  img = img.replace( "url(", "");
  img = img.replace( "jpg)", "jpg");
  img = img.replace( "thumbs/", "");
 }
}
function X_openImage( obj)
{
 img = obj.parentNode.parentNode.style.backgroundImage;
 if ( img != "") {
  img = img.replace( /%22/g, "");
  img = img.replace( /\"/g, "");
  img = img.replace( "url(", "");
  img = img.replace( "jpg)", "jpg");
  img = img.replace( "thumbs/", "");
  window.open(img);
 }
}

function openImage( obj)
{
 img = obj.parentNode.parentNode.style.backgroundImage;
 if ( img != "") {
  img = img.replace( /%22/g, "");
  img = img.replace( /\"/g, "");
  img = img.replace( "url(", "");
  img = img.replace( "jpg)", "jpg");
  img = img.replace( "thumbs/", "");
  
  obj.bigImage = new Image();
  obj.bigImage.onload = function() {
 	 document.body.style.overflow='hidden';
   imageBox = document.createElement("DIV");
 	 imageBox.className = "imageMagnifiedCover";
   imageBox.id = "_largeProductImageCover";
   imageBox.onclick = function() {
    document.documentElement.onscroll = null;
    document.body.removeChild(document.getElementById('_largeProductImage'));
    document.body.removeChild(document.getElementById('_largeProductImageCover'));
   };

   document.body.appendChild(imageBox);

   maxH = eval( 95 * imageBox.offsetHeight / 100);
   if ( maxH > this.height) maxH = this.height;
   maxW = eval( 95 * imageBox.offsetWidth / 100);

/*   document.documentElement.onscroll = function() {
    t = document.documentElement.scrollTop;
    document.getElementById('_largeProductImage').style.top = t+"px";
    document.getElementById('_largeProductImageCover').style.top = t+"px";
   };*/

   imageHolder = document.createElement("DIV");
 	 imageHolder.className = "imageMagnified";
   imageHolder.id = "_largeProductImage";
   imageHolder.innerHTML = "<table summary='' style='width:100%;height:100%;'><tr><td align='center' valign='middle'><img src='"+this.src+"' height='"+maxH+"' alt='productImage' style='border:3px double #000;' /><span style='color:#fff;font-weight:bold;'>Click to close</span></td></tr></table>";
   imageHolder.onclick = function() {
    document.documentElement.onscroll = null;
    document.body.removeChild(document.getElementById('_largeProductImage'));
    document.body.removeChild(document.getElementById('_largeProductImageCover'));
   };
   document.body.appendChild(imageHolder);
 	 document.body.style.overflow='';
  };
  obj.bigImage.src = img;
 }
}

/**** VALIDATION FUNCTIONS ****/
function isNum( value)
{
 if (value=="") return(false);
 var PNum = new String( value);
 var regex = /[^0-9\-]/;
 return !regex.test(PNum);
}
function isFloat( value)
{
 if (value=="") return(false);
 var PNum = new String( value);
 var regex = /[^0-9\.\-]/;
 return !regex.test(PNum);
}

function isMoney( value)
{
 return( isFloat(value));
}
function isDate( value)
{
 // Format is always day/month/year
 // An empty field will be recognized as valid
 success = false;

 if ( value == "") return( "");
 aDate = value.split('/');

 if ( aDate.length != 3) {
  if ( value.length == 6) {
 	 // Assume 2 digits for day, month and year
 	 aDate = new Array();
 	 aDate[0] = value.substr(0,2);
 	 aDate[1] = value.substr(2,2);
 	 aDate[2] = value.substr(4,2);
 	}
  if ( value.length == 8) {
 	 // Assume 2 digits for day, month and a 4 digit year
 	 aDate = new Array();
 	 aDate[0] = value.substr(0,2);
 	 aDate[1] = value.substr(2,2);
 	 aDate[2] = value.substr(4,4);
 	}
 }

 if ( aDate.length == 3) {
  _day = aDate[0];
	 _month = aDate[1];
	 _year = aDate[2];
	 if ( isNum( _day) && isNum( _month) && isNum( _year)) {
	  _day = eval( _day);
	  _month = eval( _month);
	  _year = eval( _year);
	  if ( _year < 30) {
	   _year += 2000;
	  }
 		else {
	   if ( _year < 100) {
	    _year += 1900;
	   }
 		}
 	 theDate = new Date( _year, _month-1, _day);
 	 _day = theDate.getDate();
 	 _month = theDate.getMonth()+1;
 	 strDay = _day;
 	 if ( _day < 10) {
 	  strDay = "0"+_day;
 	 }
 	 strMonth = _month;
 	 if ( _month < 10) {
 	  strMonth = "0"+_month;
 	 }
 	 strYear = theDate.getFullYear();
 	 strDate = strDay+"/"+strMonth+"/"+strYear;
   success = true;
 	}
 }
 if ( success) {
  return( strDate);
 } else {
  return( false);
 }
}

function isEmailAddress( value) {
 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 return ( reg.test(value));
}

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/number/fmt-money [v1.1]

Number.prototype.formatMoney = function(c, d, t){
	var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

function stripEmptyNodes( blk)
{
 var i;
 for (i=0;i<blk.childNodes.length;i++) {
  if ( blk.childNodes[i].nodeName == "#text") {
   text = blk.childNodes[i].innerText?blk.childNodes[i].innerText:blk.childNodes[i].textContent;
   if ( text && trim(text)=="") {
    blk.removeChild(blk.childNodes[i]);
    i--;
   }
  } else {
   if ( blk.hasChildNodes()) {
    stripEmptyNodes( blk.childNodes[i]);
   }
  }
 }
}
