// JavaScript Document
function ApplicationString()
{
	this.EscapeCharacters = function(data)
	{
				if ((data)&& (data != ""))
				{
					data = data.toString();
					//data = data.replace(/\^/g, '%5E');
					data = data.replace(/"/g, 'xinchx22');
					data = data.replace(/\(/g, '%28');
					data = data.replace(/\)/g, '%29');
					data = data.replace(/!/g, '%21');
					data = data.replace(/\*/g, "%2A");
					data = data.replace(/\//g,"x2Fs");
					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,"x2B");
					data = data.replace(/-/g,"dshx2D");
					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,"xA3");
					data = data.replace(/£/g,"xA3");
					//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,"x26amp")
					data = data.replace(/&/g,"x26amp")
					data = data.replace(/\./g,"x2Ed")

					//alert(data);
				}
				return data;
	}
	
	this.RevertCharacters = function(data)
	{
				if ((data)&& (data != ""))
				{
					//data = unescape(data);
					//data = data.replace(/%5E/g, '^');
					data = data.replace(/xinchx22/g, '"');
					data = data.replace(/%28/g, '(');
					data = data.replace(/%29/g, ')');
					data = data.replace(/%21/g, '!');
					data = data.replace(/%2A/g, "*");
					
					data = data.replace(/x26amp/g,"&amp;");
					data = data.replace(/x2Fs/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(/x2B/g,"+");
					data = data.replace(/dshx2D/g,"-");
					data = data.replace(/%3C/g,"<");
					data = data.replace(/%3E/g,">");
					data = data.replace(/xA3/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(/x26ampamp;nbsp;/g, '&nbsp;');
					data = data.replace(/x2Ed/g,".")

				}
				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) 
		{ 
			//alert(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 = 300;		
/*
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
					}
				}
				//alert(curleft + ' ' + curtop);
				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.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-=30;
				window.setTimeout('ChangeOpacity('+k+', \''+container+'\', \''+direction+'\')', 10);
				return;
			}/*else if (k <= 0)  
			{
				//hide container
			}*/
		}
		if (direction == 'up')
		{
			if (k < 100) 
			{
				k+=15;
				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 Dropdown (parent, dropdown, position, up) //y x must be detemined in case of the edge of window... //position right left up down
			{
				clearTimeout(ClearDropDownTimer);
				ChangeOpacity(40, dropdown, 'up');
				
				parent = getitem(parent);
				//alert(parent.id);
				var x = findPos(parent);
				//alert(x);
				curleft = x[0];
				curtop = x[1];
				itm = getitem(dropdown);
				//alert(itm);
				//alert(itm.offsetHeight);
				//if (y)
				//{
					//alert(curtop);
					if (!position || typeof(position) == 'undefined')
					{
						h = parseInt(parent.offsetHeight);	
						if (!h || h == 0) 
							h = 14;
						y = itm.offsetHeight;
						if (y==0) 
							y = itm.style.height;
						var tp = (parseInt(curtop) + h);
						//alert(tp);
						itm.style.top =  tp+ 'px';
						itm.style.left = curleft + 'px';

					}
					else if (position == 'right-up')
					{
						if (!up)
							up = 10;
						y = parseInt(parent.offsetWidth);
						if (!y)
							y = parseInt(parent.style.width);
						itm.style.position.absolute;
						var x = Array();
						var usrag  = navigator.userAgent;
						x = usrag.split('Firefox');
						
						if (x.length == 2)
						itm.style.left = (curleft+(y-10))+'px';
						else 
						itm.style.left = (y-10)+'px';
						itm.style.top = (parseInt(curtop)-parseInt(up)) + '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
					}
				}
				//alert(curleft + ' ' + curtop);
				return [curleft,curtop];
			}

			var ClearDropDownTimer;
			function ClearDropDown(ChildToClear) 
			{
				ClearDropDownTimer = setTimeout('window.clearTimeout(ClearDropDownTimer);var x = getitem(\''+ChildToClear+'\'); x.style.display=\'none\'; ', 100);
			}



/*==============================================================================

Application:   Utility Function
Author:        John Gardner

Version:       V1.0
Date:          18th November 2003
Description:   Used to check the validity of a UK postcode

Version:       V2.0
Date:          8th March 2005
Description:   BFPO postcodes implemented.
               The rules concerning which alphabetic characters are allowed in 
               which part of the postcode were more stringently implementd.
  
Version:       V3.0
Date:          8th August 2005
Description:   Support for Overseas Territories added                 
  
Version:       V3.1
Date:          23rd March 2008
Description:   Problem corrected whereby valid postcode not returned, and 
							 'BD23 DX' was invalidly treated as 'BD2 3DX' (thanks Peter 
               Graves)        
  
Version:       V4.0
Date:          7th October 2009
Description:   Character 3 extended to allow 'pmnrvxy' (thanks to Jaco de Groot)          
              
  
Parameters:    toCheck - postcodeto be checked. 

This function checks the value of the parameter for a valid postcode format. The 
space between the inward part and the outward part is optional, although is 
inserted if not there as it is part of the official postcode.

If the postcode is found to be in a valid format, the function returns the 
postcode properly formatted (in capitals with the outward code and the inward
code separated by a space. If the postcode is deemed to be incorrect a value of 
false is returned.
  
Example call:
  
  if (checkPostCode (myPostCode)) {
    alert ("Postcode has a valid format")
  } 
  else {alert ("Postcode has invalid format")};
                    
------------------------------------------------------------------------------*/

function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkpmnrstuvwxy]";                         // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "{1}" + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

	function EscapeCharacters (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,"xA3");
					data = data.replace(/£/g,"xA3");
					//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,"x26amp")
					data = data.replace(/&/g,"x26amp")
					//alert(data);
				}
				return data;
	}

