// JavaScript Document
var diff = 0;
var scrolled = 30
function pageScroll() {
		if (scrolled<diff){
			window.scrollBy(0,30); // horizontal and vertical scroll increments
			scrolled+=30
			scrolldelay = setTimeout('pageScroll()',100)
		}
}

var openIndex = -1;

function ClientClick(id) 
{
	scrolled = 30;
	var clicked = document.getElementById("client"+id);
	var popup = document.getElementById("popup"+id);
	var x = _getRealX(clicked);
	var y = _getRealY(clicked);
	var w = document.body.offsetWidth;
	var h = document.body.offsetHeight;

	//-----go direclyy version START
	
	if(openIndex!=id)
	{
		openPup(id);
		closePup(openIndex);
		openIndex = id;
	}
	else
	{
		closePup(id);
		openIndex = -1;
	}
}

function closePup(id)
{
	if(id != "-1")
	{
		var openDiv = document.getElementById("client"+id.toString());
		var openPup = document.getElementById("popup"+id.toString());

		try 
		{
			openDiv.childNodes[0].className = openDiv.childNodes[0].className.replace("CBI_On","CBI_Off");
			_SwitchImageToOrginal (openDiv);
		} 
		catch(e) 
		{}
		
		openPup.style.top = "-500px";
		openPup.style.left = "10px";
	}
}

function openPup(id)
{
	var openDiv = document.getElementById("client"+id.toString());
	var openPup = document.getElementById("popup"+id.toString());
	
	var tempx = 0;
	var tempy = 0;
	var x = _getRealX(openDiv);
	var y = _getRealY(openDiv);
	var w = document.body.offsetWidth;
	var h = document.body.offsetHeight;
	
	if (window.navigator.appName.toLowerCase().indexOf("explorer")>-1)
	{
		tempx = x - 30;
		tempy = y + 110;
	}
	else
	{
		tempx = x - 108;
		tempy = y + 1120;
	}	
	
	if (tempx + openPup.offsetWidth >= w) 
	{
		tempx = (w - openPup.offsetWidth - 30); 
	}
	else if (tempx<0) 
	{
		tempx = 10;
	}
	
	if (tempy+openPup.offsetHeight >= h)
	{
		if (window.navigator.appName.toLowerCase().indexOf("explorer")>-1){
			var theY= getScrollPos().y
			diff = (openPup.offsetHeight+tempy)-(theY+h)+50
			//alert(diff)
		}else{
			
			var theY= getScrollPos().y
			//diff = (openPup.offsetHeight+tempy)-(theY+h)-1000
			diff = tempy - openPup.offsetHeight - theY - h
			//alert(diff+" "+openPup.offsetHeight+" "+tempy+" "+" "+theY+" "+h)
		}
		
		if (diff>0){
			scrolldelay = setTimeout('pageScroll()',100);
		}
	}

	try 
	{
		openDiv.childNodes[0].className = openDiv.childNodes[0].className.replace("CBI_Off","CBI_On");
		_SwitchImageToGrayScale (openDiv);
	} 
	catch(e) 
	{}
	
	openPup.style.top = tempy + "px";
	openPup.style.left = tempx + "px";
}

var Pops = new Array();

function GatherAllPopups() {
	var a = document.getElementById("_all").childNodes;
	for (var i=0;i<a.length;i++) {
		if (typeof a[i] != "undefined" 
			&& typeof a[i].tagName != "undefined" 
			&& a[i] != null 
			&& a[i].tagName != null 
			&& a[i].tagName != "") 
		{
			if (a[i].tagName.toLowerCase() == "div" && a[i].className == "ClientPop") 
			{
				a[i]._open = false;
				Pops.push(a[i]);
			}
		}
	}
}


function _getRealX(who) {
	// Returns the true X (from left 0) of an object.
	// The parameter can be either reference of an ID of the object
	var obj = (typeof who == "string")?document.getElementById(who):who;
	var res = 0;
	var t = who;
	while (1 == 1) {
		if (typeof t.offsetLeft != "undefined") res += t.offsetLeft;
		t = t.offsetParent;
		if (t == document.body) return res;
	}
}

function _getRealY(who) {
	// Returns the true Y (from top 0) of an object.
	// The parameter can be either reference of an ID of the object
	var obj = (typeof who == "string")?document.getElementById(who):who;
	var res = 0;
	var t = who;
	while (1 == 1) {
		if (typeof t.offsetTop != "undefined") res += t.offsetTop;
		t = t.offsetParent;
		if (t == document.body) return res;
	}
}

function _SwitchImageToGrayScale (who)
{
	var alter = who.style.backgroundImage.toString();
	var img_Noextension = alter.substring(0,alter.lastIndexOf("."));
	var img_extension = alter.substring(alter.lastIndexOf("."));
	
	who.style.backgroundImage = img_Noextension + "_gs" + img_extension;
}

function _SwitchImageToOrginal (who)
{
	var alter = who.style.backgroundImage.toString();
	var img_Noextension = alter.substring(0,alter.lastIndexOf("_gs."));
	if (img_Noextension != "")
	{
		var img_extension = alter.substring(alter.lastIndexOf("."));
		who.style.backgroundImage = img_Noextension + "" + img_extension;
	}
}
//------------
function getScrollPos()
{
    if (window.pageYOffset)
	{
        return {y:window.pageYOffset, x:window.pageXOffset};
    }
    if(document.documentElement && document.documentElement.scrollTop)
	{
        return {y:document.documentElement.scrollTop, x:document.documentElement.scrollLeft};
    }
    if(document.body)
	{
        return {y:document.body.scrollTop, x:document.body.scrollLeft};
    }
   	return {x:0, y:0};

}

function Changelocation(clientid)
{
	document.location.href = "customer.aspx?itmid=" + "" + clientid;
}
