/*
 * Copyright (c) 2008, Aleajecta
 * All rights reserved.
 * 
 * The Service and any necessary software used in connection with the 
 * Service ("Software") contain proprietary and confidential information 
 * that is protected by applicable intellectual property and other laws.
 * You agree not to modify, rent, lease, loan, sell, distribute or create
 * derivative works based on the Service or the Software, in whole or in part.
 */
/**
 * @author Greenseed
 *
 *
 * @namespace ShopEngine
 * @sdoc sdoc/common.sdoc
 *
 * where i store the browser id
 */
var BrowserId = 0;
var BROWSER_MOZ = 0;
var BROWSER_IE = 1;
var BROWSER_NS = 2;
var BROWSER_SAF = 4;
var BROWSER_OP = 8;
var BROWSER_KO = 16;
//alert(navigator.userAgent);
if(navigator.userAgent.indexOf('Firefox') > -1) //Mozzila/Firefox
    BrowserId = BROWSER_MOZ;
else if(document.all) //IE
    BrowserId = BROWSER_IE;
else if(document.layers) //Nescape
    BrowserId = BROWSER_NS; 
else if(navigator.userAgent.indexOf('Safari') > -1)
    BrowserId = BROWSER_SAF;
else if(navigator.userAgent.indexOf('Opera') > -1)
    BrowserId = BROWSER_OP;
else if(navigator.userAgent.indexOf('Konqueror') > -1)
    BrowserId = BROWSER_KO; 

var Blur, bgImage;

/** @id commonInit */
var commonInit = new Array();
/** @id userInit */
var userInit = new Array();
/** @id adminInit */
var adminInit = new Array();


var moronIE = (document.all ? true : false);

function CreateElement(tagName){return document.createElement(tagName)}

function GetElementById(id){return document.getElementById(id)}

function GetElementsByName(owner,tagName){return owner.getElementsByTagName(tagName)}

/** @id wordWrap */
String.prototype.wordWrap = function(maxLineLenght,addOnMaxLenght, c)
{
	var i, j, s, r = this.split("\n");
	if(maxLineLenght > 0) for(i in r)
	{
	    for(s = r[i], r[i] = ""; s.length > maxLineLenght;
	        j = c ? maxLineLenght : (j = s.substr(0, maxLineLenght).match(/\S*$/)).input.length - j[0].length
	        || maxLineLenght,
	        r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? addOnMaxLenght : "")
	    );
	    r[i] += s;
	}
	return r.join("\n");
};
//Take MS time and convert to Normal Display Time for Human
Number.prototype.MStoTime = function()
{
    var date = new Date();
    var value = this;
    if( value < 10000000000) 
        value *= 1000;
    date.setTime(value/*+3600000*/); //Correct the New Time Formula
    return date; 
};/*
Array.prototype.max = function( dimension )
{
    var maxValue = 0;
    if (typeof dimension != "undefine" && dimension) 
        for (var itr in this) 
            maxValue = Math.max(maxValue,Number(this[dimension]));
    else 
        for (var itr in this) 
            maxValue = Math.max(maxValue,Number(this));
    return maxValue;   
};

Array.prototype.min = function( dimension )
{
    var minValue = 0;
    if (typeof dimension != "undefine" && dimension) 
        for (var itr in this) 
            minValue = Math.min(minValue,Number(this[dimension]));
    else 
        for (var itr in this) 
            minValue = Math.min(minValue,Number(this));
    return minValue;   
};*/

GetElementsByClassName = function(className) 
{
	var children = document.getElementsByTagName('*') || document.all;
	var elements = new Array();
  
	for (var i = 0; i < children.length; i++) 
    {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) 
        {
			if (classNames[j] == className) 
            {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}
function wait(ms)
{
    var date = Date.now();
    var curDate = null;

    do { curDate = Date.now(); }
    while(curDate-date < ms);
}
/**
 * Set/Change Style Sheet Rules
 * @param {Bool} tvDocument if true will take Tv.document, else take document.
 * @param {String} targetSheet Filename, who will be URL searched.
 * @param {String} indexIdentifier String that will be searched to identifie the cssRule Index.
 * @param {String} propertyName The css propety i wan to set.
 * @param {String} propertyValue Value of the property to set.
 */
function SetSSRule(tvDocument,targetSheet,indexIdentifier,propertyName,propertyValue)
{
    var container = document;
    if(container.styleSheets) 
    {
        var text = '';
        for (var sheet in container.styleSheets) 
        {
            if(!container.styleSheets[sheet].href || container.styleSheets[sheet].href.indexOf(targetSheet) < 0)
                continue;
            for (var itr in container.styleSheets[sheet][(moronIE ? 'rules' : 'cssRules')] ) 
            {
                if(typeof container.styleSheets[sheet][(moronIE ? 'rules' : 'cssRules')][itr] == 'object' ) 
                {
                    if (container.styleSheets[sheet][(moronIE ? 'rules' : 'cssRules')][itr].selectorText.toLowerCase().indexOf(indexIdentifier.toLowerCase()) > -1) 
                        container.styleSheets[sheet][(moronIE ? 'rules' : 'cssRules')][itr].style[propertyName] = propertyValue;
                }
            }
        }
    } 
}


/** @id Initialize */
function Initialize()
{
    Blur = GetElementById("blur");
    bgImage = GetElementById("bgImage");

    while (commonInit.length) 
        commonInit.shift()();
    while (userInit.length) 
        userInit.shift()();
    while (adminInit.length) 
        adminInit.shift()();
    
    Blur.style.display = "none";
    
    //setTimeout('TestingGround()',0);
}
function TestingGround()
{
    ;
}





/*cookie
   1. First the name-value pair ('ppkcookie1=testcookie')
   2. then a semicolon and a space
   3. then the expiry date in the correct format ('expires=Thu, 2 Aug 2001 20:47:11 UTC')
   4. again a semicolon and a space
   5. then the path (path=/)


setTimeout(function(thisObj) { thisObj.methodToCall(); }, time, this);


/*Element.getOpacity = function(element){
  return $(element).getStyle('opacity');
}

Element.setOpacity = function(element, value){
  return $(element).setStyle({opacity:value});
}*/

//for(var itr in ItemView[0])
//alert(itr.toLocaleString());

//alert(document.Frames);

