// AggreScrape JavaScript library

var $Library = 
{
	
	$DHTML: (document.getElementById || document.all || document.layers),
		
	display: function(obj)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		obj.style.display = "";
	},		


	 extend: function(dest,source)
	 {
	 	for (prop in source)
			dest[prop] = source[prop];
  		return dest;	 
	 },
	
	
	getElementById: function(id)
	{
		if(!$Library.$DHTML)
			return null;
			
		if(typeof id != "string")
			return id;
			
		if (document.getElementById)
		{
			return document.getElementById(id);
		}
		else if (document.all)
		{
			return document.all[id];
		}
		else if (document.layers)
		{
			var obj =  document.layers[id];
			if(!obj)
				return null; 
			
			obj.style = {};
			return obj;
		}	
		
		return null;
	  
	},	


	getMousePosition: function(e)
	{
		var m = new Object;
		
		if(e)
		{
			if( typeof( e.pageX ) == 'number' ) 
			{
			 m.x = e.pageX;
			 m.y = e.pageY;
			}
			else // Firefox
			{
				 m.x = e.clientX;
				 m.y = e.clientY;
			}
		}
		else
		{
			e = window.event;
			m.x = e.clientX;
			m.y = e.clientY;
			
			if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) )		
			{
				m.x += document.documentElement.scrollLeft;
				m.y += document.documentElement.scrollTop;
			} 
			
			else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) )		 
			{
				m.x += document.body.scrollLeft;
				m.y += document.body.scrollTop;
			}
		}
		
		return m;
	},	


	getSizeDynamic: function (obj)
	{
		if( !(obj = $Library.getElementById(obj)) )
			return null;		
		
		var size = new Object;
		size.width = obj.offsetWidth;
		size.height = obj.offsetHeight;
		
		return size;
	}	,

	
	getPositionDynamic: function(obj)
	{
		if( !(obj = $Library.getElementById(obj)) )
			return null;			
		
		var pos = new Object;
		pos.x = 0;
		pos.y = 0;
		while (obj.offsetParent)
		{
			pos.x += obj.offsetLeft;
			pos.y += obj.offsetTop;
			obj = obj.offsetParent;
		}	
		
		return pos;
	},

	
	getPositionStatic: function(obj)
	{
		if( !(obj = $Library.getElementById(obj)) )
			return null;			
		
		var pos = new Object;
		if(!(pos.x = parseInt(obj.style.left)))
			pos.x = 0;
			
		if(!(pos.y = parseInt(obj.style.top)))	
			pos.y = 0;
			
		return pos;
	},

	hide: function(obj)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		obj.style.visibility = "hidden";
	},	
	
	
	include: function(file)
	{
		document.write('<' + 'script');
		document.write(' language="javascript"');
		document.write(' type="text/javascript"');
		document.write(' src="'+file+'">');
		document.write('</' + 'script' + '>');	
	},

	isArray: function(v)
	{	
	   if(!v)

	   	return false;	
	   else if (v.constructor.toString().indexOf("Array") == -1)
		  return false;
	   else
		  return true;	
	},
		
	
	setColor: function(obj,color)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		obj.style.color = color;
	},


	setCookie: function(name, value, expires, path, domain, secure)
	{
		
		var today = new Date(); //  in milliseconds
		today.setTime( today.getTime() );
			
		//to make it for hours, delete * 24, for minutes, delete * 60 * 24
		if (expires)
			expires = expires * 1000 * 60 * 60 * 24;

		var expireDate = new Date( today.getTime() + (expires) );
		
		document.cookie = name + "=" +escape( value ) 
		+( ( expires ) ? ";expires=" + expireDate.toGMTString() : "" )  
		+( ( path ) ? ";path=" + path : "" )  
		+( ( domain ) ? ";domain=" + domain : "" ) 
		+( ( secure ) ? ";secure" : "" );
	},

	setHtml: function(obj,html)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		obj.innerHTML = html;
	},


	show: function(obj)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		obj.style.visibility = "";
	},
	
	toggle: function(obj)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		if(obj.style.display == "")
			obj.style.display ="none";
		else
			obj.style.display = "";
	},
	
	unDisplay: function(obj)
	{
		if(!(obj = $Library.getElementById(obj)))
			return;
			
		obj.style.display = "none";
	}
	
};



 $Library.form = 
{		

	getValue: function(formName,elementName)
	{
		if(document.forms[formName])
		{
			if(document.forms[formName].elements[elementName])
				return document.forms[formName].elements[elementName].value;
		}
	},
	
	setValue: function(formName,elementName,value)
	{
		if(document.forms[formName])
		{
			if(document.forms[formName].elements[elementName])
				document.forms[formName].elements[elementName].value = value;
		}
	}
	

};

 
function $xml()
{

	function createHttpRequest() 
	{
		if (window.ActiveXObject) 
			return  new ActiveXObject("Microsoft.XMLHTTP");
		else if (window.XMLHttpRequest) 
			return new XMLHttpRequest();
		else
			return null;		
	}	
	

	this.read = function(file,fOnFinishCallback,arg)
	{
		if(!file)
			return false;
			
		var xmlHttp = createHttpRequest();
		if(!xmlHttp)
			return false;
		
		xmlHttp.open("GET",file,true);
		xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xmlHttp.setRequestHeader("Pragma","no-cache");
		xmlHttp.setRequestHeader("Cache-Control","no-cache");
		xmlHttp.send(null);	
	
		xmlHttp.onreadystatechange =  function()
		{	
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				if(xmlHttp.responseText && fOnFinishCallback)
					fOnFinishCallback(xmlHttp.responseText,"text",arg);				
				else if(xmlHttp.responseXML && fOnFinishCallback)
					fOnFinishCallback(xmlHttp.responseXML,"xml",arg);

			}
			
		}	
	}
	

	this.send = function(where,what,callback,arg)
	{
		if(!where)
			return false;
			
		var xmlHttp = createHttpRequest();
		if(!xmlHttp)
			return false;
		
		xmlHttp.open("POST",where);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");		
		xmlHttp.send(what);	
	
		xmlHttp.onreadystatechange =  function()
		{	
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				if(callback)
					callback(arg);
			}
			else
			{
				throw "$xml::send(): Unknown return status code - (status:"+xmlHttp.status+", readyState:"+xmlHttp.readyState+")";	
			}
			
		}	
	}
	

} 

function onKeyPressDecimal(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[ a-zA-Z!@#$%^&*()-+_=|?<>,'";:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressEmail(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[ !#$%^&*()-+=|?<>,'";:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressText(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[#$%^&*()-+=|<>;:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressURL(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[ !@#$%^*()-+=|<>";\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressBlockSpecials(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[ !@#$%^&*()-+=|?<>.,'";_:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressBlockSpecial(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[!@#$%^&*()-+=|?<>.,'";_:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressOnlyLetters(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[0-9!@#$%^&*()-+=|?<>._,'";:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}
function onKeyPressOnlyNumbers(e)
{
        var key = window.event ? e.keyCode : e.which;
        var keychar = String.fromCharCode(key);
        reg = /[ a-zA-Z!@#$%^&*()-+=_|?<>.,'";:\/\\\[\]{}~`]/;
        return !reg.test(keychar);
}


