/*
# # # # # # #
# CHANGELOG
#
# V0.01 SDW      2008-11-26                         Original Code
# V0.02 SDW      2008-11-26                         Implement Themes; 
# V0.03 SDW      2008-11-27                         Fixed bug in resizePage(); when using a page border and a fixed height site
#													Fixed bug using float on fixed height sites	
# V0.04 SDW      2008-12-02                         Add draw flash function; Add scrollDiv function
# V0.05 SDW      2008-12-09                         Added loadArticle and updateSearchArticles functions
#
*/
var is_IE = 0;
var is_firefox = 0;
var loaded = 0;
nav  = navigator.userAgent;

var global_url = "http://www.gladstonebrookes.co.uk/";
var s_global_url = 'http://www.gladstonebrookes.co.uk/';

re = /MSIE/gi;
if(nav.match(re)){
	is_IE = 1;
}else{
	re = /Firefox/gi;
	if(nav.match(re)){
		is_firefox = 1;
	}
	
}

var load_side_only = 0;
var logon_form = null;
var page_y = 100;
var option_y = 100;
var menu_y = 100;
var speed = 10;
var inc = 10;
var inc_x = 40;
var inc_y = 10;
var flash_frame_h = 0;
var show_laymans = false;
var site_fixed_height = 0;
var site_float = 1;
var site_width = 1000;
var flash_disabled = 0;
var last_menu_obj = null;
var menu_in_obj = null;
var menu_out_obj = null;
var menus_loaded = Array();
var page_type = "";
var page_id = "";
var products = Array();
var qa_arr = Array();
var menu_width= 200;
var left_menu_width = 300;
var right_menu_width = 300;
var header_img_repeat = 0;
var main_overflow_x = 0;
var main_overflow_y = 1;
var left_overflow_x = 0;
var left_overflow_y = 1;
var right_overflow_x = 0;
var right_overflow_y = 1;
var site_float_y = 1;
var flash_color_1 = "#333333";
var flash_color_2 = "#333333";
var flash_highlight_color = "#333333";
var flash_main_color_1 = "#333333";
var flash_main_color_2 = "#333333";
var flash_bg_color = "#ffffff";
var flash_back_width = 240;
var default_postage = 4.95;
var non_default_postage = 10.95;
var default_postage_text = "Postage & Insurance";
var non_default_postage_text = "International Postage";	
var top_bar_font_color = '#ffffff';
var dropdown_menu_left_offset = 1;
var mem_allow_logon = 1;
var gallery_show_img_name = 0;
var gallery_img_name_color ='#ff0000';
var header_height = 220;
var header_type = 1;
var can_get_basket = 0;
var footer_bar_height = 80;
var print_header = "";
var gallery_background_random = 0;
var page_back_img_below_header = 0;
var basket_empty_txt ="";
var main_menu_btn_spacing = 1;
var dropdown_min_height = 25;
var form_error_color = "#ff0000";
var ARTICLES_TITLE = "Articles";
var USE_HTACCESS_REWRITE = 1;
var DEFAULT_NAME = "Gladstone Brookes";

function flashAction(action){
	closeAllMenus();
	switch(action){
	}
}

function checkEnterPressed(e){
	
	if( !e ) { 
		if( window.event ) { 
			e = window.event;
		}else{
			return false;
		}
	}
	
	if( typeof( e.which ) == 'number' ) { 
		e = e.which; 
		if (e=='13')return true;	
	} else if( typeof( e.keyCode ) == 'number' ) { 
		//IE, NS 6+, Mozilla 0.9+ 
		e = e.keyCode; 
		if (e=='13')return true;	 
	} else if( typeof( e.charCode ) == 'number' ) { 
		//also NS 6+, Mozilla 0.9+ 
		e = e.charCode; 
		if (e=='13')return true;	
	} else { 
		return false;; 
	} 

}

function bookmark(){
	
	title = document.title;
	url = document.location;
	
	if (window.external){ 
		try{
			window.external.AddFavorite(url,title);
		}catch(e){
		}
	}
	if (window.sidebar){
		try{
			window.sidebar.addPanel(title,url,'');
		}catch(e){
		}
	} 

}


function updateDivHTML(id,txt,is_encoded){
	
	if(document.getElementById(id)){
		document.getElementById(id).innerHTML = (is_encoded == 1) ? decode64(txt) : txt;
	}
	
}

function checkemail(email){
		
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email))
			return true;
		else{
			return false;
		}
		
}

function printPrep(html){
               re = /(<[^>]*)\bname[\s]*=[\s]*(['"]?)[^\2\s>]+/gi;
                if(html.match(re)){
                                html = html.replace(re,"$1");
                }
                re = /(<[^>]*)\bid[\s]*=[\s]*(['"]?)[^\2\s>]+/gi;
                if(html.match(re)){
                                html = html.replace(re,"$1");
                }
                re = /<script>.*?<\/script>/gi;
                if(html.match(re)){
                                html = html.replace(re,"");
                }
				
				re = /overflow: hidden;/gi;
                if(html.match(re)){
                                html = html.replace(re,"");
                }
                return html;
}

function printDiv(div){
	if(div && document.getElementById('print_div')){
		document.getElementById('print_div').innerHTML = print_header;
		document.getElementById('print_div').innerHTML += printPrep(div.innerHTML);
		window.print();
	}
}

function updatePrintDiv(){
	
	if((document.getElementById('main_content')) && (document.getElementById('print_div'))){
		document.getElementById('print_div').innerHTML = print_header;
		document.getElementById('print_div').innerHTML += printPrep(document.getElementById('main_content').innerHTML);
	}
	
}

function createControls(){
	
	document.write("<iframe name=\"main_frame\" id=\"main_frame\"></iframe>\r\n");
	document.write("<iframe name=\"process_frame\" id=\"process_frame\"></iframe>\r\n");
	document.write("<iframe name=\"process_frame2\" id=\"process_frame2\"></iframe>\r\n");
	document.write("<iframe name=\"logon_frame\" id=\"logon_frame\"></iframe>\r\n");
		
}

function formatQAItem(str){
	
	re=/<AND>/gi
	str = str.replace(re,"&");
	
	re=/<DBLQUOTE>/gi
	str = str.replace(re,'"');
	
	re=/<SGLQUOTE>/gi
	str = str.replace(re,"'");
	
	return str;
	
}

function loadQA(id){

	try{
		
		if(qa_arr[id]){
				
			arr = qa_arr[id];
			last_cat1 = "";
			last_cat2 = "";
			current_list = null;
			for(i=0;i<arr.length;i++){
			
				cat1 = arr[i]["category1"];
				cat2 = arr[i]["category2"];
				if(last_cat1 != cat1){
					last_cat1 = cat1;
					last_cat2 = cat2;
					newItem = document.createElement('option');
					newItem.value = cat2;
					
					newItem.text = (cat2 != "") ? "-- "+formatQAItem(cat2) : "-- "+formatQAItem(cat1);
					
					re=/\W/gi;
					cat_str = cat1.replace(re,"").toLowerCase();
					list = document.getElementById(cat_str+"_cat2_"+id);
					if(list){
						current_list = list;
						try{
							list.add(newItem,null);
						}catch(ie_err){
							list.add(newItem);
						}
					}else{
						//alert("list not exist");
						current_list = null;
					}
				}
				
				if((last_cat2 != cat2)&&(current_list)){
					last_cat2 = cat2;
					newItem = document.createElement('option');
					newItem.value = cat2;
					newItem.text = "-- "+cat2;
					try{
						list.add(newItem,null);
					}catch(ie_err){
						list.add(newItem);
					}
				}
				
			
			}
			
			
			
		}
	
	}catch(qa_err){
		//alert(qa_err);
	}
	
}

function clearList(list){
	
	if((list)&&(list.length > 0)){
		
		for(l=(list.length-1);l>=0;l--){
			list.remove(l);
		}
		list.length = 0;
		
	}
	
}

function showQABlank(cat_str,cat,id){
	
	//alert("BLANK\r\n"+cat_str+"\r\n"+cat+"\r\n"+id);
	blank_div = document.getElementById(cat_str+"_blank_"+id);
	if((blank_div)&&(qa_arr[id])){
		//run though arr and hide all other in the category
		
		arr = qa_arr[id];
		for(a=0;a<arr.length;a++){
			
			if(arr[a]["category1"] == cat){
				
				div = document.getElementById("txt_div_"+a+"_"+id);
				if(div){
					div.style.display = "none";
				}
			}
			
		}
		
		blank_div.style.display = "block";
	}
	
	
}

function loadQuestions(list,index,cat,id){
	
	//alert(list.id+"\r\n"+index+"\r\n"+cat+"\r\n"+id);
	if(index > -1){
		val = list[index].value;
		//alert(val);
		re=/\W/gi;
		cat_str = cat.replace(re,"").toLowerCase();
		list = document.getElementById(cat_str+"_qs_"+id);
		
		if(list){
			 //clear list first
			 clearList(list);
			 showQABlank(cat_str,cat,id);
			 
			 if(val == "resetlist"){
				 //alert("list reset");
				if(document.getElementById('qs_div_'+id)){
					document.getElementById('qs_div_'+id).innerHTML = "&nbsp;";
				}
				
			 }else{
			 	//alert("load questions");
				if(document.getElementById('qs_div_'+id)){
					document.getElementById('qs_div_'+id).innerHTML = "Now choose your question";
				}
				newItem = document.createElement('option');
				newItem.value = "reset";
				newItem.text = "Select your question here";
				newItem.style.color = "#666666";
				try{
					list.add(newItem,null);
				}catch(ie_err){
					list.add(newItem);
				}
				
				arr = qa_arr[id];
				for(a=0;a<arr.length;a++){
					if((arr[a]["category1"] == cat)&&(arr[a]["category2"] == val)){
						newItem = document.createElement('option');
						newItem.value = a;
						newItem.text = "-- "+formatQAItem(arr[a]["question"]);
						try{
							list.add(newItem,null);
						}catch(ie_err){
							list.add(newItem);
						}
					}
					
				}
			 
			 }
			 
		}else{
			//alert("list not found");
		}
		
	}
	
}

function loadAnswer(list,index,cat,id){
	//alert("LOAD ANSWER\r\n"+list.id+"\r\n"+index+"\r\n"+id);
	if(index > -1){
		val = list[index].value;
		Math.abs(val);
		//alert(val);
		re=/\W/gi;
		cat_str = cat.replace(re,"").toLowerCase();
		
		if(qa_arr[id]){
			//run though arr and hide all other in the category
			found = 0;
			arr = qa_arr[id];
			for(a=0;a<arr.length;a++){
				
				if(arr[a]["category1"] == cat){
					div = document.getElementById("txt_div_"+a+"_"+id);
					if(div){
						div.style.display = (a == val) ? "block":"none";
						if(a==val){
							found = 1;
						}
					}
				}
				
			}
			blank_div = document.getElementById(cat_str+"_blank_"+id);
			if(blank_div){
				blank_div.style.display = (found == 1)? "none" : "block";
			}
		}
		
	}
	
}

function stopScrollDiv(id){
	//alert("STOP "+id);
	if(window[id]){
		clearTimeout(window[id]);
	}
	
}

function startScrollDiv(id){
	//alert("Start "+id);
	if(window[id]){
		clearTimeout(window[id]);
	}
	window[id] = setInterval("scrollDiv('"+id+"')",60);
}

function scrollDiv(id){
			
	if((document.getElementById("d_"+id))&&(document.getElementById("s_"+id))){
			
			try{
			
				frame_h = parseInt(parent.document.getElementById("d_"+id).style.height);
				div_h = document.getElementById("s_"+id).clientHeight;
				
				t = parseInt(document.getElementById("s_"+id).style.top);

				if(t > (0-div_h)){
					document.getElementById("s_"+id).style.top = (t-1) +"px";
				}else{
					document.getElementById("s_"+id).style.top = frame_h +"px";
				}
				
				
			}catch(e){
			
			}
		
	}
	
}


function toggleShowSearch(div,search_box_tag){
	
	if(search_box_tag){
		search_box_tag = "_"+search_box_tag;
	}else{
		search_box_tag = "";
	}
	
	img = div+"_img";
	
	re1=/_down/gi;
	re2=/_up/gi;
	
	if(document.getElementById(img)){
		
		shown = (document.getElementById(img).src.match(re1)) ? 1:0
		
	
		document.getElementById(img).src = (shown == 1)? document.getElementById(img).src.replace(re1,"_up") : document.getElementById(img).src.replace(re2,"_down");
		
		
		if(document.getElementById(div)){
			
			document.getElementById(div).style.display = (shown==1) ? "block":"none";
			resizePage();
			
		}
		
		show_search_box = (shown==1) ? 1:0;
		
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()+6);
	
		parent.document.cookie = "show_search_box"+search_box_tag+"="+show_search_box+";expires="+expireDate.toGMTString()+";path=/";
	
	}
	
	
}



function toggleMainMenu(bool){
	if(document.getElementById('header_menu')){
		document.getElementById('header_menu').style.display=(bool)? "block":"none";
	}
}


function toggleHeader(bool){
	
	check_h = (bool)? "block":"none";
	if(document.getElementById('header').style.display != check_h){
		document.getElementById('header').style.height =(bool)? header_height+"px":"0px";
		document.getElementById('header').style.display =(bool)? "block":"none";
	}
	
	if((document.getElementById('custom_header'))&&(document.getElementById('custom_header').style.display != check_h)){
		document.getElementById('custom_header').style.display =(bool)? "block":"none";
	}
	

}

function toggleFooter(bool){
	
	check_h = (bool)? "block":"none";
	if((document.getElementById('footer_menu'))&&(document.getElementById('footer_menu').style.display != check_h)){
		document.getElementById('footer_menu').style.display =(bool)? "block":"none";
	}
	
}


function updateHeader(html){
	if(document.getElementById('custom_header')){
		if(document.getElementById('custom_header').innerHTML != decode64(html)){
			document.getElementById('custom_header').innerHTML=decode64(html);
		}
	}
}

function removeLastSearchOption(rewrite_flag){
	
	
		search_options = "";
	
		theCookie=""+parent.document.cookie;
		cookieName = "search_options"+DEFAULT_NAME.toLowerCase();
		
		ind=theCookie.indexOf(cookieName);
			
		if (ind==-1 || cookieName=="") {
				basket = "";
		}else{
				ind1=theCookie.indexOf(';',ind);
				if (ind1==-1) {
					ind1=theCookie.length; 
				}
				val =  unescape(theCookie.substring(ind+cookieName.length+1,ind1));
				search_options = val;
				
		}
		
		//alert(search_options);
		if(search_options != ""){
			search_opt_arr = search_options.split("|");
			
			new_search_options = "";
			for(i=0;i<search_opt_arr.length-1;i++){
					new_search_options += (new_search_options != "") ? "|" : "";
					new_search_options += search_opt_arr[i];
			}
			
			//alert(new_search_options);
			expireDate = new Date;
			expireDate.setMonth(expireDate.getMonth()+2);
			document.cookie = "search_options"+DEFAULT_NAME.toLowerCase()+"="+new_search_options+";expires="+expireDate.toGMTString()+";path=/";
			
			if(rewrite_flag){
				var loc = window.location+"";
				re=/page\d+$/g
				loc = loc.replace(re,"");
				window.location  = loc;
				
			}else if(current_page != ""){
				p_url = global_url+current_page.substr(1);
				//check query
				//alert(p_url);
				
				q_arr = p_url.split("?");
				q_arr2 = q_arr[1].split("&");
				
				new_q_str = "";
				for(i=0;i<q_arr2.length;i++){
					
					if((q_arr2[i].split("=")[0] != "rs") && (q_arr2[i].split("=")[0] != "cp")){
						new_q_str += (new_q_str == "") ? q_arr2[i] : "&"+q_arr2[i];
					}
				}	
				
				p_url = q_arr[0]+"?"+new_q_str;
				//alert(p_url);
				loadPage(p_url);
			}
			
		}
	
	
}


function getCalenderPosition(coord,myevent){
	
	w = document.documentElement.clientWidth;
	h = document.documentElement.clientHeight;
	
	val = getCurrentMousePosition(coord,myevent);
	
	if(coord == "x"){
		w += document.documentElement.scrollLeft;
		cal_center_w =  Math.ceil( parseInt(document.getElementById('calender').clientWidth)/2);
		if((val + cal_center_w) > w){
			x = w - (cal_center_w * 2)
		}else{
			x = val - cal_center_w
		}
		return x;
	}
	
	if(coord == "y"){
		h += document.documentElement.scrollTop;
		cal_center_h =  Math.ceil( parseInt(document.getElementById('calender').clientHeight)/2);
		if((val + cal_center_h) > h){
			y = h - (cal_center_h * 2)
		}else{
			y = val - cal_center_h
		}
		return y;
	}
	
	return 0;
	 
}

function getCurrentMousePosition(coord,myevent){
	
	try{
		start_move = 0;
		if(mouse_move_started == 0){
			start_move = 1;
			startMouseMove();
		}
		getMouseXY(myevent);
		if(start_move == 1){
			mouse_move_started = 0;
			document.onmousemove = null;
		}
		
		if(coord == "x"){
			return tempX;
		}
		
		if(coord == "y"){
			return tempY;
		}
		
	}catch(er){
	}
	
	return 0;
}

function clearSearchOptions(reload_p,rewrite_flag){	
		
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()-2);
		document.cookie = "search_options"+DEFAULT_NAME.toLowerCase()+"=;expires="+expireDate.toGMTString()+";path=/";
		if(USE_HTACCESS_REWRITE == 0){
			document.cookie = "search_article_options=;expires="+expireDate.toGMTString()+";path=/";
			document.cookie = "show_search_box_article=;expires="+expireDate.toGMTString()+";path=/";
		}
		document.cookie = "show_search_box=;expires="+expireDate.toGMTString()+";path=/";

		if(reload_p){
			
			if(rewrite_flag){
				var loc = window.location+"";
				re=/page\d+$/g
				loc = loc.replace(re,"");
				window.location  = loc;
			}else if(current_page != ""){
				p_url = global_url+current_page.substr(1)+"&clear";
				//check query
				//alert(p_url);
				
				q_arr = p_url.split("?");
				q_arr2 = q_arr[1].split("&");
				
				new_q_str = "";
				for(i=0;i<q_arr2.length;i++){
					
					if((q_arr2[i].split("=")[0] != "rs") && (q_arr2[i].split("=")[0] != "cp")&& (q_arr2[i].split("=")[0] != "show_all")){
						new_q_str += (new_q_str == "") ? q_arr2[i] : "&"+q_arr2[i];
					}
				}	
				
				p_url = q_arr[0]+"?"+new_q_str;
				//alert(p_url);
				loadPage(p_url);
			}

			
		}
	
}

function updateSearchArticles(keyword,category,date_from,date_to){
	
	str = encode64(keyword+"") + "|" + encode64(category+"") + "|" + encode64(date_from+"") + "|" + encode64(date_to+"");
	expireDate = new Date;
	expireDate.setMonth(expireDate.getMonth()+2);
	document.cookie = "search_article_options="+str+";expires="+expireDate.toGMTString()+";path=/";
	
	if(current_page != ""){
		p_url = global_url+current_page.substr(1)+"&1";
		//check query
		q_arr = p_url.split("?");
		q_arr2 = q_arr[1].split("&");
		
		var load_cat_tag = "";
		
		new_q_str = "";
		for(i=0;i<q_arr2.length;i++){
			if(q_arr2[i].split("=")[0] == "load_article"){
				load_cat_tag = q_arr2[i].split("=")[1];
			}
			
			if((q_arr2[i].split("=")[0] != "rs") && (q_arr2[i].split("=")[0] != "cp")){
				new_q_str += (new_q_str == "") ? q_arr2[i] : "&"+q_arr2[i];
			}
		}	
		
		p_url = q_arr[0]+"?"+new_q_str;
		loadPage(p_url);
		
	}else if(USE_HTACCESS_REWRITE == 1){
			var loc = window.location+"";
			re=/page\d+$/g
			loc = loc.replace(re,"");
			window.location  = loc;
	}
	
}

function updateSearchOption(opt,type,rewrite_flag){
	
	if(opt != ""){
		
		//alert(opt);
		
		search_options = "";
	
		theCookie=""+parent.document.cookie;
		cookieName = "search_options"+DEFAULT_NAME.toLowerCase();
		
		ind=theCookie.indexOf(cookieName);
			
		if (ind==-1 || cookieName=="") {
				basket = "";
		}else{
				ind1=theCookie.indexOf(';',ind);
				if (ind1==-1) {
					ind1=theCookie.length; 
				}
				val =  unescape(theCookie.substring(ind+cookieName.length+1,ind1));
				search_options = val;
				if(search_options == ";"){
					search_options = "";
				}
					
				
		}
		
		//alert(search_options);
		if(search_options != ""){
			search_opt_arr = search_options.split("|");
			//search_opt_arr.sort();
		}else{
			search_opt_arr = Array();
		}
		
		if(type == "add"){
			
			found = 0;
			for(i=0;i<search_opt_arr.length;i++){
				if(search_opt_arr[i] == opt){
					found = 1;
					break;
				}
			}
			
			if(found == 0){
				search_opt_arr.push(opt);
			}
			
		}else if(type == "remove"){
			
			found = 0;
			for(i=0;i<search_opt_arr.length;i++){
				if(search_opt_arr[i] == opt){
					search_opt_arr.splice(i,1);
					break;
				}
			}
			
			
		}
		
		new_search_options = "";
		for(i=0;i<search_opt_arr.length;i++){
				new_search_options += (new_search_options != "") ? "|" : "";
				new_search_options += search_opt_arr[i];

		}
	
		//alert(search_options);
		//alert(new_search_options);
		
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()+2);
		document.cookie = "search_options"+DEFAULT_NAME.toLowerCase()+"="+new_search_options+";expires="+expireDate.toGMTString()+";path=/";
		
		if(search_options != new_search_options){
			
			if(rewrite_flag){
				var loc = window.location+"";
				re=/page\d+$/g
				loc = loc.replace(re,"");
				//alert(loc);
				window.location  = loc;
			}else if(new_search_options == ""){
				loc = window.location;
				window.location = loc;
			}else if(current_page != ""){
				p_url = global_url+current_page.substr(1)+"&1";
				//check query
				//alert(p_url);
				q_arr = p_url.split("?");
				q_arr2 = q_arr[1].split("&");
				
				new_q_str = "";
				for(i=0;i<q_arr2.length;i++){
					
					if((q_arr2[i].split("=")[0] != "rs") && (q_arr2[i].split("=")[0] != "cp")){
						new_q_str += (new_q_str == "") ? q_arr2[i] : "&"+q_arr2[i];
					}
				}	
				
				p_url = q_arr[0]+"?"+new_q_str;
				//alert(p_url);
				loadPage(p_url);
			}
		}
	
	}
	
}

function showLoading(){
	
		document.getElementById('main_content').innerHTML = "<div style=\"padding:20px;\"><div style=\"display:inline;padding:2px;background-color:#ffffff;\">loading please wait...</div></div>";
		//document.getElementById('left_content').innerHTML = "";
		//document.getElementById('right_content').style.display="none";//innerHTML = "";
		
}


function updateMainContent(){
	frame = window.frames['main_frame'];
	document.getElementById('main_frame').style.display = "block";
	if(frame.document.getElementById('page_details')){
	
		document.getElementById('main_content').innerHTML = frame.document.getElementById('page_details').innerHTML;
		updatePrintDiv();
		//alert(document.getElementById('main_content').innerHTML);
		//page_y = parseInt(frame.document.getElementById('page_details').clientHeight) +20;
		
		try{
		
				if(frame.document.getElementById('left_menu_details')){
					
					if(frame.document.getElementById('left_menu_details').innerHTML != "LEAVE"){
						document.getElementById('left_content').innerHTML = frame.document.getElementById('left_menu_details').innerHTML;
						//menu_y = parseInt(frame.document.getElementById('left_menu_details').clientHeight) +20;
						
					}
					
				}else{
					
					if(document.getElementById('left_content')){
						document.getElementById('left_content').innerHTML = "";
					}
					menu_y = 100;
					
				}
				
				
				if(frame.document.getElementById('right_menu_details')){
					
					document.getElementById('right_content').style.display = "block";
					if(frame.document.getElementById('right_menu_details').innerHTML != "LEAVE"){
						document.getElementById('right_content').innerHTML = frame.document.getElementById('right_menu_details').innerHTML;
						//option_y = parseInt(frame.document.getElementById('right_menu_details').clientHeight) +20;
						
					}
					
				}else{
					if(document.getElementById('right_content')){
						document.getElementById('right_content').innerHTML = "";
					}
					option_y = 100;
					
				}
				try{
					closeAllMenus();
				}catch(e){
				}
		
		}catch(e1){
		}
		
		try{
			frame.onPageComplete();
		}catch(e){
			//alert(e);
		}
		
	}
	
	
	window.frames['main_frame'].src = "";
	resizePage();
	document.getElementById('main_frame').style.display = "none";
}


function loadFlashPage(type,p){
	
	if(type != ""){
		loadPage(global_url+"scripts/pages.php?page_type="+type+"&p="+p);
	}else{
		loadPageNum(p);
	}
	
}

var auto_load_cat = "";

function rtnHome(){
	
	var str = decode64("aHR0cDovLw==");
	var re = new RegExp("https://");
	window.location.href =  global_url.replace(re,str);
}


function loadMenu(type,id,page_type){
	
	frame = (type == 1) ? "side_menu_frame":"features_frame";
	
	str = type+"|"+id+"|"+page_type;
	str = encode64(str);
	document.getElementById(frame).src = global_url+"scripts/options.php?"+str;
	
}

var gallery_style = 0;
var gallery_downloads = 0;

var flash_load_str = "";
var load_flash_on_complete = 0;
var side_menu_moving = 0;
var right_menu_moving = 0;
function loadFlash(str){
	if(!str){
		str = "";
	}
	if(str != ""){
			temp = str.split(":");
			flash = temp[0].toLowerCase();
			
			re1 = /\s{1,}/gi;
			flash = flash.replace(re1,"_");
			size = temp[1];
			if(!temp[2]){
				xtra = "";
			}else{
				xtra = temp[2];
			}
			
			var w = Math.abs(temp[4]);
			
			if(side_menu_moving == 0){
				
				if((flash_in==0)||(flash_frame_h != size)){
						
						load_flash_on_complete = 1;
						flash_load_str = str;
						document.getElementById('flash_frame').innerHTML = "";
						
						if(flash_frame_h < size){
							flash_frame_h = size;
							flashIn();
						
						}else{
							flash_frame_h = size;
							flash_out_h=size;
							flashOut();
						
						}
						
				}else{
					
						load_flash_on_complete = 0;
						flash_load_str = "";
						re=/gallery carousel/gi;
						if(str.match(re)){
								f_file = loadSWF(flash,flash+".swf?global_url="+global_url+"&gallery="+temp[2]+"&page="+temp[3]+"&style="+gallery_style+"&downloads="+gallery_downloads+"&high_c="+flash_highlight_color+"&show_name="+gallery_show_img_name+"&name_c="+gallery_img_name_color+"&bg_color="+flash_bg_color+"&w="+w);
							}else{
								f_file =loadSWF(flash,flash+".swf?global_url="+global_url+"&c1="+flash_color_1+"&c2="+flash_color_2+"&high_c="+flash_highlight_color+"&main_c1="+flash_main_color_1+"&main_c2="+flash_main_color_2+"&bw="+flash_back_width+"&xtra="+xtra+"&w="+w);
						}
						document.getElementById('flash_frame').innerHTML = f_file;
				
				}
				
			}else{
				load_flash_on_complete = 1;
				flash_load_str = str;
			}
	
	
	}else if(flash_in ==1){
		load_flash_on_complete = 0;
		flash_out_h = 0;
		flash_load_str = "";
		document.getElementById('flash_frame').innerHTML = "";
		flashOut();
	}
	
}

function loadFlashDiv(str,divname){
	
	div = document.getElementById(divname);
	if(div){
		if(str == ""){
			div.innerHTML = "";
		}else{
			
			temp = str.split(":");
			flash = temp[0].toLowerCase();
			
			re1 = /\s{1,}/gi;
			flash = flash.replace(re1,"_");
			size = temp[1];
			if(!temp[2]){
				xtra = "";
			}else{
				xtra = temp[2];
			}
			
			var w = Math.abs(temp[4]);
			
			re=/gallery carousel/gi;
			if(str.match(re)){
					f_file = loadSWF(flash,flash+".swf?global_url="+global_url+"&gallery="+temp[2]+"&page="+temp[3]+"&style="+gallery_style+"&downloads="+gallery_downloads+"&high_c="+flash_highlight_color+"&show_name="+gallery_show_img_name+"&name_c="+gallery_img_name_color+"&bg_color="+flash_bg_color+"&w="+w);
				}else{
					f_file =loadSWF(flash,flash+".swf?global_url="+global_url+"&c1="+flash_color_1+"&c2="+flash_color_2+"&high_c="+flash_highlight_color+"&main_c1="+flash_main_color_1+"&main_c2="+flash_main_color_2+"&bw="+flash_back_width+"&xtra="+xtra+"&w="+w);
			}
			div.innerHTML = f_file;
		}
	}
}

function loadSWF(f,fs,width,height,path,scale,salign){
	//alert(f);
	//alert(fs);
	
	if((!path)||(path == "")){
		path = global_url+'flash/';
	}
	if(!width){
		width = "100%";
	}
	if(!height){
		height = "100%";
	}
	if(!scale){
		scale = "noscale";
	}
	if(!salign){ //lt rt t lb b rb
		salign = "";
	}
	f_file = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" id="'+f+'" align="middle"><param name="salign" value="'+salign+'" /><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+path+fs+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="scale" value="'+scale+'" /><param name="wmode" value="transparent" /><embed src="'+path+fs+'" loop="false" menu="false" quality="high"  scale="'+scale+'" wmode="transparent"  width="'+width+'" height="'+height+'" salign="'+salign+'" name="'+f+'"  align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	return f_file;
}

function drawFlash(f,fs,w,h,path,scale){
	//alert("draw flash");
	//alert(fs);
	document.write(loadSWF(f,fs,w,h,path,scale));
}


function loadSWFBackground(swf_back_file,swf_scale_type,swf_alignment){
	document.write(loadSWF("swf_back",swf_back_file,"100%","100%",global_url+"flash/",swf_scale_type,swf_alignment));
}

function openWindow(id,url,w,h){
	
	resizeable = "no";
	if(!w){
		w = "800";
		resizeable = "yes";
	}
	if(!h){
		h = "600";
		resizeable = "yes";
	}
	params = 'width='+w+', height='+h+', resizable='+resizeable+', scrollbars=no, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no';
	var fwin = window.open(url, id, params);
	if (fwin && window.focus) fwin.focus();

	
}

var last_cat_src = "";
function loadCatalogue(product_id,cat1,cat2,brand,tag,auto){
	
	moveCalender(-2000,-2000);
	str = str1 = product_id+","+cat1+","+cat2+","+brand+","+tag;
	str = encode64(str);
	showLoading();
	document.getElementById('main_frame').src = last_cat_src = global_url+"scripts/pages.php?load_catalogue="+str;
	
}

function loadArticle(article_id,list_type,category,no_of_records,date_from,date_to){
	
	moveCalender(-2000,-2000);
	str = str1 = article_id+","+list_type+","+category+","+no_of_records+","+date_from+","+date_to;
	str = encode64(str);
	showLoading();
	document.getElementById('main_frame').src = last_cat_src = global_url+"scripts/pages.php?load_article="+str;
	
}

function cancelStyle(){
}

function loadPageStyle(img,flag,background_image,background_repeat){
	
	//alert(img+"\r\n"+flag+"\r\n"+background_image+"\r\n"+background_repeat);
	re_img=/.jpg/gi;
	
	flag = Math.abs(flag);
	
	try{
		
		folder_path = (img == "header_default.jpg") ? "images/" : "uploads/image/";
		header_img = ((img != "")&&(flag=='1')) ? "url("+global_url+folder_path+img+")" :  "none";
		
		if(document.getElementById('header_img_div').style.backgroundImage != header_img){
			document.getElementById('header_img_div').style.backgroundImage = header_img ;
			
			document.getElementById('header_img_div').style.backgroundRepeat = (header_img_repeat == 1) ? "repeat-x" : "no-repeat";
			document.getElementById('header_img_div').style.backgroundPosition = "50% 0px";
			
		}
		
	}catch(e1){
		document.getElementById('header').style.backgroundImage ="none";
	}
	
	try{
		if((background_image)&&(background_image != "")&&(background_image.substr(0,8) != "gallery:")){
				if(document.getElementById('main_page_back').style.backgroundImage != "url("+global_url+"uploads/image/"+background_image+")"){
					document.getElementById('main_page_back').style.backgroundImage = "url("+global_url+"uploads/image/"+background_image+")";
				}
				document.getElementById('main_page_back').style.backgroundRepeat = (background_repeat != "") ? background_repeat : "repeat";
			
		}else if(background_image.substr(0,8) != "gallery:"){
				document.getElementById('main_page_back').style.backgroundImage = 'none';
		}
		
		
	}catch(e1){
	}
	
	
	
	
}

function drawFlashHeader(rtn){
	
	obj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%" id="flash_header" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+global_url+'flash/flash_header.swf?global_url='+global_url+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="salign" value="t" /><param name="wmode" value="transparent" /><embed src="'+global_url+'flash/flash_header.swf?global_url='+global_url+'" loop="false" menu="false" quality="high" scale="noscale" wmode="transparent" salign="t" width="100%" height="100%" name="flash_header" swLiveConnect=true align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	if((is_IE == 0)&&(is_firefox==0)){		
		ver = GetSwfVer();
		if(ver < "10.0.22"){
				obj = '<div style=\"padding:50px;\" align=\"right\">Please download the latest <a href=\"http://get.adobe.com/flashplayer/\" target=\"_blank\" style=\"color:#000000;\"><u>flash player</u></a></div>';
		}
	}
	if(!rtn){
		document.write(obj);
	}else{
		return obj;
	}
}

function drawFlashHeaderMC(){
	site_f_width = (site_width == 0) ? parseInt(document.documentElement.clientWidth) : site_width;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+site_f_width+'" height="100%" id="flash_header_mc" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+global_url+'flash/flash_header_mc.swf?global_url='+global_url+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="wmode" value="transparent" /><embed src="'+global_url+'flash/flash_header_mc.swf?global_url='+global_url+'" loop="false" menu="false" quality="high" scale="noscale" wmode="transparent" width="'+site_f_width+'" height="100%" name="flash_header_mc" swLiveConnect=true align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}

var lastbg_color = "transparent";
var lastf_color = top_bar_font_color;
function toggleBackStyle(field,tog){
	
	try{
		if(tog == 1){
			lastbg_color = (field.style.backgroundColor) ? field.style.backgroundColor : lastbg_color;
			lastf_color = (field.style.color) ? field.style.color : lastf_color;
		}
		field.style.backgroundColor = (tog == 1) ? "#ffffff":lastbg_color;
		field.style.color = (tog == 1) ? "#000000": lastf_color;
	}catch(transErr){
	}
	
}

function forgotPassword(secure_flag){
	var str = (secure_flag ==1) ? "s_forgot_password":"forgot_password";
	document.getElementById('main_frame').src = last_cat_src = global_url+"scripts/pages.php?"+str;
}

function flashSearch(txt){
	
	var re=/[^a-zA-Z0-9\s_£&\?\.\-\:\/]/gi
	txt = txt.replace(re,'');
	
	var re=/\s+/gi
	txt = txt.replace(re,' ');
			
	var re=/\s/gi
	test = txt.replace(re,"");
	
	
	if(test != ""){
		//urlencode
		
		if(USE_HTACCESS_REWRITE == 1){
		var dir_str = "";
		
		var search_arr = txt.split(' ');
		for(var i=0;i<search_arr.length;i++){
			search_arr[i] = trim(search_arr[i]);
			if(search_arr[i] != ""){
				dir_str += (dir_str == "")? "":"/";
				dir_str += urlencode(search_arr[i]);
			}
		}
		
		var str = decode64("aHR0cDovLw==");
		var re = new RegExp("https://");
		top.window.document.location =  global_url.replace(re,str)+"search/"+dir_str;
		
		}else{
				txt = encode64(txt);
				loadPage(global_url+"scripts/search.php?"+txt);
		}
		
	}else{
		rtnHome();
	}
	
}

var default_search_txt = "enter keyword";
function checkClearSearch(){
	
	if(document.search_form.search_txt.value  == default_search_txt){
		document.search_form.search_txt.value='';
	}
}

function checkSearch(){
	
	closeAllMenus();
	
	fm = document.search_form;
	
	if((fm.search_txt.value  == "")||(fm.search_txt.value  == default_search_txt)||(fm.search_txt.value  == "searching...")){
	
		fm.search_txt.value = default_search_txt;
		fm.search_txt.focus();
		fm.search_txt.select();
	
	}else{
		
		flashSearch(fm.search_txt.value);
		toggleBackStyle(fm.search_txt,0);
		
	}
	
	
}

function reloadPage(){
	if(current_page != ""){
		document.getElementById('main_frame').src = global_url+current_page;
	}
}

function openDocument(doc){
	
	window.open(global_url+"scripts/document.php?"+doc);
	setTimeout("reloadPage()",5000);
	
}

function askQuestion(){
	
	
	document.getElementById('main_frame').src = global_url+"scripts/ask_question.php?edit=new";
	
	
}


function formatPassword(field){
	
	val = field.value;
	re = /\W/gi
	
	if(val.match(re)){
		val = val.replace(re,'');	
		if(document.getElementById('error_txt')){
			document.getElementById('error_txt').innerHTML = "Your password can only contain letters, numbers or the underscore(_)";
			if(document.getElementById('error_box')){
				document.getElementById('error_box').style.display = "block";
			}
			resizePage();
		}else{
			alert("Your password can only contain letters, numbers or the underscore(_)")
		}
		field.focus();
		field.value = val;
	}else{
		if(document.getElementById('error_txt')){
			  document.getElementById('error_txt').innerHTML = "&nbsp;";
			  if(document.getElementById('error_box')){
					document.getElementById('error_box').style.display = "none";
				}
			  resizePage();
		}
	}
	
	
}

function checkPasswordLength(field){
	if((field.value.length < 6)&&(field.value.length > 0)){
		if(document.getElementById('error_txt')){
			  document.getElementById('error_txt').innerHTML = "Your password must be at least 6 characters in length";
			  if(document.getElementById('error_box')){
					document.getElementById('error_box').style.display = "block";
				}
			  resizePage();
		}else{
			alert("Your password must be at least 6 characters in length");
		}
		field.value = "";
	 	field.focus();
	}else{
		if(document.getElementById('error_txt')){
			  document.getElementById('error_txt').innerHTML = "&nbsp;";
			  if(document.getElementById('error_box')){
					document.getElementById('error_box').style.display = "none";
				}
			  resizePage();
		}
	}
	
	
}

function checkPasswordMatch(field,original,rtn){
	
	if((original) && (field.value != "") && (original.value != "")){

			if(rtn){
				return (original.value == field.value)? true : false;
			}else{
				if(original.value != field.value){
					if(document.getElementById('error_txt')){
						document.getElementById('error_txt').innerHTML = "Please re-confirm your password";
						if(document.getElementById('error_box')){
							document.getElementById('error_box').style.display = "block";
						}
						resizePage();
					}else{
						alert("Please re-confirm your password")
					}
					field.value = "";
					field.focus();
				}else{
					if(document.getElementById('error_txt')){
						  document.getElementById('error_txt').innerHTML = "&nbsp;";
						  if(document.getElementById('error_box')){
								document.getElementById('error_box').style.display = "none";
							}
						  resizePage();
					}
				}
			}
			
	}else{
		if(document.getElementById('error_txt')){
			  document.getElementById('error_txt').innerHTML = "&nbsp;";
			  if(document.getElementById('error_box')){
					document.getElementById('error_box').style.display = "none";
				}
			  resizePage();
		}
	}
	
	return true;
	
}

function closeSearch(clear){
	
	fm = document.search_form;
	fm.search_txt.value  = (clear)?"":last_search;
	fm.search_txt.disabled = false;
	fm.search_btn.value  = "product code"
	fm.search_btn.disabled = false;
	
	
}

var last_search = "";
function searchProduct(keyword){

	last_search = keyword;
	
	fm = document.search_form;
	fm.search_txt.value  = "searching..."
	fm.search_txt.disabled = true;
	fm.search_btn.value  = "..."
	fm.search_btn.disabled = true;
	
	str = str1 = "search_products|"+keyword+"|";
	str = encode64(str);
	document.getElementById('main_frame').src = global_url+"scripts/pages.php?load_catalogue="+str;
	
	
	
	
}


function showSearchResults(clear){
	
	
	fm = document.search_form;
	fm.search_txt.value  = (clear)?"":last_search;
	fm.search_txt.disabled = false;
	fm.search_btn.value  = "product code"
	fm.search_btn.disabled = false;
	
	
	
}



var flash_in = 0;

function flashIn(){
	
	if(flash_disabled == 0){
		  h=flash_frame_h;
		  document.getElementById('flash_frame').style.height = h + "px";
		  document.getElementById('main_content').style.top = document.getElementById('right_content').style.top = h + "px";
		  document.getElementById('main_content').style.borderTop = document.getElementById('right_content').style.borderTop = "1px solid #333333";
		  resizePage();
		  flash_in = 1;
		  loadFlash(flash_load_str);
	}
	
}

var flash_out_h = 0;

function flashOut(){
	
		  h = flash_out_h;
		  document.getElementById('flash_frame').style.height = h + "px";
		  document.getElementById('main_content').style.top = document.getElementById('right_content').style.top = h + "px";
		  
		  if(flash_out_h > 0){
							  
				  flash_in = 1;
				  loadFlash(flash_load_str);
			  
		  }else{
				  flash_in = 0;
				  flash_load_str = "";
				  loadFlash(flash_load_str);
				  document.getElementById('main_content').style.borderTop = document.getElementById('right_content').style.borderTop = "0px solid #333333";
				  
		  }
		  flash_frame_h = flash_out_h;
		  resizePage();
	
}




function featuresIn(){
	
	site_f_width = (site_width == 0) ? parseInt(document.documentElement.clientWidth) : site_width;
	w = right_menu_width;
	document.getElementById('right_content').style.width = w + "px";
	side_w = parseInt(document.getElementById('left_content').style.width);
	document.getElementById('right_content').style.left = (site_f_width +  1-w) + "px";
	document.getElementById('main_content').style.width = (site_f_width - side_w - w) + "px";
	
}



function featuresOut(){
	
	site_f_width = (site_width == 0) ? parseInt(document.documentElement.clientWidth) : site_width;
	option_y = 100;
	w = 0;
	document.getElementById('right_content').style.width = w + "px";
	side_w = parseInt(document.getElementById('left_content').style.width);
	document.getElementById('right_content').style.left = (site_f_width + 1-w) + "px";
	document.getElementById('main_content').style.width = (site_f_width - side_w - w) + "px";
	
}





function sideMenuIn(){
	
	site_f_width = (site_width == 0) ? parseInt(document.documentElement.clientWidth) : site_width;
	w = left_menu_width;
	document.getElementById('left_content').style.width = w + "px";
	document.getElementById('main_content').style.left = (w+1) + "px";
	document.getElementById('flash_frame').style.width = (site_f_width - left_menu_width) + "px";
	document.getElementById('flash_frame').style.left = left_menu_width + "px";
	features_w = parseInt(document.getElementById('right_content').style.width);
	if(right_menu_moving == 1){
		features_w -= 20;
	}
	document.getElementById('main_content').style.width =  (site_f_width - features_w - w) + "px";
}



function sideMenuOut(){
	
	site_f_width = (site_width == 0) ? parseInt(document.documentElement.clientWidth) : site_width;
	menu_y = 100;
	w=0;
	document.getElementById('left_content').style.width = w + "px";
	document.getElementById('main_content').style.left =   (w+1) + "px";
	document.getElementById('flash_frame').style.left = "0px";
	document.getElementById('flash_frame').style.width = site_f_width + "px";
	features_w = parseInt(document.getElementById('right_content').style.width);
	document.getElementById('main_content').style.width = (site_f_width - features_w) + "px";
	
}


var resize_running = 0;

function resizePage(){
	
	
		
		if(resize_running == 0){
			resize_running = 1;
			
			//return false;
			h =  parseInt(document.documentElement.clientHeight) ;
			w =  parseInt(document.documentElement.clientWidth) ;
			w_start = w;
			
			if((document.getElementById('header'))&&(document.getElementById('header').innerHTML == "")){
				//document.getElementById('header').style.height="100px";
			}
			
			if((document.getElementById('background_header_div'))&&(document.getElementById('background_header_div').style.display=='none')){
				document.getElementById('background_header_div').style.display='block';
			}
			
			if((document.getElementById('background_footer_div'))&&(document.getElementById('background_footer_div').style.display=='none')){
				document.getElementById('background_footer_div').style.display='block';
			}
		
			if((document.getElementById('footer_menu'))&&(parseInt(document.getElementById('footer_menu').style.top = -1000))){
				document.getElementById('footer_menu').style.top = "0px";
			}
			
			if(is_IE == 1){//fix for ie
				if(document.getElementById('custom_header')){
					document.getElementById('custom_header').style.width = (w) +"px";
				}
				if(document.getElementById('main_div')){
					document.getElementById('main_div').style.width = (w) +"px";
				}
			}
			
	
			
			try{
				if((site_fixed_height > 0) && (site_float_y == 1)){
					
					t = ( Math.floor((h - site_fixed_height)/2) > 0) ? Math.floor((h - site_fixed_height)/2) : 0;
					
					if(document.getElementById('main_div')){
							document.getElementById('main_div').style.top= (t) +"px";
					}
					
					if(document.getElementById('background_header_div')){
							document.getElementById('background_header_div').style.top= (t) +"px";
					}
					
					
					
				}
				
			}catch(e){
				//alert(1);
			}
			
			
		
			try{
				
				if(site_width == 0){
					
					
					if(document.getElementById('main_page')){
							document.getElementById('main_page').style.width = (w) +"px";
					}
					if(document.getElementById('main_page_back')){
							document.getElementById('main_page_back').style.width = (w) +"px";
					}
					if(document.getElementById('background_header_div')){
							document.getElementById('background_header_div').style.width = (w) +"px";
					}
					
					if(document.getElementById('background_footer_div')){
							document.getElementById('background_footer_div').style.width = (w) +"px";
					}
					
					if(document.getElementById('flash_background')){
							document.getElementById('flash_background').style.width = (w) +"px";
					}
					
					if(document.getElementById('header_img_div')){
							document.getElementById('header_img_div').style.width = (w) +"px";
					}
					
					if(document.getElementById('header')){
							document.getElementById('header').style.width = (w) +"px";
					}
					if(document.getElementById('header_menu')){
							document.getElementById('header_menu').style.width = (w) +"px";
					}
					
					
					
					if(document.getElementById('footer_menu')){
							document.getElementById('footer_menu').style.width = (w) +"px";
					}
					
					
					
					if(document.getElementById('main_menu')){
							document.getElementById('main_menu').style.width = (w) +"px";
					}
					
					
					if(document.getElementById('dropdown_menus')){
						document.getElementById('dropdown_menus').style.left = 0 +"px";
					}
					
					left_w = 0;
					right_w = 0;
					
					if(document.getElementById('left_content')){
						auto = 0;
						if(document.getElementById('left_content').style.overflowY == "auto"){
							document.getElementById('left_content').style.overflowY = "hidden";
							auto = 1;
						}
						left_w = parseInt(document.getElementById('left_content').clientWidth);
						
						if(auto == 1){
							document.getElementById('left_content').style.overflowY = "auto";
						}
					}
					
					if(document.getElementById('right_content')){
						
						auto = 0;
						if(document.getElementById('right_content').style.overflowY == "auto"){
							document.getElementById('right_content').style.overflowY = "hidden";
							auto = 1;
						}
						right_w = parseInt(document.getElementById('right_content').clientWidth);
						if(auto == 1){
							document.getElementById('right_content').style.overflowY = "auto";
						}
					}
					
					m_w = 0;
					
				
					
					if(document.getElementById('main_content')){
							m_w = ((w-left_w-right_w) > 100) ? (w-left_w-right_w) : 100;
							document.getElementById('main_content').style.width = (m_w) +"px";
							//alert(left_w+"r\n"+right_w+"\r\n"+m_w);
					}
					
					if(document.getElementById('right_content')){
						 document.getElementById('right_content').style.left = (m_w + left_w+2) + "px";
					}
					
					
					m_w = 0;
					
	
					if(document.getElementById('flash_frame')){
							m_w = ((w-left_w) > 10) ? (w-left_w) : 10;
							document.getElementById('flash_frame').style.width = (m_w) +"px";
					}
					
					
					
				}else{
					
					if(document.getElementById('dropdown_menus')){
						drop_left = Math.round((w-(site_width+2))/2);
						if(drop_left < 0){ drop_left = 0; }
						
						document.getElementById('dropdown_menus').style.left = drop_left +"px";
					}
											
				
					/*this_w = (w > site_width) ? w : site_width;
					if(document.getElementById('background_header_div')){
							document.getElementById('background_header_div').style.width = (this_w) +"px";
					}
					
					if(document.getElementById('background_footer_div')){
							document.getElementById('background_footer_div').style.width = (this_w) +"px";
					}*/
					
					
				}
				
				
			}catch(e){
			}
			
		
			try{
		
					
					header_h = ((document.getElementById('header'))&&(document.getElementById('header').style.display == "block")) ? parseInt(document.getElementById('header').clientHeight) : 0 ;
					flash_h = (document.getElementById('flash_frame')) ? parseInt(document.getElementById('flash_frame').style.height):0 ;
					flash_h += (document.getElementById('flash_frame')) ? parseInt(document.getElementById('flash_frame').style.top):0 ;
					header_menu_h = ((document.getElementById('header_menu'))&&(document.getElementById('header_menu').style.display == "block")) ? parseInt(document.getElementById('header_menu').style.height) : 0;
					
					if(document.getElementById('main_content')){
						document.getElementById('main_content').style.display = "block";
						page_y = parseInt(document.getElementById('main_content').clientHeight)+20;
						
						 

					}
					
					if((document.getElementById('main_page_back')) && (document.getElementById('main_page_back').style.display == "none")){
						document.getElementById('main_page_back').style.display = "block";
					}
					
					if(document.getElementById('left_content')){
						 menu_y = parseInt(document.getElementById('left_content').clientHeight) + 20;
					}
					
					if(document.getElementById('right_content')){
						 option_y = parseInt(document.getElementById('right_content').clientHeight)+20;
					}
					
					footer_h = 0;
					if(document.getElementById('footer_menu')){
						 footer_h = parseInt(document.getElementById('footer_menu').clientHeight);
					}
					
					if(document.getElementById('main_content')){
						document.getElementById('main_content').style.overflowX = (main_overflow_x == 1) ? "auto" : "hidden";
					}
					
					if(document.getElementById('right_content')){
						document.getElementById('right_content').style.overflowX = (right_overflow_x == 1) ? "auto" : "hidden";
					}
					
					if(document.getElementById('left_content')){
						document.getElementById('left_content').style.overflowX = (left_overflow_x == 1) ? "auto" : "hidden";
					}
					
					
					
					if(site_fixed_height == 0){
					
							
							this_page_y = page_y+flash_h;
							this_option_y = option_y + flash_h;
							
							t_y = (menu_y > this_page_y)? menu_y : this_page_y;
							t_y = (this_option_y > t_y)? this_option_y : t_y;
							
							//alert("page_y:"+this_page_y+"\r\nmenu_y:"+menu_y+"\r\noption_y:"+this_option_y+"\r\nt_y:"+t_y+"\r\n(h - header_h  - footer_h):"+(h - header_h  - footer_h));
							
						
							
							if((t_y ) > (h - header_h - header_menu_h  - footer_h)){
								
									h1 = (t_y - flash_h - footer_h) ;
					
									h2 = (t_y  );
								
									h3 = (t_y - 1);
									
									if(document.getElementById('main_page')){
										document.getElementById('main_page').style.height = (t_y) +"px";
									}
									
									if(document.getElementById('dropdown_menus')){
										document.getElementById('dropdown_menus').style.top = (header_h + header_menu_h) +"px";
									}
									
									if(document.getElementById('main_page_back')){
										
										main_page_back_h = t_y  + header_h + header_menu_h + footer_h+ 4;
										main_page_back_t = 0;
										if(page_back_img_below_header >0){
											main_page_back_h -= header_h;
											main_page_back_t += header_h;
										}
										if((page_back_img_below_header ==2)&&(document.getElementById('main_menu'))){
											main_page_back_h -= header_menu_h;
											main_page_back_t += header_menu_h;
										}
										
										document.getElementById('main_page_back').style.height = main_page_back_h +"px";
										document.getElementById('main_page_back').style.top = main_page_back_t +"px";
									}
									
									
									if(document.getElementById('background_shadow_left')){
										document.getElementById('background_shadow_left').style.height = (t_y  + header_h + header_menu_h  + footer_h + 4) +"px";
									}
									if(document.getElementById('background_shadow_right')){
										document.getElementById('background_shadow_right').style.height = (t_y  + header_h + header_menu_h  + footer_h + 4) +"px";
										document.getElementById('background_shadow_left').style.display = document.getElementById('background_shadow_right').style.display = ((w >= (site_width+22)) && (site_width > 0)) ? "block":"none";
									}
									
									if(document.getElementById('flash_background')){
										document.getElementById('flash_background').style.height = (t_y  + header_h + header_menu_h  + footer_h+ 4) +"px";
									}
									if(document.getElementById('header_img_div')){
										document.getElementById('header_img_div').style.height = ((t_y  + header_h + header_menu_h  + footer_h+ 4) - parseInt(document.getElementById('header_img_div').style.top))  +"px";
									}
									
									if(document.getElementById('background_header_div')){
										document.getElementById('background_header_div').style.height = (t_y  + header_h + header_menu_h  + footer_h+ 4) +"px";
									}
									
									
									if(document.getElementById('background_footer_div')){
										document.getElementById('background_footer_div').style.height =(t_y  + header_h + header_menu_h  + footer_h+ 4) +"px";
										document.getElementById('background_footer_div').style.top = (0)  +"px";
									}
									
									
									if(document.getElementById('disable_page')){
										document.getElementById('disable_page').style.height = (t_y  + header_h + header_menu_h  + footer_h+ 4) +"px";
									}
									
									if(document.getElementById('lbOverlay')){
										document.getElementById('lbOverlay').style.top = "0px";
										document.getElementById('lbOverlay').style.height = (t_y  + header_h + header_menu_h  + footer_h+ 4) +"px";
										if((is_IE == 1) && ((t_y  + header_h + header_menu_h  + footer_h+ 4) > 1500)){
											document.getElementById('lbOverlay').style.backgroundImage= "url("+global_url+"images/black-trans.png)";
											document.getElementById('lbOverlay').style.backgroundColor = "transparent";
											
										}else{
											document.getElementById('lbOverlay').style.backgroundImage="none";
											document.getElementById('lbOverlay').style.backgroundColor = "#000";
										}
									}
								
							}else{
									
									h1 = (h-header_h-footer_h - header_menu_h  - flash_h);
									if(h1 < 10){h1=10;};
							
									h2 = (h-header_h - header_menu_h -footer_h);
									if(h2 < 10){h2=10;};
							
									h3 = (h-header_h- header_menu_h -101 - footer_h - flash_h);
									if(h3 < 10){h3=10;};
									
								
									
									if(document.getElementById('main_page')){
										document.getElementById('main_page').style.height = (h2-4) +"px";
										
									}
									
									if(document.getElementById('dropdown_menus')){
										document.getElementById('dropdown_menus').style.top = (header_h + header_menu_h) +"px";
									}
									
									if(document.getElementById('main_page_back')){
										main_page_back_h = h;
										main_page_back_t = 0;
										if(page_back_img_below_header >0){
											main_page_back_h -= header_h;
											main_page_back_t += header_h;
										}
										
										if((page_back_img_below_header ==2)&&(document.getElementById('main_menu'))){
											
											main_page_back_h -= header_menu_h;
											main_page_back_t += header_menu_h;
										}
										

										document.getElementById('main_page_back').style.height = main_page_back_h +"px";
										document.getElementById('main_page_back').style.top = main_page_back_t +"px";
										
									}
									
									
									if(document.getElementById('background_shadow_left')){
										document.getElementById('background_shadow_left').style.height = (h) +"px";
									}
									if(document.getElementById('background_shadow_right')){
										document.getElementById('background_shadow_right').style.height = (h) +"px";
										document.getElementById('background_shadow_left').style.display = document.getElementById('background_shadow_right').style.display = ((w >= (site_width+22)) && (site_width > 0)) ? "block":"none";
									}
									
									
									if(document.getElementById('header_img_div')){
										document.getElementById('header_img_div').style.height =  ((h)- parseInt(document.getElementById('header_img_div').style.top)) +"px";
									}
									
									if(document.getElementById('background_header_div')){
										document.getElementById('background_header_div').style.height = "100%";
									}
									
									if(document.getElementById('background_footer_div')){
										document.getElementById('background_footer_div').style.height = "100%";
									}
									
									if(document.getElementById('flash_background')){
										document.getElementById('flash_background').style.height = "100%"
									}
									
									
									if(document.getElementById('disable_page')){
										document.getElementById('disable_page').style.height = (h) +"px";
									}
									
									if(document.getElementById('lbOverlay')){
										document.getElementById('lbOverlay').style.top = "0px";
										document.getElementById('lbOverlay').style.height = (h) +"px";
										if((is_IE == 1) && (h > 1500)){
											document.getElementById('lbOverlay').style.backgroundImage= "url("+global_url+"images/black-trans.png)";
											document.getElementById('lbOverlay').style.backgroundColor = "transparent";
											
										}else{
											document.getElementById('lbOverlay').style.backgroundImage="none";
											document.getElementById('lbOverlay').style.backgroundColor = "#000";
										}
									}
									
									
									
									
							}
					
					
					}else{			
									body_h = h;
									h = site_fixed_height;
									//check min size of main content
									min_size = h-flash_h-footer_h-50;
									if(min_size < 50){
										
										//check flash_h and close if needed
										if(flash_h>0){
											
											flash_disabled =1;
											flash_out_h =0;
											
											if(window['flash_out']){
												clearTimeout(window['flash_out']);
											}
											if(window['flash_in']){
												clearTimeout(window['flash_in']);
											}
											flashOut();
										
											flash_h = 0;
											
											min_size = h-header_h-flash_h-header_menu_h-footer_h-50;
											
											
											if(min_size < 50){
												site_fixed_height = h + Math.abs(min_size) + 50;
											}
										}
									}
									
								
									if(site_float == 1){
										h_top = Math.round((body_h - h)/2);
										if(h_top < 0){ h_top = 0; }
									}else{
										h_top = 0;
									}
									
									if(site_float == 2){
										
											var page_border = (document.getElementById('main_page_back')) ? parseInt(document.getElementById('main_page_back').style.borderTopWidth) : 0;
											
											if(document.getElementById('main_content')){
												document.getElementById('main_content').style.top  = (flash_h>0) ? flash_h+"px" : page_border+"px";
												//document.getElementById('main_content').style.overflowY = (main_overflow_y == 1) ? "auto" : "hidden";
												document.getElementById('main_content').style.height = (h-header_menu_h-flash_h) +"px";
											}
											
											if(document.getElementById('right_content')){
												document.getElementById('right_content').style.top  = (flash_h>0) ? flash_h+"px" : page_border+"px";
												//document.getElementById('right_content').style.overflowY = (right_overflow_y == 1) ? "auto" : "hidden";
												document.getElementById('right_content').style.height =  (h-header_menu_h-flash_h) +"px";
											}
											
											if(document.getElementById('left_content')){
												document.getElementById('left_content').style.top =  page_border+"px";
												//document.getElementById('left_content').style.overflowY = (left_overflow_y == 1) ? "auto" : "hidden";
												document.getElementById('left_content').style.height = (h-header_menu_h) +"px";
												
											}
											
											
											if(document.getElementById('main_page')){
												document.getElementById('main_page').style.height = (h-header_menu_h-2) +"px";
												document.getElementById('main_page').style.top = 0 + "px";
											}
											
											if(document.getElementById('dropdown_menus')){
												document.getElementById('dropdown_menus').style.top = (header_h + header_menu_h) +"px";
											}
											
											
										
											
											
											if(document.getElementById('main_page_back')){
												document.getElementById('main_page_back').style.top = header_h + "px";
												document.getElementById('main_page_back').style.height = (h) +"px";
											}
										
									}else{
									
											if(document.getElementById('main_content')){
												document.getElementById('main_content').style.top  = (flash_h>0) ? flash_h+"px" : page_border+"px";
												//document.getElementById('main_content').style.overflowY = (main_overflow_y == 1) ? "auto" : "hidden";
												document.getElementById('main_content').style.height = (h-header_h-header_menu_h-flash_h) +"px";
											}
											
											if(document.getElementById('right_content')){
												document.getElementById('right_content').style.top  =  (flash_h>0) ? flash_h+"px" : page_border+"px";
												//document.getElementById('right_content').style.overflowY = (right_overflow_y == 1) ? "auto" : "hidden";
												document.getElementById('right_content').style.height = (h-header_h-header_menu_h-flash_h) +"px";
											}
											
											if(document.getElementById('left_content')){
												document.getElementById('left_content').style.top =  page_border+"px";
												//document.getElementById('left_content').style.overflowY = (left_overflow_y == 1) ? "auto" : "hidden";
												document.getElementById('left_content').style.height =  (h-header_h-header_menu_h) +"px";
												
											}
											
											if(document.getElementById('main_page')){
												document.getElementById('main_page').style.height = (h-header_h-header_menu_h-2) +"px";
												document.getElementById('main_page').style.top = 0 + "px";
											}
											
											if(document.getElementById('dropdown_menus')){
												document.getElementById('dropdown_menus').style.top = (0- (h-header_h-2)) +"px";
											}
									
											
											if(document.getElementById('main_page_back')){
												document.getElementById('main_page_back').style.top = h_top + "px";
												document.getElementById('main_page_back').style.height = (h) +"px";
											}
													
									
									}
									
									
									
									
									
									
									
									if(document.getElementById('flash_background')){
										document.getElementById('flash_background').style.height = (h) +"px";
									}
									
									if(document.getElementById('disable_page')){
										h2 = (parseInt(document.documentElement.clientHeight) > h) ? parseInt(document.documentElement.clientHeight) : h;
										document.getElementById('disable_page').style.height = (h2) +"px";
									}
									
									if(document.getElementById('lbOverlay')){
										h2 = (parseInt(document.documentElement.clientHeight) > h) ? parseInt(document.documentElement.clientHeight) : h;
										document.getElementById('lbOverlay').style.top = "0px";
										document.getElementById('lbOverlay').style.height = (h2) +"px";
										if((is_IE == 1) && (h2 > 1500)){
											document.getElementById('lbOverlay').style.backgroundImage= "url("+global_url+"images/black-trans.png)";
											document.getElementById('lbOverlay').style.backgroundColor = "transparent";
										}else{
											document.getElementById('lbOverlay').style.backgroundImage="none";
											document.getElementById('lbOverlay').style.backgroundColor = "#000";
										}
									}
										
									if(document.getElementById('header_img_div')){
										document.getElementById('header_img_div').style.top = h_top + "px";
										document.getElementById('header_img_div').style.height =  (h+header_h) +"px";
									}
									
									
									if(document.getElementById('background_shadow_left')){
										document.getElementById('background_shadow_left').style.top = h_top + "px";
										document.getElementById('background_shadow_left').style.height = (h) +"px";
									}
									if(document.getElementById('background_shadow_right')){
										document.getElementById('background_shadow_right').style.top = h_top + "px";
										document.getElementById('background_shadow_right').style.height = (h) +"px";
										document.getElementById('background_shadow_left').style.display = document.getElementById('background_shadow_right').style.display = ((w >= (site_width+22)) && (site_width > 0)) ? "block":"none";
									}
									
									h += header_h + footer_h;
									back_h = (body_h > h) ? body_h : h;
									if(document.getElementById('background_header_div')){
										document.getElementById('background_header_div').style.height = (back_h) +"px";
										document.getElementById('background_header_div').style.top = (0)  +"px";
									}
									
									if(document.getElementById('background_footer_div')){
										document.getElementById('background_footer_div').style.height = (back_h) +"px";
										document.getElementById('background_footer_div').style.top = (0)  +"px";
									}
									
								
					}
					
					
					
					
			
			}catch(e){
			}
			
			
			try{
				
				if(document.getElementById('page_logo') && (document.getElementById('page_logo').style.display != "block")){
						document.getElementById('page_logo').style.display = "block";
				}
				
			}catch(e){
			}
			resize_running = 0;
			//fix for IE
			w = parseInt(document.documentElement.clientWidth);
			if(w != w_start){
				resizePage();
			}
		}
	
		

}


var submenu_left = menu_width;
var submenu_width = menu_width;

var menu_image_height = 200;
var submenu_height = menu_image_height;
var submenu_top = 0;

var item_menu_left = menu_width * 2;
var item_menu_width = 400;
var item_menu_height = menu_image_height;
var disable_item_out = 0;
var disable_sub_out = 0;


var last_goto = 0;

function shopCheckOut(){
	window.location.href = s_global_url + "checkout";
}

function viewBasket(){
	window.location.href = s_global_url + "basket";
}

function getBasket(){
	document.getElementById('process_frame').src = global_url+"scripts/catalogue.php?getBasket";
}

function memberLogin(type,details,reload_page,is_member,is_logged_in){
	try{
		closeLightBox();
	}catch(lb_err){
	}
	//alert(type+"\r\n"+details+"\r\n"+reload_page+"\r\n"+is_member+"\r\n"+is_logged_in);
	if(mem_allow_logon == 1){
		if(type == 0){
				
			expireDate = new Date;
			expireDate.setMonth(expireDate.getMonth()-6);
			expires = expireDate.toGMTString();
			document.cookie = "m_details=;expires="+expires+";path=/";
			document.cookie = "is_logged_in=;expires="+expires+";path=/";
			document.cookie = "is_member=;expires="+expires+";path=/";
			
			if(Math.abs(reload_page) == 1){
				rtnHome();
				//window.location.href = s_global_url+mem_logon_text.toLowerCase();
			}else{
				memberStatus(0,0,'');
			}
		}
		
		if(type == 1){
			current_page = "/scripts/members.php";
			document.getElementById('main_frame').src = global_url+"scripts/members.php?1";
		}
		
		if(type == 2){
			
			d = decode64(details);
			d_arr = d.split("|");
			if(d_arr.length >= 5){
				
				member_name = decode64(d_arr[0]);
				expireDate = new Date;
				expireDate.setMonth(expireDate.getMonth()+3);
				expires = expireDate.toGMTString();
				document.cookie = "m_details="+details+";expires="+expires+";path=/";
				document.cookie = "is_member=1;expires="+expires+";path=/";
				expireDate = new Date;
				expireDate.setMinutes(expireDate.getMinutes()+120);
				expires = expireDate.toGMTString();
				document.cookie = "is_logged_in=1;expires="+expires+";path=/";
				
				memberStatus(1,1,member_name);
				
				if(Math.abs(reload_page) == 1){
					if(current_page != ""){
						src = global_url+current_page.substr(1);
						top.window.location.href = src;
					}else{
						var loc = top.window.document.location+"";
						top.window.location.href = loc;
					}
				}
				
			}else{
				memberStatus(0,0,'');
				if(Math.abs(reload_page) == 1){
					if(current_page != ""){
						src = global_url+current_page.substr(1);
						top.window.location.href = src;
					}else{
						var loc = top.window.document.location+"";
						top.window.location.href = loc;
					}
				}
			}
		
			
		}
		
		if(type == 3){ //update details
			
			d = decode64(details);
			d_arr = d.split("|");
			if(d_arr.length >= 5){
				member_name = decode64(d_arr[0]);
				expireDate = new Date;
				expireDate.setMonth(expireDate.getMonth()+3);
				expires = expireDate.toGMTString();
				document.cookie = "m_details="+details+";expires="+expires+";path=/";
				document.cookie = "is_member="+is_member+";expires="+expires+";path=/";
				expireDate = new Date;
				expireDate.setMinutes(expireDate.getMinutes()+120);
				expires = expireDate.toGMTString();
				document.cookie = "is_logged_in="+is_logged_in+";expires="+expires+";path=/";
				memberStatus(is_member,is_logged_in,member_name);
			
			}else{
				memberStatus(0,0,'');
			}
			
		}
		
		if(type == 4){
			current_page = "/scripts/members.php";
			document.getElementById('main_frame').src = global_url+"scripts/members.php?2";
		}
		

	
	}
	
	
}

var mem_logon_text = "Your Account";
var mem_logon_text_dir = "Your Account";

function memberStatus(is_member,is_logged_in,member_name){
	
	//alert(is_member+"\r\n"+is_logged_in+"\r\n"+member_name);
	if(mem_allow_logon == 1){
		
		div = document.getElementById('main_frame');
		
		txt = "";
		if(is_member == 1){
			txt = "Welcome "+member_name;
		}
		if((is_logged_in == 0)&&(div)){
			//txt += "<a href=\"#"+mem_logon_text+"\" onmouseover=\"javascript:this.style.cursor='pointer';\" onclick=\"javascript:memberLogin(1);\">";
			txt += "<a href=\""+s_global_url+mem_logon_text_dir.toLowerCase()+"\">";
			txt += (is_member == 1)? "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;"+mem_logon_text : mem_logon_text;
			txt += "</a>";
		}else if(is_member == 1){
			if(div){
				txt += "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\""+s_global_url+mem_logon_text_dir.toLowerCase()+"\">"+mem_logon_text+"</a>";
			}
			if(is_logged_in == 1){
				txt += "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href=\"#\" onclick=\"javascript:memberLogin(0,'',1);\">Sign&nbsp;Out</a>";
			}else if(!div){
				txt += "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;You are not signed in.";
			}
		}
		
		updateLogOnTxt(txt);
	}
	
}

var log_txt = "";
function updateLogOnTxt(txt){
	
	if(document.getElementById('logon_status_txt')){
		try{
		document.getElementById('logon_status_txt').innerHTML = txt;
		}catch(e){
		}
	}
	
}



function start(){
	/*expireDate = new Date;
	expireDate.setMonth(expireDate.getMonth()-2);
	parent.document.cookie = "search_catalogue_order=;expires="+expireDate.toGMTString()+";path=/";
	*/
	
	if(is_IE == 1){
		document.body.scroll = "yes";
	}
	//clearSearchOptions();
	updatePrintDiv();
	
	try{
		onPageComplete();
	}catch(e){
		//alert(e);
	}
	
	
	//document.getElementById('main_content').style.display = "block";
	//document.getElementById('left_content').style.display = "block";
	//document.getElementById('right_content').style.display = "block";
	//document.getElementById('flash_frame').style.display = "block";
	resizePage();
	
	if(mem_allow_logon == 1){
		document.getElementById('logon_frame').src = global_url+"scripts/members.php?checklogon";
	}
	if(can_get_basket == 1){
		document.getElementById('process_frame').src = global_url+"scripts/catalogue.php?getBasket";
	}
	
	if(page_images.length > 0){
		loadOtherImages();
	}
	
		
}

var default_bg_top_img = "";
var default_bg_bottom_img = "";
var default_pg_border_color = ""; 
var default_menu_border_color = "";
var default_menu_font_color = "";
var current_menu_font_color = "";

function setThemeDefaults(){
	if(document.getElementById('background_header_div')){
		default_bg_top_img = document.getElementById('background_header_div').style.backgroundImage;
	}
	if(document.getElementById('background_footer_div')){
		default_bg_bottom_img = document.getElementById('background_footer_div').style.backgroundImage;
	}
	if(document.getElementById('main_page_back')){
		if(document.getElementById('main_page_back').style.borderColor){
			default_pg_border_color = document.getElementById('main_page_back').style.borderColor;
		}else if(document.getElementById('main_page_back').style.borderTopColor){
			default_pg_border_color = document.getElementById('main_page_back').style.borderTopColor;
		}else if(document.getElementById('main_page_back').style.borderBottomColor){
			default_pg_border_color = document.getElementById('main_page_back').style.borderBottomColor;
		}else if(document.getElementById('main_page_back').style.borderLeftColor){
			default_pg_border_color = document.getElementById('main_page_back').style.borderLeftColor;
		}else if(document.getElementById('main_page_back').style.borderRightColor){
			default_pg_border_color = document.getElementById('main_page_back').style.borderRightColor;
		}
	}
	
	if(document.getElementById('header_menu')){
		if(document.getElementById('header_menu').style.borderColor){
			default_menu_border_color = document.getElementById('header_menu').style.borderColor;
		}else if(document.getElementById('header_menu').style.borderTopColor){
			default_menu_border_color = document.getElementById('header_menu').style.borderTopColor;
		}else if(document.getElementById('header_menu').style.borderBottomColor){
			default_menu_border_color = document.getElementById('header_menu').style.borderBottomColor;
		}else if(document.getElementById('header_menu').style.borderLeftColor){
			default_menu_border_color = document.getElementById('header_menu').style.borderLeftColor;
		}else if(document.getElementById('header_menu').style.borderRightColor){
			default_menu_border_color = document.getElementById('header_menu').style.borderRightColor;
		}
	}
	
	if(total_btns > 0){
		for(i=1;i<(total_btns+1);i++){
			if(document.getElementById('main_btn_'+i)){
				default_menu_font_color = current_menu_font_color = document.getElementById('main_btn_'+i).style.color;
				break;
			}
		}
	}
	
	
}


function updateTheme(bg_top_img,bg_bottom_img,pg_border_color,menu_border_color,menu_font_color){
	
	current_menu_font_color = (menu_font_color != "") ? menu_font_color : default_menu_font_color;
	
	if(document.getElementById('background_header_div')){
		if(bg_top_img == "none"){
			document.getElementById('background_header_div').style.backgroundImage ="none";
		}else{
			document.getElementById('background_header_div').style.backgroundImage = (bg_top_img != "") ? "url("+bg_top_img+")" : default_bg_top_img;
		}
	}
	if(document.getElementById('background_footer_div')){
		if(bg_bottom_img == "none"){
			document.getElementById('background_footer_div').style.backgroundImage ="none";
		}else{
			document.getElementById('background_footer_div').style.backgroundImage = (bg_bottom_img != "") ? "url("+bg_bottom_img+")" : default_bg_bottom_img;
		}
	}
	if(document.getElementById('main_page_back')){
		obj = document.getElementById('main_page_back').style;
		obj.borderColor=obj.borderTopColor=obj.borderBottomColor=obj.borderLeftColor=obj.borderRightColor= (pg_border_color != "") ? pg_border_color : default_pg_border_color;
	}
	if(document.getElementById('header_menu')){
		obj = document.getElementById('header_menu').style;
		obj.borderColor=obj.borderTopColor=obj.borderBottomColor=obj.borderLeftColor=obj.borderRightColor= (menu_border_color != "") ? menu_border_color : default_menu_border_color;
	}
	if(total_btns > 0){
		for(i=1;i<(total_btns+1);i++){
			if(document.getElementById('main_btn_'+i)){
				document.getElementById('main_btn_'+i).style.color = (menu_font_color != "") ? menu_font_color : default_menu_font_color;
			}
		}
	}
	
}

var menu_dif = 0;
var menu_z = 0;



function loadTopPage(p){
	top.location.href=p;
}
function loadPage(p){
	closeAllMenus();
	moveCalender(-2000,-2000);
	showLoading();
	document.getElementById('main_frame').src = p;

	try{
		document.getElementById('main_frame').focus();
	}catch(e){
	}
	
}

function loadPageJS(p){
	closeAllMenus();
	moveCalender(-2000,-2000);
	showLoading();
	document.getElementById('main_frame').src = p;
	try{
		document.getElementById('main_frame').focus();
	}catch(e){
	}
	
}

function loadPageNum(p){
	closeAllMenus();
	moveCalender(-2000,-2000);
	showLoading();
	document.getElementById('main_frame').src = global_url+"scripts/pages.php?p="+p;
	
	try{
		document.getElementById('main_frame').focus();
	}catch(e){
	}
	
}


function loadMemberPageNum(p){
	closeAllMenus();
	moveCalender(-2000,-2000);
	showLoading();
	document.getElementById('main_frame').src = global_url+"scripts/members.php?p="+p;
	
	try{
		document.getElementById('main_frame').focus();
	}catch(e){
	}
	
}

function checkMenuOut(m){
	
	if(window[m+'out']){
		clearTimeout(window[m+'out']);
	}
	window[m+'out'] = setTimeout("menuOut('"+m+"')",250);
		
}

function clearMenuOut(m){

	if(window[m+'out']){
		clearTimeout(window[m+'out']);
	}
}

function reloadMenu(mod){
	
	if(mod!=current_module){
		current_module = mod;
		menu_height_array = Array();
		document.getElementById('dropdown_menus').innerHTML = "";
		document.getElementById('main_menu').innerHTML = "<div style=\"font-size:5px;\">&nbsp</div><div style=\"width:100%;text-align:center;\" id=\"menu_loading_txt\">loading menu...</div>";
		document.getElementById('process_frame').src = global_url+"scripts/menu.php?main|"+encode64(mod)+"|"+encode64(current_menu_font_color+"");
	}
	
}

function createMenu(menu_table_enc,menu_enc,main_menu_back_width,main_menu_width,main_menu_left,t_btns,btn_width){
	
	total_btns = total_menus = t_btns;
	menu_width = btn_width;
	document.getElementById('main_menu').style.left = main_menu_left +"px";
	document.getElementById('main_menu').innerHTML = decode64(menu_table_enc);
	document.getElementById('dropdown_menus').innerHTML = decode64(menu_enc);
	
}


var menu_max_height = 550;
var menu_height_array = Array();
var menu_width_array = Array();

function menuIn(m){

	abort = 0
	
	if(document.getElementById('main_btn_'+m)){
	
		num = Math.abs(m);
		site_f_width = (site_width == 0) ? parseInt(document.documentElement.clientWidth) : site_width;
		
				//update btn background
		checkMainBtnOver(m);
		closeAllMenus(m);
		
		try{
			if(document.getElementById('menu_'+m)){
					if(!menu_height_array[num]){
		
						this_l = document.getElementById('menu_'+m).style.left;
						document.getElementById('menu_'+m).style.left = "-2000px";
						document.getElementById('menu_'+m).style.top = "-6000px";
						document.getElementById('menu_'+m).style.display = "block";
						
						this_div = document.getElementById('menu_content_'+num);
						if(this_div){
								d_w = parseInt(this_div.clientWidth);
								d_h = parseInt(this_div.clientHeight);
								menu_height_array[num] = d_h;
								menu_width_array[num] = d_w;
								if(document.getElementById("menu_shadow_"+num)){
									document.getElementById("menu_shadow_"+num).style.width = d_w +"px"; 
								}
								document.getElementById('menu_'+m).style.display = "none";
								document.getElementById('menu_'+m).style.left = ((parseInt(this_l) + d_w) < (menu_width * total_menus)) ?  this_l : parseInt(this_l) + num + ((menu_width * total_menus) - (parseInt(this_l) + d_w)) + "px"; 
								document.getElementById('menu_'+m).style.top = "0px";
						}else{
							abort = 1;
						}
		
					}
		
					if(abort == 0){
		
							menu_z ++;
							document.getElementById('menu_'+m).style.zIndex = menu_z;
	
							height = menu_height_array[num];	
							
							//fixed for IE7
							var html = "OK";
							try{
								var elements = document.getElementsByName('dd_menu_links');
								html = elements[(num-1)].innerHTML;
							}catch(html_err){
							}
										
							//if(menu_can_move == 0){
		
										if((height > dropdown_min_height)&&(html != "")){
											
													h = height;
													//work out left
													
													l = parseInt(document.getElementById('main_menu').style.left) + dropdown_menu_left_offset;
													if(m > 1){
														l +=1;
													}
													for(b=1;b<(num);b++){
														this_w = parseInt(document.getElementById("main_btn_"+b).clientWidth)
														l +=this_w;
														if(b > 1){
															l+=main_menu_btn_spacing;
														}
													}
		
													//l = parseInt(document.getElementById(m).style.left);
													w = menu_width_array[num];
		
													//avail = parseInt(document.documentElement.clientWidth) - (((parseInt(document.documentElement.clientWidth)-site_f_width) / 2) + l);
													avail = site_f_width - l;
												
													if(avail < w){
														document.getElementById('menu_'+m).style.left = (l - (w - avail) - 1) + "px";
													}else{
														document.getElementById('menu_'+m).style.left = (l) + "px";
													}
													if(document.getElementById("menu_shadow_"+num)){
														document.getElementById("menu_shadow_"+num).style.height = (h+4) + "px";
													}
													document.getElementById('menu_'+m).style.display = "block";
													
													process_menu = null;
													process_height = 0;
		
		
										}
		
							//}
							
		
					}else{
		
								process_menu = null;
								process_height = 0;
					}
			}else{
				//menu doesn't exist
			}
		
		}catch(err){
			alert(err);
		}
		
	
	}
	
	
}
var closeAll = 0;
var current_menu = 0;

function closeAllMenus(menu){
		
		for(i=1;i<=total_menus;i++){
			this_m = "menu_"+(i);
			if(document.getElementById(this_m)){
					
					if((menu) && (menu == i)){
					}else if(current_menu == (i)){
					}else{
						menuOut(i);
					}
			}		
			
		}
	
}



function menuOut(m,debug){

	if(debug){
		
	}
	if(window[m+'out']){
		clearTimeout(window[m+'out']);
	}
	checkMainBtnOut(m);
	if(document.getElementById('menu_'+m)){
				document.getElementById('menu_'+m).style.display = "none";
				process_menu = null;
				process_height = 0;
	}
	
}


function checkMainBtnOver(id){
		for(i=1;i<=total_btns;i++){		
				if(i != id){
					 checkMainBtnOut(i);
				}
		}
		try{
			if(document.getElementById('main_btn_'+id)&&(document.getElementById('main_btn_'+id).className != "main_menu_selected")){
				w = parseInt(document.getElementById('main_btn_'+id).clientWidth);
				x = 0 - 200 - Math.floor((200 - w)/2);
				document.getElementById('main_btn_'+id).style.backgroundPosition = x+"px 0px ";
			}
		}catch(btn_e){
		}
}

function checkMainBtnOut(id){
	try{
		if(document.getElementById('main_btn_'+id)&&(document.getElementById('main_btn_'+id).className != "main_menu_selected")){
			var w = parseInt(document.getElementById('main_btn_'+id).clientWidth);
			var x = 0 - Math.floor((200 - w)/2);
			document.getElementById('main_btn_'+id).style.backgroundPosition = x+"px 0px";
		}
	}catch(btn_e){
	}
}


var current_date_div = null;
var calender_left = -2000;
var calender_top = -2000;
function showCalender(field,left,top,dateMin,dateMax,startdate,div){
		
		value = field.value;
		current_date_div = (div) ? div : null;
		current_date_field  = field;
		
		if((value == "")&&(startdate)){
			value = startdate;
		}
		
		calender_left = left;
		calender_top  = top;
		document.getElementById('calender_frame').src = global_url+"admin/calendar_popup.php?field="+field+"&value="+value+"&date_min="+dateMin+"&date_max="+dateMax;

}

function moveCalender(left,top){
		
		document.getElementById('calender').style.left = left +"px";
		document.getElementById('calender').style.top = top +"px";
	
}

function formatDate(div,date){
	if(div){
		date_arr = date.split("-");
		div.innerHTML = ((date == "")||(date == "0000-00-00")) ? "&nbsp" : date_arr[2]+" "+date_arr[1]+" "+date_arr[0];
	}
}


function updateDiv(date){
	
	if(current_date_div){
		formatDate(current_date_div,date);
	}
	
}

function checkOver(btn){
	
		btn.className = btn.className +"_over";
		btn.style.cursor='pointer';
		
}

function checkOut(btn){
	
	re = /_over/gi;
	if(btn.className.match(re)){
		newClass = btn.className.replace(re,"");
		btn.className = newClass;
	}
	btn.style.cursor='default';
	
}


function getCookieValue(cookieName){
	
	theCookie=""+document.cookie;
	
	ind=theCookie.indexOf(cookieName);
 	if (ind==-1 || cookieName=="") {
			val = "";
	}else{
 			ind1=theCookie.indexOf(';',ind);
 			if (ind1==-1) {
				ind1=theCookie.length; 
			}
			val =  unescape(theCookie.substring(ind+cookieName.length+1,ind1));
			
	}
	
	if(val == ";"){
		val = "";
	}
	
	return val;
	
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function urlencode (str) {
    
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
                ret += '%20'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}


var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}


//image transitions function

var cache_page_images = new Array();

var current_image = 0;
var current_image_url = global_url+"images/trans.gif";
var image_change_delay = (is_IE)? 14 * 1000  : 10 * 1000; // 10 seconds
var inital_image_change_delay = 5 * 1000; // 7 seconds
var divid = "main_page_back";
var imageid = "main_page_back_img";
function loadOtherImages() {
	
	if(page_images.length > 1){
				
		var d = new Date();
		var before;
		var after;
		var j = 0;
		var start_swap_img = 0;
		for (var i=0;i<page_images.length;i++)
		{
			d = new Date();
			before = d.getTime();
			if(j==0){
				changeOpac(0, imageid);
				if(document.getElementById(imageid).src != global_url+"images/" + page_images[i]){
					document.getElementById(imageid).src = current_image_url;
					blendimage(divid, imageid, global_url+"images/" + page_images[i], 2500) ;
				}else{
					document.getElementById(imageid).src  = global_url+"images/" + page_images[i] ;
					start_swap_img = 1;
					current_image_url = global_url+"images/" + page_images[i];
				}
			}
	
			cache_page_images[j] = new Image();
			cache_page_images[j].src = global_url+"images/" + page_images[i];
			
			d = new Date();
			after = d.getTime();
	
			// don't bother if it takes too long
			if ((after - before) >  5000) break;
			j++;
		}
		
		if(start_swap_img == 1){
			if(window['image_changer']){
				clearTimeout(window['image_changer']);
			}
			window['image_changer'] = setTimeout("swapImage()",inital_image_change_delay);
		}
	
	}else{
		document.getElementById(imageid).src  = global_url+"images/" + page_images[0] ;
		current_image_url = global_url+"images/" + page_images[0];
	}
	//swapImage();
}


function clearSwapImages(){
	
	if(window['image_changer']){
		clearTimeout(window['image_changer']);
	}
	for(i = 0; i <= 100; i++) { 
		if(window['opt_'+i]){
			clearTimeout(window['opt_'+i]);
		}
	}
	if((imageid)&&(document.getElementById(imageid))){
		changeOpac(0, imageid);
		document.getElementById(imageid).src = current_image_url;
		document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
	}
	image_changer = null;
	page_images = new Array();
	cache_page_images = new Array();
	current_image = 0;
	
}
var next_img = 0;
function swapImage() 
{
	
	if(window['image_changer']){
		clearTimeout(window['image_changer']);
	}
	
	for(i = 0; i <= 100; i++) { 
		if(window['opt_'+i]){
			clearTimeout(window['opt_'+i]);
		}
	}
	
	var n = cache_page_images.length;

	if(gallery_background_random == 1){
			do 
			{	
					i = Math.floor(Math.random() * n);
			} 
			while (!cache_page_images[i] || (i == current_image && n > 1));
	
	}else{
			i = Math.abs(next_img) + 1;
			if(i == n){
				i=0;
			}
			next_img = i;
	}
	
	if(cache_page_images[i]){
		blendimage(divid, imageid, cache_page_images[i].src, 2500)
		current_image = i;
	}
	
	
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
	
	
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	if((id)&&(document.getElementById(id))){
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ")";
		//debug(opacity+", ");
	}
}

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}

function blendimage(divid, imageid, imagefile, millisec) { 
	
	if( document.getElementById(divid)){
		var speed = Math.round(millisec / 100); 
		var timer = 100; 
		 
		//set the current image as background 
	
		document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
		current_image_url = imagefile;
		
		
		 
		//make image transparent 
		changeOpac(0, imageid); 
		
		if(document.getElementById('debug_txt')){
			document.getElementById('debug_txt').innerHTML = current_image_url+"<br>";
		}
		 
		//make new image 
		document.getElementById(imageid).src = imagefile; 
		document.getElementById(imageid).display = "block";
	
		//fade in image 
		for(i = 0; i <= 100; i++) { 
			window['opt_'+i] = setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
			timer++; 
		}
		
		window['image_changer'] = setTimeout("swapImage()",image_change_delay);
		
	}
}

/******************************
CHECK NUMBER
******************************/

function checkNumber(field,type){

	switch(type){
		case "full":		thisNum = parseInt(field.value);
		break;
		
		case "decimal":		t1 = field.value;
							t2 = round_decimals(t1, 2);
							t3 = pad_with_zeros(t2, 2);
							thisNum = t3;
		break;
		
	}

	thisNum1 = ""+ thisNum;
	if(thisNum1.substr(0,3) == "NaN"){
		field.value = (type == "full") ? "0" : "0.00";
	}else{
		field.value = thisNum
	}
}


function formatNumber(num,type){
	switch(type){
		

		case "full":		thisNum = parseInt(num);
		break;
		
		case "decimal":		t1 = num
							t2 = round_decimals(t1, 2);
							t3 = pad_with_zeros(t2, 2);
							thisNum = t3;
		break;
		
	}
	
	thisNum1 = ""+ thisNum;
	if(thisNum1.substr(0,3) == "NaN"){
		return  (type == "full") ? "0" : "0.00";
	}else{
		return  thisNum;
	}
	
	
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}



function pad_with_zeros(rounded_value, decimal_places) {

  
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1
    }
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


/******************************
END CHECK NUMBER END
******************************/

function disablePage(bool){
		if(document.getElementById("disable_page")){
			document.getElementById("disable_page").style.display = (bool)? "block":"none";
		}
}


function toggleObj(id1,id2,id3,id4){
	
	//id1 & id3 shown, id2 & id4 hidden
	
	if(document.getElementById(id1)){
		dis = document.getElementById(id1).style.display;
		document.getElementById(id1).style.display = (dis == "none")?"block":"none";
		if(document.getElementById(id3)){
			document.getElementById(id3).style.display = (dis == "none")?"block":"none";
		}
		if(document.getElementById(id2)){
			document.getElementById(id2).style.display = (dis == "none")?"none":"block";
		}
		if(document.getElementById(id4)){
			document.getElementById(id4).style.display = (dis == "none")?"none":"block";
		}
	}
	
	try{
		resizePage();
	}catch(e){
	}
}

/***********************
Scroll Gallery Functions
************************/

var gallery_scroll_bar_offset_x = 0;
var gallery_containers = Array();
var current_scroll_timer = null;
var current_scroll_timer2 = null;
var gallery_start_l = 0;
var gallery_sb_start_l = 0;
var gallery_start_l = 0;
var gallery_img_inc = 1;
var auto_scroll_speed = 10;
var gallery_img_inc_speed = auto_scroll_speed;
var gallery_global_inc_speed =100; 
var gallery_can_scroll_img = 0;
var gallery_scroll = 0;
var gallery_sb_direction = "right";
var auto_scroll_g_x = 0;
var auto_scroll_inc = 1;
var gallery_firstload = 1;
//scroll gallery functions

function toggleGalleryHTML(img,id){
	
	if(document.getElementById(id)){
		dis = document.getElementById(id).style.display;
		document.getElementById(id).style.display = (dis == "block")?"none":"block";
		img.alt = (dis == "block")? "click here to show more information" : "click here to hide more information";
	}
	
}
function positionScrollBar(div1,div_container1,div2,div_container2,scroll_div,id,offset,scale,total_h){
	if((document.getElementById(div1)) && (document.getElementById(div_container1)) && (document.getElementById(div2)) && (document.getElementById(div_container2)) && (document.getElementById(scroll_div))){
			if(offset){
				gallery_scroll_bar_offset_x = offset;
			}
			main_w = parseInt(document.getElementById(div_container1).clientWidth);
			main_h = parseInt(document.getElementById(div_container1).clientHeight);
			main_img_w = parseInt(document.getElementById(div1).clientWidth);
			main_img_l = parseInt(document.getElementById(div1).style.left);
			scroll_bar = document.getElementById(scroll_div);
			
			var scrollbar_border = (scroll_bar.style.borderWidth) ? parseInt(scroll_bar.style.borderWidth) : 0;
			scrollbar_h = parseInt(scroll_bar.style.height) - (scrollbar_border * 2);
			ratio = main_w/main_h;
			scrollbar_w = Math.round((scrollbar_h) * ratio * scale) ;
			
			if((id)&&(!gallery_containers[id])){
				temp_arr = Array();
				temp_arr[0] = document.getElementById(div1);
				temp_arr[1] = document.getElementById(div_container1);
				temp_arr[2] = document.getElementById(div2);
				temp_arr[3] = document.getElementById(div_container2);
				temp_arr[4] = scroll_bar;
				temp_arr[5] = 0; //div1 offset
				gallery_containers[id] = temp_arr;
			}
			
			
			preview_w = parseInt(document.getElementById(div_container2).clientWidth);
			preview_h = parseInt(document.getElementById(div_container2).style.height);
			preview_img_w = parseInt(document.getElementById(div2).clientWidth);
			preview_img_l = parseInt(document.getElementById(div2).style.left);
			scroll_div_l = parseInt(scroll_bar.style.left);
			
			d = new Date();
			
			if(main_img_w < main_w){
				
					scroll_bar.style.display = "none";
					document.getElementById(div1).style.left = "0px";
					document.getElementById(div2).style.left = "0px";
				
			}else{
				
					//check image
					scale = main_img_w / preview_img_w;
					
					if(preview_img_l < 0){
						if((preview_img_w - Math.abs(preview_img_l)) < preview_w){
							new_l = preview_w - preview_img_w;
							document.getElementById(div2).style.left = new_l+ "px";					
							gallery_containers[id][5]= Math.round(new_l*scale);
							document.getElementById(div1).style.left = (0 - Math.round(scroll_div_l*scale) + Math.round(new_l*scale))+ "px";
							
							
						}
					}else if(preview_img_l > 0){
							new_l = 0;
							document.getElementById(div2).style.left = new_l+ "px";					
							gallery_containers[id][5]= Math.round(new_l*scale);
							document.getElementById(div1).style.left = (0 - Math.round(scroll_div_l*scale) + Math.round(new_l*scale))+ "px";
					}
					
					
					if(scroll_div_l > 0){
						
						max_x = (preview_img_w < preview_w) ? preview_img_w  :preview_w
						if(is_IE == 0){
							max_x -=2;
						}
						
						scroll_w = scroll_div_l+scrollbar_w;
						
						if(scroll_w > max_x){
							l =  max_x - scrollbar_w; 
							scroll_bar.style.left = l;
							document.getElementById(div1).style.left = (0 - Math.round(l*scale) + gallery_containers[id][5])+ "px";
							
						}
					}
					
					
					if(scroll_div_l < 0){
						l =  0; 
						scroll_bar.style.left = l;
						document.getElementById(div1).style.left = (0 - Math.round(l*scale) + gallery_containers[id][5])+ "px";
						
					}
		
					
					
					if(gallery_firstload == 1){
						sb_top_max = (main_h + preview_h + 10);
						var sb_h = parseInt(scroll_bar.style.height);
						
						var dif = total_h - main_h - sb_h ;
						if(dif < 0){
							sb_top  = main_h+10;
							scroll_bar.style.height = (scrollbar_h + dif ) + "px";
						}else{
							sb_top = main_h+dif;
							var border_w = (scroll_bar.style.borderWidth) ? parseInt(scroll_bar.style.borderWidth) : 0;
							scroll_bar.style.height = (total_h - main_h - dif - (border_w * 2) ) + "px";
						}
						scroll_bar.style.top =  sb_top + "px";
						gallery_firstload = 0;
					}
					scroll_bar.style.width = scrollbar_w + "px";
					scroll_bar.style.display = "block";
					
					startMouseMove();
			
			}
			
	}
	
	
}


function clearScrollDivBar(id,not_t1,not_t2){
	
	gallery_can_scroll_img = 0;
	gallery_scroll = 0;
	document.documentElement.style.cursor='default';
	
	if((current_scroll_timer)&&(!not_t1)){
		clearInterval(current_scroll_timer);
	}
	if((current_scroll_timer2)&&(!not_t2)){
		clearInterval(current_scroll_timer2);
	}
		
}

function checkGalleryScroll(id){
	if(gallery_scroll == 1){
		disablePage(true);
	}else{
		disablePage(false);
	}
}


function scrollDivImg(id,scale){
	//debug("scrollDivImg<br>",1);
	this_direction = (gallery_img_inc < 0) ? "right":"left";
	if((gallery_can_scroll_img == 1) &&(this_direction == gallery_sb_direction)){
		
		div1 = gallery_containers[id][0];
		div2 = gallery_containers[id][2];
		div_container2 = gallery_containers[id][3];
		this_l = parseInt(div2.style.left) + gallery_img_inc;
		preview_w = parseInt(div_container2.clientWidth);
		preview_img_w = parseInt(div2.clientWidth);
			
			
		//debug(this_l+",");
		//check this_l 
		if(gallery_img_inc < 0){
			if(this_l < (preview_w - preview_img_w)){
				this_l = (preview_w - preview_img_w);
				gallery_can_scroll_img = 0;
				gallery_img_inc = 0;
				stopGalleryAutoScroll(id)
			}
		}
		
		if(gallery_img_inc > 0){
			if(this_l > 0){
				this_l = 0;
				gallery_can_scroll_img = 0;
				gallery_img_inc = 0;
				stopGalleryAutoScroll(id)
			}
		}
		
		div2.style.left = this_l +"px";
		//debug("<br>"+div2.style.left);
		gallery_containers[id][5]= parseInt(gallery_containers[id][5]) + Math.round(gallery_img_inc*scale);
		
		
	}else{
		if(current_scroll_timer2){
			clearInterval(current_scroll_timer2);
		}
		stopGalleryAutoScroll(id);
	}
	
}


function stopGalleryAutoScroll(id){
	if(window["auto_scroll_g_"+id]){
		clearInterval(window["auto_scroll_g_"+id]);
	}
	
	gallery_img_inc_speed = gallery_global_inc_speed;
}
function startGalleryAutoScroll(id){
	if(gallery_containers[id]){	
		auto_scroll_g_x += auto_scroll_inc;
		x = auto_scroll_g_x
		scrollDivBar(id,null,x);
		clearScrollDivBar(id);
		window["auto_scroll_g_"+id] = setTimeout("startGalleryAutoScroll('"+id+"')",gallery_img_inc_speed);
	}
	
}
function galleryJumpTo(id){
	
	if(gallery_containers[id]){	
		x = tempX - gallery_scroll_bar_offset_x;
		scrollDivBar(id);
		clearScrollDivBar(id);
	}
}

function scrollDivBar(id,firstdown,x){
	
	
	gallery_scroll = 1;
	document.documentElement.style.cursor='move';
	
	if(!x){
		x = tempX - gallery_scroll_bar_offset_x;
	}
	//document.getElementById('background_header_div').innerHTML = x;
	if(document.getElementById('x_pos_'+id)){
		document.getElementById('x_pos_'+id).innerHTML = x;
	}
	y = tempY;
	
	if(gallery_containers[id]){	
				
		div1 = gallery_containers[id][0];
		div_container1 = gallery_containers[id][1];
		div2 = gallery_containers[id][2];
		div_container2 = gallery_containers[id][3];
		scroll_div = gallery_containers[id][4];
		
		
		l = parseInt(scroll_div.style.left);
		last_l = l;
		
		if(firstdown){
			gallery_start_l = x;
			gallery_sb_start_l = l;
		}
		
		main_w = parseInt(div_container1.clientWidth);
		main_h = parseInt(div_container1.style.height);
		main_img_w = parseInt(div1.style.width);// - gallery_scroll_bar_offset_x;
		main_img_l = parseInt(div1.style.left);
		
		preview_w = parseInt(div_container2.clientWidth);
		preview_h = parseInt(div_container2.style.height);
		preview_img_w = parseInt(div2.style.width);
		preview_img_l = parseInt(div2.style.left);
		
		scroll_div_w = parseInt(scroll_div.style.width);
		if(scroll_div.style.border){
			scroll_div_w+= (is_IE == 1)? parseInt(scroll_div.style.borderRightWidth)*2 : parseInt(scroll_div.style.borderRightWidth);
		}else if (is_IE != 1){
			scroll_div_w -= 2;
		}
		
		//set min_x and max_x
		min_x = 0;
		max_x = (preview_img_w < preview_w) ? preview_img_w  :preview_w;
		if(is_IE == 0){
			max_x -=2;
		}
		l = gallery_sb_start_l + (x - gallery_start_l);
		
		scale = main_img_w / preview_img_w;
		
		gallery_sb_direction = (l < last_l) ? "left":"right";
		
		if(l < min_x){
			l = min_x;
			if(preview_img_w > preview_w){
					gallery_can_scroll_img = 1;
					gallery_img_inc = 10;
					scrollDivImg(id,scale);
					//current_scroll_timer2 = setInterval("scrollDivImg('"+id+"',"+scale+")",gallery_img_inc_speed);
			}
		}
		
		if(( l+scroll_div_w) > max_x){
			l = max_x - scroll_div_w;
			
			if(preview_img_w > preview_w){
				gallery_can_scroll_img = 1;
				gallery_img_inc = -10;
				scrollDivImg(id,scale);
				//current_scroll_timer2 = setInterval("scrollDivImg('"+id+"',"+scale+")",gallery_img_inc_speed);
			}
			
		}
		scroll_div.style.left = l+ "px";
		
		div1_offset = parseInt(gallery_containers[id][5]);
		
		div1_l = (0 - Math.round((l+2)*scale) + div1_offset);
		div1_l_max = (0-main_img_w+main_w);
		
		debug(div1_l+","+div1_l_max,1);
		
		div1.style.left = (div1_l < div1_l_max)? div1_l_max+ "px" : div1_l+ "px";
		debug("<br>"+div1.style.left);
		if((l==0)&&(parseInt(div2.style.left) == 0)){
			div1.style.left = "0px";
		}
		if((div1) && (div_container1) && (div2) && (div_container2) && (scroll_div)){
			current_scroll_timer = setTimeout("scrollDivBar('"+id+"')",1);
		}
	
	}
	
}


/**************************
Thumbnail Gallery Functions
***************************/
var thumbnail_popups = Array();
var popup = null;
var thumbnail_popup_on = 0;

function setupThumbnailGallery(html,id,popup_on,border_color){
	
	thumbnail_popup_on = popup_on;
	if((document.getElementById('popup')) && (popup === null)){
		popup = document.getElementById('popup');
		if(html){
			popup.innerHTML = decode64(html);
			
		}
	}
	
	var j = 0;
	for (var i=0;i<thumbnail_popups[id].length;i++)
	{		
		img = document.getElementById('img_'+j+'_'+id);
		if(img){
			img.className='alpha_100';
			var popup_html = thumbnail_popups[id][i]['popup'];
			if(popup_html != ""){
				img.onmouseover= function(){this.style.cursor='pointer';this.className='alpha_40';};
				img.onmouseout=function(){this.className='alpha_100';}
			}
		}
		j++;
	}
	
}


function loadPopUpHtml(id,n){
	
	var div = document.getElementById('popup_html');
	if((popup)&&(div)){
		
		var popup_html = thumbnail_popups[id][n]['popup'];
		if(popup_html != ""){
			popup_html = decode64(popup_html);
			div.innerHTML = popup_html ;
		}
		var bool = (popup_html != "") ? true:false;
		
		showHTMLPopUp(bool)
		
	}
	
}

function closeHTMLPopUp(){
	showHTMLPopUp(false);
}


function showHTMLPopUp(bool){
		if((popup)){
			popup.style.display = (bool) ? "block":"none";
			if(bool){
				centerPopUp();
			}
		}
}


function centerPopUp(){
	if(popup){
		var mcw =  parseInt(document.getElementById('main_page').clientWidth);
		var mch =  parseInt(document.getElementById('main_div').clientHeight);
		
		if((parseInt(document.documentElement.clientHeight) < mch) ){
			mch = parseInt(document.documentElement.clientHeight) + document.documentElement.scrollTop;
		}
		
		var lw = parseInt(popup.clientWidth);
		var lh = parseInt(popup.clientHeight) ;
		popup.style.left =  (Math.round((mcw-lw + parseInt(document.getElementById('left_content').clientWidth) )/2)+ "px") 
		popup.style.top = Math.round((mch-lh)/2) -parseInt(document.getElementById('header').clientHeight)  + "px";
	}
}

/******************************
END Thumbnail Gallery Functions
*******************************/

/******************
Light Box Functions
*******************/
var lightbox = null;
var lightbox_image = null;
var lightbox_back = null;
var lightbox_zoom_back = null;
var lightbox_zoom = null;
var lightbox_zoom_tool = null;
var lightbox_w = 0;
var lightbox_h = 0;
var lightbox_inc_x = 0;
var lightbox_inc_y = 0;
var lightbox_mtw = 0;
var lightbox_mth = 0;
var lightbox_speed = 100;
var lightbox_millisec = 1000;
var lightbox_moving = 0;
var lightbox_images = Array();
var lightbox_img_cache = Array();
var lightbox_mov_int = null;
var lightbox_y_offset = 0;
var lightbox_x_offset = 0;
var lightbox_zoom_scale = 1;
var lightbox_type = 1;
var lightbox_border = 0;

function setupLightBox(html,id,type,border_color){
	
	lightbox_type = type;
	if((document.getElementById('lightbox')) && (lightbox === null)){
		lightbox = document.getElementById('lightbox');
		if(html){
			lightbox.innerHTML = decode64(html);
			
		}
		if(document.getElementById('lightbox_image')){
			lightbox_image = document.getElementById('lightbox_image');
			if(border_color != ""){
				lightbox_image.style.border = "1px solid "+border_color;
				lightbox_border = 1;
			}
		}
		if(document.getElementById('lightbox_back')){
			lightbox_back = document.getElementById('lightbox_back');
			
		}
		if((document.getElementById('lightbox_zoom_'+id))&&(document.getElementById('lightbox_zoom_tool'))){
			lightbox_zoom = document.getElementById('lightbox_zoom_'+id);
			lightbox_zoom_tool = document.getElementById('lightbox_zoom_tool');
		}else{
			lightbox_zoom = null;
		}
		
		if(document.getElementById('lightbox_zoom_back_'+id)){
			lightbox_zoom_back = document.getElementById('lightbox_zoom_back_'+id);
		}else{
			lightbox_zoom_back = null;
		}
		
		loadLightBoxImages(id);
	}
	
}


function loadLightBoxImages(id) {
		
	var j = 0;

	for (var i=0;i<lightbox_images[id].length;i++)
	{
		d = new Date();
		before = d.getTime();
		light_img = decode64(lightbox_images[id][i]['light']);
		if(lightbox_type < 3){
			image_img = decode64(lightbox_images[id][i]['image']);
		}
		
		w = Math.abs(lightbox_images[id][i]['w']);
		h = Math.abs(lightbox_images[id][i]['h']);
		w2 = Math.abs(lightbox_images[id][i]['w2']);
		h2 = Math.abs(lightbox_images[id][i]['h2']);	
		n = Math.abs(lightbox_images[id][i]['n']);	
		
		lightbox_img_cache[id][j]= {light:null,image:null,w:w,h:h,w2:w2,h2:h2};
		
		lightbox_img_cache[id][j]['light'] = new Image();
		lightbox_img_cache[id][j]['light'] .src = light_img;
		lightbox_img_cache[id][j]['image']   = new Image();
		if(lightbox_type < 3){
			lightbox_img_cache[id][j]['image'].src = image_img;
		}
		
		
		img = document.getElementById('img_'+j+'_'+id);
		if(img){
			img.className='alpha_100';
			img.onmouseover= function(){this.style.cursor='pointer';this.className='alpha_40';};
			img.onmouseout=function(){this.className='alpha_100';}
		}
		
		j++;
	}
	
		
}

function loadLightBoxImage(id,n){
		
	clearMoveLightBox();
	clearLightBoxFade();
	
	if(lightbox_img_cache[id][n]){
		img1 = lightbox_img_cache[id][n]['light'];
		img2 = lightbox_img_cache[id][n]['image'];
		w = Math.abs(lightbox_img_cache[id][n]['w']);
		h = Math.abs(lightbox_img_cache[id][n]['h']);
		w2 = Math.abs(lightbox_img_cache[id][n]['w2']);
		h2 = Math.abs(lightbox_img_cache[id][n]['h2']);
		
		lightbox_zoom_scale = w2/w;
		
		if(lightbox){
			if((lightbox_zoom_tool)&&(lightbox_zoom)){
				
				if(lightbox_type == 2){
					lightbox_zoom.style.height = (h) + "px";
					lightbox_zoom.style.top = "11px";
				}
				
				lightbox_zoom_tool.style.width = Math.round(parseInt(lightbox_zoom.style.width) / lightbox_zoom_scale) + "px";
				lightbox_zoom_tool.style.height = Math.round(parseInt(lightbox_zoom.style.height) / lightbox_zoom_scale) + "px";
			}
			
			
			showLightBoxImage(img1,w,h,img2,w2,h2,id,n);
			showLightBox(true);
			startMouseMove();
			lightbox_mov_int = setInterval("moveLightBoxZoom()",1);
			//centerLightBox();
		}
		
	}
}

function closeLightBox(){
	debug("<br>stopLightBoxZoom()<br>");
	stopLightBoxZoom();
	debug("<br>clearLightBoxFade()<br>");
	clearLightBoxFade();
	debug("<br>clearMoveLightBox()<br>");
	clearMoveLightBox();
	debug("<br>showLightBox(false)<br>");
	showLightBox(false);
	//resizeLightBox(50,50);
}

function showLightBoxImage(img,w,h,img2,w2,h2,id,n){
		
		if(lightbox_image){
			
			var plus = (lightbox_type == 2) ? 300 : 0;
			
			var l_style = (lightbox_border == 1)? "style='top:11px;'":"";
			lightbox_image.innerHTML= "<img id='lightbox_current_img' src='"+img.src+"' width='"+w+"' height='"+h+"' "+l_style+" onmouseover='javascript:startLightBoxZoom();'>";
			if(lightbox_type == 2){
				lightbox_image.innerHTML += "<div id=\"lightbox_txt\" style=\"top:"+(Math.round((h-60)/2))+"px;\">Move your mouse over the image to view in more detail.</div>";
			}
			
			if(lightbox_type == 3){
				var popup_html = lightbox_images[id][n]['popup'];
				if(popup_html != ""){
					lightbox_image.innerHTML += "<div id=\"lightbox_popup_txt\" style=\"height:"+(h-40)+"px;\">"+decode64(popup_html)+"</div>";
					plus = 300;
				}
				
			}
				
			changeOpac(0, 'lightbox_current_img');
			if(lightbox_zoom){
				lightbox_zoom.innerHTML= "<img id='lightbox_zoom_img' src='"+img2.src+"' width='"+w2+"' height='"+h2+"'>";
			}
			
			lightbox_w = w+plus;
			lightbox_h = h;
			
			clearMoveLightBox();
			resizeLightBox(w+plus,h);
			
		}
	
}

function clearMoveLightBoxZoom(){
	if(lightbox_mov_int){
		clearInterval(lightbox_mov_int);
		lightbox_mov_int = null;
	}
}

function moveLightBoxZoom(){

	if(lightbox_type < 3){
		
		lightbox_y_offset = parseInt(lightbox.style.top) ;
		x = tempX - lightbox_x_offset- Math.round((parseInt(document.documentElement.clientWidth) - parseInt(document.getElementById('main_page').clientWidth))/2);
		y = tempY  - lightbox_y_offset - parseInt(document.getElementById('header').clientHeight);
			
		var lightbox_zoom_tool_width = (lightbox_zoom_tool) ? parseInt(lightbox_zoom_tool.style.width):0;
		var lightbox_zoom_tool_height = (lightbox_zoom_tool) ? parseInt(lightbox_zoom_tool.style.height):0;
		
		l = x - Math.round(lightbox_zoom_tool_width/2);
		t = y - Math.round(lightbox_zoom_tool_width/2);
		
		debug("tempY:"+tempY+"<br>y:"+y+"<br>lightbox_y_offset:"+lightbox_y_offset+"<br>top:"+t+"<br>"+document.documentElement.scrollTop,1);
		 
		min_x = 10;
		max_x = (lightbox_type == 2) ? parseInt(lightbox_image.style.width)-300 - lightbox_zoom_tool_width + 8 : parseInt(lightbox_image.style.width) - lightbox_zoom_tool_width + 8;
		   
		if(l < min_x){
			l = min_x;
		}
		if(l > max_x){
			l = max_x;
		}
		   
		min_y = 10;
		max_y = parseInt(lightbox_image.style.height) - lightbox_zoom_tool_height + 9;
		   
		if(t < min_y){
			t = min_y;
		}
		if(t > max_y){
			t = max_y;
		}
		   
		   
		zoom_l = (10*lightbox_zoom_scale) - (l*lightbox_zoom_scale);
		zoom_t = (10*lightbox_zoom_scale) - (t*lightbox_zoom_scale);
		   
		lightbox_zoom_tool.style.left = l +"px";
		lightbox_zoom_tool.style.top = t +"px";
			
		if(document.getElementById('lightbox_zoom_img')){
			 document.getElementById('lightbox_zoom_img').style.left = zoom_l +"px";
			 document.getElementById('lightbox_zoom_img').style.top = zoom_t +"px";
		}
		
		var lb_max_x = (lightbox_type == 2) ? (parseInt(lightbox_image.style.width))+10 - 300 : (parseInt(lightbox_image.style.width))+10
	
		if( (x < 10)||(x > lb_max_x) || (y < 10)||(y > (parseInt(lightbox_image.style.height))+10) ){
			stopLightBoxZoom()
		}
								  
	}

	
}

function startLightBoxZoom(){
	
	if((lightbox_zoom)&&(lightbox_zoom_tool)){
		showLightBoxZoom(true);
	}
	
}

function stopLightBoxZoom(){
	
	if((lightbox_zoom)&&(lightbox_zoom_tool)){
		//clearMoveLightBoxZoom();
		showLightBoxZoom(false);	
	}
	
}

function showLightBoxZoom(bool){
	if(lightbox_zoom){
		lightbox_zoom.style.display = (bool) ? "block":"none";
	}
	if(lightbox_zoom_tool){
		lightbox_zoom_tool.style.display = (bool) ? "block":"none";
	}
	if(lightbox_zoom_back){
		lightbox_zoom_back.style.display = (bool) ? "block":"none";
	}
	
}

function showLightBox(bool){
	if(lightbox){
		if(bool){
			centerLightBox();
		}
		lightbox.style.display = (bool) ? "block":"none";
	}
}

function moveLightBox(){
	
		w = lightbox_w;
		h = lightbox_h;	
		
		mcw = (lightbox_type == 1)? parseInt(document.getElementById('main_content').clientWidth) : parseInt(document.getElementById('main_page').clientWidth);
		mch = (lightbox_type == 1)? parseInt(document.getElementById('main_content').clientHeight) : parseInt(document.getElementById('main_div').clientHeight);
		
		if((lightbox_type == 2) && (parseInt(document.documentElement.clientHeight) < mch)){
			mch = parseInt(document.documentElement.clientHeight) + (document.documentElement.scrollTop*2);
		}
		if((cw == lightbox_mtw)&&(ch == lightbox_mth)){
			clearMoveLightBox();
			return false;
		}
		
		if((lightbox_inc_x != 0)&&(cw != lightbox_mtw)){
			w = (cw +lightbox_inc_x);
			if(((lightbox_inc_x > 0) && (w > lightbox_mtw)) || ((lightbox_inc_x < 0) && (w < lightbox_mtw)) ){
					w = Math.abs(lightbox_mtw);
			}
			lightbox_image.style.width = w+"px";
			lightbox_back.style.width = (w+20)+"px";
			lightbox.style.left = (lightbox_type == 1)? (Math.round((mcw-(w+20))/2) + parseInt(document.getElementById('left_content').clientWidth) + "px") : (Math.round((mcw-(w+20))/2) + "px");
			lightbox_x_offset = parseInt(lightbox.style.left);
		}
		
		if((lightbox_inc_y != 0)&&(ch != lightbox_mth)){
			h = (ch +lightbox_inc_y);
			if(((lightbox_inc_y > 0) && (h > lightbox_mth)) || ((lightbox_inc_y < 0) && (h < lightbox_mth)) ){
					h = Math.abs(lightbox_mth);
			}
			lightbox_image.style.height = h+"px";
			lightbox_back.style.height = (h+20)+"px";
			lightbox.style.top = Math.round((mch-(h+20))/2)  + "px";
			
		}
		
	
}	

function clearLightBoxFade(){
	
	for(i = 0; i <= 100; i++) { 
		if(window['opt_lb_'+i]){
			clearTimeout(window['opt_lb_'+i]);
		}
	}
}


function clearMoveLightBox(){
	
	for(i = 0; i <= lightbox_speed; i++) { 
		if(window['move_lb_'+i]){
			clearTimeout(window['move_lb_'+i]);
		}
	}
	lightbox_moving  = 0;
}

function resizeLightBox(w,h){
		
		
		if((lightbox_back)&&(lightbox_image)){
			lightbox_mtw = w;
			lightbox_mth = h;
			
			var speed = Math.round(lightbox_millisec / lightbox_speed); 
			var timer = 0; 
						
			cw = parseInt(lightbox_image.style.width);
			ch = parseInt(lightbox_image.style.height);
			
			lightbox_inc_x = ((lightbox_mtw - cw));///lightbox_speed) ; 
			lightbox_inc_y = ((lightbox_mth - ch));///lightbox_speed) ; 
		
			
			if(lightbox_inc_x > 0){
				lightbox_inc_x += 1;
			}else if(lightbox_inc_x < 0){
				lightbox_inc_x -= 1;
			}
			
			if(lightbox_inc_y > 0){
				lightbox_inc_y += 1;
			}else if(lightbox_inc_y < 0){
				lightbox_inc_y -= 1;
			}
			
			lightbox_inc_x  = Math.round(lightbox_inc_x);
			lightbox_inc_y  = Math.round(lightbox_inc_y);
			
			
			
			lightbox_moving  = 1;
			//move image
			/*for(i = 0; i <= lightbox_speed; i++) { 
				window['move_lb_'+i] = setTimeout("moveLightBox()",(timer * speed)); 
				timer++; 
			}*/
			
			moveLightBox();
			
			
			
			debug("START<br>",1);
			
			/*for(i = 0; i <= 100; i++) { 
				window['opt_lb_'+i] = setTimeout("changeOpac("+i+", 'lightbox_current_img')",(i* speed));  
			}*/
			changeOpac(100, 'lightbox_current_img');
			
			
			
			
			
		}
	
}



function centerLightBox(){
	if((lightbox)){
		mcw =  parseInt(document.getElementById('main_page').clientWidth);
		mch = parseInt(document.getElementById('main_content').clientHeight);
		
		if((lightbox_type == 2) && (parseInt(document.documentElement.clientHeight) < mch)){
			mch = parseInt(document.documentElement.clientHeight) + (document.documentElement.scrollTop*2);
		}
		
		var lw = lightbox_w + 20;
		var lh = lightbox_h + 20;
		//alert(mcw+" > "+lw+"\r\n"+mch+" > "+lh);
		lightbox.style.left = (Math.round((mcw-lw)/2))  + "px";//(lightbox_type == 2)? (Math.round((mcw-lw)/2))  + "px" : (Math.round((mcw-lw)/2) + parseInt(document.getElementById('left_content').clientWidth) + "px") 
		lightbox.style.top = Math.round((mch-lh)/2) + "px";
	}
}

/******************
END Light Box Functions
*******************/

/*****************
START ROTATOR BOX
*****************/

var rotator_box_items = Array();
function rotateBox(key,delay){
	div = document.getElementById('pr_'+key);
	if((rotator_box_items[key])&&(div));{
		no_items = Math.abs(rotator_box_items[key]['no_items']);
		current_item = Math.abs(rotator_box_items[key]['current_item']);
		h = Math.abs(rotator_box_items[key]['h']);
		if(current_item >= no_items){
			current_item = 0;
		}
		rotator_box_items[key]['current_item'] = current_item + 1;
		try{
			div.style.top = (0- (current_item * h)) + "px";
			setTimeout("rotateBox('"+key+"',"+delay+")",delay);
		}catch(e){
		}
	}
	
}

/*****************
END ROTATOR BOX
*****************/
var selected_current_back_color = "";
var selected_current_font_color = "";
function changeTrans(field,bool){
	
	if(bool){
		selected_current_back_color = field.style.backgroundColor;
		selected_current_font_color = field.style.color;
	}
	
	field.style.backgroundColor = (bool) ? "#ffffff" : selected_current_back_color;
	field.style.color = (bool) ? "#333333" : selected_current_font_color;
	
}



function depth(obj){
		var level = 1;
		while(obj.parentNode.className != listClass){
			if (obj.tagName == "UL") level++;
			obj = obj.parentNode;
		};
		return level;
};	
	
var expandTo = 1;
var listClass = "bloglinks";
function toggleList(li){
	
	//alert(li);
	var elements = li.getElementsByTagName("ul");
	//alert(elements.length);
	
	//if(li.getElementsByTagName("ul").length > 0){
			
			//var ul = li.getElementsByTagName("ul")[0];
			//ul.style.display = (depth(ul) <= expandTo) ? "block" : "none";
			//li.className = (depth(ul) <= expandTo) ? "expanded" : "collapsed";
	
	//}	

}





/*****
DEBUG
*****/

function debug(str,replace_all){
	div = document.getElementById('debug')
	if(div){
		 div.innerHTML = (replace_all) ? str : div.innerHTML+str;
	}
}





// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			//alert("flashVer="+flashVer);
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i=0;i<objAttrs.length;i++)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i=0;i<params.length;i++)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i=0;i<embedAttrs.length;i++)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "id":
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}




/*
# # # # # # #
# CHANGELOG
#
# V0.01 SDW      2008-11-26                          Original Code
#
*/
var password_pass = 0;

var processing = 0;
function sendCustomerDetails(res,success){
	
	fm = document.theForm;
	
	if(res){
			
			document.getElementById('status_txt').innerHTML = res;
			if(success == 0){
				document.getElementById('btn_row').style.display = "block";
				fm.customer_email.disabled = false;
			}
			
	}else if(processing == 0){
			
			email = fm.customer_email.value;
			
			document.getElementById('email_fail_row').style.display = "none";
			document.getElementById('process_row').style.display = "none";
			document.getElementById('btn_row').style.display = "block";
			
			if(!checkemail(email)){
				document.getElementById('email_fail_row').style.display = "block";
				fm.customer_email.focus();
				fm.customer_email.select();
				return false;
			}
			fm.customer_email.disabled = true;
			document.getElementById('status_txt').innerHTML = "processing details please wait....";
			document.getElementById('process_row').style.display = "block";
			document.getElementById('btn_row').style.display = "none";
			
			email = encode64(email);
			
			document.getElementById('process_frame').src = global_url+"scripts/forgot_password.php?"+email;
			
	}
	
}

function updateRememberMe(box){
	
	if(box.checked == true){
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()+12);
	}else{
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()-12);
	}
	document.cookie = "remember_me="+document.theForm.customer_email.value+";expires="+expireDate.toGMTString()+";path=/";
}

function memberContinue(){
	
	fm = document.theForm;
	email = fm.customer_email.value;
	document.getElementById('password_fail_row').style.display = "none";
	document.getElementById('email_fail_row').style.display = "none";
	document.getElementById('username_fail_row').style.display = "none";
	document.getElementById('process_row').style.display = "none";
	document.getElementById('btn_row').style.display = "block";
	
	if(parseInt(document.theForm.MEM_LOGON_TYPE.value) == 0){
	
		if(!checkemail(email)){
			document.getElementById('email_fail_row').style.display = "block";
			fm.customer_email.focus();
			fm.customer_email.select();
			resizePage();
			return false;
		}
	
	}else{
		
		if(email == ""){
			document.getElementById('username_fail_row').style.display = "block";
			fm.customer_email.focus();
			fm.customer_email.select();
			resizePage();
			return false;
		}
		
	}
	
	
	if(fm.remember_me.checked == true){
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()+12);
	}else{
		expireDate = new Date;
		expireDate.setMonth(expireDate.getMonth()-12);
	}
	document.cookie = "remember_me="+email+";expires="+expireDate.toGMTString()+";path=/";
	
	password = fm.customer_password.value;
	
	customer_type = 1;
	if(password == ""){
			document.getElementById('password_fail_row').style.display = "block";
			fm.customer_password.focus();
			return false;
	}else if(password_pass == 0){
			
			fm.customer_email.disabled = true;
			fm.customer_password.disabled = true;
			
			document.getElementById('status_txt').innerHTML = "checking details please wait....";
			document.getElementById('process_row').style.display = "block";
			document.getElementById('btn_row').style.display = "none";
			
			email = parent.encode64(email);
			password = parent.encode64(password);
			
			str = email+"|"+password+"|1";
			str = parent.encode64(str);
			document.getElementById('process_frame').src = global_url+"scripts/check_details.php?"+str;
			
			return false;
		
	}
		
	memberProcess();
	
	
}


function memberProcess(res){
	
	

	fm = document.theForm;
	
	if(res){
		
			fm.customer_email.disabled = false;
			fm.customer_password.disabled = false;
			
			document.getElementById('status_txt').innerHTML = res;
			document.getElementById('btn_row').style.display = "block";
				
		
	}
	
}






/*
# # # # # # #
# CHANGELOG
#
# V0.01 SDW      2008-11-26                          Original Code
#
*/

// JavaScript Document
/*
# # # # # # #
# CHANGELOG
#
# V0.01 SDW      2008-11-26                          Original Code
# V0.02 SDW      2008-12-10                          Added checkNewsSearchForm(),  clearNewsSearchForm();
#
*/

function toggleForm(id,num){
	
	btn = (Math.abs(num) > 0) ? document.getElementById("toggle_btn"+num+"_"+id) : document.getElementById("toggle_btn_"+id);
	div = (Math.abs(num) > 0) ? document.getElementById("form_row"+num+"_"+id):document.getElementById("form_row_"+id);
	
	if((btn)&&(div)){
		img = btn.src.split("/").pop();
		reg = new RegExp(img);
		new_img = (img == "arrow_up.png")? "arrow_down.png":"arrow_up.png";
		btn.src = btn.src.replace(reg,new_img);
		div.style.display = (new_img == "arrow_up.png") ? "block":"none";
		resizePage();
	}
	
	
	
}

function updateFlags(id){
	
	form = null;
	if(document.forms["form_"+id]){
		form = document.forms["form_"+id];
	}
	if((form != null)&&(form['flags'])){
		flags = "";
		for(var i=0; i<form.length;i++){
			if((form[i].name=='flag')&&(form[i].type == "checkbox")){
				if(form[i].checked == true){
					flags += (flags == "") ? "":"^";
					flags += form[i].value;
				}
			}
		}
		form['flags'].value = flags;
	}
	
}


function emailRegistered(id,email_field_name){

	div = document.getElementById('form_div_'+id);	
	form = document.forms["form_"+id];
	if((div)&&(form)){
		disableBtns(form,1);
		div.style.display="block";
		if(form[email_field_name]){
			form[email_field_name].value = "";
			form[email_field_name].focus();
		}
		resizePage();
	}

}


function showForm(id){

	form = document.getElementById('form_hidden_row_'+id);	
	if(form){
		form.style.display="block";
		resizePage();
	}

}

function resetForm(id){
	
	form = null;
	if(document.forms["form_"+id]){
		form = document.forms["form_"+id];
		form.reset();
		
		disableBtns(form,1);
		form.action = "javascript:";
		form.todo.value = "";

		document.getElementById('form_result_txt_'+id).innerHTML = "";
		document.getElementById('form_result_div_'+id).style.display= "none";
		document.getElementById('form_div_'+id).style.display= "block";
		resizePage();
				
	}
	
}

function replaceForm(id,str){
		
		try{
			document.getElementById('form_div_'+id).innerHTML = decode64(str);
			document.getElementById('form_result_txt_'+id).innerHTML = "";
			document.getElementById('form_result_div_'+id).style.display= "none";
			document.getElementById('form_div_'+id).style.display= "block";
		}catch(form_err){
			
		}
	
}

function updateEncodedResultTxt(id,str){
	
	res = document.getElementById('form_result_txt_'+id);
	if(res){
		res.innerHTML = decode64(str);
	}
		
}

function updateHiddenFormValue(field,type,hidden_field_name,separator,form_id){
//this,'select','register_industry_sectors','|','".$unique_id."'	
	form = null;
	
	if(document.forms["form_"+form_id]){
		form = document.forms["form_"+form_id];
	}
	
	if((form != null)&&(form[field.name])&&(form[hidden_field_name])){
			
			rtn_value = "";
			if(type == "select"){
				
					for(f=0;f<field.length;f++){
							if(field[f].selected== true){
								rtn_value += (rtn_value == "") ? "" : separator;
								rtn_value +=field[f].value;
							}
						
					}
				
			}
			form[hidden_field_name].value = rtn_value;
		
	}
	
	
}
function formCheckEmail(field,ignore_blank){
		
		email = field.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email)){
			return true;
		}else if((email == "")&&(ignore_blank == 1)){
			return true;
		}else{
			field.value = "";
			alert("Please enter a valid email address");
			try{
				field.focus();
			}catch(e){}
			return false;
		}
		
}

function checkUploadFile(file){
	
		allowed_arr = Array("doc","rtf","txt","htm","docx");
		
		file_arr = file.split(".");
		last = file_arr.length - 1;
		ext = file_arr[last].toLowerCase();
		file_ok = false;
		
		for(a=0;a<allowed_arr.length;a++){
			
			if(ext == allowed_arr[a]){
				
					file_ok = true;
					break;
			}
			
		}
	
		return file_ok;
	
}

function disableBtns(form,enable){
	
	for(b=0;b<form.length;b++){
		
		if(form[b].type == "button"){
			form[b].disabled = (!enable) ? true : false;
		}
		
	}
	
	
}

function removeLastKeyword(id){
	
	fm = document.forms['form_'+id];
	if((fm)&&(fm.keyword)&&(fm.keyword.value != "")){
		
		key_arr  = fm.keyword.value.split("|");
		new_key = "";
		for(i=0;i<(key_arr.length-1);i++){
			new_key+=(new_key == "")? key_arr[i] : "|"+key_arr[i];
		}
		
		fm.keyword.value = new_key;
		fm.keyword_search.value = "";
				   
		checkNewsSearchForm(id);
	}
	
}

function clearAllKeywords(id){
	
	fm = document.forms['form_'+id];
	if((fm)&&(fm.keyword)&&(fm.keyword.value != "")){
		fm.keyword.value = "";
		fm.keyword_search.value = "";
		checkNewsSearchForm(id)
	}
	
}

function removeSearchKeyword(id,val){
	
	fm = document.forms['form_'+id];
	if((fm)&&(fm.keyword)&&(fm.keyword.value != "")){
		
		key_arr  = fm.keyword.value.split("|");
		
		new_key = "";
		for(i=0;i<key_arr.length;i++){
			if(key_arr[i] != val){
				new_key+=(new_key == "")? key_arr[i] : "|"+key_arr[i];
			}
		}
		
		fm.keyword.value = new_key;
		fm.keyword_search.value = "";
		checkNewsSearchForm(id);
		
	}
	
}

function addToSearchKeyword(id,val){
	
	fm = document.forms['form_'+id];
	if((fm)&&(fm.keyword)&&(val != "")){
		fm.keyword.value += (fm.keyword.value == "") ? encode64(val) : "|"+encode64(val);
	}
	
	
}

function checkNewsSearchForm(id){
	
	fm = document.forms['form_'+id];
	if(fm){
		
		keyword = "";
		category = "";
		date_from = "";
		date_to = "";
		
		for(i=0;i<fm.length;i++){
			if(fm[i].type != "button"){
				//alert(fm[i].name+"="+fm[i].value);
				if(fm[i].name == "date_from"){
					date_from = fm[i].value;
				}
				if(fm[i].name == "date_to"){
					date_to = fm[i].value;
				}
				if(fm[i].name == "keyword_search"){
					addToSearchKeyword(id,fm[i].value);
				}
				
				if(fm[i].name == "keyword"){
					keyword = fm[i].value;
				}
				
				if((fm[i].name.substr(0,4) == "cat_")&&(fm[i].checked == true)){
					category += (category == "") ? fm[i].value : "|"+fm[i].value;
				}
			}
			
		}
		
		
		if((date_from > date_to)&&(date_from != "")&&(date_to != "")){
			fm.date_from.value = date_to
			formatDate(document.getElementById('date_from_div_'+id),date_to);
			fm.date_to.value = date_from
			formatDate(document.getElementById('date_to_div_'+id),date_from);
			date_to = fm.date_to.value;
			date_from = fm.date_from.value 
		}
			
		updateSearchArticles(keyword,category,date_from,date_to)
		
	}
	

}

function clearNewsSearchForm(id){
	
	clearSearchOptions(1);

}


function checkForm(type,action,id){
	
	
	/*alert(type);
	alert(aciton);
	alert(id);*/
	
	form = null;
	for(i=0;i<document.forms.length;i++){
		if(document.forms[i].name == "form_"+id){
			form = document.forms[i];
			break;
			
		}
		
	}

	
	if(form != null){
			faillist = "";
			invalidlist = "";
			to_focus = null;
			check_arr = Array();
			todo = type;
			
			/*for(i=0;i<form.length;i++){
				alert(form[i].name+"="+form[i].value);
			}*/
			
			if((type == "enquiry")||(type == "member")){
				
				check_arr.push({field:"firstname",txt:"first name",type:"text"});
				check_arr.push({field:"surname",txt:"last name",type:"text"});
				check_arr.push({field:"email",txt:"email address",type:"valid_text"});
				check_arr.push({field:"telephone1",txt:"a primary contact number",type:"text"});
				check_arr.push({field:"postcode",txt:"your postcode",type:"valid_text"});
				check_arr.push({field:"enquiry",txt:"enquiry details",type:"text"});
		
			}
			
			
			if(type == "faq ask"){

				check_arr.push({field:"your_name",txt:"your name",type:"text"});
				check_arr.push({field:"your_email",txt:"your email address",type:"valid_text"});
				check_arr.push({field:"your_question",txt:"your question",type:"text"});

			}
			
			
			if(type == "logon"){

				check_arr.push({field:"customer_uname",txt:"your username",type:"text"});
				check_arr.push({field:"customer_pword",txt:"your password",type:"text"});

			}
			
			if(type == "logon_blog"){

				check_arr.push({field:"customer_uname",txt:"your email address",type:"valid_text"});
				check_arr.push({field:"customer_pword",txt:"your password",type:"text"});
				todo = "logon";

			}

			if(type == "register"){
				
				check_arr.push({field:"register_firstname",txt:"your first name",type:"text"});
				check_arr.push({field:"register_surname",txt:"your surname",type:"text"});
				check_arr.push({field:"register_email",txt:"your email address",type:"valid_text"});
				check_arr.push({field:"register_telephone1",txt:"a primary contact number",type:"text"});
				check_arr.push({field:"register_postcode",txt:"your postcode",type:"valid_text"});
		
			}
			
			if(type == "member_full_details"){
				
				check_arr.push({field:"up_title",txt:"your title",type:"text"});
				check_arr.push({field:"up_firstname",txt:"your first name",type:"text"});
				check_arr.push({field:"up_surname",txt:"your surname",type:"text"});
				check_arr.push({field:"up_address1",txt:"the first line of your address",type:"text"});
				check_arr.push({field:"up_postcode",txt:"your postcode",type:"text"});
				check_arr.push({field:"up_country",txt:"your country",type:"text"});
				check_arr.push({field:"up_email1",txt:"your email address",type:"valid_text"});
				check_arr.push({field:"up_telephone1",txt:"your primary contact number",type:"text"});
			}
			
			
			if(type == "member_password"){
				
				check_arr.push({field:"current_password",txt:"your current password",type:"text"});
				check_arr.push({field:"new_password",txt:"your new password",type:"text"});
				check_arr.push({field:"confirm_password",txt:"confirm your new password",type:"text"});
	
			}
			
			
			if(type == "post_comment"){
				
				var ok = confirm("Are you sure you want to post this commment?");
				if(ok == false){
					return false;
				}
				
				check_arr.push({field:"blog_comment",txt:"your comment",type:"text"});
		
			}
			
			for(i=0;i<check_arr.length;i++){
				
					txt = check_arr[i]['txt'];
					field = check_arr[i]['field'];
					type = check_arr[i]['type'];
										
					
					if(type.substr(0,6) == 'valid_'){
						type = 	type.substr(6);
						if((valid_format_error[field])&&(valid_format_error[field] == 1)){
							invalidlist += (invalidlist == "") ? txt : ", " +txt;
							to_focus = (to_focus == null) ? form[field] : to_focus; 
						}
					}
					
					if(type == "text"){
						
						if((form[field])&&(form[field].value == "")){
							faillist += (faillist == "") ? txt : ", " +txt;
							to_focus = (to_focus == null) ? form[field] : to_focus; 
						}
					
					}
					
					if(type == "text2"){
						field_val_ok = 0;
						field_arr = field.split("|");
						for(f=0;f<field_arr.length;f++){
							
							if((form[field_arr[f]])&&(form[field_arr[f]].value != "")){
								field_val_ok = 1;
								break;
							}
						}
						
						if(field_val_ok == 0){
							faillist += (faillist == "") ? txt : ", " +txt;
							to_focus = (to_focus == null) ? form[field_arr[0]] : to_focus; 
						}
					
					}
					
					if(type == "checkbox"){
						
					
						if((form[field])&&(form[field].checked == false)){
							faillist += (faillist == "") ? txt : ", " +txt;
						}
					
					}
					
					if(type == "radio"){
						
					
						if((form[field])){
							
							radio_selected = 0;
							for(r=0;r<form[field].length;r++){
								if(form[field][r].checked == true){
									radio_selected = 1;
									break;
								}
							}
							if(radio_selected == 0){
							  faillist += (faillist == "") ? txt : ", " +txt;
							}
						}
					
					}
					if(type == "file"){
						
						if((form[field])&&(form[field].value == "")){
							faillist += (faillist == "") ? txt : ", " +txt;
							to_focus = (to_focus == null) ? form[field] : to_focus; 
						}else if((form[field])&&(!checkUploadFile(form[field].value))){
							txt += " - in a valid word document format or plain text";
							faillist += (faillist == "") ? txt : ", " +txt;
							to_focus = (to_focus == null) ? form[field] : to_focus; 
							
						}
						
					}
					
					if(type == "file2"){
						if((form[field])&&(form[field].value != "")){
							if(!checkUploadFile(form[field].value)){
								txt += "the document in a valid word document format or plain text";
								faillist += (faillist == "") ? txt : ", " +txt;
								to_focus = (to_focus == null) ? form[field] : to_focus; 
								
							}
						}
						
					}
				
			}
			
			
			
			
			if((invalidlist != "")||(faillist != "")){
				tmp = "";
				tmp += (invalidlist != "")? "The following details were not recognised:- \r\n"+invalidlist+"\r\n\r\n":"";
				tmp += (faillist != "")? "Please complete the following:- \r\n"+faillist+"\r\n":"";
				alert(tmp);
				try{
					to_focus.focus();
					to_focus.select();
				}catch(e){
				}
			}else{
				
				if(todo == "member_password"){
					
					if(!checkPasswordMatch(form['confirm_password'],form['new_password'],1)){
						checkPasswordMatch(form['confirm_password'],form['new_password']);
						return false;
					}
				}
				
				form.action = action;
				form.todo.value = todo;
				disableBtns(form);
				
				try{
					if(pageTracker){
						try{
							var p_url = "/"+action.substr(global_url.length);
							pageTracker._trackPageview(p_url);
						}catch(track_err){
						}
					}
				}catch(page_tracker_err){
				}
				
				form.submit();
				document.getElementById('form_result_txt_'+id).innerHTML = "processing please wait....";
				document.getElementById('form_result_div_'+id).style.display= "block";
				document.getElementById('form_div_'+id).style.display= "none";
				resizePage();
				
				
				
			}
			
	
	}
	
	
	
	
	
}
/*
# # # # # # #
# CHANGELOG
#
# V0.01 SDW      2008-11-26                          Original Code
#
*/
var IE = document.all?true:false;
var tempX = 0
var tempY = 0
var max_x = null;
var max_y = null;
var mouse_move_started = 0;


function startMouseMove(){
	
	if(mouse_move_started == 0){
		mouse_move_started = 1;
		if(window.Event && document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
	
		// Set-up to use getMouseXY function onMouseMove
		document.onmousemove = getMouseXY;
	}

}

function getMouseXY(e) {
	
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.documentElement.scrollLeft 
    tempY = event.clientY + document.documentElement.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  return true
}


function showTag(id,text,show){
	
	
	if(window['pres_alpha']){
		clearTimeout(window['pres_alpha']);
	}
	
	if(text != ""){
		
		if(document.getElementById(id)){
			
			h = document.documentElement.clientHeight;
			header_h = parseInt(document.getElementById('header').style.height)
			//alert(h+"\r\n"+tempY);
			
			if( (tempY - 20 + 200)  > h){
				h1 = (h - 200)
			}else{
				h1 = (tempY - 20);
			}
			w1 = tempX + 10;
			re1=/alpha_/gi;
			this_class = document.getElementById(id).className;
			alpha = this_class.replace(re1,"");
			alpha = Math.abs(alpha);
			if(show == 1){
				document.getElementById(id).style.left = (show == 1) ? (w1) + "px" : "-1000px";
				document.getElementById(id).style.top = (show == 1) ?  h1 + "px" : "-1000px";
			}
			document.getElementById(id).style.height = "180px";
			text = decode64(text);
			re=/\n/gi;
			text = text.replace(re,"<br>");
			document.getElementById(id).innerHTML = text;
			
			if(show == 1){
				
					if(alpha < 100){
						text = encode64(text);
						document.getElementById(id).className = "alpha_" + (alpha + 10);
						window['pres_alpha'] = setTimeout("showTag('"+id+"','"+text+"',"+show+")",10);
						
					}else{
						
						document.getElementById(id).className = "alpha_100";
					}
			
			}else{
					
					if(alpha > 0){
						text = encode64(text);
						document.getElementById(id).className = "alpha_" + (alpha - 10);
						window['pres_alpha'] = setTimeout("showTag('"+id+"','"+text+"',"+show+")",10);
						
					}else{
						
						document.getElementById(id).className = "alpha_0";
						document.getElementById(id).style.left =  "-1000px";
						document.getElementById(id).style.top =  "-1000px";
					}
				
			}
			
		}
		
		
		
		
	}
	
	
}
/*
# # # # # # # #
# CHANGELOG
# 2009-06-18 GPJ	Original Code
# 2009-06-30 GPJ	Converted to JS
# 2009-06-30 GPJ	Added 'name' type
# 2009-07-01 GPJ	MOD construct pat_name1 from title_arr and qual_arr (Allow easy modification to regex by adding to arrays) 
# 2009-07-08 GPJ	Added types:  'address','case','card','date'
# 2009-07-27 GPJ	Converted back to PHP
#

# # # # # # # #
# PURPOSE
# Validate and reformat string according to type
#			

# # # # # # # #
# ARGS
# Passed	(str,type='guess',result_format,args="")
#			str		String to be validated / formatted
#			type	See table below
#			format	String governing format of return value, format-elements are replaced by derived values, other chars returned in sequence.If NOT passed then default taken from table below
#			args	Behaviour control flags passed as concatenated string of single letters (eg MV ) See table below
# 					V		Validate only (Return true or false, otherwise return reformatted or false)
#					A		Return parts[] array, otherwise return fstr / false
#					F		Postcode: Check Foreign postcodes (USA / Can), return unformatted, or false if matched as F
#					M		Tel: Restrict valid matches to Mobile numbers
#					X		ALL: Return '' in lieu of false (Unless V)
#					S		Strict (Type specific)
#					E		Use Ext information
#					5		Allow 5 digit phone numbers

#
#						default
#			type		result		args								format elements
#			-			-			V	A	F	M	X	S	E	5		-		
# 			name		'1 2'		x	x								0:Title, 1:Forename, 2:Middle names, 3:Surname, 4:Qualifiers, 5:Initials (surname initial is dropped if surname is in result), 6:Gender ('M'|'F'|'' inferred from title), 7:ALL with TitleCase applied
#			postcode	'1 2'		x	x	x							0:Incode alpha, 1:Incode alnum, 2:Outcode
#			tel			'1 2'		x	x		x			x	x		0:Int, 1:STD, 2:Num
#			email		'0@1'		x	x								0:user, 1:domain, 2:TLD													
#			card		'1 2 3 4'	x	x								0:Provider, 1:First quad(ish), 2:Second quad(ish), 3:Third quad(ish), 4:Fourth quad(ish)
#			case		'0'								x				0:Sentence case(Capitalise start of sentence), 1:Initial case(Capitalise start of word), 2:Name case(Capitalise start of word & hypenated parts), S:Strict(Lowercase anything else, unless word contains number, or no vowel), C:Compress(Remove multiple spaces, and force space after punctuation.)
#			date		'4/5/3'		x									0:st|nd|rd|th, 1:d, 2:m, 3:yy, 4:dd, 5:mm, 6:yyyy, 7:Mth, 8:Month
#			address					x
#			guess												
#
# Returns	Reformatted string if recognised as type, modified by result_format & args passed
#			OR Array of parts if args contains 'A'
#			OR FALSE if not recognised as type OR if required elements of result_format cannot be derived
#

# # # # # # # #
# PSEUDOCODE
# 1.	Initialise
# 2.	Match pattern
# 3.	Establish parts
# 4.	Build result
# 5.	Respond
#		


*/

// MAIN function
function fn_valid_format(str,type,result_format,args){
	
	//////////////////
	// SUBFUNCTIONS //
	//////////////////

	function luhn_check(number,validators) {
		//return true if number is valid card, else return false
		if(!validators){validators='05';} //<- default allow mudulus to be 0 or 5 (0 is original check, 5 used to extend number of cards in circulation)
		var number=number.replace(/\D/g,''); //<- Strip any non-digits
		var number_length=number.length;
		var parity=number_length % 2; //<- weighting applies to every 2nd digit AS READ FROM RIGHT TO LEFT.
		var total=0;
		for (i=0; i < number_length; i++) {
			var digit=number.charAt(i);
			// Multiply alternate digits by two
			if (i % 2 == parity) {
				digit=digit * 2;
				if (digit > 9) {digit=digit - 9;} //<- If the sum is two digits, add them together (effectively)
			}
			total += parseInt(digit);
		}
		
		// If the total mod 10 equals 0, the number is valid
		var validator = (total % 10);
		return((validators.indexOf(validator) != -1)? true:false);
	}

	function change_case(str,result_format,args){
		//result_format
		//	'0' Sentence case: 	Capitalise start of sentence.
		//	'1'	Initial case:	Capitalise start of word
		//	'2'	Name case:		Capitalise start of word & hypenated parts
		//	'3' Strict:			Lowercase anything else (unless word contains number, or no vowel)
		//	'4' Auto space:		Compress multiple spaces, force space after punctuation.
		//args
		//	'S' Strict:			Lowercase anything else (unless word contains number, or no vowel)
		//	'C' Compress space:	Compress multiple spaces, force space after punctuation.
		
		if(!result_format){result_format='';}
		if((result_format.indexOf('0') == -1)&&(result_format.indexOf('1') == -1)&&(result_format.indexOf('2') == -1) ){result_format += '0';} //<- Default action in absence of 0,1,2
		
		var pat_words	= /\s*[\S]*/g;
		var fstr = str+'';
		var parts = Array();
		var matches = Array();
		var temp = Array();	
		var result = '';
		if( fstr.match(pat_words) ){
			matches = fstr.match(pat_words);
			
			var prev_c = ' ';
			var prev_2c = '';
			var prev_3c = '';
			var c = '';
			var prev_non_spc = '.'; //<- Primes recognition of start of sentence for case 0
			
			for(j=0; j< matches.length; j++){
				m = matches[j];
				if( ((result_format.indexOf('4') != -1)||(args.indexOf('C') != -1)) ){m = m.replace(/ {2,}/,' ')}		//<- Compress multiple spaces if 4 in result
				for(i=0; i< (m.length); i++){
					c = m.substr(i,1);
					fc = c; //<- Assume unformatted to start
					if     ( (result_format.indexOf('0') != -1)&&((".:").indexOf(prev_non_spc) != -1) ){fc = c.toUpperCase()}		//<- Force UPPER	0 in result and first char in sentence
					else if( (result_format.indexOf('1') != -1)&&((".: (").indexOf(prev_c) != -1) ){fc = c.toUpperCase()}			//<- Force UPPER	1 in result and first char in word
					else if( (result_format.indexOf('2') != -1)&&((".: ('-\n").indexOf(prev_c) != -1) ){fc = c.toUpperCase()}			//<- Force UPPER	2 in result and first char in word or broken part
					else if( ((result_format.indexOf('3') != -1)||(args.indexOf('S') != -1))&&(m.match(/[aeiou]/i))&&(!m.match(/[0-9]/i)) ){fc = c.toLowerCase()}	//<- Force lower	3 in result and word contains vowel and no number
																							 
					if( (result_format.indexOf('2') != -1)&&(prev_2c == 'Mc') ){fc = c.toUpperCase();}
					if( (result_format.indexOf('2') != -1)&&(prev_3c == 'Mac') ){fc = c.toUpperCase();}
					result += fc;
					prev_3c = prev_2c+fc;
					prev_2c = prev_c+fc;
					prev_c = fc;
					tmp = " ";
					//if(tmp.indexOf(fc) == -1){prev_non_spc = fc;}
					if(fc.match(/\S/)){prev_non_spc = fc;}

				}
			}
		}
		//alert('#result_format#'+result_format);
		return result;
	}


	// PHP in_array() - tests for value in array
	function in_array(needle, haystack, argStrict) {
		var key = '', strict = !!argStrict;	// !!val typecasts val to bool
		if(strict){
			for(key in haystack){
				if(haystack[key] === needle){return true;}
			}
		}else{
			for(key in haystack){
				if(haystack[key] == needle){return true;}
			}
		}
		return false;
	}

	// PHP trim() - removes leading and trailing whitespace
	function trim(str){
		//if((!str)||(str == '')){return str;}
		return str.replace(/^\s+/, '').replace(/\s+$/, '');
	}

	//////////////////
	//     MAIN     //
	//////////////////
	
	if((!type)||(type=="")){type='guess';}
	if((!args)||(args=="")){args="";}
	var args_arr = (args)? args.split(""):Array();
	var title_arr = Array('mr','master','sir','mrs','ms','miss','madam','dame','dr','doctor');
	var qual_arr = Array('b.a','b.sc','b.eng','b.ed','m.a','m.sc','ph.d','g.p');

	var pat_qual = '';
	for(var i=0;i<qual_arr.length;i++){
		pat_qual += (i==0)? qual_arr[i].replace('.','(?:\\.)?'):'|'+qual_arr[i].replace('.','(?:\\.)?');
	}
	
	var pat_title = '';
	for(var i=0;i<title_arr.length;i++){
		pat_title += (i==0)? title_arr[i]:'|'+title_arr[i];
	}
	
	// Patterns
	var pat_pc1		= /^(([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]))( *)([0-9][ABD-HJLNP-UW-Z]{2}))$/i;	//<- match '1 2'
	var pat_pc2		= /^(([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])))$/i;									//<- match '1'
	var pat_pc3		= /^(([A-PR-UWYZ]|[A-HK-Y][A-PR-UWYZ]))$/i;																								//<- match '0'
	var pat_pc4		= /^((\d{5}-\d{4})|(\d{5})|([ABCEGHJKLMNPRSTVXY]\d[A-Z]\s?\d[A-Z]\d))$/i;																//<- Regular expression for US (ZIP and ZIP+4) and Canadian postal codes. It allows 5 digits for the first US postal code and requires that the +4, if it exists, is four digits long. Canadain postal codes can contain a space and take form of A1A 1A1. The letters can be upper or lower case, but the first letter must be one of the standard Canadian zones: A,B,C,E,G,H,J,K,L,M,N,P,R,S,T,V,X,Y.
	
	var pat_email1	= /^(([0-9a-z]([\-.\w_\&\']*[0-9a-z_\-\&\'])*)@(([0-9a-z][\-\w]*[0-9a-z]\.)+([a-z]{2,9})))$/i;											//<- (1) It allows usernames with 1 or 2 alphanum characters, or 3+ chars can have -._ in the middle. username may NOT start/end with -._ or any other non alphanumeric character. (2) It allows heirarchical domain names (e.g. me@really.big.com). Similar -._ placement rules there. (3) It allows 2-9 character alphabetic-only TLDs. (4) No IP email addresse	
	
	var pat_tel1	= /^(\+\d{3}[\s-]?|\+\d{1,2}[\s-])?\s*((0|\(\d+\))?([\d\s-]+))((x|ex|ext|extn|extension)?[\s-]*(\d*))$/;								//<- UK telphone, allows international prefix, area, number, ext
	
	var pat_name1	= new RegExp('^(('+pat_title+')[\\s\\.]+)?([\\w\\s\'-\\.]+?)([\\s\\.]+(\\(.+\\)|'+pat_qual+'))?[\\s\\.]*$', 'i');						//<- Add other titles or qualifications to arrays above !!
	
	var pat_words	= /\s*[\S]*/g;
	
	
	var pat_cc_amex15	= /^(3[47]\d{2})(?:[:\-\s])?(\d{6})(?:[:\-\s])?(\d{5})$/;													//<- AmEx			(15) 34,37
	var pat_cc_dine14	= /^(3[68]\d{2}|30[05]\d)(?:[:\-\s])?(\d{6})(?:[:\-\s])?(\d{4})$/;											//<- Diners Club	(14) 300-305, 36 
	var pat_cc_disc16a	= /^(6011)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;										//<- Discover		(16) 6011,
	var pat_cc_disc16b	= /^(622[1-9])(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;									//<- Discover		(16) 622126-622925 (tests for 6221-6229)
	var pat_cc_disc16c	= /^(64[4-9]\d|65\d{2})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;							//<- Discover		(16) 644-649, 65
	var pat_cc_jcb16	= /^(35[2-8]\d)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;									//<- JCB			(16) 3528-3589 (tests 352-358)
	var pat_cc_laser	= /^(6304|6706|6771|6709)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4,7})$/; 					//<- Laser			(16-19) 6304, 6706, 6771, 6709
	var pat_cc_maest	= /^(5018|5020|5038|6304|6759|6761|6763)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{0,7})$/; 		//<- Maestro 		(12-19) 5018,5020,5038,6304,6759,6761,6763
	var pat_cc_mast16	= /^(5[1-5]\d{2})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;								//<- MC				(16) 51,55
	var pat_cc_solo		= /^(6334|6767)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4}|\d{6}|\d{7})$/; 					//<- Solo			(16,18,19) 6334, 6767
	var pat_cc_switcha	= /^(4903|4905|4911|4936|6333|6759)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4}|\d{6}|\d{7})$/;	//<- Switch			(16,18,19) 4903,4905,4911,4936,6333,6759
	var pat_cc_switchb	= /^(5641)(?:[:\-\s])?(82\d{2})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4}|\d{6}|\d{7})$/;						//<- Switch			(16,18,19) 564182
	var pat_cc_switchc	= /^(6331)(?:[:\-\s])?(10\d{2})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4}|\d{6}|\d{7})$/;						//<- Switch			(16,18,19) 633110
	var pat_cc_viselec	= /^(4175|4917|4913|4508|4844)(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;					//<- VISA Electron	(16) 417500,4917,4913,4508,4844
	var pat_cc_visa		= /^(4\d{3})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d|\d{4})$/;									//<- VISA			(13,16) 4
	
	var pat_cc_unk		= /^(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})(?:[:\-\s])?(\d{4})$/;										//<- UNKNOWN but check if passes luhn_check()
	
	
	var pat_date_1		= /^(\d{1,2})(?:[^\d\w]+)(\d{1,2})(?:[^\d\w]+)(\d{2}|\d{4})$|^(\d{1,2})(?:\[^\d\w]+)(\d{1,2})$|^(\d{1,2})(?:[^\d\w]+)(\d{2}|\d{4})$/;	//<- d|dd.m|mm.yy|yyyy  or  d|dd.m|mm  or  m|mm.yy|yyyy
	var pat_date_1g		= /^(\d{1,2})(?:[^\d\w]+)(\d{1,2})(?:[^\d\w]+)(\d{2}|\d{4})$/;						//<- d|dd.m|mm.yy|yyyy used for guess
	var pat_date_2		= /^(\d{1,2})(?:st|nd|rd|th)?(?:[\.:\-\s]+)(\w+)(?:[\.:\-\s]+)(\d{2}|\d{4})$/i;		//<- d|dd|dth abc yy|yyyy
	

	// Guessing type
	if((type == '')||(trim((type+'').toLowerCase()) == 'guess')){
		var matches = Array();
		var days_in_month = Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
		
		if( trim((str+'').toUpperCase()).match(pat_pc1) )									{return('postcode');}
		else if( (in_array('F',args_arr))&&(trim((str+'').toUpperCase()).match(pat_pc4)) )	{return('postcode US/Can');}
		else if( trim((str+'').toLowerCase()).match(pat_email1) )							{return('email');}
		else if( (trim(str+'').match(pat_cc_unk))&&(luhn_check(str)) )						{return('card');}
		else if( (trim(str+'').match(pat_cc_amex15))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_dine14))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_disc16a))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_disc16b))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_disc16c))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_jcb16))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_laser))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_maest))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_mast16))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_solo))&&(luhn_check(str)) )						{return('card');}
		else if( (trim(str+'').match(pat_cc_switcha))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_switchb))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_switchc))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_viselec))&&(luhn_check(str)) )					{return('card');}
		else if( (trim(str+'').match(pat_cc_visa))&&(luhn_check(str)) )						{return('card');}
		else if( trim(str+'').match(pat_date_1g) ){
			matches = trim(str+'').match(pat_date_1g);
			if( (parseInt(matches[1])>=1)
			&&(parseInt(matches[1])<=days_in_month[parseInt(matches[2])])
			&&(parseInt(matches[2])>=1)
			&&(parseInt(matches[2])<=12) )													{return('date');}
		}
		else if( trim(str+'').match(pat_date_2) )											{return('date');}
		else if( trim((str+'').toLowerCase()).match(pat_tel1) )								{return('phone');}
		else{return(false);}
	}

	// Validate and format
	var valid = false;
	var validate = (in_array('V',args_arr))? true:false;
	var return_arr = (in_array('A',args_arr))? true:false;
	
	
	switch(trim(type+'').toLowerCase()){

////////////
		case 'name':
		case 'user':
		case 'username':
			//result_format
			//	'0' Title
			//	'1'	Forename
			//	'2'	Middle names
			//	'3' Surname
			//	'4' Qualifiers
			//	'5'	Initials (Full initials if Surname not required in result, otherwise surname initial is dropped)
			//	'6'	Gender (inferred from title)
			//	'7' Full given info
			if((!result_format)||(result_format=="")){result_format='1 3';}
			var fstr = trim((str+''));
			var parts = Array();
			var matches = Array();
			var temp = Array();
			
			if( fstr.match(pat_name1) ){ //Personal Name
				matches = fstr.match(pat_name1);
				parts[0] = matches[2]; //<- Title
				var temp1 = matches[3]; //<- raw Name
				parts[5] = matches[5]; //<- Qualifiers
				parts[7] = matches[0]; //<- raw ALL
				temp = temp1.split(/[\s\.]+/);
				var temp2 = '';
				parts[2] = '';
				
				switch(''+temp.length){
					case '0':
						break;

					case '1':
						if((!parts[0])||(parts[0] == '')){parts[1] = temp[0];} //<- Assume forename
						else{parts[3] = temp[0];} //<- Assume surname
						break;
					
					case '2':
						parts[1] = temp[0]; 			//<- Assume forename
						parts[3] = temp[1]; 			//<- Assume surname
						parts[4] = temp[0].substr(0,1) //<- Assume initials (excl surname)
						break;
						
					default:
						parts[1] = temp[0]; 			//<- Assume forename
						parts[4] = temp[0].substr(0,1); //<- Assume initials (excl surname)
						
						for(i=1; i<(temp.length -1); i++){
							parts[2] += (i == 1)? temp[i] : ' '+temp[i];
							parts[4] += temp[i].substr(0,1); //<- Assume initials (excl surname)
						}
						parts[3] = temp[temp.length -1]; //<- Assume surname
						break;
				}
				
				switch(parts[0].toLowerCase()){
					case 'mr':
					case 'master':
					case 'sir':
						parts[6] = 'M';
						break;
						
					case 'mrs':
					case 'ms':
					case 'miss':
					case 'madam':
					case 'dame':
						parts[6] = 'F';
						break;
						
					default:
						parts[6] = '';
						break;				
				}

				if( (('x'+result_format).indexOf('0') != -1)&&(parts[0] == '') ){return false;}		//If result_format requires  nonexistent parts[]
				if( (('x'+result_format).indexOf('1') != -1)&&(parts[1] == '') ){return false;}		//If result_format requires  nonexistent parts[]
				if( (('x'+result_format).indexOf('3') != -1)&&(parts[3] == '') ){return false;}		//If result_format requires  nonexistent parts[]
				if( (('x'+result_format).indexOf('4') != -1)&&(parts[4] == '') ){return false;}		//If result_format requires  nonexistent parts[]
				if( (('x'+result_format).indexOf('3') == -1)&&(('x'+result_format).indexOf('4') != -1) ){parts[4] += parts[3].substr(0,1);}		//Add surname initial to initials if surname not required

				/*parts[0] = name_case(parts[0]);
				parts[1] = name_case(parts[1]);
				parts[2] = name_case(parts[2]);
				parts[3] = name_case(parts[3]);
				if(parts[4]){parts[4] = parts[4].toUpperCase();}
				parts[7] = name_case(parts[7]);*/

				if(parts[0]){parts[0] = change_case(parts[0],'2');}
				if(parts[1]){parts[1] = change_case(parts[1],'2');}
				if(parts[2]){parts[2] = change_case(parts[2],'2');}
				if(parts[3]){parts[3] = change_case(parts[3],'2');}
				if(parts[4]){parts[4] = parts[4].toUpperCase();}
				if(parts[7]){parts[7] = change_case(parts[7],'2');}


				valid = true;
			}else{
				return false;
			}


			if(return_arr){return(parts);}
			else{
				result = '';
				for(i=0; i < (result_format+'').length; i++){
					j = result_format.substr(i,1);
					switch(j){
						case'0':
						case'1':
						case'2':
						case'3':
						case'4':
						case'5':
						case'6':
						case'7':
							if(parts[j]){result += parts[j];}
							break;
						default:
							result += j+'';
							break;
					}
				}
				result = (trim(result)).replace(/\s{2,}/,' ');
				return (validate)? valid:result;
			}
			break;
			
////////////
		case 'postcode':
		case 'pcode':
		case 'pc':
			//result_format
			//	'0' Incode alpha only
			//	'1'	Incode alphanumeric
			//	'2'	Outcode

			//args
			//	'F' check foreign postcodes (US and Canadian)

			//eg
			//	'BL14JU',''		returns 'BL1 4JU'
			//	'BL14JU','1 2'	returns 'BL1 4JU'
			//	'BL14JU','12'	returns 'BL14JU'
			//	'BL14JU','1'	returns 'BL1'
			//	'BL14JU','0'	returns 'BL'
			//	'BL14JU','F'	returns 'BL1 4JU'
			//	'84118-3423','F'	returns '84118-3423'
			//	'84118-3423','F'	returns '84118-3423'
			//	'84118-3423',''		returns FALSE
			//	Malformed postcode returns false (NB Malformed isn't the same as nonexistent BL99 4JU is correctly formed bt doesn't exist)
			
			var check_foreign = (in_array('F',args_arr))? true:false;
			if((!result_format)||(result_format=="")){result_format='1 2';}
			var fstr = trim((str+'').toUpperCase());
			var parts = Array();
			var matches = Array();
			var temp = Array();
			
			if( fstr.match(pat_pc1) ){ //Full postcode
				matches = fstr.match(pat_pc1);
				//matches(2) = Incode BL1
				//matches(6) = Spaces
				//matches(7) = Outcode	4JU
				parts[1] = matches[2];
				parts[2] = matches[7];
				temp = matches[2].match(/^[\D]*/);
				parts[0] = temp[0];	// BL
				valid = true;
			}else if( fstr.match(/^GIR *0AA$/i) ){ //Special case
				parts[1] = 'GIR';
				parts[2] = '0AA';
				parts[0] = 'GIR';
				valid = true;
			}else if( fstr.match(pat_pc2) ){ //Alphanumeric Incode only
				matches = fstr.match(pat_pc2);
				parts[1] = matches[2];
				temp = matches[2].match(/^[\D]*/);
				parts[0] = temp[0];	// BL
				if( ('x'+result_format).indexOf('2') != -1 ){return false;}		//If result_format requires  parts[2] then error
				valid = true;
			}else if( fstr.match(pat_pc3) ){ //Alpha Incode only
				matches = fstr.match(pat_pc3);
				parts[0] = matches[0];// BL		
				if( ('x'+result_format).indexOf('2') != -1 ){return false;}		//If result_format requires  parts[2] then error
				if( ('x'+result_format).indexOf('1') != -1 ){return false;}		//If result_format requires  parts[1] then error
				valid = true;
			}else if( (check_foreign)&&(fstr.match(pat_pc4)) ){ //US or Canadian
				valid = true;
				return (validate)? valid:result; // Special Case: Break out here before result is modified
			}else{
				return false;
			}
			
			
			if(return_arr){return(parts);}
			else{
				result = '';
				for(i=0; i < (result_format+'').length; i++){
					j = result_format.substr(i,1);
					switch(j){
						case'0':
						case'1':
						case'2':
							result += parts[j];
							break;
						default:
							result += j+'';
							break;
					}
				}
				return (validate)? valid:result;
			}
			break;


////////////
		case 'tel':
		case 'telephone':
		case 'phone':
			//result_format
			//	'0' Int code
			//	'1'	Area
			//	'2'	Number
			//	'3'	Ext
			
			//args
			//	'M' Restrict valid to mobile numbers
			//	'S' Strict: false if not able to supply requested result_format, else allow +44 and area code to be missing
			//	'E' Prefix extension with 'ext'
			//	'5' Allow 5 digit number
			
			//	'+44 (0)1204 467440',''		returns '01204 467440'
			//	'+44 (0)1204 467440','1 2'	returns '01204 467440'
			//	'+44 (0)1204 467440','0 1 2'returns '+44 1204 467440'
			//	'+44 (0)1204 467440','12'	returns '01204467440'
			//	'+44 (0)1204 467440','2'	returns '467440'
			//	'+44 (0)1204 467440','M2'	returns FALSE
			//	'+44 (0)7976 467440','M2'	returns '467440'
			//	Malformed number returns false	(NB Malformed isn't the same as nonexistent +99 (0)999 999999 is correctly formed bt doesn't exist)
			var is_mobile = false;
			var check_mobile = (in_array('M',args_arr))? true:false;
			var check_strict = (in_array('S',args_arr))? true:false;
			var use_ext = (in_array('E',args_arr))? true:false;
			var allow_5dig = (in_array('5',args_arr))? true:false;
			
			if((!result_format)||(result_format=="")){result_format='0 1 2 3';use_ext = true;}
			var fstr = trim((str+'').toLowerCase());
			var parts = Array();
			var matches = Array();

			if( fstr.match(pat_tel1) ){ //Full
				matches = fstr.match(pat_tel1);
				parts[0] = trim(matches[1]+'');		//<- +044
				var temp1 = trim(matches[3]);		//<- 0 or (...)
				var temp2 = trim(matches[4]);		//<- combined 1 2 (excluding leading 0 above)
				temp2 = temp2.replace(/[\s-]/g,'');
				exception_arr = Array('121','131','141','151','161','191');
				var len1 = (in_array(temp2.substr(0,3),exception_arr))? 3:4;
				if( ((temp2.length == 5)&&(allow_5dig))||(temp2.length == 6)){
					//Assume only Number given
					if((parts[0] != '')||(temp1 != '')){return false;}
					if( (('x'+result_format).indexOf('0') != -1)&&(check_strict==true) ){return false;} 
					if( (('x'+result_format).indexOf('1') != -1)&&(check_strict==true) ){return false;} 
					parts[2] = temp2;
					parts[3] = trim(matches[7]);	//<- ext
				}else if((temp2.length == 9)||(temp2.length == 10)){
					//Assume area code given
					if( (parts[0] == '')&&(('x'+result_format).indexOf('0') != -1)&&(check_strict==true) ){return false;} 													//<- +44 required in result but not provided
					parts[1] = temp2.substr(0,len1); //<- Area, but still missing leading 0 or (...)
					parts[2] = temp2.substr(len1);   //<- Number
					parts[3] = trim(matches[7]);	 //<- Ext
					if(parts[1].substr(0,1) == '7'){is_mobile = true;}
				}else{
					return false;
				}
				if((temp2.length == 5)&&(is_mobile)){return false;}																											//<- Last caveat - mobile can't be 5 digit number
				
				
				
				if( ('x'+result_format).indexOf('0') == -1 ){temp1 = temp1.replace(/[\(\)]/g,'');}																			//<- Drop area brackets if not using +44 in result
				if( temp1 == '' ){temp1 = '0';} 																															//<- populate area start if wasn't passed with +44
				if( ((('x'+result_format).indexOf('0') == -1)||(parts[0] == ''))&&(parts[1]) ){parts[1] = temp1+parts[1];} 													//<- Prepend area code with '0' or (...) when result doesn't use +44
				if( (parts[1] == '')&&(('x'+result_format).indexOf('1') != -1)&&(check_strict==true) ){return false;} 															//<- Area required in result but not provided
				//if( (parts[1].substr(0,1) != '0')&&(('x'+result_format).indexOf('1') != -1 )){return false;} 																//<- Area required in result but doesn't start with '0'
				
				valid = true;
			}else{
				return false;
			}
		
			if(return_arr){return(parts);}
			else{
				result = '';
				for(i=0; i < (result_format+'').length; i++){
					j = result_format.substr(i,1);
					switch(j){
						case'0':
						case'1':
						case'2':
							result += (parts[j])? parts[j]:'';
							break;
						case'3':
							result += (parts[j])? ((use_ext == true)? 'ext'+parts[j]:parts[j]):'';
							break;
						default:
							result += j+'';
							break;
					}
				}
				result = (trim(result)).replace(/\s{2,}/,' ');
				
				if((check_mobile)&&(!is_mobile)){
					valid = false;
					result = false;
				}
				
				return (validate)? valid:result;
				break;
			}
		
			break;


////////////
		case 'email':
		case 'mail':
			//result_format
			//	'0' User
			//	'1'	Domain
			//	'2'	TLD
		
			//	'gavin.jackson@LANtec.co.uk',''		returns 'gavin.jackson@lantec.co.uk'
			//	'gavin.jackson@LANtec.co.uk','0@1'	returns 'gavin.jackson@lantec.co.uk'
			//	'gavin.jackson@LANtec.co.uk','0'	returns 'gavin.jackson'
			//	'gavin.jackson@LANtec.co.uk','1'	returns 'lantec.co.uk'
			//	'gavin.jackson@LANtec.co.uk','2'	returns 'uk'
			//	Malformed address returns false	(NB Malformed isn't the same as nonexistent username@domain.couk is correctly formed bt doesn't exist)

			if((!result_format)||(result_format=="")){result_format='0@1';}
			var fstr = trim((str+'').toLowerCase());
			var parts = Array();
			var matches = Array();
			var temp = Array();

			if( fstr.match(pat_email1) ){ //Full email
				matches = fstr.match(pat_email1);
				//$matches(2) = User
				//$matches(4) = Domain
				//$matches(6) = TLD
				parts[0] = matches[2];
				parts[1] = matches[4];
				parts[2] = matches[6];
				valid = true;

			}else{
				return false;
			}
		
			if(return_arr){return(parts);}
			else{
				result = '';
				for(i=0; i < (result_format+'').length; i++){
					j = (result_format+'').substr(i,1);
					switch(j){
						case'0':
						case'1':
						case'2':
							result += parts[j]+'';
							break;
						default:
							result += j+'';
							break
					}
				}
				return (validate)? valid:result;
			}
			break;			
			

////////////
		case 'case':
		case 'title':
			//result_format
			//	'0' Sentence case: 	Capitalise start of sentence.
			//	'1'	Initial case:	Capitalise start of word
			//	'2'	Name case:		Capitalise start of word & hypenated parts
			//	'3' Strict:			Lowercase anything else (unless word contains number, or no vowel)
			//	'4' Auto space:		Compress multiple spaces, force space after punctuation.
			result = change_case(str,result_format,args);
			return (validate)? true:result;
			break;			
			
////////////
		case 'card':
		case 'cc':
			//result_format
			//	'0' Provider 
			//	'1' First quad-ish
			//	'2' Second quad-ish
			//	'3' Third quad-ish
			//	'3' Fourth quad-ish

			
			var parts = Array();
			var matches = Array();
			var temp = Array();
			
			
			fstr = str.replace(/\D/g,''); //<- lose non-digits (NB allows strict pat_cc's above to accept spurious spacing)
			if(fstr.match(pat_cc_amex15)){
				//AmEx
				parts[0] = 'AmEx';
				if((!result_format)||(result_format=="")){result_format='1 2 3';}
				matches = fstr.match(pat_cc_amex15);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				valid = true;
						
			}else if(fstr.match(pat_cc_dine14)){
				//Diners Club
				parts[0] = 'Diners Club';
				if((!result_format)||(result_format=="")){result_format='1 2 3';}
				matches = fstr.match(pat_cc_dine14);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
			valid = true;
						
			}else if(fstr.match(pat_cc_disc16a)){
				//Discover
				parts[0] = 'Discover';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_disc16a);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
				
			}else if(fstr.match(pat_cc_disc16b)){
				//Discover
				parts[0] = 'Discover';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_disc16b);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
				
			}else if(fstr.match(pat_cc_disc16c)){
				//Discover
				parts[0] = 'Discover';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_disc16c);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
			
			}else if(fstr.match(pat_cc_jcb16)){
				//JCB
				parts[0] = 'JCB';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_jcb16);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
			
			}else if(fstr.match(pat_cc_laser)){
				//Laser
				parts[0] = 'Laser';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_laser);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
			
			}else if(fstr.match(pat_cc_maest)){
				//Maestro
				parts[0] = 'Maestro';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_maest);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;

			}else if(fstr.match(pat_cc_mast16)){
				//Mastercard
				parts[0] = 'Mastercard';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_mast16);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
					
			}else if(fstr.match(pat_cc_solo)){
				//Solo
				parts[0] = 'Solo';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_solo);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
					
			}else if(fstr.match(pat_cc_switcha)){
				//Switch
				parts[0] = 'Switch';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_switcha);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
					
			}else if(fstr.match(pat_cc_switchb)){
				//Switch
				parts[0] = 'Switch';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_switchb);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
					
			}else if(fstr.match(pat_cc_switchc)){
				//Switch
				parts[0] = 'Switch';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_switchc);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
					
			}else if(fstr.match(pat_cc_viselec)){
				//Visa Electron
				parts[0] = 'Visa Electron';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_viselec);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
					
			}else if(fstr.match(pat_cc_visa)){
				//Visa
				parts[0] = 'Visa';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_visa);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;
			
			}else if(fstr.match(pat_cc_unk)){
				//Unknown 16 digit
				parts[0] = 'UNKNOWN';
				if((!result_format)||(result_format=="")){result_format='1 2 3 4';}
				matches = fstr.match(pat_cc_unk);
				if(!luhn_check(fstr)){return false;}
				parts[1] = matches[1];
				parts[2] = matches[2];
				parts[3] = matches[3];
				parts[4] = matches[4];
				valid = true;

			}else{
				return false;	
			}
			
			
			if((!result_format)||(result_format=="")){result_format='1 2 3 4';} //<- Shouldn't be needed
			if(return_arr){return(parts);}
			else{
				result = '';
				for(i=0; i < (result_format+'').length; i++){
					j = result_format.substr(i,1);
					switch(j){
						case'0':
						case'1':
						case'2':
						case'3':
						case'4':
							result += (parts[j])? parts[j]:'';
							break;
						default:
							result += j+'';
							break;
					}
				}
				
				if(!valid){result = false;}
				return (validate)? valid:result;
				break;
			}
			
			break;			
			
////////////
		case 'date':
		case 'dat':
			//result_format
			//	'0' st|nd|rd|th
			//	'1'	d
			//	'2'	m
			//	'3' yy
			//	'4' dd
			//	'5' mm
			//	'6' yyyy
			//	'7' Mth
			//	'8' Month
			
			//	eg						returns
			//	'2 jan 93',''			02/01/93
			//	'2 jan 93','4/5/6'		02/01/1993
			//	'2 jan 93','10 7 '3'	2nd Jan '93
			//	'2 jan 93','10 8 6'		2nd January 1993
			//	'2 jan 93','5/3'		01/93
			//	'2 jan 93','654'		19930102
			
			if((!result_format)||(result_format=="")){result_format='4/5/3';}
			var fstr = trim((str+'').toLowerCase());
			var parts = Array();
			var matches = Array();
			var this_year = (new Date().getFullYear())+'';
			var this_yy = this_year.substr(2);
			var this_cc = this_year.substr(0,2);
			var this_yy_num = Math.abs(this_yy);
			var years_ahead = 20; //<- Years ahead for yy to be considered as future year, else consider yy as past year when converting to yyyy
			
			var days_in_month = Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
			var month_short = Array('','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
			var month_long = Array('','january','february','march','april','may','june','july','august','september','october','november','december');
			var dflag = false;
			
			if( fstr.match(pat_date_1) ){ // n/n/n
				matches = fstr.match(pat_date_1);
				
				if(matches[1]){ //<- dmy in [1][2][3]
					if((matches[1]<1)||(matches[1]>days_in_month[parseInt(matches[2])])){return false;} //Validate day
					if((matches[2]<1)||(matches[2]>12)){return false;} //Validate month
						// Allow year to be 0-9999 so no validation
					var tmp_d = matches[1];
					parts[0] = ((tmp_d == '1')||(tmp_d == '21')||(tmp_d == '31'))? 'st':((tmp_d == '2')||(tmp_d == '22'))? 'nd':((tmp_d == '3')||(tmp_d == '23'))? 'rd':'th';
					parts[1] = (matches[1] < 10)? matches[1].substr(matches[1].length-1):matches[1];
					parts[4] = (matches[1] < 10)? ('0'+matches[1]).substr(('0'+matches[1]).length-2):matches[1];
					parts[2] = (matches[2] < 10)? matches[2].substr(matches[2].length-1):matches[2];
					parts[5] = (matches[2] < 10)? ('0'+matches[2]).substr(('0'+matches[2]).length-2):matches[2];
					parts[3] = matches[3].substr(matches[3].length-2);
					parts[6] = (Math.abs(matches[3]) < this_yy_num+years_ahead)? (this_cc+matches[3]).substr((this_cc+matches[3]).length-4):((parseInt(this_cc)-1)+matches[3]).substr(((parseInt(this_cc)-1)+matches[3]).length-4);
					parts[7] = month_short[Math.abs(matches[2])].substr(0,1).toUpperCase()+month_short[Math.abs(matches[2])].substr(1);
					parts[8] = month_long[Math.abs(matches[2])].substr(0,1).toUpperCase()+month_long[Math.abs(matches[2])].substr(1);
																																		   
				}else if(matches[6]){ //<- my in [6][7]
					if((matches[6]<1)||(matches[6]>12)){return false;} //Validate month
						// Allow year to be 0-9999 so no validation
					parts[2] = (matches[6] < 10)? matches[6].substr(matches[6].length-1):matches[6];
					parts[5] = (matches[6] < 10)? ('0'+matches[6]).substr(('0'+matches[6]).length-2):matches[6];
					parts[3] = matches[7].substr(matches[7].length-2);
					parts[6] = matches[7];
					parts[7] = month_short[Math.abs(matches[6])].substr(0,1).toUpperCase()+month_short[Math.abs(matches[6])].substr(1);
					parts[8] = month_long[Math.abs(matches[6])].substr(0,1).toUpperCase()+month_long[Math.abs(matches[6])].substr(1);
							   
				}else{ //<- dm or my in [4][5]
					
					if(matches[4]>12){dflag = true;}
					else if(matches[5]>12){dflag = false;}
					else{ //<- Guess based on result requirements, otherwise assume my (as in credit card expiry)
						if((result_format.indexOf('1') != -1)||(result_format.indexOf('4') != -1)){dflag = true;}
						else{dflag = false;}
					}
					
					if(dflag){ //<- dm in [4][5]
						if((matches[4]<1)||(matches[4]>days_in_month[matches[5]+0])){return false;} //Validate day
						if((matches[5]<1)||(matches[5]>12)){return false;} //Validate month
						parts[1] = (matches[4] < 10)? matches[4].substr(matches[4].length-1):matches[4];
						parts[4] = (matches[4] < 10)? ('0'+matches[4]).substr(('0'+matches[4]).length-2):matches[4];
						parts[2] = (matches[5] < 10)? matches[5].substr(matches[5].length-1):matches[5];
						parts[5] = (matches[5] < 10)? ('0'+matches[5]).substr(('0'+matches[5]).length-2):matches[5];
						parts[7] = month_short[Math.abs(matches[5])].substr(0,1).toUpperCase()+month_short[Math.abs(matches[5])].substr(1);
						parts[8] = month_long[Math.abs(matches[5])].substr(0,1).toUpperCase()+month_long[Math.abs(matches[5])].substr(1);
					}else{ //<- my in [4][5]
						if((matches[4]<1)||(matches[4]>12)){return false;} //Validate month
							// Allow year to be 0-9999 so no validation
						parts[2] = (matches[4] < 10)? matches[4].substr(matches[4].length-1):matches[4];
						parts[5] = (matches[4] < 10)? ('0'+matches[4]).substr(('0'+matches[4]).length-2):matches[4];
						parts[3] = matches[5].substr(matches[5].length-2);
						parts[6] = (Math.abs(matches[5]) < this_yy_num+years_ahead)? (this_cc+matches[5]).substr((this_cc+matches[5]).length-4):((parseInt(this_cc)-1)+matches[5]).substr(((parseInt(this_cc)-1)+matches[5]).length-4);
						parts[7] = month_short[Math.abs(matches[4])].substr(0,1).toUpperCase()+month_short[Math.abs(matches[4])].substr(1);
						parts[8] = month_long[Math.abs(matches[4])].substr(0,1).toUpperCase()+month_long[Math.abs(matches[4])].substr(1);
					}
					
				}
				valid = true;
				
			}else if( fstr.match(pat_date_2) ){
				matches = fstr.match(pat_date_2);
				
				var tmp_mon = matches[2].toLowerCase().substr(0,3);
				if(!in_array(tmp_mon,month_short)){return false;} //Validate month
				var tmp_mon_idx = 0;
				for(i=1; i<13; i++){
					if(tmp_mon == month_short[i]){tmp_mon_idx = i;}
				}
				if((matches[1]<1)||(matches[1]>days_in_month[tmp_mon_idx])){return false;} //Validate day
					// Allow year to be 0-9999 so no validation
				var tmp_d = matches[1];
				parts[0] = ((tmp_d == '1')||(tmp_d == '21')||(tmp_d == '31'))? 'st':((tmp_d == '2')||(tmp_d == '22'))? 'nd':((tmp_d == '3')||(tmp_d == '23'))? 'rd':'th';
				parts[1] = (matches[1] < 10)? matches[1].substr(matches[1].length-1):matches[1];
				parts[4] = (matches[1] < 10)? ('0'+matches[1]).substr(('0'+matches[1]).length-2):matches[1];
				parts[2] = tmp_mon_idx+'';
				parts[5] = ('0'+tmp_mon_idx).substr(('0'+tmp_mon_idx).length-2);
				parts[3] = matches[3].substr(matches[3].length-2);
				parts[6] = (Math.abs(matches[3]) < this_yy_num+years_ahead)? (this_cc+matches[3]).substr((this_cc+matches[3]).length-4):((parseInt(this_cc)-1)+matches[3]).substr(((parseInt(this_cc)-1)+matches[3]).length-4);
				parts[7] = month_short[tmp_mon_idx].substr(0,1).toUpperCase()+month_short[tmp_mon_idx].substr(1);
				parts[8] = month_long[tmp_mon_idx].substr(0,1).toUpperCase()+month_long[tmp_mon_idx].substr(1);
																																		  				
				valid = true;
			}else{
				return false;
			}

			if(return_arr){return(parts);}
			else{
				result = '';
				for(i=0; i < (result_format+'').length; i++){
					j = result_format.substr(i,1);
					switch(j){
						case'0':
						case'1':
						case'2':
						case'3':
						case'4':
						case'5':
						case'6':
						case'7':
						case'8':
							result += (parts[j])? parts[j]:'';
							break;
						default:
							result += j+'';
							break;
					}
				}
				
				if(!valid){result = false;}
				return (validate)? valid:result;
				break;
			}
			
			break;			
			
////////////
		case 'address':
		case 'addr':
			//result_format
			// <not applicable>
			result = change_case(str,'234'); //<-- Name-case, strict, compress spaces
			var	tmp_result = result;
			var addr_arr = result.split(/[,\n]/g);
			var replace_me = '';
			var postcode = '';
			var guess = '';
			for(k=0; k< (addr_arr.length); k++){
				guess = fn_valid_format(addr_arr[k],'guess');
				if(fn_valid_format(addr_arr[k],'guess') == 'postcode'){
					replace_me = addr_arr[k].replace(/^\s*/,'');
					postcode = fn_valid_format(addr_arr[k],'postcode','1 2');
				}
				result = tmp_result.replace(replace_me,postcode);
			}
			return (validate)? true:result;
			break;			
			
	}		
}



///////////////////////////////////////////////////////////////////////////////////////////////////
//Call via this proxy function to allow control overreturn values and formatting of on screen errors
/////////////////////////////////////////////////////////////////////////////////////////////////////

var valid_format_styles = Array();
var valid_format_error = Array();
function valid_format(obj,str,type,result_format,args){

	//Preserve original style of obj
	if(!valid_format_styles[obj.name]){
		valid_format_styles[obj.name] = (obj.style.color)? obj.style.color:'NOCOLOR';
	}
	var fstr = fn_valid_format(str,type,result_format,args);
	if(str == ''){fstr = '';}
	if(fstr === false){
		obj.style.color = form_error_color;
		valid_format_error[obj.name] = '1';
		obj.value = str;
		return(str);
	}else{
		if(valid_format_styles[obj.name] == 'NOCOLOR'){obj.style.removeAttribute('color');}
		else if(valid_format_styles[obj.name]){obj.style.color = valid_format_styles[obj.name];}
		valid_format_error[obj.name] = '0';
		obj.value = fstr;
		return(fstr);
	}

}

//MooTools, My Object Oriented Javascript Tools. Copyright (c) 2006 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('o ci={cj:\'1.11\'};k $77(N){m(N!=9N)};k $F(N){B(!$77(N))m O;B(N.5i)m\'G\';o F=7c N;B(F==\'2I\'&&N.ch){22(N.84){Y 1:m\'G\';Y 3:m(/\\S/).2v(N.ax)?\'cg\':\'cd\'}}B(F==\'2I\'||F==\'k\'){22(N.9C){Y 2t:m\'1z\';Y 7y:m\'5C\';Y 18:m\'4R\'}B(7c N.V==\'4M\'){B(N.3r)m\'ce\';B(N.8t)m\'1b\'}}m F};k $2a(){o 54={};M(o i=0;i<1b.V;i++){M(o K 1a 1b[i]){o ap=1b[i][K];o 6d=54[K];B(6d&&$F(ap)==\'2I\'&&$F(6d)==\'2I\')54[K]=$2a(6d,ap);14 54[K]=ap}}m 54};o $R=k(){o 1p=1b;B(!1p[1])1p=[c,1p[0]];M(o K 1a 1p[1])1p[0][K]=1p[1][K];m 1p[0]};o $5e=k(){M(o i=0,l=1b.V;i<l;i++){1b[i].R=k(1U){M(o 1V 1a 1U){B(!c.1L[1V])c.1L[1V]=1U[1V];B(!c[1V])c[1V]=$5e.6x(1V)}}}};$5e.6x=k(1V){m k(W){m c.1L[1V].4j(W,2t.1L.bh.1X(1b,1))}};$5e(7Z,2t,6i,aN);k $2A(N){m!!(N||N===0)};k $4T(N,aY){m $77(N)?N:aY};k $8c(3s,1D){m 1c.9q(1c.8c()*(1D-3s+1)+3s)};k $3A(){m L 96().9w()};k $55(1H){cf(1H);ck(1H);m 1n};o 3M=k(N){N=N||{};N.R=$R;m N};o cl=L 3M(U);o cr=L 3M(Q);Q.6e=Q.33(\'6e\')[0];U.4a=!!(Q.5r);B(U.9o)U.2P=U[U.6C?\'cs\':\'ag\']=1e;14 B(Q.aC&&!Q.cq&&!cp.cm)U.4x=U[U.4a?\'cn\':\'5x\']=1e;14 B(Q.co!=1n)U.8r=1e;U.cc=U.4x;8X.R=$R;B(7c 5B==\'9N\'){o 5B=k(){};B(U.4x)Q.aJ("cb");5B.1L=(U.4x)?U["[[bZ.1L]]"]:{}}5B.1L.5i=k(){};B(U.ag)5j{Q.c0("c1",O,1e)}5c(e){};o 18=k(1J){o 5Z=k(){m(1b[0]!==1n&&c.1i&&$F(c.1i)==\'k\')?c.1i.4j(c,1b):c};$R(5Z,c);5Z.1L=1J;5Z.9C=18;m 5Z};18.1l=k(){};18.1L={R:k(1J){o 7m=L c(1n);M(o K 1a 1J){o 9m=7m[K];7m[K]=18.9l(9m,1J[K])}m L 18(7m)},3i:k(){M(o i=0,l=1b.V;i<l;i++)$R(c.1L,1b[i])}};18.9l=k(2l,2i){B(2l&&2l!=2i){o F=$F(2i);B(F!=$F(2l))m 2i;22(F){Y\'k\':o 8i=k(){c.1r=1b.8t.1r;m 2i.4j(c,1b)};8i.1r=2l;m 8i;Y\'2I\':m $2a(2l,2i)}}m 2i};o 7u=L 18({bY:k(fn){c.4v=c.4v||[];c.4v.1k(fn);m c},7z:k(){B(c.4v&&c.4v.V)c.4v.aK().2g(10,c)},bX:k(){c.4v=[]}});o 2p=L 18({1B:k(F,fn){B(fn!=18.1l){c.$19=c.$19||{};c.$19[F]=c.$19[F]||[];c.$19[F].5S(fn)}m c},1h:k(F,1p,2g){B(c.$19&&c.$19[F]){c.$19[F].1q(k(fn){fn.3a({\'W\':c,\'2g\':2g,\'1b\':1p})()},c)}m c},4C:k(F,fn){B(c.$19&&c.$19[F])c.$19[F].2K(fn);m c}});o 43=L 18({2Y:k(){c.C=$2a.4j(1n,[c.C].R(1b));B(c.1B){M(o 3z 1a c.C){B($F(c.C[3z]==\'k\')&&(/^67[A-Z]/).2v(3z))c.1B(3z,c.C[3z])}}m c}});2t.R({7b:k(fn,W){M(o i=0,j=c.V;i<j;i++)fn.1X(W,c[i],i,c)},36:k(fn,W){o 4Y=[];M(o i=0,j=c.V;i<j;i++){B(fn.1X(W,c[i],i,c))4Y.1k(c[i])}m 4Y},2D:k(fn,W){o 4Y=[];M(o i=0,j=c.V;i<j;i++)4Y[i]=fn.1X(W,c[i],i,c);m 4Y},4F:k(fn,W){M(o i=0,j=c.V;i<j;i++){B(!fn.1X(W,c[i],i,c))m O}m 1e},bU:k(fn,W){M(o i=0,j=c.V;i<j;i++){B(fn.1X(W,c[i],i,c))m 1e}m O},3k:k(3r,15){o 3S=c.V;M(o i=(15<0)?1c.1D(0,3S+15):15||0;i<3S;i++){B(c[i]===3r)m i}m-1},8e:k(1g,V){1g=1g||0;B(1g<0)1g=c.V+1g;V=V||(c.V-1g);o 8g=[];M(o i=0;i<V;i++)8g[i]=c[1g++];m 8g},2K:k(3r){o i=0;o 3S=c.V;6Z(i<3S){B(c[i]===3r){c.74(i,1);3S--}14{i++}}m c},1j:k(3r,15){m c.3k(3r,15)!=-1},bV:k(1O){o N={},V=1c.3s(c.V,1O.V);M(o i=0;i<V;i++)N[1O[i]]=c[i];m N},R:k(1z){M(o i=0,j=1z.V;i<j;i++)c.1k(1z[i]);m c},2a:k(1z){M(o i=0,l=1z.V;i<l;i++)c.5S(1z[i]);m c},5S:k(3r){B(!c.1j(3r))c.1k(3r);m c},bW:k(){m c[$8c(0,c.V-1)]||1n},80:k(){m c[c.V-1]||1n}});2t.1L.1q=2t.1L.7b;2t.1q=2t.7b;k $A(1z){m 2t.8e(1z)};k $1q(41,fn,W){B(41&&7c 41.V==\'4M\'&&$F(41)!=\'2I\'){2t.7b(41,fn,W)}14{M(o 1w 1a 41)fn.1X(W||41,41[1w],1w)}};2t.1L.2v=2t.1L.1j;6i.R({2v:k(79,2U){m(($F(79)==\'2z\')?L 7y(79,2U):79).2v(c)},3d:k(){m 5O(c,10)},aH:k(){m 66(c)},8a:k(){m c.3g(/-\\D/g,k(31){m 31.8d(1).7A()})},aL:k(){m c.3g(/\\w[A-Z]/g,k(31){m(31.8d(0)+\'-\'+31.8d(1).5L())})},8R:k(){m c.3g(/\\b[a-z]/g,k(31){m 31.7A()})},5T:k(){m c.3g(/^\\s+|\\s+$/g,\'\')},7r:k(){m c.3g(/\\s{2,}/g,\' \').5T()},5E:k(1z){o 1s=c.31(/\\d{1,3}/g);m(1s)?1s.5E(1z):O},5G:k(1z){o 3C=c.31(/^#?(\\w{1,2})(\\w{1,2})(\\w{1,2})$/);m(3C)?3C.bh(1).5G(1z):O},1j:k(2z,s){m(s)?(s+c+s).3k(s+2z+s)>-1:c.3k(2z)>-1},b5:k(){m c.3g(/([.*+?^${}()|[\\]\\/\\\\])/g,\'\\\\$1\')}});2t.R({5E:k(1z){B(c.V<3)m O;B(c.V==4&&c[3]==0&&!1z)m\'c2\';o 3C=[];M(o i=0;i<3;i++){o 5d=(c[i]-0).4l(16);3C.1k((5d.V==1)?\'0\'+5d:5d)}m 1z?3C:\'#\'+3C.2c(\'\')},5G:k(1z){B(c.V!=3)m O;o 1s=[];M(o i=0;i<3;i++){1s.1k(5O((c[i].V==1)?c[i]+c[i]:c[i],16))}m 1z?1s:\'1s(\'+1s.2c(\',\')+\')\'}});7Z.R({3a:k(C){o fn=c;C=$2a({\'W\':fn,\'I\':O,\'1b\':1n,\'2g\':O,\'4f\':O,\'6f\':O},C);B($2A(C.1b)&&$F(C.1b)!=\'1z\')C.1b=[C.1b];m k(I){o 1p;B(C.I){I=I||U.I;1p=[(C.I===1e)?I:L C.I(I)];B(C.1b)1p.R(C.1b)}14 1p=C.1b||1b;o 3N=k(){m fn.4j($4T(C.W,fn),1p)};B(C.2g)m 9M(3N,C.2g);B(C.4f)m c3(3N,C.4f);B(C.6f)5j{m 3N()}5c(c9){m O};m 3N()}},bT:k(1p,W){m c.3a({\'1b\':1p,\'W\':W})},6f:k(1p,W){m c.3a({\'1b\':1p,\'W\':W,\'6f\':1e})()},W:k(W,1p){m c.3a({\'W\':W,\'1b\':1p})},c8:k(W,1p){m c.3a({\'W\':W,\'I\':1e,\'1b\':1p})},2g:k(2g,W,1p){m c.3a({\'2g\':2g,\'W\':W,\'1b\':1p})()},4f:k(aV,W,1p){m c.3a({\'4f\':aV,\'W\':W,\'1b\':1p})()}});aN.R({3d:k(){m 5O(c)},aH:k(){m 66(c)},1F:k(3s,1D){m 1c.3s(1D,1c.1D(3s,c))},2q:k(5Y){5Y=1c.3w(10,5Y||0);m 1c.2q(c*5Y)/5Y},c7:k(fn){M(o i=0;i<c;i++)fn(i)}});o P=L 18({1i:k(el,1U){B($F(el)==\'2z\'){B(U.2P&&1U&&(1U.1w||1U.F)){o 1w=(1U.1w)?\' 1w="\'+1U.1w+\'"\':\'\';o F=(1U.F)?\' F="\'+1U.F+\'"\':\'\';57 1U.1w;57 1U.F;el=\'<\'+el+1w+F+\'>\'}el=Q.aJ(el)}el=$(el);m(!1U||!el)?el:el.2j(1U)}});o 26=L 18({1i:k(T){m(T)?$R(T,c):c}});26.R=k(1U){M(o 1V 1a 1U){c.1L[1V]=1U[1V];c[1V]=$5e.6x(1V)}};k $(el){B(!el)m 1n;B(el.5i)m 2F.52(el);B([U,Q].1j(el))m el;o F=$F(el);B(F==\'2z\'){el=Q.6W(el);F=(el)?\'G\':O}B(F!=\'G\')m 1n;B(el.5i)m 2F.52(el);B([\'2I\',\'c4\'].1j(el.6S.5L()))m el;$R(el,P.1L);el.5i=k(){};m 2F.52(el)};Q.6Y=Q.33;k $$(){o T=[];M(o i=0,j=1b.V;i<j;i++){o 1S=1b[i];22($F(1S)){Y\'G\':T.1k(1S);Y\'c5\':1C;Y O:1C;Y\'2z\':1S=Q.6Y(1S,1e);62:T.R(1S)}}m $$.5M(T)};$$.5M=k(1z){o T=[];M(o i=0,l=1z.V;i<l;i++){B(1z[i].$6r)6l;o G=$(1z[i]);B(G&&!G.$6r){G.$6r=1e;T.1k(G)}}M(o n=0,d=T.V;n<d;n++)T[n].$6r=1n;m L 26(T)};26.73=k(K){m k(){o 1p=1b;o 1x=[];o T=1e;M(o i=0,j=c.V,3N;i<j;i++){3N=c[i][K].4j(c[i],1p);B($F(3N)!=\'G\')T=O;1x.1k(3N)};m(T)?$$.5M(1x):1x}};P.R=k(1J){M(o K 1a 1J){5B.1L[K]=1J[K];P.1L[K]=1J[K];P[K]=$5e.6x(K);o aB=(2t.1L[K])?K+\'26\':K;26.1L[aB]=26.73(K)}};P.R({2j:k(1U){M(o 1V 1a 1U){o 4m=1U[1V];22(1V){Y\'8J\':c.4A(4m);1C;Y\'19\':B(c.6j)c.6j(4m);1C;Y\'1J\':c.6o(4m);1C;62:c.7l(1V,4m)}}m c},28:k(el,ay){el=$(el);22(ay){Y\'9k\':el.3n.91(c,el);1C;Y\'94\':o 3x=el.8I();B(!3x)el.3n.86(c);14 el.3n.91(c,3x);1C;Y\'1o\':o 8Z=el.88;B(8Z){el.91(c,8Z);1C}62:el.86(c)}m c},7Y:k(el){m c.28(el,\'9k\')},6v:k(el){m c.28(el,\'94\')},c6:k(el){m c.28(el,\'3P\')},ct:k(el){m c.28(el,\'1o\')},b2:k(){o T=[];$1q(1b,k(4t){T=T.7P(4t)});$$(T).28(c);m c},2K:k(){m c.3n.bl(c)},9G:k(9V){o el=$(c.cu(9V!==O));B(!el.$19)m el;el.$19={};M(o F 1a c.$19)el.$19[F]={\'1O\':$A(c.$19[F].1O),\'1I\':$A(c.$19[F].1I)};m el.78()},cT:k(el){el=$(el);c.3n.cU(el,c);m el},bn:k(1K){c.86(Q.cS(1K));m c},7s:k(1A){m c.1A.1j(1A,\' \')},9z:k(1A){B(!c.7s(1A))c.1A=(c.1A+\' \'+1A).7r();m c},9E:k(1A){c.1A=c.1A.3g(L 7y(\'(^|\\\\s)\'+1A+\'(?:\\\\s|$)\'),\'$1\').7r();m c},cR:k(1A){m c.7s(1A)?c.9E(1A):c.9z(1A)},1P:k(K,J){22(K){Y\'21\':m c.bk(66(J));Y\'cO\':K=(U.2P)?\'cP\':\'cQ\'}K=K.8a();22($F(J)){Y\'4M\':B(![\'cV\',\'ak\'].1j(K))J+=\'4W\';1C;Y\'1z\':J=\'1s(\'+J.2c(\',\')+\')\'}c.1N[K]=J;m c},4A:k(1Z){22($F(1Z)){Y\'2I\':P.72(c,\'1P\',1Z);1C;Y\'2z\':c.1N.87=1Z}m c},bk:k(21){B(21==0){B(c.1N.4z!="4O")c.1N.4z="4O"}14{B(c.1N.4z!="8G")c.1N.4z="8G"}B(!c.6p||!c.6p.cW)c.1N.ak=1;B(U.2P)c.1N.36=(21==1)?\'\':"7d(21="+21*35+")";c.1N.21=c.$1W.21=21;m c},2h:k(K){K=K.8a();o 1M=c.1N[K];B(!$2A(1M)){B(K==\'21\')m c.$1W.21;1M=[];M(o 1N 1a P.4c){B(K==1N){P.4c[1N].1q(k(s){o 1N=c.2h(s);1M.1k(5O(1N)?1N:\'bo\')},c);B(K==\'2R\'){o 4F=1M.4F(k(5d){m(5d==1M[0])});m(4F)?1M[0]:O}m 1M.2c(\' \')}}B(K.1j(\'2R\')){B(P.4c.2R.1j(K)){m[\'bf\',\'7T\',\'2Q\'].2D(k(p){m c.2h(K+p)},c).2c(\' \')}14 B(P.97.1j(K)){m[\'bi\',\'bs\',\'az\',\'a6\'].2D(k(p){m c.2h(\'2R\'+p+K.3g(\'2R\',\'\'))},c).2c(\' \')}}B(Q.aF)1M=Q.aF.d2(c,1n).d3(K.aL());14 B(c.6p)1M=c.6p[K]}B(U.2P)1M=P.b6(K,1M,c);B(1M&&K.2v(/2E/i)&&1M.1j(\'1s\')){m 1M.68(\'1s\').74(1,4).2D(k(2E){m 2E.5E()}).2c(\' \')}m 1M},bg:k(){m P.7H(c,\'2h\',1b)},61:k(6u,1g){6u+=\'d1\';o el=(1g)?c[1g]:c[6u];6Z(el&&$F(el)!=\'G\')el=el[6u];m $(el)},9W:k(){m c.61(\'2l\')},8I:k(){m c.61(\'3x\')},d0:k(){m c.61(\'3x\',\'88\')},80:k(){m c.61(\'2l\',\'cX\')},cY:k(){m $(c.3n)},8H:k(){m $$(c.aC)},8o:k(el){m!!$A(c.33(\'*\')).1j(el)},5R:k(K){o 25=P.6A[K];B(25)m c[25];o 7V=P.a3[K]||0;B(!U.2P||7V)m c.cZ(K,7V);o 81=c.cN[K];m(81)?81.ax:1n},cM:k(K){o 25=P.6A[K];B(25)c[25]=\'\';14 c.a7(K);m c},cA:k(){m P.7H(c,\'5R\',1b)},7l:k(K,J){o 25=P.6A[K];B(25)c[25]=J;14 c.cB(K,J);m c},6o:k(1Z){m P.72(c,\'7l\',1Z)},5s:k(){c.b3=$A(1b).2c(\'\');m c},cC:k(1K){o 3q=c.4D();B([\'1N\',\'2s\'].1j(3q)){B(U.2P){B(3q==\'1N\')c.b4.87=1K;14 B(3q==\'2s\')c.7l(\'1K\',1K);m c}14{c.bl(c.88);m c.bn(1K)}}c[$77(c.83)?\'83\':\'b1\']=1K;m c},cz:k(){o 3q=c.4D();B([\'1N\',\'2s\'].1j(3q)){B(U.2P){B(3q==\'1N\')m c.b4.87;14 B(3q==\'2s\')m c.5R(\'1K\')}14{m c.b3}}m($4T(c.83,c.b1))},4D:k(){m c.6S.5L()},1l:k(){2F.3V(c.33(\'*\'));m c.5s(\'\')}});P.b6=k(K,1M,G){B($2A(5O(1M)))m 1M;B([\'2N\',\'2y\'].1j(K)){o 1I=(K==\'2y\')?[\'1u\',\'4n\']:[\'1o\',\'3P\'];o 3l=0;1I.1q(k(J){3l+=G.2h(\'2R-\'+J+\'-2y\').3d()+G.2h(\'4w-\'+J).3d()});m G[\'1E\'+K.8R()]-3l+\'4W\'}14 B(K.2v(/2R(.+)bf|34|4w/)){m\'bo\'}m 1M};P.4c={\'2R\':[],\'4w\':[],\'34\':[]};[\'bi\',\'bs\',\'az\',\'a6\'].1q(k(9v){M(o 1N 1a P.4c)P.4c[1N].1k(1N+9v)});P.97=[\'cy\',\'cv\',\'cw\'];P.7H=k(el,23,1O){o 1M={};$1q(1O,k(1t){1M[1t]=el[23](1t)});m 1M};P.72=k(el,23,7G){M(o 1t 1a 7G)el[23](1t,7G[1t]);m el};P.6A=L 3M({\'4R\':\'1A\',\'M\':\'cx\',\'cD\':\'cE\',\'cK\':\'cL\',\'cJ\':\'cI\',\'cF\':\'cG\',\'cH\':\'d4\',\'bI\':\'bN\',\'bB\':\'bJ\',\'J\':\'J\',\'7D\':\'7D\',\'7E\':\'7E\',\'7J\':\'7J\',\'7Q\':\'7Q\'});P.a3={\'4N\':2,\'4s\':2};P.2H={6J:{2C:k(F,fn){B(c.8j)c.8j(F,fn,O);14 c.bD(\'67\'+F,fn);m c},3h:k(F,fn){B(c.a4)c.a4(F,fn,O);14 c.bP(\'67\'+F,fn);m c}}};U.R(P.2H.6J);Q.R(P.2H.6J);P.R(P.2H.6J);o 2F={T:[],52:k(el){B(!el.$1W){2F.T.1k(el);el.$1W={\'21\':1}}m el},3V:k(T){M(o i=0,j=T.V,el;i<j;i++){B(!(el=T[i])||!el.$1W)6l;B(el.$19)el.1h(\'3V\').78();M(o p 1a el.$1W)el.$1W[p]=1n;M(o d 1a P.1L)el[d]=1n;2F.T[2F.T.3k(el)]=1n;el.5i=el.$1W=el=1n}2F.T.2K(1n)},1l:k(){2F.52(U);2F.52(Q);2F.3V(2F.T)}};U.2C(\'9t\',k(){U.2C(\'7v\',2F.1l);B(U.2P)U.2C(\'7v\',bH)});o 2X=L 18({1i:k(I){B(I&&I.$bq)m I;c.$bq=1e;I=I||U.I;c.I=I;c.F=I.F;c.3v=I.3v||I.bF;B(c.3v.84==3)c.3v=c.3v.3n;c.aK=I.bx;c.bG=I.bC;c.bK=I.bz;c.bO=I.by;B([\'8b\',\'5a\'].1j(c.F)){c.bS=(I.9p)?I.9p/bQ:-(I.bE||0)/3}14 B(c.F.1j(\'1t\')){c.6O=I.9K||I.bL;M(o 1w 1a 2X.1O){B(2X.1O[1w]==c.6O){c.1t=1w;1C}}B(c.F==\'9X\'){o 6Q=c.6O-bM;B(6Q>0&&6Q<13)c.1t=\'f\'+6Q}c.1t=c.1t||6i.bA(c.6O).5L()}14 B(c.F.2v(/(6h|3m|bw)/)){c.1Y={\'x\':I.8E||I.9f+Q.2Z.5V,\'y\':I.8w||I.at+Q.2Z.63};c.9B={\'x\':I.8E?I.8E-U.99:I.9f,\'y\':I.8w?I.8w-U.9i:I.at};c.bR=(I.9K==3)||(I.bv==2);22(c.F){Y\'90\':c.2o=I.2o||I.ca;1C;Y\'8Y\':c.2o=I.2o||I.8A}c.aU()}m c},1R:k(){m c.6U().6X()},6U:k(){B(c.I.6U)c.I.6U();14 c.I.db=1e;m c},6X:k(){B(c.I.6X)c.I.6X();14 c.I.eK=O;m c}});2X.6m={2o:k(){B(c.2o&&c.2o.84==3)c.2o=c.2o.3n},aD:k(){5j{2X.6m.2o.1X(c)}5c(e){c.2o=c.3v}}};2X.1L.aU=(U.8r)?2X.6m.aD:2X.6m.2o;2X.1O=L 3M({\'eL\':13,\'6P\':38,\'eJ\':40,\'1u\':37,\'4n\':39,\'eI\':27,\'eF\':32,\'eG\':8,\'eH\':9,\'57\':46});P.2H.2p={1B:k(F,fn){c.$19=c.$19||{};c.$19[F]=c.$19[F]||{\'1O\':[],\'1I\':[]};B(c.$19[F].1O.1j(fn))m c;c.$19[F].1O.1k(fn);o 76=F;o 2w=P.2p[F];B(2w){B(2w.7F)2w.7F.1X(c,fn);B(2w.2D)fn=2w.2D;B(2w.F)76=2w.F}B(!c.8j)fn=fn.3a({\'W\':c,\'I\':1e});c.$19[F].1I.1k(fn);m(P.8V.1j(76))?c.2C(76,fn):c},4C:k(F,fn){B(!c.$19||!c.$19[F])m c;o 1m=c.$19[F].1O.3k(fn);B(1m==-1)m c;o 1t=c.$19[F].1O.74(1m,1)[0];o J=c.$19[F].1I.74(1m,1)[0];o 2w=P.2p[F];B(2w){B(2w.2K)2w.2K.1X(c,fn);B(2w.F)F=2w.F}m(P.8V.1j(F))?c.3h(F,J):c},6j:k(1Z){m P.72(c,\'1B\',1Z)},78:k(F){B(!c.$19)m c;B(!F){M(o 6g 1a c.$19)c.78(6g);c.$19=1n}14 B(c.$19[F]){c.$19[F].1O.1q(k(fn){c.4C(F,fn)},c);c.$19[F]=1n}m c},1h:k(F,1p,2g){B(c.$19&&c.$19[F]){c.$19[F].1O.1q(k(fn){fn.3a({\'W\':c,\'2g\':2g,\'1b\':1p})()},c)}m c},au:k(15,F){B(!15.$19)m c;B(!F){M(o 6g 1a 15.$19)c.au(15,6g)}14 B(15.$19[F]){15.$19[F].1O.1q(k(fn){c.1B(F,fn)},c)}m c}};U.R(P.2H.2p);Q.R(P.2H.2p);P.R(P.2H.2p);P.2p=L 3M({\'8N\':{F:\'90\',2D:k(I){I=L 2X(I);B(I.2o!=c&&!c.8o(I.2o))c.1h(\'8N\',I)}},\'8P\':{F:\'8Y\',2D:k(I){I=L 2X(I);B(I.2o!=c&&!c.8o(I.2o))c.1h(\'8P\',I)}},\'5a\':{F:(U.8r)?\'8b\':\'5a\'}});P.8V=[\'6h\',\'eM\',\'5z\',\'5n\',\'5a\',\'8b\',\'90\',\'8Y\',\'2M\',\'9X\',\'eN\',\'eS\',\'4e\',\'7v\',\'9t\',\'eT\',\'5o\',\'eR\',\'eQ\',\'3F\',\'eO\',\'eP\',\'48\',\'aE\',\'8s\',\'eE\',\'2G\'];7Z.R({3e:k(W,1p){m c.3a({\'W\':W,\'1b\':1p,\'I\':2X})}});26.R({eV:k(3q){m L 26(c.36(k(el){m(P.4D(el)==3q)}))},a8:k(1A,2J){o T=c.36(k(el){m(el.1A&&el.1A.1j(1A,\' \'))});m(2J)?T:L 26(T)},a2:k(4u,2J){o T=c.36(k(el){m(el.4u==4u)});m(2J)?T:L 26(T)},a9:k(1w,82,J,2J){o T=c.36(k(el){o 2i=P.5R(el,1w);B(!2i)m O;B(!82)m 1e;22(82){Y\'=\':m(2i==J);Y\'*=\':m(2i.1j(J));Y\'^=\':m(2i.6K(0,J.V)==J);Y\'$=\':m(2i.6K(2i.V-J.V)==J);Y\'!=\':m(2i!=J);Y\'~=\':m 2i.1j(J,\' \')}m O});m(2J)?T:L 26(T)}});k $E(1S,36){m($(36)||Q).9P(1S)};k $et(1S,36){m($(36)||Q).6Y(1S)};$$.3B={\'5C\':/^(\\w*|\\*)(?:#([\\w-]+)|\\.([\\w-]+))?(?:\\[(\\w+)(?:([!*^$]?=)["\']?([^"\'\\]]*)["\']?)?])?$/,\'4a\':{7L:k(1x,3b,1d,i){o 2r=[3b.eu?\'7N:\':\'\',1d[1]];B(1d[2])2r.1k(\'[@4u="\',1d[2],\'"]\');B(1d[3])2r.1k(\'[1j(7P(" ", @4R, " "), " \',1d[3],\' ")]\');B(1d[4]){B(1d[5]&&1d[6]){22(1d[5]){Y\'*=\':2r.1k(\'[1j(@\',1d[4],\', "\',1d[6],\'")]\');1C;Y\'^=\':2r.1k(\'[es-er(@\',1d[4],\', "\',1d[6],\'")]\');1C;Y\'$=\':2r.1k(\'[eo(@\',1d[4],\', 2z-V(@\',1d[4],\') - \',1d[6].V,\' + 1) = "\',1d[6],\'"]\');1C;Y\'=\':2r.1k(\'[@\',1d[4],\'="\',1d[6],\'"]\');1C;Y\'!=\':2r.1k(\'[@\',1d[4],\'!="\',1d[6],\'"]\')}}14{2r.1k(\'[@\',1d[4],\']\')}}1x.1k(2r.2c(\'\'));m 1x},7O:k(1x,3b,2J){o T=[];o 4a=Q.5r(\'.//\'+1x.2c(\'//\'),3b,$$.3B.ac,ep.eq,1n);M(o i=0,j=4a.ev;i<j;i++)T.1k(4a.ew(i));m(2J)?T:L 26(T.2D($))}},\'9T\':{7L:k(1x,3b,1d,i){B(i==0){B(1d[2]){o el=3b.6W(1d[2]);B(!el||((1d[1]!=\'*\')&&(P.4D(el)!=1d[1])))m O;1x=[el]}14{1x=$A(3b.33(1d[1]))}}14{1x=$$.3B.33(1x,1d[1]);B(1d[2])1x=26.a2(1x,1d[2],1e)}B(1d[3])1x=26.a8(1x,1d[3],1e);B(1d[4])1x=26.a9(1x,1d[4],1d[5],1d[6],1e);m 1x},7O:k(1x,3b,2J){m(2J)?1x:$$.5M(1x)}},ac:k(9Z){m(9Z==\'7N\')?\'9Y://aS.eB.eC/eA/7N\':O},33:k(3b,6S){o 7M=[];M(o i=0,j=3b.V;i<j;i++)7M.R(3b[i].33(6S));m 7M}};$$.3B.23=(U.4a)?\'4a\':\'9T\';P.2H.7R={6N:k(1S,2J){o 1x=[];1S=1S.5T().68(\' \');M(o i=0,j=1S.V;i<j;i++){o 9U=1S[i];o 1d=9U.31($$.3B.5C);B(!1d)1C;1d[1]=1d[1]||\'*\';o 2r=$$.3B[$$.3B.23].7L(1x,c,1d,i);B(!2r)1C;1x=2r}m $$.3B[$$.3B.23].7O(1x,c,2J)},9P:k(1S){m $(c.6N(1S,1e)[0]||O)},6Y:k(1S,2J){o T=[];1S=1S.68(\',\');M(o i=0,j=1S.V;i<j;i++)T=T.7P(c.6N(1S[i],1e));m(2J)?T:$$.5M(T)}};P.R({6W:k(4u){o el=Q.6W(4u);B(!el)m O;M(o 1r=el.3n;1r!=c;1r=1r.3n){B(!1r)m O}m el},ez:k(1A){m c.6N(\'.\'+1A)}});Q.R(P.2H.7R);P.R(P.2H.7R);P.R({44:k(){22(c.4D()){Y\'48\':o 1I=[];$1q(c.C,k(3z){B(3z.7Q)1I.1k($4T(3z.J,3z.1K))});m(c.7J)?1I:1I[0];Y\'ab\':B(!(c.7E&&[\'ex\',\'ey\'].1j(c.F))&&![\'4O\',\'1K\',\'eU\'].1j(c.F))1C;Y\'ad\':m c.J}m O},ae:k(){m $$(c.33(\'ab\'),c.33(\'48\'),c.33(\'ad\'))},5A:k(){o 5f=[];c.ae().1q(k(el){o 1w=el.1w;o J=el.44();B(J===O||!1w||el.7D)m;o 7C=k(4m){5f.1k(1w+\'=\'+7e(4m))};B($F(J)==\'1z\')J.1q(7C);14 7C(J)});m 5f.2c(\'&\')}});P.R({3G:k(x,y){c.5V=x;c.63=y},7g:k(){m{\'2G\':{\'x\':c.5V,\'y\':c.63},\'3l\':{\'x\':c.4b,\'y\':c.3R},\'7h\':{\'x\':c.71,\'y\':c.5P}}},3p:k(2k){2k=2k||[];o el=c,1u=0,1o=0;do{1u+=el.fp||0;1o+=el.fh||0;el=el.fj}6Z(el);2k.1q(k(G){1u-=G.5V||0;1o-=G.63||0});m{\'x\':1u,\'y\':1o}},aQ:k(2k){m c.3p(2k).y},aP:k(2k){m c.3p(2k).x},4E:k(2k){o 1v=c.3p(2k);o N={\'2y\':c.4b,\'2N\':c.3R,\'1u\':1v.x,\'1o\':1v.y};N.4n=N.1u+N.2y;N.3P=N.1o+N.2N;m N}});P.2p.7S={7F:k(fn){B(U.6B){fn.1X(c);m}o 5X=k(){B(U.6B)m;U.6B=1e;U.1H=$55(U.1H);c.1h(\'7S\')}.W(c);B(Q.5m&&U.4x){U.1H=k(){B([\'6B\',\'8p\'].1j(Q.5m))5X()}.4f(50)}14 B(Q.5m&&U.2P){B(!$(\'7I\')){o 4s=(U.5k.ff==\'fi:\')?\'://0\':\'8q:fk(0)\';Q.fg(\'<2s 4u="7I" fd 4s="\'+4s+\'"><\\/2s>\');$(\'7I\').7i=k(){B(c.5m==\'8p\')5X()}}}14{U.2C("4e",5X);Q.2C("fe",5X)}}};U.fm=k(fn){m c.1B(\'7S\',fn)};U.R({8m:k(){B(c.5x)m c.fl;B(c.9a)m Q.4B.9c;m Q.2Z.9c},8n:k(){B(c.5x)m c.fo;B(c.9a)m Q.4B.9d;m Q.2Z.9d},93:k(){B(c.2P)m 1c.1D(Q.2Z.4b,Q.2Z.71);B(c.4x)m Q.4B.71;m Q.2Z.71},92:k(){B(c.2P)m 1c.1D(Q.2Z.3R,Q.2Z.5P);B(c.4x)m Q.4B.5P;m Q.2Z.5P},8u:k(){m c.99||Q.2Z.5V},8v:k(){m c.9i||Q.2Z.63},7g:k(){m{\'3l\':{\'x\':c.8m(),\'y\':c.8n()},\'7h\':{\'x\':c.93(),\'y\':c.92()},\'2G\':{\'x\':c.8u(),\'y\':c.8v()}}},3p:k(){m{\'x\':0,\'y\':0}}});o 1f={};1f.2T=L 18({C:{3X:18.1l,1Q:18.1l,7w:18.1l,2f:k(p){m-(1c.av(1c.7W*p)-1)/2},49:fb,2x:\'4W\',3T:1e,98:50},1i:k(C){c.G=c.G||1n;c.2Y(C);B(c.C.1i)c.C.1i.1X(c)},2n:k(){o 3A=$3A();B(3A<c.3A+c.C.49){c.4p=c.C.2f((3A-c.3A)/c.C.49);c.4q();c.4k()}14{c.1R(1e);c.2j(c.17);c.1h(\'1Q\',c.G,10);c.7z()}},2j:k(17){c.12=17;c.4k();m c},4q:k(){c.12=c.4o(c.15,c.17)},4o:k(15,17){m(17-15)*c.4p+15},1g:k(15,17){B(!c.C.3T)c.1R();14 B(c.1H)m c;c.15=15;c.17=17;c.3F=c.17-c.15;c.3A=$3A();c.1H=c.2n.4f(1c.2q(bd/c.C.98),c);c.1h(\'3X\',c.G);m c},1R:k(29){B(!c.1H)m c;c.1H=$55(c.1H);B(!29)c.1h(\'7w\',c.G);m c},2w:k(15,17){m c.1g(15,17)},f1:k(29){m c.1R(29)}});1f.2T.3i(L 7u,L 2p,L 43);1f.3t={48:k(K,17){B(K.2v(/2E/i))m c.2Q;o F=$F(17);B((F==\'1z\')||(F==\'2z\'&&17.1j(\' \')))m c.73;m c.9j},2V:k(el,K,5b){B(!5b.1k)5b=[5b];o 15=5b[0],17=5b[1];B(!$2A(17)){17=15;15=el.2h(K)}o 1y=c.48(K,17);m{\'15\':1y.2V(15),\'17\':1y.2V(17),\'1y\':1y}}};1f.3t.9j={2V:k(J){m 66(J)},56:k(15,17,2O){m 2O.4o(15,17)},44:k(J,2x,K){B(2x==\'4W\'&&K!=\'21\')J=1c.2q(J);m J+2x}};1f.3t.73={2V:k(J){m J.1k?J:J.68(\' \').2D(k(v){m 66(v)})},56:k(15,17,2O){o 12=[];M(o i=0;i<15.V;i++)12[i]=2O.4o(15[i],17[i]);m 12},44:k(J,2x,K){B(2x==\'4W\'&&K!=\'21\')J=J.2D(1c.2q);m J.2c(2x+\' \')+2x}};1f.3t.2Q={2V:k(J){m J.1k?J:J.5G(1e)},56:k(15,17,2O){o 12=[];M(o i=0;i<15.V;i++)12[i]=1c.2q(2O.4o(15[i],17[i]));m 12},44:k(J){m\'1s(\'+J.2c(\',\')+\')\'}};1f.7T=1f.2T.R({1i:k(el,K,C){c.G=$(el);c.K=K;c.1r(C)},3Z:k(){m c.2j(0)},4q:k(){c.12=c.1y.56(c.15,c.17,c)},2j:k(17){c.1y=1f.3t.48(c.K,17);m c.1r(c.1y.2V(17))},1g:k(15,17){B(c.1H&&c.C.3T)m c;o 2e=1f.3t.2V(c.G,c.K,[15,17]);c.1y=2e.1y;m c.1r(2e.15,2e.17)},4k:k(){c.G.1P(c.K,c.1y.44(c.12,c.C.2x,c.K))}});P.R({f2:k(K,C){m L 1f.7T(c,K,C)}});1f.4c=1f.2T.R({1i:k(el,C){c.G=$(el);c.1r(C)},4q:k(){M(o p 1a c.15)c.12[p]=c.1y[p].56(c.15[p],c.17[p],c)},2j:k(17){o 2e={};c.1y={};M(o p 1a 17){c.1y[p]=1f.3t.48(p,17[p]);2e[p]=c.1y[p].2V(17[p])}m c.1r(2e)},1g:k(N){B(c.1H&&c.C.3T)m c;c.12={};c.1y={};o 15={},17={};M(o p 1a N){o 2e=1f.3t.2V(c.G,p,N[p]);15[p]=2e.15;17[p]=2e.17;c.1y[p]=2e.1y}m c.1r(15,17)},4k:k(){M(o p 1a c.12)c.G.1P(p,c.1y[p].44(c.12[p],c.C.2x,p))}});P.R({3U:k(C){m L 1f.4c(c,C)}});1f.26=1f.2T.R({1i:k(T,C){c.T=$$(T);c.1r(C)},4q:k(){M(o i 1a c.15){o 5Q=c.15[i],47=c.17[i],3u=c.1y[i],5U=c.12[i]={};M(o p 1a 5Q)5U[p]=3u[p].56(5Q[p],47[p],c)}},2j:k(17){o 2e={};c.1y={};M(o i 1a 17){o 47=17[i],3u=c.1y[i]={},9u=2e[i]={};M(o p 1a 47){3u[p]=1f.3t.48(p,47[p]);9u[p]=3u[p].2V(47[p])}}m c.1r(2e)},1g:k(N){B(c.1H&&c.C.3T)m c;c.12={};c.1y={};o 15={},17={};M(o i 1a N){o 85=N[i],5Q=15[i]={},47=17[i]={},3u=c.1y[i]={};M(o p 1a 85){o 2e=1f.3t.2V(c.T[i],p,85[p]);5Q[p]=2e.15;47[p]=2e.17;3u[p]=2e.1y}}m c.1r(15,17)},4k:k(){M(o i 1a c.12){o 5U=c.12[i],3u=c.1y[i];M(o p 1a 5U)c.T[i].1P(p,3u[p].44(5U[p],c.C.2x,p))}}});1f.ah=1f.2T.R({C:{2k:[],1E:{\'x\':0,\'y\':0},9r:1e},1i:k(G,C){c.12=[];c.G=$(G);c.1G={\'1R\':c.1R.W(c,O)};c.1r(C);B(c.C.9r){c.1B(\'3X\',k(){Q.1B(\'5a\',c.1G.1R)}.W(c));c.1B(\'1Q\',k(){Q.4C(\'5a\',c.1G.1R)}.W(c))}},4q:k(){M(o i=0;i<2;i++)c.12[i]=c.4o(c.15[i],c.17[i])},3G:k(x,y){B(c.1H&&c.C.3T)m c;o el=c.G.7g();o 1I={\'x\':x,\'y\':y};M(o z 1a el.3l){o 1D=el.7h[z]-el.3l[z];B($2A(1I[z]))1I[z]=($F(1I[z])==\'4M\')?1I[z].1F(0,1D):1D;14 1I[z]=el.2G[z];1I[z]+=c.C.1E[z]}m c.1g([el.2G.x,el.2G.y],[1I.x,1I.y])},f0:k(){m c.3G(O,0)},eZ:k(){m c.3G(O,\'bu\')},eW:k(){m c.3G(0,O)},eX:k(){m c.3G(\'bu\',O)},8A:k(el){o 1r=c.G.3p(c.C.2k);o 3v=$(el).3p(c.C.2k);m c.3G(3v.x-1r.x,3v.y-1r.y)},4k:k(){c.G.3G(c.12[0],c.12[1])}});1f.eY=1f.2T.R({C:{2b:\'8Q\'},1i:k(el,C){c.G=$(el);c.3c=L P(\'4Z\',{\'8J\':$R(c.G.bg(\'34\'),{\'9y\':\'4O\'})}).6v(c.G).b2(c.G);c.G.1P(\'34\',0);c.2Y(C);c.12=[];c.1r(c.C);c.4X=1e;c.1B(\'1Q\',k(){c.4X=(c.12[0]===0)});B(U.5x)c.1B(\'1Q\',k(){B(c.4X)c.G.2K().28(c.3c)})},4q:k(){M(o i=0;i<2;i++)c.12[i]=c.4o(c.15[i],c.17[i])},8Q:k(){c.34=\'34-1o\';c.64=\'2N\';c.1E=c.G.3R},8M:k(){c.34=\'34-1u\';c.64=\'2y\';c.1E=c.G.4b},ba:k(2b){c[2b||c.C.2b]();m c.1g([c.G.2h(c.34).3d(),c.3c.2h(c.64).3d()],[0,c.1E])},bb:k(2b){c[2b||c.C.2b]();m c.1g([c.G.2h(c.34).3d(),c.3c.2h(c.64).3d()],[-c.1E,0])},3Z:k(2b){c[2b||c.C.2b]();c.4X=O;m c.2j([-c.1E,0])},4d:k(2b){c[2b||c.C.2b]();c.4X=1e;m c.2j([0,c.1E])},f3:k(2b){B(c.3c.3R==0||c.3c.4b==0)m c.ba(2b);m c.bb(2b)},4k:k(){c.G.1P(c.34,c.12[0]+c.C.2x);c.3c.1P(c.64,c.12[1]+c.C.2x)}});1f.7U=k(2f,2U){2U=2U||[];B($F(2U)!=\'1z\')2U=[2U];m $R(2f,{f4:k(1m){m 2f(1m,2U)},f9:k(1m){m 1-2f(1-1m,2U)},fa:k(1m){m(1m<=0.5)?2f(2*1m,2U)/2:(2-2f(2*(1-1m),2U))/2}})};1f.3o=L 3M({fc:k(p){m p}});1f.3o.R=k(7B){M(o 2f 1a 7B){1f.3o[2f]=L 1f.7U(7B[2f]);1f.3o.7X(2f)}};1f.3o.7X=k(2f){[\'f8\',\'f7\',\'f5\'].1q(k(89){1f.3o[2f.5L()+89]=1f.3o[2f][\'f6\'+89]})};1f.3o.R({eD:k(p,x){m 1c.3w(p,x[0]||6)},em:k(p){m 1c.3w(2,8*(p-1))},dw:k(p){m 1-1c.bj(1c.dx(p))},dy:k(p){m 1-1c.bj((1-p)*1c.7W/2)},dv:k(p,x){x=x[0]||1.du;m 1c.3w(p,2)*((x+1)*p-x)},dr:k(p){o J;M(o a=0,b=1;1;a+=b,b/=2){B(p>=(7-4*a)/11){J=-1c.3w((11-6*a-11*p)/4,2)+b*b;1C}}m J},ds:k(p,x){m 1c.3w(2,10*--p)*1c.av(20*p*1c.7W*(x[0]||1)/3)}});[\'dt\',\'dz\',\'dA\',\'dG\'].1q(k(2f,i){1f.3o[2f]=L 1f.7U(k(p){m 1c.3w(p,[i+2])});1f.3o.7X(2f)});o 4g={};4g.2T=L 18({C:{3J:O,2x:\'4W\',3X:18.1l,al:18.1l,1Q:18.1l,as:18.1l,8S:18.1l,1F:O,3E:{x:\'1u\',y:\'1o\'},4P:O,6M:6},1i:k(el,C){c.2Y(C);c.G=$(el);c.3J=$(c.C.3J)||c.G;c.3m={\'12\':{},\'1m\':{}};c.J={\'1g\':{},\'12\':{}};c.1G={\'1g\':c.1g.3e(c),\'4i\':c.4i.3e(c),\'3D\':c.3D.3e(c),\'1R\':c.1R.W(c)};c.6V();B(c.C.1i)c.C.1i.1X(c)},6V:k(){c.3J.1B(\'5n\',c.1G.1g);m c},9F:k(){c.3J.4C(\'5n\',c.1G.1g);m c},1g:k(I){c.1h(\'al\',c.G);c.3m.1g=I.1Y;o 1F=c.C.1F;c.1F={\'x\':[],\'y\':[]};M(o z 1a c.C.3E){B(!c.C.3E[z])6l;c.J.12[z]=c.G.2h(c.C.3E[z]).3d();c.3m.1m[z]=I.1Y[z]-c.J.12[z];B(1F&&1F[z]){M(o i=0;i<2;i++){B($2A(1F[z][i]))c.1F[z][i]=($F(1F[z][i])==\'k\')?1F[z][i]():1F[z][i]}}}B($F(c.C.4P)==\'4M\')c.C.4P={\'x\':c.C.4P,\'y\':c.C.4P};Q.2C(\'2M\',c.1G.4i);Q.2C(\'5z\',c.1G.1R);c.1h(\'3X\',c.G);I.1R()},4i:k(I){o ao=1c.2q(1c.dH(1c.3w(I.1Y.x-c.3m.1g.x,2)+1c.3w(I.1Y.y-c.3m.1g.y,2)));B(ao>c.C.6M){Q.3h(\'2M\',c.1G.4i);Q.2C(\'2M\',c.1G.3D);c.3D(I);c.1h(\'as\',c.G)}I.1R()},3D:k(I){c.69=O;c.3m.12=I.1Y;M(o z 1a c.C.3E){B(!c.C.3E[z])6l;c.J.12[z]=c.3m.12[z]-c.3m.1m[z];B(c.1F[z]){B($2A(c.1F[z][1])&&(c.J.12[z]>c.1F[z][1])){c.J.12[z]=c.1F[z][1];c.69=1e}14 B($2A(c.1F[z][0])&&(c.J.12[z]<c.1F[z][0])){c.J.12[z]=c.1F[z][0];c.69=1e}}B(c.C.4P[z])c.J.12[z]-=(c.J.12[z]%c.C.4P[z]);c.G.1P(c.C.3E[z],c.J.12[z]+c.C.2x)}c.1h(\'8S\',c.G);I.1R()},1R:k(){Q.3h(\'2M\',c.1G.4i);Q.3h(\'2M\',c.1G.3D);Q.3h(\'5z\',c.1G.1R);c.1h(\'1Q\',c.G)}});4g.2T.3i(L 2p,L 43);P.R({dF:k(C){m L 4g.2T(c,$2a({3E:{x:\'2y\',y:\'2N\'}},C))}});4g.aM=4g.2T.R({C:{6c:[],2d:O,2k:[]},1i:k(el,C){c.2Y(C);c.G=$(el);c.6c=$$(c.C.6c);c.2d=$(c.C.2d);c.1v={\'G\':c.G.2h(\'1v\'),\'2d\':O};B(c.2d)c.1v.2d=c.2d.2h(\'1v\');B(![\'70\',\'3Y\',\'4V\'].1j(c.1v.G))c.1v.G=\'3Y\';o 1o=c.G.2h(\'1o\').3d();o 1u=c.G.2h(\'1u\').3d();B(c.1v.G==\'3Y\'&&![\'70\',\'3Y\',\'4V\'].1j(c.1v.2d)){1o=$2A(1o)?1o:c.G.aQ(c.C.2k);1u=$2A(1u)?1u:c.G.aP(c.C.2k)}14{1o=$2A(1o)?1o:0;1u=$2A(1u)?1u:0}c.G.4A({\'1o\':1o,\'1u\':1u,\'1v\':c.1v.G});c.1r(c.G)},1g:k(I){c.3f=1n;B(c.2d){o 4r=c.2d.4E();o el=c.G.4E();B(c.1v.G==\'3Y\'&&![\'70\',\'3Y\',\'4V\'].1j(c.1v.2d)){c.C.1F={\'x\':[4r.1u,4r.4n-el.2y],\'y\':[4r.1o,4r.3P-el.2N]}}14{c.C.1F={\'y\':[0,4r.2N-el.2N],\'x\':[0,4r.2y-el.2y]}}}c.1r(I)},3D:k(I){c.1r(I);o 3f=c.69?O:c.6c.36(c.aO,c).80();B(c.3f!=3f){B(c.3f)c.3f.1h(\'dE\',[c.G,c]);c.3f=3f?3f.1h(\'dB\',[c.G,c]):1n}m c},aO:k(el){el=el.4E(c.C.2k);o 12=c.3m.12;m(12.x>el.1u&&12.x<el.4n&&12.y<el.3P&&12.y>el.1o)},1R:k(){B(c.3f&&!c.69)c.3f.1h(\'dC\',[c.G,c]);14 c.G.1h(\'dD\',c);c.1r();m c}});P.R({dq:k(C){m L 4g.aM(c,C)}});o 6n=L 18({C:{23:\'59\',be:1e,9g:18.1l,5h:18.1l,6w:18.1l,aG:1e,5J:\'dp-8\',aZ:O,4J:{}},7q:k(){c.2u=(U.6C)?L 6C():(U.2P?L 9o(\'en.dc\'):O);m c},1i:k(C){c.7q().2Y(C);c.C.5D=c.C.5D||c.5D;c.4J={};B(c.C.aG&&c.C.23==\'59\'){o 5J=(c.C.5J)?\'; dd=\'+c.C.5J:\'\';c.5l(\'9R-F\',\'9J/x-aS-da-d9\'+5J)}B(c.C.1i)c.C.1i.1X(c)},9s:k(){B(c.2u.5m!=4||!c.4Q)m;c.4Q=O;o 4I=0;5j{4I=c.2u.4I}5c(e){};B(c.C.5D.1X(c,4I))c.5h();14 c.6w();c.2u.7i=18.1l},5D:k(4I){m((4I>=d6)&&(4I<d7))},5h:k(){c.3L={\'1K\':c.2u.d8,\'5t\':c.2u.de};c.1h(\'5h\',[c.3L.1K,c.3L.5t]);c.7z()},6w:k(){c.1h(\'6w\',c.2u)},5l:k(1w,J){c.4J[1w]=J;m c},6a:k(2L,1T){B(c.C.aZ)c.95();14 B(c.4Q)m c;c.4Q=1e;B(1T&&c.C.23==\'5q\'){2L=2L+(2L.1j(\'?\')?\'&\':\'?\')+1T;1T=1n}c.2u.4X(c.C.23.7A(),2L,c.C.be);c.2u.7i=c.9s.W(c);B((c.C.23==\'59\')&&c.2u.d5)c.5l(\'df\',\'dl\');$R(c.4J,c.C.4J);M(o F 1a c.4J)5j{c.2u.dm(F,c.4J[F])}5c(e){};c.1h(\'9g\');c.2u.6a($4T(1T,1n));m c},95:k(){B(!c.4Q)m c;c.4Q=O;c.2u.8s();c.2u.7i=18.1l;c.7q();c.1h(\'7w\');m c}});6n.3i(L 7u,L 2p,L 43);o 9b=6n.R({C:{1T:1n,7x:1n,1Q:18.1l,6R:O,7p:O},1i:k(2L,C){c.1B(\'5h\',c.1Q);c.2Y(C);c.C.1T=c.C.1T||c.C.dn;B(![\'59\',\'5q\'].1j(c.C.23)){c.5H=\'5H=\'+c.C.23;c.C.23=\'59\'}c.1r();c.5l(\'X-dk-dj\',\'6C\');c.5l(\'dg\',\'1K/8q, 1K/dh, 9J/5t, 1K/5t, */*\');c.2L=2L},1Q:k(){B(c.C.7x)$(c.C.7x).1l().5s(c.3L.1K);B(c.C.6R||c.C.7p)c.6R();c.1h(\'1Q\',[c.3L.1K,c.3L.5t],20)},9h:k(1T){1T=1T||c.C.1T;22($F(1T)){Y\'G\':1T=$(1T).5A();1C;Y\'2I\':1T=8X.5A(1T)}B(c.5H)1T=(1T)?[c.5H,1T].2c(\'&\'):c.5H;m c.6a(c.2L,1T)},6R:k(){o 2s,3y;B(c.C.7p||(/(di|dI)2s/).2v(c.af(\'9R-F\')))3y=c.3L.1K;14{3y=[];o 5C=/<2s[^>]*>([\\s\\S]*?)<\\/2s>/dJ;6Z((2s=5C.e9(c.3L.1K)))3y.1k(2s[1]);3y=3y.2c(\'\\n\')}B(3y)(U.9O)?U.9O(3y):U.9M(3y,0)},af:k(1w){5j{m c.2u.ea(1w)}5c(e){};m 1n}});8X.5A=k(1Z){o 5f=[];M(o K 1a 1Z)5f.1k(7e(K)+\'=\'+7e(1Z[K]));m 5f.2c(\'&\')};P.R({6a:k(C){m L 9b(c.5R(\'eb\'),$2a({1T:c.5A()},C,{23:\'59\'})).9h()}});o 3H=L 3M({C:{7o:O,7k:O,49:O,5g:O},2j:k(1t,J,C){C=$2a(c.C,C);J=7e(J);B(C.7o)J+=\'; 7o=\'+C.7o;B(C.7k)J+=\'; 7k=\'+C.7k;B(C.49){o 6k=L 96();6k.e8(6k.9w()+C.49*24*60*60*bd);J+=\'; e7=\'+6k.e4()}B(C.5g)J+=\'; 5g\';Q.4K=1t+\'=\'+J;m $R(C,{\'1t\':1t,\'J\':J})},5q:k(1t){o J=Q.4K.31(\'(?:^|;)\\\\s*\'+1t.b5()+\'=([^;]*)\');m J?e5(J[1]):O},2K:k(4K,C){B($F(4K)==\'2I\')c.2j(4K.1t,\'\',$2a(4K,{49:-1}));14 c.2j(4K,\'\',$2a(C,{49:-1}))}});o 3I={4l:k(N){22($F(N)){Y\'2z\':m\'"\'+N.3g(/(["\\\\])/g,\'\\\\$1\')+\'"\';Y\'1z\':m\'[\'+N.2D(3I.4l).2c(\',\')+\']\';Y\'2I\':o 2z=[];M(o K 1a N)2z.1k(3I.4l(K)+\':\'+3I.4l(N[K]));m\'{\'+2z.2c(\',\')+\'}\';Y\'4M\':B(e6(N))1C;Y O:m\'1n\'}m 6i(N)},5r:k(4H,5g){m(($F(4H)!=\'2z\')||(5g&&!4H.2v(/^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+ec-u \\n\\r\\t])+?$/)))?1n:ed(\'(\'+4H+\')\')}};3I.ej=6n.R({1i:k(2L,C){c.2L=2L;c.1B(\'5h\',c.1Q);c.1r(C);c.5l(\'X-ek\',\'ei\')},6a:k(N){m c.1r(c.2L,\'eh=\'+3I.4l(N))},1Q:k(){c.1h(\'1Q\',[3I.5r(c.3L.1K,c.C.5g)])}});o ar=L 3M({8q:k(1Z,1J){1J=$2a({\'5N\':18.1l},1J);o 2s=L P(\'2s\',{\'4s\':1Z}).6j({\'4e\':1J.5N,\'ee\':k(){B(c.5m==\'8p\')c.1h(\'4e\')}});57 1J.5N;m 2s.6o(1J).28(Q.6e)},1y:k(1Z,1J){m L P(\'4y\',$2a({\'a1\':\'ef\',\'eg\':\'e3\',\'F\':\'1K/1y\',\'4N\':1Z},1J)).28(Q.6e)},4S:k(1Z,1J){1J=$2a({\'5N\':18.1l,\'e2\':18.1l,\'dP\':18.1l},1J);o 4S=L dQ();4S.4s=1Z;o G=L P(\'8x\',{\'4s\':1Z});[\'4e\',\'8s\',\'aE\'].1q(k(F){o I=1J[\'67\'+F];57 1J[\'67\'+F];G.1B(F,k(){c.4C(F,1b.8t);I.1X(c)})});B(4S.2y&&4S.2N)G.1h(\'4e\',G,1);m G.6o(1J)},6s:k(58,C){C=$2a({1Q:18.1l,an:18.1l},C);B(!58.1k)58=[58];o 6s=[];o 6q=0;58.1q(k(1Z){o 8x=L ar.4S(1Z,{\'5N\':k(){C.an.1X(c,6q);6q++;B(6q==58.V)C.1Q()}});6s.1k(8x)});m L 26(6s)}});o 3O=L 18({V:0,1i:k(2I){c.N=2I||{};c.5K()},5q:k(1t){m(c.6t(1t))?c.N[1t]:1n},6t:k(1t){m(1t 1a c.N)},2j:k(1t,J){B(!c.6t(1t))c.V++;c.N[1t]=J;m c},5K:k(){c.V=0;M(o p 1a c.N)c.V++;m c},2K:k(1t){B(c.6t(1t)){57 c.N[1t];c.V--}m c},1q:k(fn,W){$1q(c.N,fn,W)},R:k(N){$R(c.N,N);m c.5K()},2a:k(){c.N=$2a.4j(1n,[c.N].R(1b));m c.5K()},1l:k(){c.N={};c.V=0;m c},1O:k(){o 1O=[];M(o K 1a c.N)1O.1k(K);m 1O},1I:k(){o 1I=[];M(o K 1a c.N)1I.1k(c.N[K]);m 1I}});k $H(N){m L 3O(N)};3O.3H=3O.R({1i:k(1w,C){c.1w=1w;c.C=$R({\'aw\':1e},C||{});c.4e()},aX:k(){B(c.V==0){3H.2K(c.1w,c.C);m 1e}o 4H=3I.4l(c.N);B(4H.V>dR)m O;3H.2j(c.1w,4H,c.C);m 1e},4e:k(){c.N=3I.5r(3H.5q(c.1w),1e)||{};c.5K()}});3O.3H.2H={};[\'R\',\'2j\',\'2a\',\'1l\',\'2K\'].1q(k(23){3O.3H.2H[23]=k(){3O.1L[23].4j(c,1b);B(c.C.aw)c.aX();m c}});3O.3H.3i(3O.3H.2H);o 2Q=L 18({1i:k(2E,F){F=F||(2E.1k?\'1s\':\'3C\');o 1s,2m;22(F){Y\'1s\':1s=2E;2m=1s.8h();1C;Y\'2m\':1s=2E.b9();2m=2E;1C;62:1s=2E.5G(1e);2m=1s.8h()}1s.2m=2m;1s.3C=1s.5E();m $R(1s,2Q.1L)},54:k(){o 5I=$A(1b);o 7d=($F(5I[5I.V-1])==\'4M\')?5I.dO():50;o 1s=c.8e();5I.1q(k(2E){2E=L 2Q(2E);M(o i=0;i<3;i++)1s[i]=1c.2q((1s[i]/ 35 * (35 - 7d)) + (2E[i] /35*7d))});m L 2Q(1s,\'1s\')},dN:k(){m L 2Q(c.2D(k(J){m 51-J}))},dK:k(J){m L 2Q([J,c.2m[1],c.2m[2]],\'2m\')},dL:k(7a){m L 2Q([c.2m[0],7a,c.2m[2]],\'2m\')},dM:k(7a){m L 2Q([c.2m[0],c.2m[1],7a],\'2m\')}});k $dS(r,g,b){m L 2Q([r,g,b],\'1s\')};k $dT(h,s,b){m L 2Q([h,s,b],\'2m\')};2t.R({8h:k(){o 5W=c[0],65=c[1],75=c[2];o 2W,6y,8k;o 1D=1c.1D(5W,65,75),3s=1c.3s(5W,65,75);o 4p=1D-3s;8k=1D/51;6y=(1D!=0)?4p/1D:0;B(6y==0){2W=0}14{o 8l=(1D-5W)/4p;o 8W=(1D-65)/4p;o br=(1D-75)/4p;B(5W==1D)2W=br-8W;14 B(65==1D)2W=2+8l-br;14 2W=4+8W-8l;2W/=6;B(2W<0)2W++}m[1c.2q(2W*bc),1c.2q(6y*35),1c.2q(8k*35)]},b9:k(){o br=1c.2q(c[2]/35*51);B(c[1]==0){m[br,br,br]}14{o 2W=c[0]%bc;o f=2W%60;o p=1c.2q((c[2]*(35-c[1]))/dZ*51);o q=1c.2q((c[2]*(b7-c[1]*f))/bm*51);o t=1c.2q((c[2]*(b7-c[1]*(60-f)))/bm*51);22(1c.9q(2W/60)){Y 0:m[br,t,p];Y 1:m[q,br,p];Y 2:m[p,br,t];Y 3:m[p,q,br];Y 4:m[t,p,br];Y 5:m[br,p,q]}}m O}});o 9x=L 18({C:{6b:20,8O:1,6F:k(x,y){c.G.3G(x,y)}},1i:k(G,C){c.2Y(C);c.G=$(G);c.8y=([U,Q].1j(G))?$(Q.4B):c.G},1g:k(){c.8z=c.9A.3e(c);c.8y.2C(\'2M\',c.8z)},1R:k(){c.8y.3h(\'2M\',c.8z);c.1H=$55(c.1H)},9A:k(I){c.1Y=(c.G==U)?I.9B:I.1Y;B(!c.1H)c.1H=c.2G.4f(50,c)},2G:k(){o el=c.G.7g();o 1m=c.G.3p();o 3F={\'x\':0,\'y\':0};M(o z 1a c.1Y){B(c.1Y[z]<(c.C.6b+1m[z])&&el.2G[z]!=0)3F[z]=(c.1Y[z]-c.C.6b-1m[z])*c.C.8O;14 B(c.1Y[z]+c.C.6b>(el.3l[z]+1m[z])&&el.2G[z]+el.3l[z]!=el.7h[z])3F[z]=(c.1Y[z]-el.3l[z]+c.C.6b-1m[z])*c.C.8O}B(3F.y||3F.x)c.1h(\'6F\',[el.2G.x+3F.x,el.2G.y+3F.y])}});9x.3i(L 2p,L 43);o 8B=L 18({C:{6F:18.1l,1Q:18.1l,8L:k(1m){c.4h.1P(c.p,1m)},2b:\'8M\',6E:35,1E:0},1i:k(el,4h,C){c.G=$(el);c.4h=$(4h);c.2Y(C);c.8K=-1;c.8D=-1;c.2n=-1;c.G.1B(\'5n\',c.9D.3e(c));o 6H,1E;22(c.C.2b){Y\'8M\':c.z=\'x\';c.p=\'1u\';6H={\'x\':\'1u\',\'y\':O};1E=\'4b\';1C;Y\'8Q\':c.z=\'y\';c.p=\'1o\';6H={\'x\':O,\'y\':\'1o\'};1E=\'3R\'}c.1D=c.G[1E]-c.4h[1E]+(c.C.1E*2);c.a5=c.4h[1E]/2;c.ai=c.G[\'5q\'+c.p.8R()].W(c.G);c.4h.1P(\'1v\',\'70\').1P(c.p,-c.C.1E);o 8U={};8U[c.z]=[-c.C.1E,c.1D-c.C.1E];c.3D=L 4g.2T(c.4h,{1F:8U,3E:6H,6M:0,3X:k(){c.6L()}.W(c),8S:k(){c.6L()}.W(c),1Q:k(){c.6L();c.29()}.W(c)});B(c.C.1i)c.C.1i.1X(c)},2j:k(2n){c.2n=2n.1F(0,c.C.6E);c.6G();c.29();c.1h(\'8L\',c.a0(c.2n));m c},9D:k(I){o 1v=I.1Y[c.z]-c.ai()-c.a5;1v=1v.1F(-c.C.1E,c.1D-c.C.1E);c.2n=c.8C(1v);c.6G();c.29();c.1h(\'8L\',1v)},6L:k(){c.2n=c.8C(c.3D.J.12[c.z]);c.6G()},6G:k(){B(c.8K!=c.2n){c.8K=c.2n;c.1h(\'6F\',c.2n)}},29:k(){B(c.8D!==c.2n){c.8D=c.2n;c.1h(\'1Q\',c.2n+\'\')}},8C:k(1v){m 1c.2q((1v+c.C.1E)/c.1D*c.C.6E)},a0:k(2n){m c.1D*2n/c.C.6E}});8B.3i(L 2p);8B.3i(L 43);o e0=1f.ah.R({1i:k(C){c.1r(U,C);c.5w=(c.C.5w)?$$(c.C.5w):$$(Q.5w);o 5k=U.5k.4N.31(/^[^#]*/)[0]+\'#\';c.5w.1q(k(4y){B(4y.4N.3k(5k)!=0)m;o 3K=4y.4N.6K(5k.V);B(3K&&$(3K))c.9L(4y,3K)},c);B(!U.5x)c.1B(\'1Q\',k(){U.5k.e1=c.3K})},9L:k(4y,3K){4y.1B(\'6h\',k(I){c.3K=3K;c.8A(3K);I.1R()}.3e(c))}});o 9S=L 18({C:{4L:O,3X:18.1l,1Q:18.1l,2S:1e,6M:3,9H:k(G,2S){2S.1P(\'21\',0.7);G.1P(\'21\',0.7)},9e:k(G,2S){G.1P(\'21\',1);2S.2K();c.3V.2K()}},1i:k(5p,C){c.2Y(C);c.5p=$(5p);c.T=c.5p.8H();c.4L=(c.C.4L)?$$(c.C.4L):c.T;c.1G={\'1g\':[],\'5y\':c.5y.3e(c)};M(o i=0,l=c.4L.V;i<l;i++){c.1G.1g[i]=c.1g.3e(c,c.T[i])}c.6V();B(c.C.1i)c.C.1i.1X(c);c.1G.5o=c.5o.3e(c);c.1G.29=c.29.W(c)},6V:k(){c.4L.1q(k(3J,i){3J.1B(\'5n\',c.1G.1g[i])},c)},9F:k(){c.4L.1q(k(3J,i){3J.4C(\'5n\',c.1G.1g[i])},c)},1g:k(I,el){c.4G=el;c.8F=c.5p.4E();B(c.C.2S){o 1v=el.3p();c.1E=I.1Y.y-1v.y;c.3V=L P(\'4Z\').28(Q.4B);c.2S=el.9G().28(c.3V).4A({\'1v\':\'3Y\',\'1u\':1v.x,\'1o\':I.1Y.y-c.1E});Q.2C(\'2M\',c.1G.5y);c.1h(\'9H\',[el,c.2S])}Q.2C(\'2M\',c.1G.5o);Q.2C(\'5z\',c.1G.29);c.1h(\'3X\',el);I.1R()},5y:k(I){o J=I.1Y.y-c.1E;J=J.1F(c.8F.1o,c.8F.3P-c.2S.3R);c.2S.1P(\'1o\',J);I.1R()},5o:k(I){o 12=I.1Y.y;c.2l=c.2l||12;o 6P=((c.2l-12)>0);o 6T=c.4G.9W();o 3x=c.4G.8I();B(6T&&6P&&12<6T.4E().3P)c.4G.7Y(6T);B(3x&&!6P&&12>3x.4E().1o)c.4G.6v(3x);c.2l=12},dY:k(9Q){m c.5p.8H().2D(9Q||k(el){m c.T.3k(el)},c)},29:k(){c.2l=1n;Q.3h(\'2M\',c.1G.5o);Q.3h(\'5z\',c.1G.29);B(c.C.2S){Q.3h(\'2M\',c.1G.5y);c.1h(\'9e\',[c.4G,c.2S])}c.1h(\'1Q\',c.4G)}});9S.3i(L 2p,L 43);o aI=L 18({C:{aT:k(3W){3W.1P(\'4z\',\'8G\')},aW:k(3W){3W.1P(\'4z\',\'4O\')},8T:30,bp:35,bt:35,1A:\'dX\',5F:{\'x\':16,\'y\':16},4V:O},1i:k(T,C){c.2Y(C);c.45=L P(\'4Z\',{\'4R\':c.C.1A+\'-3W\',\'8J\':{\'1v\':\'3Y\',\'1o\':\'0\',\'1u\':\'0\',\'4z\':\'4O\'}}).28(Q.4B);c.3c=L P(\'4Z\').28(c.45);$$(T).1q(c.9I,c);B(c.C.1i)c.C.1i.1X(c)},9I:k(el){el.$1W.42=(el.4N&&el.4D()==\'a\')?el.4N.3g(\'9Y://\',\'\'):(el.a1||O);B(el.53){o 6z=el.53.68(\'::\');B(6z.V>1){el.$1W.42=6z[0].5T();el.$1W.5u=6z[1].5T()}14{el.$1W.5u=el.53}el.a7(\'53\')}14{el.$1W.5u=O}B(el.$1W.42&&el.$1W.42.V>c.C.8T)el.$1W.42=el.$1W.42.6K(0,c.C.8T-1)+"&dU;";el.1B(\'8N\',k(I){c.1g(el);B(!c.C.4V)c.8f(I);14 c.1v(el)}.W(c));B(!c.C.4V)el.1B(\'2M\',c.8f.3e(c));o 29=c.29.W(c);el.1B(\'8P\',29);el.1B(\'3V\',29)},1g:k(el){c.3c.1l();B(el.$1W.42){c.53=L P(\'b0\').28(L P(\'4Z\',{\'4R\':c.C.1A+\'-53\'}).28(c.3c)).5s(el.$1W.42)}B(el.$1W.5u){c.1K=L P(\'b0\').28(L P(\'4Z\',{\'4R\':c.C.1A+\'-1K\'}).28(c.3c)).5s(el.$1W.5u)}$55(c.1H);c.1H=c.4d.2g(c.C.bp,c)},29:k(I){$55(c.1H);c.1H=c.3Z.2g(c.C.bt,c)},1v:k(G){o 1m=G.3p();c.45.4A({\'1u\':1m.x+c.C.5F.x,\'1o\':1m.y+c.C.5F.y})},8f:k(I){o am={\'x\':U.8m(),\'y\':U.8n()};o 2G={\'x\':U.8u(),\'y\':U.8v()};o 3W={\'x\':c.45.4b,\'y\':c.45.3R};o 1V={\'x\':\'1u\',\'y\':\'1o\'};M(o z 1a 1V){o 1m=I.1Y[z]+c.C.5F[z];B((1m+3W[z]-2G[z])>am[z])1m=I.1Y[z]-c.C.5F[z]-3W[z];c.45.1P(1V[z],1m)}},4d:k(){B(c.C.aq)c.1H=c.3Z.2g(c.C.aq,c);c.1h(\'aT\',[c.45])},3Z:k(){c.1h(\'aW\',[c.45])}});aI.3i(L 2p,L 43);o dV=L 18({1i:k(){c.6D=$A(1b);c.19={};c.4U={}},1B:k(F,fn){c.4U[F]=c.4U[F]||{};c.19[F]=c.19[F]||[];B(c.19[F].1j(fn))m O;14 c.19[F].1k(fn);c.6D.1q(k(5v,i){5v.1B(F,c.4i.W(c,[F,5v,i]))},c);m c},4i:k(F,5v,i){c.4U[F][i]=1e;o 4F=c.6D.4F(k(2i,j){m c.4U[F][j]||O},c);B(!4F)m;c.4U[F]={};c.19[F].1q(k(I){I.1X(c,c.6D,5v)},c)}});o 7t=1f.26.R({C:{7K:18.1l,aa:18.1l,3Q:0,4d:O,2N:1e,2y:O,21:1e,7f:O,7n:O,3T:O,6I:O},1i:k(){o C,2B,T,2d;$1q(1b,k(4t,i){22($F(4t)){Y\'2I\':C=4t;1C;Y\'G\':2d=$(4t);1C;62:o 2r=$$(4t);B(!2B)2B=2r;14 T=2r}});c.2B=2B||[];c.T=T||[];c.2d=$(2d);c.2Y(C);c.2l=-1;B(c.C.6I)c.C.3T=1e;B($2A(c.C.4d)){c.C.3Q=O;c.2l=c.C.4d}B(c.C.1g){c.C.3Q=O;c.C.4d=O}c.3U={};B(c.C.21)c.3U.21=\'b8\';B(c.C.2y)c.3U.2y=c.C.7n?\'aj\':\'4b\';B(c.C.2N)c.3U.2N=c.C.7f?\'9n\':\'5P\';M(o i=0,l=c.2B.V;i<l;i++)c.aR(c.2B[i],c.T[i]);c.T.1q(k(el,i){B(c.C.4d===i){c.1h(\'7K\',[c.2B[i],el])}14{M(o 2O 1a c.3U)el.1P(2O,0)}},c);c.1r(c.T);B($2A(c.C.3Q))c.3Q(c.C.3Q)},aR:k(3j,G,1m){3j=$(3j);G=$(G);o 2v=c.2B.1j(3j);o 3S=c.2B.V;c.2B.5S(3j);c.T.5S(G);B(3S&&(!2v||1m)){1m=$4T(1m,3S-1);3j.7Y(c.2B[1m]);G.6v(3j)}14 B(c.2d&&!2v){3j.28(c.2d);G.28(c.2d)}o aA=c.2B.3k(3j);3j.1B(\'6h\',c.3Q.W(c,aA));B(c.C.2N)G.4A({\'4w-1o\':0,\'2R-1o\':\'7j\',\'4w-3P\':0,\'2R-3P\':\'7j\'});B(c.C.2y)G.4A({\'4w-1u\':0,\'2R-1u\':\'7j\',\'4w-4n\':0,\'2R-4n\':\'7j\'});G.b8=1;B(c.C.7n)G.aj=c.C.7n;B(c.C.7f)G.9n=c.C.7f;G.1P(\'9y\',\'4O\');B(!2v){M(o 2O 1a c.3U)G.1P(2O,0)}m c},3Q:k(25){25=($F(25)==\'G\')?c.T.3k(25):25;B((c.1H&&c.C.3T)||(25===c.2l&&!c.C.6I))m c;c.2l=25;o N={};c.T.1q(k(el,i){N[i]={};o 3Z=(i!=25)||(c.C.6I&&(el.3R>0));c.1h(3Z?\'aa\':\'7K\',[c.2B[i],el]);M(o 2O 1a c.3U)N[i][2O]=3Z?0:el[c.3U[2O]]},c);m c.1g(N)},dW:k(25){m c.3Q(25)}});1f.7t=7t;',62,956,'||||||||||||this||||||||function||return||var|||||||||||||if|options|||type|element||event|value|property|new|for|obj|false|Element|document|extend||elements|window|length|bind||case||||now||else|from||to|Class|events|in|arguments|Math|param|true|Fx|start|fireEvent|initialize|contains|push|empty|pos|null|top|args|each|parent|rgb|key|left|position|name|items|css|array|className|addEvent|break|max|offset|limit|bound|timer|values|properties|text|prototype|result|style|keys|setStyle|onComplete|stop|selector|data|props|prop|tmp|call|page|source||opacity|switch|method||index|Elements||inject|end|merge|mode|join|container|parsed|transition|delay|getStyle|current|set|overflown|previous|hsb|step|relatedTarget|Events|round|temp|script|Array|transport|test|custom|unit|width|string|chk|togglers|addListener|map|color|Garbage|scroll|Methods|object|nocash|remove|url|mousemove|height|fx|ie|Color|border|ghost|Base|params|parse|hue|Event|setOptions|documentElement||match||getElementsByTagName|margin|100|filter||||create|context|wrapper|toInt|bindWithEvent|overed|replace|removeListener|implement|toggler|indexOf|size|mouse|parentNode|Transitions|getPosition|tag|item|min|CSS|iCss|target|pow|next|scripts|option|time|shared|hex|drag|modifiers|change|scrollTo|Cookie|Json|handle|anchor|response|Abstract|returns|Hash|bottom|display|offsetHeight|len|wait|effects|trash|tip|onStart|absolute|hide||iterable|myTitle|Options|getValue|toolTip||iTo|select|duration|xpath|offsetWidth|Styles|show|load|periodical|Drag|knob|check|apply|increase|toString|val|right|compute|delta|setNow|cont|src|argument|id|chains|padding|webkit|link|visibility|setStyles|body|removeEvent|getTag|getCoordinates|every|active|str|status|headers|cookie|handles|number|href|hidden|grid|running|class|image|pick|checker|fixed|px|open|results|div||255|collect|title|mix|clear|getNow|delete|sources|post|mousewheel|fromTo|catch|bit|native|queryString|secure|onSuccess|htmlElement|try|location|setHeader|readyState|mousedown|move|list|get|evaluate|setHTML|xml|myText|instance|links|webkit419|moveGhost|mouseup|toQueryString|HTMLElement|regexp|isSuccess|rgbToHex|offsets|hexToRgb|_method|colors|encoding|setLength|toLowerCase|unique|onload|parseInt|scrollHeight|iFrom|getProperty|include|trim|iNow|scrollLeft|red|domReady|precision|klass||walk|default|scrollTop|layout|green|parseFloat|on|split|out|send|area|droppables|mp|head|attempt|evType|click|String|addEvents|date|continue|fix|XHR|setProperties|currentStyle|counter|included|images|hasKey|brother|injectAfter|onFailure|generic|saturation|dual|Properties|loaded|XMLHttpRequest|instances|steps|onChange|checkStep|mod|alwaysHide|Listeners|substr|draggedKnob|snap|getElements|code|up|fKey|evalScripts|tagName|prev|stopPropagation|attach|getElementById|preventDefault|getElementsBySelector|while|relative|scrollWidth|setMany|Multi|splice|blue|realType|defined|removeEvents|regex|percent|forEach|typeof|alpha|encodeURIComponent|fixedHeight|getSize|scrollSize|onreadystatechange|none|path|setProperty|proto|fixedWidth|domain|evalResponse|setTransport|clean|hasClass|Accordion|Chain|unload|onCancel|update|RegExp|callChain|toUpperCase|transitions|qs|disabled|checked|add|pairs|getMany|ie_ready|multiple|onActive|getParam|found|xhtml|getItems|concat|selected|Dom|domready|Style|Transition|flag|PI|compat|injectBefore|Function|getLast|node|operator|innerText|nodeType|iProps|appendChild|cssText|firstChild|easeType|camelCase|DOMMouseScroll|random|charAt|copy|locate|newArray|rgbToHsb|merged|addEventListener|brightness|rr|getWidth|getHeight|hasChild|complete|javascript|gecko|abort|callee|getScrollLeft|getScrollTop|pageY|img|mousemover|coord|toElement|Slider|toStep|previousEnd|pageX|coordinates|visible|getChildren|getNext|styles|previousChange|onTick|horizontal|mouseenter|velocity|mouseleave|vertical|capitalize|onDrag|maxTitleChars|lim|NativeEvents|gr|Object|mouseout|first|mouseover|insertBefore|getScrollHeight|getScrollWidth|after|cancel|Date|borderShort|fps|pageXOffset|opera|Ajax|clientWidth|clientHeight|onDragComplete|clientX|onRequest|request|pageYOffset|Single|before|Merge|pp|fullHeight|ActiveXObject|wheelDelta|floor|wheelStops|onStateChange|beforeunload|iParsed|direction|getTime|Scroller|overflow|addClass|getCoords|client|constructor|clickedElement|removeClass|detach|clone|onDragStart|build|application|which|useLink|setTimeout|undefined|execScript|getElement|converter|Content|Sortables|normal|sel|contents|getPrevious|keydown|http|prefix|toPosition|rel|filterById|PropertiesIFlag|removeEventListener|half|Left|removeAttribute|filterByClass|filterByAttribute|onBackground|input|resolver|textarea|getFormElements|getHeader|ie6|Scroll|getPos|fullWidth|zoom|onBeforeStart|win|onProgress|distance||timeout|Asset|onSnap|clientY|cloneEvents|cos|autoSave|nodeValue|where|Bottom|idx|elementsProperty|childNodes|relatedTargetGecko|error|defaultView|urlEncoded|toFloat|Tips|createElement|shift|hyphenate|Move|Number|checkAgainst|getLeft|getTop|addSection|www|onShow|fixRelatedTarget|interval|onHide|save|picked|autoCancel|span|textContent|adopt|innerHTML|styleSheet|escapeRegExp|fixStyle|6000|fullOpacity|hsbToRgb|slideIn|slideOut|360|1000|async|Width|getStyles|slice|Top|sin|setOpacity|removeChild|600000|appendText|0px|showDelay|extended||Right|hideDelay|full|button|menu|shiftKey|metaKey|altKey|fromCharCode|frameborder|ctrlKey|attachEvent|detail|srcElement|control|CollectGarbage|readonly|frameBorder|alt|keyCode|111|readOnly|meta|detachEvent|120|rightClick|wheel|pass|some|associate|getRandom|clearChain|chain|DOMElement|execCommand|BackgroundImageCache|transparent|setInterval|embed|boolean|injectInside|times|bindAsEventListener|err|fromElement|iframe|khtml|whitespace|collection|clearTimeout|textnode|nodeName|MooTools|version|clearInterval|Window|taintEnabled|webkit420|getBoxObjectFor|navigator|all|Document|ie7|injectTop|cloneNode|borderStyle|borderColor|htmlFor|borderWidth|getText|getProperties|setAttribute|setText|colspan|colSpan|tabindex|tabIndex|maxlength|accessKey|accesskey|rowspan|rowSpan|removeProperty|attributes|float|styleFloat|cssFloat|toggleClass|createTextNode|replaceWith|replaceChild|zIndex|hasLayout|lastChild|getParent|getAttribute|getFirst|Sibling|getComputedStyle|getPropertyValue|maxLength|overrideMimeType|200|300|responseText|urlencoded|form|cancelBubble|XMLHTTP|charset|responseXML|Connection|Accept|html|ecma|With|Requested|close|setRequestHeader|postBody||utf|makeDraggable|Bounce|Elastic|Quad|618|Back|Circ|acos|Sine|Cubic|Quart|over|drop|emptydrop|leave|makeResizable|Quint|sqrt|java|gi|setHue|setSaturation|setBrightness|invert|pop|onerror|Image|4096|RGB|HSB|hellip|Group|showThisHideOpen|tool|serialize|10000|SmoothScroll|hash|onabort|screen|toGMTString|decodeURIComponent|isFinite|expires|setTime|exec|getResponseHeader|action|Eaeflnr|eval|readystatechange|stylesheet|media|json|JSON|Remote|Request||Expo|Microsoft|substring|XPathResult|UNORDERED_NODE_SNAPSHOT_TYPE|with|starts|ES|namespaceURI|snapshotLength|snapshotItem|checkbox|radio|getElementsByClassName|1999|w3|org|Pow|contextmenu|space|backspace|tab|esc|down|returnValue|enter|dblclick|keypress|submit|reset|blur|focus|keyup|resize|password|filterByTag|toLeft|toRight|Slide|toBottom|toTop|clearTimer|effect|toggle|easeIn|InOut|ease|Out|In|easeOut|easeInOut|500|linear|defer|DOMContentLoaded|protocol|write|offsetTop|https|offsetParent|void|innerWidth|onDomReady||innerHeight|offsetLeft'.split('|'),0,{}))

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('5(T 8=="1B"){d 8=k Q()}5(T 8.X=="1B"){8.X=k Q()}5(T 8.y=="1B"){8.y=k Q()}8.D=f(1y,p,w,h,1o,c,1p,1K,1h,1x){5(!m.13){g}4.1V=1x?1x:"2w";4.1R=8.X.1n(4.1V);4.1w=k Q();4.17=k Q();4.1D=k 29();5(1y){4.l("L",1y)}5(p){4.l("p",p)}5(w){4.l("S",w)}5(h){4.l("R",h)}5(1o){4.l("1e",k 8.v(1o.2B().V(".")))}4.P=8.y.1U();5(!12.2A&&m.1u&&4.P.E>7){8.D.1S=B}5(c){4.1J("2C",c)}d q=1p?1p:"2E";4.1J("2F",q);4.l("10",I);4.l("W",I);d 1Y=(1K)?1K:12.16;4.l("1Q",1Y);4.l("15","");5(1h){4.l("15",1h)}};8.D.1P={10:f(1q){4.1r=!1q?"2G.L":1q;4.l("10",B)},l:f(2e,1Z){4.1D[2e]=1Z},j:f(22){g 4.1D[22]},1J:f(23,2c){4.1w[23]=2c},1F:f(){g 4.1w},U:f(2a,26){4.17[2a]=26},2Z:f(2d){g 4.17[2d]},28:f(){g 4.17},1H:f(){d 18=k 29();d u;d 1t=4.28();H(u 1f 1t){18[18.G]=u+"="+1t[u]}g 18},1T:f(){d o="";5(C.1z&&C.1m&&C.1m.G){5(4.j("W")){4.U("27","2N");4.l("L",4.1r)}o="<2P 2Q=\\"2R/x-2S-2T\\" 2U=\\""+4.j("L")+"\\" S=\\""+4.j("S")+"\\" R=\\""+4.j("R")+"\\" O=\\""+4.j("O")+"\\"";o+=" p=\\""+4.j("p")+"\\" 11=\\""+4.j("p")+"\\" ";d 1v=4.1F();H(d u 1f 1v){o+=[u]+"=\\""+1v[u]+"\\" "}d 1A=4.1H().2g("&");5(1A.G>0){o+="2h=\\""+1A+"\\""}o+="/>"}1b{5(4.j("W")){4.U("27","2W");4.l("L",4.1r)}o="<1N p=\\""+4.j("p")+"\\" 2Y=\\"30:31-32-33-34-35\\" S=\\""+4.j("S")+"\\" R=\\""+4.j("R")+"\\" O=\\""+4.j("O")+"\\">";o+="<1I 11=\\"37\\" 1L=\\""+4.j("L")+"\\" />";d 1G=4.1F();H(d u 1f 1G){o+="<1I 11=\\""+u+"\\" 1L=\\""+1G[u]+"\\" />"}d 1M=4.1H().2g("&");5(1M.G>0){o+="<1I 11=\\"2h\\" 1L=\\""+1M+"\\" />"}o+="</1N>"}g o},2i:f(14){5(4.j("10")){d 1O=k 8.v([6,0,2j]);5(4.P.1d(1O)&&!4.P.1d(4.j("1e"))){4.l("W",B);4.U("2k",2l(4.j("1Q")));m.1k=m.1k.2m(0,2n)+" - 1W 2o 2p";4.U("2q",m.1k)}}5(4.1R||4.j("W")||4.P.1d(4.j("1e"))){d n=(T 14=="2r")?m.13(14):14;n.2s=4.1T();g B}1b{5(4.j("15")!=""){m.16.1E(4.j("15"))}}g I}};8.y.1U=f(){d A=k 8.v([0,0,0]);5(C.1z&&C.1m.G){d x=C.1z["2y 1W"];5(x&&x.20){A=k 8.v(x.20.1E(/([a-2D-Z]|\\s)+/,"").1E(/(\\s+r|\\s+b[0-9]+)/,".").V("."))}}1b{5(C.25&&C.25.1C("2H 2J")>=0){d t=1;d 1g=3;2M(t){19{1g++;t=k 1a("z.z."+1g);A=k 8.v([1g,0,0])}1c(e){t=J}}}1b{19{d t=k 1a("z.z.7")}1c(e){19{d t=k 1a("z.z.6");A=k 8.v([6,0,21]);t.2V="2X"}1c(e){5(A.E==6){g A}}19{t=k 1a("z.z")}1c(e){}}5(t!=J){A=k 8.v(t.3a("$1e").V(" ")[1].V(","))}}}g A};8.v=f(F){4.E=F[0]!=J?1i(F[0]):0;4.Y=F[1]!=J?1i(F[1]):0;4.1l=F[2]!=J?1i(F[2]):0};8.v.1P.1d=f(N){5(4.E<N.E){g I}5(4.E>N.E){g B}5(4.Y<N.Y){g I}5(4.Y>N.Y){g B}5(4.1l<N.1l){g I}g B};8.X={1n:f(1j){d q=m.16.2u||m.16.2x;5(1j==J){g q}5(q){d K=q.1s(1).V("&");H(d i=0;i<K.G;i++){5(K[i].1s(0,K[i].1C("="))==1j){g K[i].1s((K[i].1C("=")+1))}}}g""}};8.y.1X=f(){d M=m.2K("2O");H(d i=M.G-1;i>=0;i--){M[i].O.36="38";H(d x 1f M[i]){5(T M[i][x]=="f"){M[i][x]=f(){}}}}};5(8.D.1S){5(!8.2f){8.y.2b=f(){2t=f(){};2v=f(){};12.24("2z",8.y.1X)};12.24("2L",8.y.2b);8.2f=B}}5(!m.13&&m.1u){m.13=f(p){g m.1u[p]}}d 39=8.X.1n;d 2I=8.D;d D=8.D;',62,197,'||||this|if|||deconcept|||||var||function|return|||getAttribute|new|setAttribute|document||_19|id||||axo|key|PlayerVersion|||SWFObjectUtil|ShockwaveFlash|_23|true|navigator|SWFObject|major|_29|length|for|false|null|_2d|swf|_2f|fv|style|installedVer|Object|height|width|typeof|addVariable|split|doExpressInstall|util|minor||useExpressInstall|name|window|getElementById|_20|redirectUrl|location|variables|_16|try|ActiveXObject|else|catch|versionIsValid|version|in|_26|_9|parseInt|_2b|title|rev|mimeTypes|getRequestParameter|_5|_7|_d|xiSWFPath|substring|_18|all|_1a|params|_a|_1|plugins|_1c|undefined|indexOf|attributes|replace|getParams|_1d|getVariablePairs|param|addParam|_8|value|_1f|object|_21|prototype|xiRedirectUrl|skipDetect|doPrepUnload|getSWFHTML|getPlayerVersion|DETECT_KEY|Flash|cleanupSWFs|_c|_f|description||_10|_11|attachEvent|userAgent|_14|MMplayerType|getVariables|Array|_13|prepUnload|_12|_15|_e|unloadSet|join|flashvars|write|65|MMredirectURL|escape|slice|47|Player|Installation|MMdoctitle|string|innerHTML|__flash_unloadHandler|search|__flash_savedUnloadHandler|detectflash|hash|Shockwave|onunload|opera|toString|bgcolor|zA|high|quality|expressinstall|Windows|FlashObject|CE|getElementsByTagName|onbeforeunload|while|PlugIn|OBJECT|embed|type|application|shockwave|flash|src|AllowScriptAccess|ActiveX|always|classid|getVariable|clsid|D27CDB6E|AE6D|11cf|96B8|444553540000|display|movie|none|getQueryParamValue|GetVariable'.split('|'),0,{}))
var Videobox = {

	init: function (options) {
		// init default options
		this.options = Object.extend({
			resizeDuration: 400,	// Duration of height and width resizing (ms)
			initialWidth: 250,		// Initial width of the box (px)
			initialHeight: 250,		// Initial height of the box (px)
			defaultWidth: 425,		// Default width of the box (px)
			defaultHeight: 350,	// Default height of the box (px)
			animateCaption: true,	// Enable/Disable caption animation
			flvplayer: 'swf/flvplayer.swf'
		}, options || {});

		this.anchors = [];
		$A($$('a')).each(function(el){
			if(el.rel && el.href && el.rel.test('^vidbox', 'i')) {
				el.addEvent('click', function (e) {
          e = new Event(e);
          e.stop();
          this.click(el);
				}.bind(this));
				this.anchors.push(el);
			}
    }, this);

		this.overlay = new Element('div').setProperty('id', 'lbOverlay').injectInside(document.body);
		this.center = new Element('div').setProperty('id', 'lbCenter').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);

		this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainer').setStyle('display', 'none').injectInside(document.body);
		this.bottom = new Element('div').setProperty('id', 'lbBottom').injectInside(this.bottomContainer);
		new Element('a').setProperties({id: 'lbCloseLink', href: '#'}).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
		this.caption = new Element('div').setProperty('id', 'lbCaption').injectInside(this.bottom);
		this.number = new Element('div').setProperty('id', 'lbNumber').injectInside(this.bottom);
		new Element('div').setStyle('clear', 'both').injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 500}).hide(),
			center: this.center.effects({duration: 500, transition: Fx.Transitions.sineInOut, onComplete: nextEffect}),
			bottom: this.bottom.effect('margin-top', {duration: 400})
		};

	},

	click: function(link) {
	
     		return this.open (link.href, link.title, link.rel);

	},
	open: function(sLinkHref, sLinkTitle, sLinkRel) {
		this.href = sLinkHref;
		this.title = sLinkTitle;
		this.rel = sLinkRel;
		this.position();
		this.setup();
		this.video(this.href);
		this.top = Window.getScrollTop() + (Window.getHeight() / 15);
		this.center.setStyles({top: this.top+'px', display: ''});
		this.fx.overlay.start(0.8);
		this.step = 1;
		this.center.setStyle('background','#fff url(loading.gif) no-repeat center');
		this.caption.innerHTML = this.title;
		this.fx.center.start({'height': [this.options.contentsHeight]});
	},

	setup: function(){
		var aDim = this.rel.match(/[0-9]+/g);
		this.options.contentsWidth = (aDim && (aDim[0] > 0)) ? aDim[0] : this.options.defaultWidth;
		this.options.contentsHeight = (aDim && (aDim[1] > 0)) ? aDim[1] : this.options.defaultHeight;

	},

	position: function(){
    this.overlay.setStyles({'top': 0+'px', 'height': document.getElementById('main_div').clientHeight+'px'});
	},

	video: function(sLinkHref){
		if (sLinkHref.match(/youtube\.com\/watch/i)) {
      this.flash = true;
			var hRef = sLinkHref;
			var videoId = hRef.split('=');
			this.videoID = videoId[1];
			this.so = new SWFObject("http://www.youtube.com/v/"+this.videoID, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
			this.so.addParam("wmode", "transparent");
		}
		else if (sLinkHref.match(/metacafe\.com\/watch/i)) {
      this.flash = true;
			var hRef = sLinkHref;
			var videoId = hRef.split('/');
			this.videoID = videoId[4];
			this.so = new SWFObject("http://www.metacafe.com/fplayer/"+this.videoID+"/.swf", "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
			this.so.addParam("wmode", "transparent");
		}
		else if (sLinkHref.match(/google\.com\/videoplay/i)) {
      this.flash = true;
			var hRef = sLinkHref;
			var videoId = hRef.split('=');
			this.videoID = videoId[1];
			this.so = new SWFObject("http://video.google.com/googleplayer.swf?docId="+this.videoID+"&hl=en", "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
			this.so.addParam("wmode", "transparent");
		}
		else if (sLinkHref.match(/ifilm\.com\/video/i)) {
		  this.flash = true;
			var hRef = sLinkHref;
			var videoId = hRef.split('video/');
			this.videoID = videoId[1];
			this.so = new SWFObject("http://www.ifilm.com/efp", "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0", "#000");
			this.so.addVariable("flvbaseclip", this.videoID+"&");
			this.so.addParam("wmode", "transparent");
		}
		else if (sLinkHref.match(/\.mov/i)) {
		  this.flash = false;
			if (navigator.plugins && navigator.plugins.length) {
          this.other ='<object id="qtboxMovie" type="video/quicktime" codebase="http://www.apple.com/qtactivex/qtplugin.cab" data="'+sLinkHref+'" width="'+this.options.contentsWidth+'" height="'+this.options.contentsHeight+'"><param name="src" value="'+sLinkHref+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
      } else {
        this.other = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+this.options.contentsWidth+'" height="'+this.options.contentsHeight+'" id="qtboxMovie"><param name="src" value="'+sLinkHref+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
      }
		}
		else if (sLinkHref.match(/\.wmv/i) || sLinkHref.match(/\.asx/i)) {
		this.flash = false;
		 this.other = '<object NAME="Player" WIDTH="'+this.options.contentsWidth+'" HEIGHT="'+this.options.contentsHeight+'" align="left" hspace="0" type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param NAME="URL" VALUE="'+sLinkHref+'"><param><param NAME="AUTOSTART" VALUE="false"></param><param name="showControls" value="true"></param><embed WIDTH="'+this.options.contentsWidth+'" HEIGHT="'+this.options.contentsHeight+'" align="left" hspace="0" SRC="'+sLinkHref+'" TYPE="application/x-oleobject" AUTOSTART="false"></embed></object>'
		}
		else if (sLinkHref.match(/\.flv/i)) {
		 this.flash = true;
//SDW edited
		 //this.so = new SWFObject(this.options.flvplayer+"?file="+sLinkHref, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0", "#000");
		 //alert(sLinkHref);
		 this.so = new SWFObject(sLinkHref, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0", "#000");
		 this.so.addParam("salign", "lt");
		 this.so.addParam("scale", "noscale");
		}
		else {
		  this.flash = true;
			this.videoID = sLinkHref;
			this.so = new SWFObject(this.videoID, "flvvideo", this.options.contentsWidth, this.options.contentsHeight, "0");
		}
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.fx.center.start({'width': [this.options.contentsWidth], 'marginLeft': [this.options.contentsWidth/-2]});
			break;
			this.step++;
		case 2:
			this.center.setStyle('background','#fff');
			this.flash ? this.so.write(this.center) : this.center.setHTML(this.other) ;
			this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', height: '0px', marginLeft: this.center.style.marginLeft, width: this.options.contentsWidth+'px',display: ''});
			if (this.options.animateCaption){
				this.fx.bottom.set(-this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
			this.step++;
		}
	},

	close: function(){
		this.fx.overlay.start(0);
		this.center.style.display = this.bottomContainer.style.display = 'none';
		this.center.innerHTML = '';
		return false;
	}

};


window.addEvent('domready', Videobox.init.bind(Videobox));
document.write('<script type="text/javascript" src="http://www.gladstonebrookes.co.uk/scripts/bespoke/forms/gladstone_forms.js"></scr' + 'ipt>');
