// JavaScript Document
function ApplicationString()
{
	this.EscapeCharacters = function(data)
	{
				if ((data)&& (data != ""))
				{
					data = data.toString();
					//data = data.replace(/\^/g, '%5E');
					data = data.replace(/"/g, '%22');
					data = data.replace(/\(/g, '%28');
					data = data.replace(/\)/g, '%29');
					data = data.replace(/!/g, '%21');
					data = data.replace(/\*/g, "%2A");
					data = data.replace(/\//g,"%2F");
					data = data.replace(/\?/g,"%3F");
					data = data.replace(/=/g,"%3D");
					data = data.replace(/@/g,"%40");
					data = data.replace(/’/g,"%27");
					data = data.replace(/'/g,"%27");
					data = data.replace(/#/g,"%23");
					data = data.replace(/\+/g,"%2B");
					data = data.replace(/-/g,"%2D");
					data = data.replace(/{/g,"%7B");
					data = data.replace(/}/g,"%7D");
					
					data = data.replace(/&lt;/g,"%3C");
					data = data.replace(/&gt;/g,"%3E");
					data = data.replace(/</g,"%3C");
					data = data.replace(/>/g,"%3E");
					
					data = data.replace(/&pound;/g,"%A3");
					data = data.replace(/£/g,"%A3");
					//data = escape(data);
					data = data.replace(/€/g,"%20AC");
					
					data = data.replace(/%2C/g,"%x2C");
					data = data.replace(/,/g,"%x2C"); //ps
					data = data.replace(/§/g,"%A7");
					data = data.replace(/&amp;copy;/g,"%A9");
					data = data.replace(/&copy;/g,"%A9");
					data = data.replace(/©/g,"%A9");
					data = data.replace(/::/g,"%x3A"); //p
					
					data = data.replace(/~~/g,"%x7E"); //p
					data = data.replace(/~/g,"%7E"); 
					data = data.replace(/;;/g,"%x3B"); //p
					data = data.replace(/;/g,"%3B");
					//data = data.replace(/||/g,"|");
					
					data = data.replace(/&amp;/g,"%26")
					data = data.replace(/&/g,"%26")
					//alert(data);
				}
				return data;
	}
	
	this.RevertCharacters = function(data)
	{
				if ((data)&& (data != ""))
				{
					//data = unescape(data);
					//data = data.replace(/%5E/g, '^');
					data = data.replace(/%22/g, '"');
					data = data.replace(/%28/g, '(');
					data = data.replace(/%29/g, ')');
					data = data.replace(/%21/g, '!');
					data = data.replace(/%2A/g, "*");
					
					data = data.replace(/%26/g,"&amp;");
					data = data.replace(/%2F/g,"\\");
					data = data.replace(/%3F/g,"?");
					data = data.replace(/%3D/g,"=");
					data = data.replace(/%40/g,"@");
					data = data.replace(/%27/g,"'");
					data = data.replace(/%23/g,"#");
					data = data.replace(/%2B/g,"+");
					data = data.replace(/%2D/g,"-");
					data = data.replace(/%3C/g,"<");
					data = data.replace(/%3E/g,">");
					data = data.replace(/%A3/g,"&pound;");
					data = data.replace(/%20AC/g,"€");
					data = data.replace(/%x2C/g,","); //pr
					data = data.replace(/%A7/g,"§");
					data = data.replace(/%7B/g,"{");
					data = data.replace(/%7D/g,"}");
					data = data.replace(/%x7E/g,"~~"); //preserved sign
					data = data.replace(/%x3B/g,";;"); //pr
					data = data.replace(/%x3A/g,"::"); //pr
					
					data = data.replace(/%7E/g,"~");
					data = data.replace(/%3B/g,";");
					data = data.replace(/%A9/g,"&copy;");
					data = data.replace(/%26amp;nbsp;/g, '&nbsp;');
				}
				return data;
	}
}

	function getitem(id)
	{
		
			var britem = false; //browser item
	
			if (document.getElementById){
				britem = document.getElementById(id);
	
			}else if (document.all){
				britem = document.all[id];
				
			}else if (document.layers){
				britem = document.layers[id];
				
			}		
			return britem;
		}



		function GenerateString(len)
		{
			var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
			var string_length = len;
			var randomstring = '';
			for (var i=0; i<string_length; i++)
			{
				var rnum = Math.floor(Math.random() * chars.length);
				randomstring += chars.substring(rnum,rnum+1);
			}
			return randomstring;
		}
		
		
		function LimitString(str, toLen)
		{
			newStr = "";
			//alert(str.length)
			if ((str) && str.length > toLen)
			{
				for (k = 0; k < toLen; k++)
				{
					newStr += str.charAt(k);
				}
				newStr += '...';
				return newStr;
			}
			return str;
		}
		


		
		function currentOpac(id, opacEnd, millisec) { 
			//standard opacity is 100 
			var currentOpac = 100; 
			 
			//if the element has an opacity set, get it 
			if(document.getElementById(id).style.opacity < 100) { 
				currentOpac = document.getElementById(id).style.opacity * 100; 
			} 
		
			//call for the function that changes the opacity 
			opacity(id, currentOpac, opacEnd, millisec) 
		} 

		function changeOpac(opacity, id) 
		{ 
			var object = getitem(id); 
			object = object.style;
			object.opacity = (opacity / 100); 
			object.MozOpacity = (opacity / 100); 
			object.KhtmlOpacity = (opacity / 100); 
			object.filter = "alpha(opacity=" + opacity + ")"; 
		} 
		
		function ReadCookie(cookieName)
		{
			 var theCookie=""+document.cookie;
			 var ind=theCookie.indexOf(cookieName);
			 if (ind==-1 || cookieName=="") return ""; 
			 var ind1=theCookie.indexOf(';',ind);
			 if (ind1==-1) ind1=theCookie.length; 
			 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
		}
		
		
zIndex = 80;
function TopWindow()
{
		var currentWindow = null;
		this.windows = Array();
		
		this.GenerateWindow = function()
		{
			var winName = this.windows.length;
			var win = document.createElement('DIV'); 
			document.appendChild(win);
			win.setAttribute('id', winName);
			winObj = getitem(win.id);
			this.windows[this.windows.length] = winObj;
			return winObj;
		}
		
		this.DropDown = function(parent, dropdown, y, x) //y x must be detemined in case of the edge of window...
			{
				parent = getitem(parent);
				//alert(parent.id);
				var x = findPos(parent);
				curleft = x[0];
				curtop = x[1];
				h = parseInt(parent.offsetHeight);		
				itm = getitem(dropdown);
		
				if (y)
				{
						y = itm.offsetHeight;
						if (y==0) 
							y = itm.style.height;
						curtop -= parseInt(y);
				}
				
				if (!h || h == 0) 
					h = 14;
				
				var tp = (parseInt(curtop) + h);
				itm.style.top =  tp+ 'px';
				itm.style.left = curleft + 'px';
				itm.style.zIndex = (zIndex + 1)
				itm.style.display = 'block';
			}
			
			findPos = function(obj)
			{
				//var obj = getitem(itm);
				var curleft = curtop = 0;
				var curleft = curtop = 0;
				if (obj.offsetParent) 
				{
					curleft = obj.offsetLeft
					curtop = obj.offsetTop
					while (obj = obj.offsetParent) 
					{
						curleft += obj.offsetLeft
						curtop += obj.offsetTop
					}
				}
				return [curleft,curtop];
			}
		




	this.SetWindow = function(wincom, title, height, width, black_out, hide)
	{
			obj = new Object();
			winbody = new Object();
			titlebar = new Object();
			
			obj = getitem(wincom[0]); 
			
			winbody = getitem(wincom[2]);
			winbody.innerHTML = "";
			
			if (hide)
			{
				obj.style.display = 'none';
				return;
			}
				x = (screen.width / 2) - (width/2);
				y = (screen.height / 2) - (screen.height / 2.05);
				//x = () - (screen.width / 4);
				
			obj.style.width = width + 'px';
			obj.style.height = height+ 'px';
			obj.style.top =  '66px';
			obj.style.left = x + 'px';
			//obj.style.postion = 'absolute';
			obj.style.zIndex = ++zIndex;
			if (obj.style.display == 'none') 
				obj.style.display = 'block';
			
			if (title)
			{
				titlebar = getitem(wincom[1]);
				titlebar.innerHTML = title;
			}
			
			
			if (black_out)
			{
				var xy= Array();
				xy = this.getPageSizeWithScroll();
				var psh = getitem('page_shadow');
				psh.style.position = 'absolute';
				psh.style.display = 'block';
				psh.style.top = 0 + 'px';
				psh.style.left = 0+'px';
				psh.style.height = xy[1]+ 'px';
				psh.style.width = xy[0] + 'px';
				//obj.style.border = '1px #333 solid';
				///TO DO with multiple windows that overshadow one each other
				//shadow_dec[shadow_page] = true;
				//shadow_page++;
			}else 
			{
				shadow_dec[shadow_page] = false;
				shadow_page++;
			}
		}
		
		this.SetWindowStyle = function(class_style_name)
		{
			for (i=0; i < class_style_name.length; i++)
				windowObject.className += class_style_name[i] + ' ';
		}
		
		this.MoveWindow = function()
		{
			
		}
		this.CloseWindoes = function()
		{
		}
		this.getPageSizeWithScroll = function()
		{
			if (window.innerHeight && window.scrollMaxY) 
			{// Firefox
				yWithScroll = window.innerHeight + window.scrollMaxY;
				xWithScroll = window.innerWidth + window.scrollMaxX;
			}
			else if (document.body.scrollHeight > document.body.offsetHeight)
			{ // all but Explorer Mac
				yWithScroll = document.body.scrollHeight;
				xWithScroll = document.body.scrollWidth;
			} 
			else 
			{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
				yWithScroll = document.body.offsetHeight + 40;
				xWithScroll = document.body.offsetWidth ; //+ 2;
			}
			arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
			return arrayPageSizeWithScroll;
		}		

}

	function ValidateEmail(eStr)
	{
			var fs = false; var ss = false; 
			if (eStr == "" || eStr == 'undefined')
				return false; 
			var s = eStr.split('@');
			var name = ""; 
			var domain = "";
			if (s.length == 2) 
			{
				name = s[0].replace(/^\s* |\s*$/g,'');
				domain = s[1].replace(/^\s* |\s*$/g,'');
				if (name.length == 0 || domain.lenght == 0)
					return false; 
			}
			
			if (domain == '') 
				return false;
			
			var x = domain.split('.');
			if (x.length < 2) 
				return false;
			if (x[1] == "" || x[0] == "") 
				return false;
			
			if (domain.charAt(domain.length-1) == '.') 
				return false;
			
			
			///locate the last dot in string.. 
			/*ss = false;
			for (i = domain.length; i >= 1; i--)
			{
				if (domain.charAt(i) == '.')
				{
					var dom = domain.split(domain.charAt(i));
					if (dom.length == 2)
						 {
							 if((!dom[0].match(/^[a-z-A-Z]+$/) || !dom[1].match(/^[a-z-A-Z ]+$/)) || (dom[1].length == 0 || dom[0].length == 0))
								return false;
						 }else 
							return false;
	
						ss = true;
					}
			}*/
			if (name.length >= 1 )//&& ss == true
				return true; 
			else 
				return false;
		}


		function ClearContent(container)
		{
			ChangeOpacity(50, container, 'down');
			//var container = getitem(container); 
			//container.innerHTML = "";
		}

	function ChangeOpacity(k, container, direction)
	{
		changeOpac(k, container);
		if (direction == 'down')
		{
			if (k > 0) 
			{
				k-=20;
				window.setTimeout('ChangeOpacity('+k+', \''+container+'\', \''+direction+'\')', 10);
				return;
			}//else 
			//{
			//	ctn = getitem(container); 
			//	ctn.innerHTML = "";
			//}
		}
		if (direction == 'up')
		{
			if (k < 100) 
			{
				k+=5;
				window.setTimeout('ChangeOpacity('+k+', \''+container+'\', \''+direction+'\')', 40);
				return;
			}
		}
	}
	
	
	function ExpandColapse( DisplObj, ImgSpan)
		{
			itm = getitem(DisplObj); 
			img = getitem(ImgSpan);
			//var divcount = document.getElementById("mac").getElementsByTagName("SPAN");
		
			if (itm.style.display == 'none'){
				//var i = 0;
				//while(i < divcount.length){
				//	divcount[i].style.display = "none";
				//	i++
				//}
				
				itm.style.display = 'block';
				img.innerHTML = ' <img src="styles/default/images/collapse_icon.gif" align="absmiddle"> ';
			}else 
			{
				itm.style.display = 'none';
				img.innerHTML = ' <img src="styles/default/images/expand_icon.gif" align="absmiddle"> ';
			}
			return false;
		}
		
		function Expand(ImgSpan, DisplObj)
		{
			itm = getitem(DisplObj); 
			img = getitem(ImgSpan);
				//if (itm.style.display == 'none'){
					itm.style.display = 'block';
					img.innerHTML = '<img src="img/collapse_icon.gif" align="absmiddle">';
				//}
		}
		
	function SetWindow(wincom, title, height, width, black_out, hide)
	{			
			obj = getitem(wincom[0]); 
			
			winbody = getitem(wincom[2]);
			winbody.innerHTML = "";
			
			if (hide)
			{
				obj.style.display = 'none';
				return;
			}
				x = (screen.width / 2) - (width/2);
				y = (screen.height / 2) - (screen.height / 2.05);
				//x = () - (screen.width / 4);
				
			obj.style.width = width + 'px';
			obj.style.height = height+ 'px';
			obj.style.top =  '66px';
			obj.style.left = x + 'px';
			//obj.style.postion = 'absolute';
			obj.style.zIndex = ++zIndex;
			if (obj.style.display == 'none') 
				obj.style.display = 'block';
			
			if (title)
			{
				titlebar = getitem(wincom[1]);
				titlebar.innerHTML = title;
			}
			
			
			if (black_out)
			{
				var xy= Array();
				xy = getPageSizeWithScroll();
				var psh = getitem('page_shadow');
				psh.style.position = 'absolute';
				psh.style.display = 'block';
				psh.style.top = 0 + 'px';
				psh.style.left = 0+'px';
				psh.style.height = xy[1]+ 'px';
				psh.style.width = xy[0] + 'px';
				//obj.style.border = '1px #333 solid';
				///TO DO with multiple windows that overshadow one each other
				//shadow_dec[shadow_page] = true;
				//shadow_page++;
			}else 
			{
				shadow_dec[shadow_page] = false;
				shadow_page++;
			}
		}
		
		function getPageSizeWithScroll ()
		{
			if (window.innerHeight && window.scrollMaxY) 
			{// Firefox
				yWithScroll = window.innerHeight + window.scrollMaxY;
				xWithScroll = window.innerWidth + window.scrollMaxX;
			}
			else if (document.body.scrollHeight > document.body.offsetHeight)
			{ // all but Explorer Mac
				yWithScroll = document.body.scrollHeight;
				xWithScroll = document.body.scrollWidth;
			} 
			else 
			{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
				yWithScroll = document.body.offsetHeight + 40;
				xWithScroll = document.body.offsetWidth ; //+ 2;
			}
			arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
			return arrayPageSizeWithScroll;
		}		


			function DropDown (parent, dropdown, y, x) //y x must be detemined in case of the edge of window...
			{
				parent = getitem(parent);
				//alert(parent.id);
				var x = findPos(parent);
				curleft = x[0];
				curtop = x[1];
				h = parseInt(parent.offsetHeight);		
				itm = getitem(dropdown);
		
				if (y)
				{
						y = itm.offsetHeight;
						if (y==0) 
							y = itm.style.height;
						curtop -= parseInt(y);
				}
				
				if (!h || h == 0) 
					h = 14;
				
				var tp = (parseInt(curtop) + h);
				itm.style.top =  tp+ 'px';
				itm.style.left = curleft + 'px';
				itm.style.zIndex = (zIndex + 1)
				itm.style.display = 'block';
			}
			
			function findPos (obj)
			{
				//var obj = getitem(itm);
				var curleft = curtop = 0;
				var curleft = curtop = 0;
				if (obj.offsetParent) 
				{
					curleft = obj.offsetLeft
					curtop = obj.offsetTop
					while (obj = obj.offsetParent) 
					{
						curleft += obj.offsetLeft
						curtop += obj.offsetTop
					}
				}
				return [curleft,curtop];
			}