/****************************************************/
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// all other content 
// @copyright Fonqi, 23. oct 2008 
/****************************************************/
if(typeof Base != "object")
	throw("Base.js must be included before Page.js!");
	
Page = {};

//Gets the width of the page 
Page.Width = function()
{
	 return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       
    document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

//Gets the height of the page 
Page.Height = function()
{
	 return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

Page.PosLeft = function()
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;

}

Page.PosTop = function()
{
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

//Adds a stylesheet to the header
Page.AddStyleSheet = function(path)
{
    var headerNode = Base.Get("<head>")[0];         
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css';
    cssNode.rel = 'stylesheet';
    cssNode.href = path;
    cssNode.media = 'screen';
    headerNode.appendChild(cssNode);
}

//Adds a style snippet to the header
Page.AddStyle = function(styleSnippet)
{
	var cssNode = document.createElement('style');
    cssNode.type = 'text/css';
    cssNode.media = 'screen';
	if(Base.Browser().Name == "microsoft internet explorer")	
	{
		Base.Get("<body>")[0].appendChild(cssNode);
		cssNode.styleSheet.cssText = styleSnippet;	
	}
	else
	{
		cssNode.innerHTML = styleSnippet;
		 Base.Get("<head>")[0].appendChild(cssNode);
	}
   
}

//Adds an external script to the header
Page.AddScript = function(path)
{
    var headerNode = Base.Get("<head>")[0];         
    var scriptNode = document.createElement('script');
    scriptNode.type = 'text/javascript';
    scriptNode.src = path;
    headerNode.appendChild(scriptNode);
}

Page.SetTitle = function(title)
{
	document.title = title;
}

Page.SetTag= function(tag, value)
{
	//document.getElementsByTagName('body')[0].innerHTML = document.getElementsByTagName('body')[0].innerHTML.replace('@['+tag+']',value);
	var tags = document.getElementsByTagName('body')[0].getElementsByTagName('*');
	var i=0, t;
	while(t = tags[i++])
	{
		if(t.childNodes[0])
		{
			var j = 0, c;
			while(c = t.childNodes[j++])
			{
				if(c.nodeType==3)
				{
					if(c.nodeValue.indexOf('@['+tag+']')>=0)
					{
						c.nodeValue=c.nodeValue.replace('@['+tag+']', value);
					}					
				}
				else if(c.nodeType==2)
				{
					if(c.nodeValue.indexOf('@['+tag+']')>=0)
					{
						c.nodeValue=c.nodeValue.replace('@['+tag+']', value);
					}					
				}
			}
		}
	}
}

Page.PngFix = function()
{
	if(Base.Browser().Name == "microsoft internet explorer" && Base.Browser().VersionNumber <10)
	{
		var inspect = 0;
		var allElements = document.getElementsByTagName("*");
		for(i = 0; i < allElements.length; i++)
		{			
			if(allElements[i].style != null && allElements[i].style["backgroundImage"].indexOf("png")>=0)
			{
				var imgPath = allElements[i].style["backgroundImage"].replace("url(","").replace(")","");					
				allElements[i].style["filter"] = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgPath+"', sizingMethod='crop')";
				allElements[i].style["backgroundImage"] = "none";				
			}
			else if(allElements[i].tagName == "IMG" && allElements[i].href.indexOf("png")>=0)
			{
				var replacer = document.createElement('div');
				allElements[i].parentNode.appendChild(replacer);			
				
				if(inspect<1)
				{
					Base.Inspect(allElements[i]);
					inspect = 1;
				}
				replacer.style["width"] = allElements[i].width+"px";
				//replacer.style["height"] = allElements[i].clientHeight+"px";
								
				replacer.style["position"] = "relative";
				replacer.style["filter"] = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+allElements[i].href+"', sizingMethod='crop')";
				allElements[i].style["display"] = "none";	
			}																
		}		
	}
}

/****************************************************/

if(typeof Base != "object")
	throw("Base.js must be included before AJAX.js!");
	
Img.prototype.Source = null;
Img.prototype.Width = 0;
Img.prototype.Height = 0;
Img.prototype.Alt = 0;
Img.prototype.element = null;

function Img(img)
{
	if(href && href != "")
		this.Source = img.href;
	else
		this.Source = img.src;
	this.Width = img.width;
	this.Height = img.height;
	this.Alt = img.alt
	this.element = img;
	return this;
}

Img.GetImages = function(extension)
{
	var allImages = document.getElementsByTagName("img");
	var retur = new Array();
	for(i = 0; i < allImages.length; i++)
	{
		retur.push(new Img(allImages[i]));
	}
	return retur;
}
