
/* ---------------------------------------------------------------- */
/* commonSetCookie                                                  */
/* ---------------------------------------------------------------- */
function commonSetCookie(cookieName, cookieValue)
{
        document.cookie = cookieName + "=" + cookieValue + "; expires=";
}

/* ---------------------------------------------------------------- */
/* commonGetCookie                                                  */
/* ---------------------------------------------------------------- */
function commonGetCookie(cookieName)
{
        var allCookie = document.cookie;
        var theValue;
        var start = allCookie.indexOf(cookieName+"=");
        if (start == -1)
			return "";
			
        var end = allCookie.indexOf(";", start);
        
        if (end == -1) 
			end = allCookie.length;
			
        var name_value = allCookie.substring(start, end);
        theValue = name_value.substring(cookieName.length+1, name_value.length);
        
        return theValue;
}

var showPopup = true;

/* ---------------------------------------------------------------- */
/* commonSetAutoStart                                               */
/* ---------------------------------------------------------------- */
function commonSetAutoStart(trueORfalse)
{
	commonSetCookie("cookieMusicAutoStart", trueORfalse);
}

var blink_speed=1200;
var blink_on=0;

function commonBlink()
{
	for (b=1; b<20; b++)
	{
		obj = eval("window.blink" + b);
	
		if (obj == undefined)
			break;

		if (blink_on==0)
		{
			obj.style.color = obj.parentNode.style.color;
		}
		else
		{
			obj.style.color = "red";
		}
	}

	if (b != 1)
	{
		if (blink_on==0)
		{
			blink_on = 1;
			speed = blink_speed;
		}
		else
		{
			blink_on = 0;
			speed = blink_speed/2;
		}
		setTimeout("commonBlink();",speed);
	}
}

/* ---------------------------------------------------------------- */
/* commonEncode	- moved to LANG.js									*/
/* ---------------------------------------------------------------- */

/* ---------------------------------------------------------------- */
/* commonDecode	- moved to LANG.js									*/
/* ---------------------------------------------------------------- */

/* ---------------------------------------------------------------- */
/* commonSortXml													*/
/* ---------------------------------------------------------------- */
function commonSortXml (xml, sortColumn, sortType, sortDir)
{
	var xslDoc = new ActiveXObject("Microsoft.XMLDOM");
    xslDoc.async = false;

    var xsl =   " <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " 	+
				" version='1.0'> " 														+
       	        " <xsl:template match='/'> " 											+
           	    " <items> " 															+
               	" <xsl:for-each select='items/item'> " 									+
				" <xsl:sort select='" + sortColumn + "'" 								+
			    "          order='" + sortDir+ "' data-type='" + sortType + "'/>" 		+
   		    	"       <xsl:copy> " 													+
           	    "           <xsl:copy-of select='*'/> " 								+
               	"       </xsl:copy> " 													+
                "   </xsl:for-each> " 													+
   	            " </items> " 															+
       	        " </xsl:template> " 													+
           	    " </xsl:stylesheet> ";

    // loading the xsl sorter
	//--------------------------------------------------------------------
    xslDoc.loadXML (xsl);

	var toSortXml = new ActiveXObject("Microsoft.XMLDOM");
	toSortXml.loadXML (xml.getElementsByTagName("items").item(0).xml);
	
	sortedXml = new ActiveXObject("Microsoft.XMLDOM");
	sortedXml.loadXML ("<data>" + toSortXml.transformNode(xslDoc) + "</data>");

	return sortedXml;	
}

/* ---------------------------------------------------------------- */
/* commonPrintPage													*/
/* ---------------------------------------------------------------- */
function commonPrintPage (type, id)
{
	var xmlRequest = new xmlObj(false);
	xmlRequest.init ("<data>"	+
						"<command>private.getPrintPage</command>"	+
						"<type>" + type + "</type>"	+
						"<id>" + id + "</id>"	+
					 "</data>");
	xmlRequest.sendRequest ('server.php', xmlRequest.obj);

	responseXml = xmlRequest.obj;

	var printFileName = responseXml.getElementsByTagName("printFileName").item(0).text;

	var height = screen.availHeight - 100;
	var width  = screen.availWidth  - 100;

	var y = 0;
	var x = (screen.availWidth  - width)  / 2;

	window.open ("tempPrints/" + printFileName, "",  "status=no,toolbar=no,menubar=yes,height=" + height + ", "	+
					 "								  width =" + width  + ", left="+x+", top="+y);

}

/* ---------------------------------------------------------------- */
/* commonAddLoadEvent												*/
/* ---------------------------------------------------------------- */
function commonAddLoadEvent(func)
{
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
	    window.onload = func;
	  } else {
	    window.onload = function() {
	      if (oldonload) {
	        oldonload();
	      }
	      func();
	    }
	  }
}

