//
// Web Service Collection Functions V1.00.1
//
//
//
// Copyright (C) 2007 Siliconetix Corp.  All Rights Reserved.
// Unpublished and Confidential Property of Siliconetix Corp.
//

var show_tip  = true;
var cache     = new Array();
var cache_key = null;

function collectionHideTip( mode )
{

	//
	// If we're called with a mode of 1, then we need to hide the box.  Otherwise, we
  	// check to see the value of show_tip and if it's true, then we start a timer
 	// and set show_tip to false, so that the timer doesn't keep getting set.
	//

	if ( mode == 1 ) {

		document.getElementById("collection-tip").style.visibility = "hidden";

	} else if ( show_tip == true ) {

		setTimeout( "collectionHideTip(1)", 3000 );
		show_tip = false;

	}

}

function collectionGetProduct( id, categoryid, pos_x, pos_y )
{
	ajaxConnector = GetXmlHttpObject()
	ajaxElement   = "collection-product"
	cache_key     = "key" + id;

	if ( cache[cache_key] != null ) {

		document.getElementById( ajaxElement).innerHTML = cache[cache_key]; 

	} else {

		document.getElementById( ajaxElement).innerHTML = "<div align=\"center\" style=\"padding: 40px 0 0 0;\"><img src=\"/images/ajax-wait.gif\" style=\"border: 0;\"></div>";

		if ( ajaxConnector != null ) {

			ajaxConnector.onreadystatechange = stateChanged
			ajaxConnector.open("GET", "/websvc-getproduct.php?id=" + id + "&categoryid=" + categoryid + "&seq=" + Math.random(), true)
			ajaxConnector.send(null)

		}

	} 

	document.getElementById("collection-product").style.top  = pos_y + "px";
	document.getElementById("collection-product").style.left = pos_x + "px";
	collectionShowProduct();

}

function collectionShowProduct()
{

	document.getElementById("collection-product").style.visibility = "visible";

}

function collectionHideProduct()
{

	document.getElementById("collection-product").style.visibility = "hidden";

}

var ajaxConnector
var ajaxElement

function stateChanged()
{

	if ( ajaxConnector.readyState == 4 || ajaxConnector.readyState == "complete" ) {

		if ( ajaxElement != null ) {

			cache[cache_key] = ajaxConnector.responseText;
			document.getElementById( ajaxElement ).innerHTML = ajaxConnector.responseText;

		}

	}

}

function GetXmlHttpObject()
{

    var objXMLHttp=null

    if ( window.XMLHttpRequest ) {

        objXMLHttp = new XMLHttpRequest()

    } else if ( window.ActiveXObject ) {

        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")

    }

    return objXMLHttp

}
