var main_div 		= null;
var aDimensions 	= new Array();
var bGobalDebugMode = 1;

function Timer()
{
	var cr = 0;
	var stoped = false;
 
	this.start = function()
	{
		cr = 0;
		stoped = false;
		next();
	}
 
	this.finish = function()
	{
		stoped = true;
		return cr * 10;
	}
 
	function next()
	{
		if(stoped)
		{
			return false;
		}
		setTimeout(next, 10);
		cr++;
		return true;
	}
 
	return this;
}

function ShadowCLS(){
	this.fOpacity 			= 0.6;
	this.fCurrentOpacity 	= 0;
	this.Style 				= null;
	this.bProcessMode		= 0;
	this.iClickCounter		= 0;
	this.move_shadow = function(){
		if(document.getElementById("shadow_div") && document.getElementById("shadow_div").style.display == "block"){
			var oShadowStyle = document.getElementById("shadow_div").style;
			if(window.pageXOffset){
				var iScrollLeft = window.pageXOffset;
			}else{
				var iScrollLeft = document.documentElement.scrollLeft;
			}
			oShadowStyle.left 	= iScrollLeft + 'px';
		}
		if(window.pageYOffset){
			var iScrollTop = window.pageYOffset;
		}else{
			var iScrollTop = document.documentElement.scrollTop;
		}
		/*if(document.getElementById('banners_block') && iScrollTop > 170){
			document.getElementById('banners_block').style.position = 'fixed';
		}*/
		/*alert(document.body.scrollHeight);
		debug_var(document.body,2);
		if(document.getElementById('quest_banner') && document.getElementById('quest_banner').style.display != 'none'){
			if(iScrollTop > 170){
				document.getElementById('quest_banner').style.marginTop = (iScrollTop - 170) + 'px';
			}
		}else if(document.getElementById('order_banner') && document.getElementById('order_banner').style.display != 'none'){
			if(iScrollTop > 170){
				document.getElementById('order_banner').style.marginTop = (iScrollTop - 170) + 'px';
			}
		}
		*/
	}
	this.getPageSize = function(){
	    var xScroll, yScroll;
	    if (window.innerHeight && window.scrollMaxY) {
	        xScroll = window.innerWidth + window.scrollMaxX;
	        yScroll = window.innerHeight + window.scrollMaxY;
	    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	        xScroll = document.body.scrollWidth;
	        yScroll = document.body.scrollHeight;
	    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	        xScroll = document.body.offsetWidth;
	        yScroll = document.body.offsetHeight;
	    }
	    var windowWidth, windowHeight;
	    if (self.innerHeight) { // all except Explorer
	        if(document.documentElement.clientWidth){
	            windowWidth = document.documentElement.clientWidth;
	        } else {
	            windowWidth = self.innerWidth;
	        }
	        windowHeight = self.innerHeight;
	    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	        windowWidth = document.documentElement.clientWidth;
	        windowHeight = document.documentElement.clientHeight;
	    } else if (document.body) { // other Explorers
	        windowWidth = document.body.clientWidth;
	        windowHeight = document.body.clientHeight;
	    }
	    // for small pages with total height less then height of the viewport
	    if(yScroll < windowHeight){
	        pageHeight = windowHeight;
	    } else {
	        pageHeight = yScroll;
	    }
	    // for small pages with total width less then width of the viewport
	    if(xScroll < windowWidth){
	        pageWidth = xScroll;
	    } else {
	        pageWidth = windowWidth;
	    }
	    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	    return arrayPageSize;
	}
	this.openShadowLayer = function (){
        if(this.Style == null){
        	if(document.getElementById("shadow_div")){
				this.Style 	= document.getElementById("shadow_div").style;
				if(document.getElementById("shadow_div").filters){
					this.fOpDisplayStap = this.fOpacity;
					this.fOpHideStap	= this.fOpacity;
				}else{
					this.fOpDisplayStap = this.fOpacity/10;
					this.fOpHideStap	= this.fOpacity/5;
				}
			}
		}
		if(this.Style){
			this.bProcessMode 		= 1;
			var aScreenDimensions 	= this.getPageSize();
			if(window.pageXOffset){
				var iScrollLeft = window.pageXOffset;
			}else{
				var iScrollLeft = document.documentElement.scrollLeft;
			}
			this.Style.left 	= iScrollLeft + 'px';
			this.Style.backgroundColor 	= "#000000";
		 	if(document.getElementById("shadow_div").filters){
		 		document.getElementById("shadow_div").filters.alpha.opacity = 0;
		 	}else{
		 		this.Style.opacity		= 0;
			}
			this.Style.display = "block";
	        if(aScreenDimensions[1] > 1000){
	        	this.Style.height 	= aScreenDimensions[1] + 'px';
	        }else{
	        	this.Style.height 	= '1000px';
	        }
	        changeShadowOpacity();
		}
	}
	this.closeShadowLayer = function(){
		if(this.Style){
			this.bProcessMode = 0;
			changeShadowOpacity();
		}
	}
	this.click = function(){
		if(this.iClickCounter >= 5 || main_div == null){
			this.iClickCounter = 0;
			this.closeShadowLayer();
		}else{
			this.iClickCounter++;
		}
	}
}

function changeShadowOpacity(){
	if(oShadow.bProcessMode){
		if(oShadow.fOpacity > oShadow.fCurrentOpacity){
			oShadow.fCurrentOpacity 	+= oShadow.fOpDisplayStap;
			setTimeout("changeShadowOpacity(1);",10);
		}else{
			oShadow.fCurrentOpacity		= oShadow.fOpacity;
		}
	}else{
		if(oShadow.fCurrentOpacity > 0){
			oShadow.fCurrentOpacity 	-= oShadow.fOpHideStap;
			setTimeout("changeShadowOpacity(0);",10);
		}else{
			oShadow.fCurrentOpacity	= 0;
			oShadow.Style.display 	= 'none';
		}
	}
 	if(document.getElementById("shadow_div").filters){
 		document.getElementById("shadow_div").filters.alpha.opacity = oShadow.fCurrentOpacity*100;
 	}else{
		oShadow.Style.opacity 		= oShadow.fCurrentOpacity;
	}
	//oShadowStyle.MozOpacity 		= fCurrentOpacity;
	//oShadowStyle.KhtmlOpacity 	= fCurrentOpacity;
}

function DataTransferCLS(){
    this.names 		= new Array();
    this.values 	= new Array();
    this.cnt 		= 0;
    this.inputs 	= new Array();
    this.iCnt 		= 0;
	this.AddData 	= function(sName,sValue){
        this.names[this.cnt] = sName;
        this.values[this.cnt] = sValue;
        this.cnt++;
    };
	this.AddInput 	= function(oInput){
        this.inputs[this.iCnt++] = oInput;
    };
	this.SendData 	= function(sPath){
		var oTrasferForm = document.createElement('FORM');
        oTrasferForm.target = 'service_frm';
        oTrasferForm.method = 'post';
        oTrasferForm.enctype="multipart/form-data";
        oTrasferForm.encoding="multipart/form-data";
        oTrasferForm.action = sPath;
        for(var item = 0; item < this.cnt;item++){
            var oInput = document.createElement('INPUT');
            oInput.type = 'hidden';
            oInput.name = this.names[item];
            oInput.value = this.values[item];
            oTrasferForm.appendChild(oInput);
        }
        for(var i = 0; i < this.iCnt;i++){
            oTrasferForm.appendChild(this.inputs[i]);
        }
        document.getElementById('output_tranfer_div').appendChild(oTrasferForm);
        oTrasferForm.submit();
        document.getElementById('output_tranfer_div').removeChild(oTrasferForm);
        document.getElementById('output_tranfer_div').innerHTML = '';
    }
}

function redirect(sURL){
	var oForm = document.createElement('FORM');
   	oForm.method = 'POST';
	oForm.action = sURL;
    document.body.appendChild(oForm);
	oForm.submit();
}

function closeStandardForm(){
	closePebuzzLayers('main_div','content_div');
	if(oForm){
		oForm = null;
	}
}

//Js debug tools
/*
debug_var(sel.duplicate(),2);
*/
function debug_var(mVar,iDebugLevel){
	oShowArea     			= document.createElement('DIV');
	document.body.appendChild(oShowArea);
	oShowArea.align					= "left";
	oShowArea.style.width 			= '640px';
	oShowArea.style.height 			= '480px';
	oShowArea.style.position 		= 'absolute';
	oShowArea.style.overflow 		= 'auto';
    oShowArea.style.left 			= '100px';
    oShowArea.style.top 			= '100px';
	oShowArea.style.backgroundColor = '#EEEEEE';
    oShowArea.style.fontSize		= '16px';
	oShowArea.innerHTML = '<div align="center" onclick="document.body.removeChild(this.parentNode);" style="font-size:16px;background-color:#FFFF55;cursor:pointer">Close</div>';
	oShowArea.innerHTML += print_r(mVar,iDebugLevel);
}

function print_r(mVar,iDebugLevel){
	var sOut = '';
	if(iDebugLevel){
		iDebugLevel--;
		switch(typeof(mVar)){
			case 'object':
			case 'array':
				sOut += typeof(mVar) + "{<BLOCKQUOTE>";
				for(key in mVar){
					try {
						sOut += "<br>" + "[" + key + "] = " + print_r(mVar[key],iDebugLevel);
					}
					catch (e) {
						sOut += "<br>" + "[" + key + "] = " + e;
					}
				}
				sOut += "</BLOCKQUOTE>}";
			break;
			case 'string':
				sOut += mVar;
			break;
			case 'number':
				sOut += mVar;
			break;
			case 'boolean':
				sOut += "boolean (" + mVar + ")";
			break;
			case 'function':
				if(0){
					sOut += mVar;
				}else{
					sOut += '...handler source code...';
				}
			break;
			default:
				sOut += typeof(mVar);
		}
	}else{
		sOut += "...";
	}
	return sOut;
}

function detectCode(event,form_id){
	var e = (window.event) ? window.event : event;
	if (e.keyCode == 13 && document.getElementById('email').value != "" && document.getElementById('pass').value != ""){
		document.getElementById(form_id).submit();
	}
}

function moveDiv2center(oDiv){
	oShadow.openShadowLayer();
	var aScreenDimensions = oShadow.getPageSize();
	if(window.pageYOffset){
		var iScrollTop = window.pageYOffset;
	}else{
		var iScrollTop = document.documentElement.scrollTop;
	}
	if(window.pageXOffset){
		var iScrollLeft = window.pageXOffset;
	}else{
		var iScrollLeft = document.documentElement.scrollLeft;
	}
	oDiv.style.top 	= Math.round(iScrollTop + aScreenDimensions[3]/2 - (oDiv.style.height.replace('px','')/2)) + "px";
	oDiv.style.left = Math.round(iScrollLeft + aScreenDimensions[2]/2 - (oDiv.style.width.replace('px','')/2)) + "px";
}

function moveDiv2centerNew(oDiv){
	oShadow.openShadowLayer();
	var oContentDiv = document.getElementById('content_div');
	var aScreenDimensions = oShadow.getPageSize();
	if(window.pageYOffset){
		var iScrollTop = window.pageYOffset;
	}else{
		var iScrollTop = document.documentElement.scrollTop;
	}
	if(window.pageXOffset){
		var iScrollLeft = window.pageXOffset;
	}else{
		var iScrollLeft = document.documentElement.scrollLeft;
	}
	oDiv.style.top 	= Math.round(iScrollTop + aScreenDimensions[3]/2 - (oContentDiv.style.height.replace('px','')/2)) + "px";
	oDiv.style.left = Math.round(iScrollLeft + aScreenDimensions[2]/2 - (oContentDiv.style.width.replace('px','')/2)) + "px";
	oContentDiv.style.height = 'auto';
}

function showAjaxLoader(){
	main_div = document.getElementById("al_main_div");
	msg_div = document.getElementById("al_area_div");
	moveDiv2center(main_div);
	main_div.style.display="block";
	msg_div.style.display="block";
}

function closeAjaxLoader(){
	closePebuzzLayers("al_main_div","al_area_div");
}

function closePebuzzLayers(sMainLayer,sInternalLayer){
	oShadow.closeShadowLayer();
	if(main_div = document.getElementById(sMainLayer)){
		main_div.style.top	= 0;
		main_div.style.left	= 0;
		main_div.style.display="none";
		if(msg_div = document.getElementById(sInternalLayer)){
			msg_div.style.display="none";
		}
	}else{
		alert('There is no "' + sMainLayer + '" object in this document.');
	}
	main_div = null;
	return false;
}

function showSFcontent(){
	if(document.all){
        debug_var(document.frames['service_frm'].document.body.innerHTML,1);
    }else{
        debug_var(document.getElementById('service_frm').contentWindow.document.body.innerHTML,1);
    }
}

function sendRequest(sPath,aParameters){
	showAjaxLoader();
	var oDataTransfer = new DataTransferCLS();
	if(aParameters){
		for(key in aParameters){
			if(typeof(aParameters[key]) == 'object'){
				oDataTransfer.AddInput(aParameters[key]);
			}else{
				oDataTransfer.AddData(key,aParameters[key]);
			}
		}
	}
	oDataTransfer.SendData(sPath);
}

/*	re = new RegExp("^[_a-z0-9.-]{2,32}@[a-z0-9.-]{3,64}\.[a-z]{2,6}?$","i");
	if (!re.test(document.getElementById("invite_email").value)){
		 alert('Error! You gave an invalid email address!');
		 return false;
	}
	*/


var qTipTag = "span";//"a,label,input"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = 0; //This is qTip's X offset//
var qTipY = 15; //This is qTip's Y offset//

//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, elements;

	var elementList = qTipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{
		elements = document.getElementsByTagName(elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tooltip.hide()};
				}
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;

	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.attachEvents = function (a) {
	if(!a.getAttribute('tiptitle'))
	{
		var sTitle = a.getAttribute("title");
		a.setAttribute("tiptitle", sTitle);
		a.removeAttribute("title");
		a.removeAttribute("alt");
		a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
		a.onmouseout = function() {tooltip.hide()};
		tooltip.show(a.getAttribute('tiptitle'))
	}
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {
	tooltip.init ();
}

var oShadow = new ShadowCLS;

