function toggleDiv(id){
	if(document.getElementById(id).style.display == 'block'){
		document.getElementById(id).style.display = 'none';
		document.getElementById('link' + id).style.color='#000';
		document.getElementById('link' + id).style.fontWeight='500';
		}
		else
		{
		document.getElementById(id).style.display = 'block';
		document.getElementById('link' + id).style.color='#0188ca';
		document.getElementById('link' + id).style.fontWeight='900';
		document.getElementById(id).style.border = '1px #0188ca solid';
		
		}	
}


/* =========== cookie ==============*/
function createCookie(name,value) {
	document.cookie = name+"="+value;
	
}
function readCookie(name) {
	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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

/* =========== rtn left(n) of string ==============*/
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function Mid(str, start, len)
	/***
			IN: str - the string we are LEFTing
				start - our string's starting position (0 based!!)
				len - how many characters from start we want to get

			RETVAL: The substring from start to start+len
	***/
	{
			// Make sure start and len are within proper bounds
			if (start < 0 || len < 0) return "";

			var iEnd, iLen = String(str).length;
			if (start + len > iLen)
					iEnd = iLen;
			else
					iEnd = start + len;

			return String(str).substring(start,iEnd);
	}
function Len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
{  return String(str).length;  }

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}


/* =========== mouse coords ==============*/
function detectMouseCoordinates(e){
    posx=0;
    posy=0;
   //alert("ad");
    if(!e) var e=window.event;
	    if(e.pageX||e.pageY){
          posx=e.pageX;
          posy=e.pageY;
    	}
	 else if(e.clientX||e.clientY){
        posx = e.clientX + document.documentElement.scrollLeft;
        posy = e.clientY + document.documentElement.scrollTop;
    }
}

/* =========== opacity ==============*/
function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
		
    } else {
        opacity(id, 100, 0, millisec);
		
    }

} 
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }

		
    } else if(opacStart < opacEnd) {
		
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
	
}
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	if(opacity < 1){document.getElementById(id).style.visibility = 'hidden';} //hide the popup
}

/*===== Width/Height ====*/
function getDivWidth(id) {

   var mydiv = document.getElementById(id);
   var curr_width = parseInt(mydiv.style.width); // removes the "px" at the end
   return curr_width;
}

function showLargeImage(str,e){
	if(str=='x' || str==''){
	str='../images/noimage.jpg';
	}
	else
	{
	str='../images/products/largeImage/' + str;
	}
	
	var scrolledy = getScrollXY();

	var aw = screen.Width;
	var ah = screen.Height;
	detectMouseCoordinates(e)
	var fposx = parseInt(posx) - parseInt(200);
	var fposy = parseInt(posy) + parseInt(10);
	
	eek = parseInt(fposy) + 800 + parseInt(10);

	if(eek > parseInt(ah)){
		fposy = fposy - 240;
	}
	if(fposy < scrolledy ){
		fposy =parseInt(posy);
	}

	//alert(bob);
	document.getElementById("largeImage").innerHTML = '<img src="' + str + '" />';
	document.getElementById("largeImage").style.display = "block";
	document.getElementById("largeImage").style.left = fposx + 'px';
	document.getElementById("largeImage").style.top = fposy + 'px'
}
	
	
function hideLargeImage(){
	document.getElementById("largeImage").style.display = 'none';
}	
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfY ];
}