/*

[js] sticky package 21:16:52 22/02/12

16:53:58 27/08/10 - jquery.colorbox.js - 9K
16:53:58 27/08/10 - javalib.js - 17K

*/

/* jquery.colorbox.js */

/*  1.3.7 */ (function(c){function o(b,d){d=d==="x"?n.width():n.height();return typeof b==="string"?Math.round(b.match(/%/)?d/100*parseInt(b,10):parseInt(b,10)):b}function K(b){b=c.isFunction(b)?b.call(h):b;return a.photo||b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function Y(){for(var b in a)if(c.isFunction(a[b])&&b.substring(0,2)!=="on")a[b]=a[b].call(h);a.rel=a.rel||h.rel||"nofollow";a.href=a.href||c(h).attr("href");a.title=a.title||h.title}function Z(b){h=b;a=c.extend({},c(h).data(s)); Y();if(a.rel!=="nofollow"){j=c(".cboxElement").filter(function(){return(c(this).data(s).rel||this.rel)===a.rel});g=j.index(h);if(g<0){j=j.add(h);g=j.length-1}}else{j=c(h);g=0}if(!q){A=q=l;L=h;try{L.blur()}catch(d){}c.event.trigger(ba);a.onOpen&&a.onOpen.call(h);r.css({opacity:parseFloat(a.opacity),cursor:a.overlayClose?"pointer":"auto"}).show();a.w=o(a.initialWidth,"x");a.h=o(a.initialHeight,"y");e.position(0);M&&n.bind("resize.cboxIE6 scroll.cboxIE6",function(){r.css({width:n.width(),height:n.height(), top:n.scrollTop(),left:n.scrollLeft()})}).trigger("scroll.cboxIE6")}N.add(E).add(F).add(t).add(O).hide();P.html(a.close).show();e.slideshow();e.load()}var s="colorbox",l=true,e,B=c.browser.msie&&!c.support.opacity,M=B&&c.browser.version<7,ba="cbox_open",I="cbox_load",Q="cbox_complete",r,k,x,p,R,S,T,U,j,n,m,J,G,O,N,t,F,E,P,y,z,u,v,h,L,g,a,q,A,$={transition:"elastic",speed:350,width:false,height:false,innerWidth:false,innerHeight:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false, scalePhotos:l,scrolling:l,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:l,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,overlayClose:l,loop:l,slideshow:false,slideshowAuto:l,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false,escKey:l,arrowKey:l};e=c.fn.colorbox=c.colorbox=function(b,d){var f= this;if(f.selector&&!f.length)return f;b=b||{};if(d)b.onComplete=d;if(!f.length||f.selector===undefined){f=c("<a/>");b.open=l}f.each(function(){c(this).data(s,c.extend({},c(this).data(s)||$,b)).addClass("cboxElement")});b.open&&Z(f[0]);return f};e.init=function(){function b(d){return c('<div id="cbox'+d+'"/>')}n=c(window);k=c('<div id="colorbox"/>');r=b("Overlay").hide();x=b("Wrapper");p=b("Content").append(m=b("LoadedContent").css({width:0,height:0}),G=b("LoadingOverlay").add(b("LoadingGraphic")), O=b("Title"),N=b("Current"),F=b("Next"),E=b("Previous"),t=b("Slideshow"),P=b("Close"));x.append(c("<div/>").append(b("TopLeft"),R=b("TopCenter"),b("TopRight")),c("<div/>").append(S=b("MiddleLeft"),p,T=b("MiddleRight")),c("<div/>").append(b("BottomLeft"),U=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"});J=c("<div id='cboxLoadingBay' style='position:absolute; width:9999px;'/>");c("body").prepend(r,k.append(x,J));if(B){k.addClass("cboxIE");M&&r.css("position","absolute")}p.children().hover(function(){c(this).addClass("hover")}, function(){c(this).removeClass("hover")}).addClass("hover");y=R.height()+U.height()+p.outerHeight(l)-p.height();z=S.width()+T.width()+p.outerWidth(l)-p.width();u=m.outerHeight(l);v=m.outerWidth(l);k.css({"padding-bottom":y,"padding-right":z}).hide();F.click(e.next);E.click(e.prev);P.click(e.close);p.children().removeClass("hover");c(".cboxElement").live("click",function(d){if(d.button!==0&&typeof d.button!=="undefined"||d.ctrlKey||d.shiftKey||d.altKey)return l;else{Z(this);return false}});r.click(function(){a.overlayClose&& e.close()});c(document).bind("keydown",function(d){if(q&&a.escKey&&d.keyCode===27){d.preventDefault();e.close()}if(q&&a.arrowKey&&!A&&j.length>1)if(d.keyCode===37&&(g>0||a.loop)){d.preventDefault();E.click()}else if(d.keyCode===39&&(g<j.length-1||a.loop)){d.preventDefault();F.click()}})};e.remove=function(){k.add(r).remove();c(".cboxElement").removeData(s).removeClass("cboxElement")};e.position=function(b,d){function f(C){R[0].style.width=U[0].style.width=p[0].style.width=C.style.width;G[0].style.height= G[1].style.height=p[0].style.height=S[0].style.height=T[0].style.height=C.style.height}var i,w=Math.max(n.height()-a.h-u-y,0)/2+n.scrollTop(),H=Math.max(n.width()-a.w-v-z,0)/2+n.scrollLeft();i=k.width()===a.w+v&&k.height()===a.h+u?0:b;x[0].style.width=x[0].style.height="9999px";k.dequeue().animate({width:a.w+v,height:a.h+u,top:w,left:H},{duration:i,complete:function(){f(this);A=false;x[0].style.width=a.w+v+z+"px";x[0].style.height=a.h+u+y+"px";d&&d()},step:function(){f(this)}})};e.resize=function(b){if(q){b= b||{};if(b.width)a.w=o(b.width,"x")-v-z;if(b.innerWidth)a.w=o(b.innerWidth,"x");m.css({width:a.w});if(b.height)a.h=o(b.height,"y")-u-y;if(b.innerHeight)a.h=o(b.innerHeight,"y");if(!b.innerHeight&&!b.height){b=m.wrapInner("<div style='overflow:auto'></div>").children();a.h=b.height();b.replaceWith(b.children())}m.css({height:a.h});e.position(a.transition==="none"?0:a.speed)}};e.prep=function(b){function d(w){var H,C,V,W,D=j.length,X=a.loop;e.position(w,function(){function aa(){B&&k[0].style.removeAttribute("filter")} if(q){B&&f&&m.fadeIn(100);if(a.iframe)c("<iframe frameborder=0"+(a.scrolling?"":" scrolling='no'")+(B?" allowtransparency='true'":"")+"/>").appendTo(m).attr({src:a.href,id:"cboxIframe",name:(new Date).getTime()});m.show();O.show().html(a.title);if(D>1){N.html(a.current.replace(/\{current\}/,g+1).replace(/\{total\}/,D)).show();F[X||g<D-1?"show":"hide"]().html(a.next);E[X||g>0?"show":"hide"]().html(a.previous);H=g>0?j[g-1]:j[D-1];V=g<D-1?j[g+1]:j[0];if(a.slideshow){t.show();g===D-1&&!X&&k.is(".cboxSlideshow_on")&& t.click()}if(a.preloading){W=c(V).data(s).href||V.href;C=c(H).data(s).href||H.href;if(K(W))c("<img/>")[0].src=W;if(K(C))c("<img/>")[0].src=C}}G.hide();a.transition==="fade"?k.fadeTo(i,1,function(){aa()}):aa();n.bind("resize.cbox",function(){e.position(0)});c.event.trigger(Q);a.onComplete&&a.onComplete.call(h)}})}if(q){var f,i=a.transition==="none"?0:a.speed;n.unbind("resize.cbox");m.remove();m=c('<div id="cboxLoadedContent"/>').html(b);m.hide().appendTo(J).css({width:function(){a.w=a.w||m.width(); a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}(),overflow:a.scrolling?"auto":"hidden"}).css({height:function(){a.h=a.h||m.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}()}).prependTo(p);c("#cboxPhoto").css({cssFloat:"none"});M&&c("select:not(#colorbox select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("cbox_cleanup",function(){this.style.visibility="inherit"});a.transition==="fade"?k.fadeTo(i,0,function(){d(0)}):d(i)}};e.load=function(){var b,d,f,i=e.prep; A=l;h=j[g];a=c.extend({},c(h).data(s));Y();c.event.trigger(I);a.onLoad&&a.onLoad.call(h);a.h=a.height?o(a.height,"y")-u-y:a.innerHeight?o(a.innerHeight,"y"):false;a.w=a.width?o(a.width,"x")-v-z:a.innerWidth?o(a.innerWidth,"x"):false;a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=o(a.maxWidth,"x")-v-z;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=o(a.maxHeight,"y")-u-y;a.mh=a.h&&a.h<a.mh?a.h:a.mh}b=a.href;G.show();if(a.inline){c('<div id="cboxInlineTemp"/>').hide().insertBefore(c(b)[0]).bind(I+" cbox_cleanup", function(){c(this).replaceWith(m.children())});i(c(b))}else if(a.iframe)i(" ");else if(a.html)i(a.html);else if(K(b)){d=new Image;d.onload=function(){var w;d.onload=null;d.id="cboxPhoto";c(d).css({margin:"auto",border:"none",display:"block",cssFloat:"left"});if(a.scalePhotos){f=function(){d.height-=d.height*w;d.width-=d.width*w};if(a.mw&&d.width>a.mw){w=(d.width-a.mw)/d.width;f()}if(a.mh&&d.height>a.mh){w=(d.height-a.mh)/d.height;f()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";i(d); j.length>1&&c(d).css({cursor:"pointer"}).click(e.next);if(B)d.style.msInterpolationMode="bicubic"};d.src=b}else c("<div>Request unsuccessful.</div>").appendTo(J).load(b,function(){i(this)})};e.next=function(){if(!A){g=g<j.length-1?g+1:0;e.load()}};e.prev=function(){if(!A){g=g>0?g-1:j.length-1;e.load()}};e.slideshow=function(){function b(){t.text(a.slideshowStop).bind(Q,function(){f=setTimeout(e.next,a.slideshowSpeed)}).bind(I,function(){clearTimeout(f)}).one("click",function(){d()});k.removeClass(i+ "off").addClass(i+"on")}var d,f,i="cboxSlideshow_";t.bind("cbox_closed",function(){t.unbind();clearTimeout(f);k.removeClass(i+"off "+i+"on")});d=function(){clearTimeout(f);t.text(a.slideshowStart).unbind(Q+" "+I).one("click",function(){b();f=setTimeout(e.next,a.slideshowSpeed)});k.removeClass(i+"on").addClass(i+"off")};if(a.slideshow&&j.length>1)a.slideshowAuto?b():d()};e.close=function(){if(q){q=false;c.event.trigger("cbox_cleanup");a.onCleanup&&a.onCleanup.call(h);n.unbind(".cbox .cboxIE6");k.add(r).stop().fadeTo("fast", 0,function(){c("#colorbox iframe").attr("src","about:blank");m.remove();k.add(r).css({opacity:1,cursor:"auto"}).hide();try{L.focus()}catch(b){}setTimeout(function(){c.event.trigger("cbox_closed");a.onClosed&&a.onClosed.call(h)},1)})}};e.element=function(){return c(h)};e.settings=$;c(e.init)})(jQuery);

/* javalib.js */

var clear="/shared/pngfix.gif" //path to clear.gif
pngfix=function(){var els=document.getElementsByTagName('*');var ip=/\.png/i;var i=els.length;while(i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';var elkids=el.getElementsByTagName('*');if (elkids){var j=elkids.length;if(el.currentStyle.position!="absolute")es.position='static';while (j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}}

function redirect_url(url){
	window.location=url;
}

var image_zoom_timer = 0;
function image_zoom(id,speed,delay,w,h,step_w,step_h,div_w,div_h){
	var step_w = (step_w == null) ? 0 : step_w;
	var step_h = (step_h == null) ? 0 : step_h;
	var div_w  = (div_w == null) ? 0 : div_w;
	var div_h  = (div_h == null) ? 0 : div_h;
	var w = (w == null) ? 0 : w;
	var h = (h == null) ? 0 : h;
	if (!step_w) {
		w = $(id).width();	ow = w;
		h = $(id).height();	oh = h;
		if (!w) {
			setTimeout("image_zoom('"+id+"',"+speed+","+delay+")",2000);
			return;
		}
		ratio = w/h;
		if (w>h){
			step_w = 1;
			step_h = 1/ratio;
		} else {
			step_w = 1/ratio;
			step_h = 1;
		}
		step_w *= speed;
		step_h *= speed;
		div = $(id).parents("div").get(0).id;
		div_w = $('#'+div).width();
		div_h = $('#'+div).height();
		// firelog("image_zoom('"+id+"',"+speed+","+delay+","+w+","+h+","+step_w+","+step_h+","+div_w+","+div_h+")");
	}
	w = w - step_w;
	h = h - step_h;
	if (h>=div_h && w>=div_w) {
		$(id).width(w).height(h);
		window.status = "Img Zoom : timer : "+image_zoom_timer+" div_w "+div_w+" div_h "+div_h+" speed "+speed+" delay "+delay+ " w "+Math.floor(w)+"/"+ow+" h "+Math.floor(h)+"/"+oh+" step_w "+step_w+" step_h "+step_h+" ratio "+ratio;
		image_zoom_timer = setTimeout("image_zoom('"+id+"',"+speed+","+delay+","+w+","+h+","+step_w+","+step_h+","+div_w+","+div_h+")",delay);
	} else {
		//window.status = 'Zoom Complete';
	}
}

function image_zoom_cancel(){
	if (image_zoom_timer) {
		window.status = "Img Zoom : cancelled";
		clearTimeout(image_zoom_timer);
	}
}

function jcarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

function highlight_inputs() {
	$(".input_button").live('mouseover', function(){
		$(this).addClass('input_button_selected');
	});
	$(".input_button").live('mouseout', function(){
		$(this).removeClass('input_button_selected');
	});
	elements = ".input_qty, .input_select, .input_text, .input_checkbox, .input_radio, .input_textarea";
	// detect IE not input_select, dissapears when you mouse off in IE */
	if (!$.support.leadingWhitespace) elements = ".input_qty, .input_text, .input_checkbox, .input_radio, .input_textarea";
	$(elements).live('mouseover', function(){ 
		$(this).addClass("input_hover");
	});
	$(elements).live('mouseout', function(){ 
		$(this).removeClass("input_hover");
	});
}

function firelog(s){
	if (typeof(console)!="undefined") console.log(s);
}

function checkId(id){
	if (!id) return;
	id = id.replace("#","");
	if (!id) return;
	c = $('#'+id).length;
	//firelog("checkId "+id+" "+c);
	return (c > 0);
}

auto_div_height_animating = new Array;
function auto_div_height(id,monitor){
	if (auto_div_height_animating[id]) return;
	if (!checkId(monitor)) {
		firelog("auto_div_height : "+monitor+' removed from dom');
		return;
	}
	//firelog("auto_div_height : ('"+id+"','"+monitor+"')");
	container = id.replace('#','')+"_container";
	cid = "#"+container;
	if (!checkId(cid)) $(id).wrap("<div id='"+container+"'></div>");
	ch = $(cid).height();
	c  = $(id).height();
	if (c != ch){
		auto_div_height_animating[id] = true;
		firelog("auto_div_height : animating c "+c+" ch "+ch+" monitor "+monitor);
		$(cid).animate(
			{ height : c }, 500,
			function() {
				firelog("auto_div_height : animation complete "+monitor);
				auto_div_height_animating[id] = false;
				if ($(id).css('display') == 'none') $(id).fadeIn();
				setTimeout("auto_div_height('"+id+"','"+monitor+"')",500);
			}	
		);
	} else {
		$(cid).css('backgroundImage','none');
		if ($(id).css('display') == 'none') $(id).fadeIn();
		//firelog("auto_div_height : c "+c+" ch "+ch+" id "+id+" cid "+cid+" "+monitor);
		setTimeout("auto_div_height('"+id+"','"+monitor+"')",500);
	}
}

// stop ajax forms being submitted for invalid forms
function check_form(formData, jqForm, options){ 
	valid = $(options.id).valid();
	if (options.fadeout){
		if (valid) $(options.target).fadeOut();
		//else $(options.target).effect("highlight", { color: '#F00' }, 3000);
	}
	return valid;
}

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_itemList[idx - 1].html);
}

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
}

function datePicker(id) {
	$("#"+id).datepicker({ 
		dateFormat: 'dd/mm/yy', 
		changeMonth: true,
		changeYear: true,
		showAnim: 'slideDown'
	});
}
function datePickerIPTC(id) {
	$("#"+id).datepicker({ 
		dateFormat: 'yymmdd', 
		changeMonth: true,
		changeYear: true,
		showAnim: 'slideDown'
	});
}

function centerDiv(div) {
	divW = $(div).width();
	divH = $(div).height();
	width  = $(window).width();
	height = $(window).height();
	x = (width/2)-(divW/2);
	y = (height/2)-(divH/2)+$(window).scrollTop();
	$(div).css('top',y).css('left',x);
	$(div).fadeIn();
}

function popup_div(img) {
	$('#popup_div').fadeOut().html("<img id='popup_img' src='/tmp'+img+'>");
	setTimeout("centerDiv('#popup_div')",2000);
}

function popup_div_no_fade(img) {
	$('#popup_div_no_fade').hide().html("<img id='popup_img' src='/tmp"+img+"'>");
	centerDiv('#popup_div_no_fade');
}

// required for $('#id').load('page.php?params=have spaces in them')
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 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;
}

function id_check(){
	var allTags = document.body.getElementsByTagName('*');
	var ids = [];
	for (var tg = 0; tg< allTags.length; tg++) {
		var tag = allTags[tg];
		if (tag.id) {
			if (ids[tag.id] && tag.id != ',ilink' && tag.id != 'filename') ids.push(tag.id+'\n');
			else ids[tag.id] = 1;
		}
	}
	alert(ids);
}

function toggle_checkbox(id) {
	el = document.getElementById(id); 
	if (!el) {
		walert("Cannot set checkbox, no such id ["+id+"]");
		return;
	}
	el.value = 1-el.value;
}

function Height() {	return $(body).height(); }
function Width() {	return $(body).width(); }
function getHeight() { return Height(); }
function getWidth() { return Width(); }

function set_valid(nm,is_valid){
	return;
	e = document.getElementById("valid_"+nm);
	if (!e) {
		walert("Cannot find id to display error looking for valid_"+nm);
	} else {
		if (is_valid) e.innerHTML = "";
		else e.innerHTML = "<img alt='This field is required.' src='/shared/cart_warning.gif'>";
	}
}

function err_row(nm,s){
	set_valid(nm,false);
	nm = nm.replace('_',' ');
	return "<li>"+nm+" "+s+"</li>\n";
}

// validate + set_valid for old carts
function validate_form(formname){
	var txt = ""; 
	e = document.getElementById(formname);
	if (!e){
		walert("Cannot validate "+formname+" no such id.");
		return true;
	}
	check_password = false;
	fields = e.elements;
	password = confirm_password = "";
	for(i=0; i<fields.length; i++)
	{
		nm  = fields[i].name;
		id  = fields[i].id;
		val = fields[i].value;
//		txt = txt + id + " " + nm + " " + "[" + val + "]<br>";
		if (id.length<8) continue;
		s = id.slice(0,8);
		if (s!="id_valid") continue;
		set_valid(nm,true);
		fields[i].style.background='#FFFFFF';
		if (id=="id_valid_not_null" && val.length==0) {
			fields[i].style.background='#FF7777';
			txt = txt + err_row(nm,"is a mandatory field.");
		}
		if (id=="id_valid_email" && !echeck(val)){
			fields[i].style.background='#FF7777';
			txt = txt + err_row(nm,"is not a valid email address.");
		}
		if (id=="id_valid_credit_card" && !checkcreditcard(val)){
			fields[i].style.background='#FF7777';
			txt = txt + err_row(nm,"is not a valid credit card number.");
		}
		if (id=="id_valid_terms"){
			val = fields[i].checked;
			if (val==false){
				alert("You must accept our terms and conditions before you can place your order.");
				return;
			}
		}
		if (nm=="password") password = val;
		if (nm=="confirm_password") {
			check_password = true;
			confirm_password = val;
		}
	}
	if (check_password && (password != confirm_password)){
		txt = txt + err_row(nm,"your passwords do not match");
		set_valid("password",false);
		set_valid("confirm_password",false);
	}
	if (txt) {
		err.innerHTML=txt
		return false;
	} else err.innerHTML="";
	return true;
}

function saveFormId(fn){
	formId = document.getElementById(fn);
	if (formId) {
		$('#spinner').show();
		formId.submit();
	} else alert('cannot save: bad form id: '+fn);
}

function conf(s){
	return window.confirm(s);
}

var activeEditors = new Array()

function activateEditor(id) {
    //alert("activate "+id);
	activeEditors[activeEditors.length] = id;
    toggleEditor(id);
}

function deactivateEditors() {
	//alert('active '+activeEditors.length);
    for(x=0;x<activeEditors.length;x++) {
		walert("Removing editor "+x);
        toggleEditor(activeEditors[x])
    }
    activeEditors.length = 0;
}

// functions
function toggleEditor(id) {
	var elm = document.getElementById(id);
	if (!elm) {
		walert("no such id "+id);
		return;
	}
	if (tinyMCE.getInstanceById(id) == null){
		walert('add' + id);
		tinyMCE.execCommand('mceAddControl', false, id);
	} else {
		walert('focus' + id);
		tinyMCE.execCommand('mceFocus', false, id);
		walert('remove' + id);
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
} 

function popup(URL,w,h) {
	aWindow=window.open(URL, "thewindow", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=yes, resize=no, menubars=no");
}

function popup_full(URL,w,h) {
	aWindow=window.open(URL, "thewindow", "toolbar=no, width="+w+", height="+h+", status=yes, scrollbars=yes, resize=yes, menubars=no");
}

function popup_clean(URL,w,h) {
	aWindow=window.open(URL, "", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=no, resize=no, menubars=no");
}

function popup_scroll(URL,w,h) {
	aWindow=window.open(URL, "", "toolbar=no, width="+w+", height="+h+", status=no, scrollbars=yes, resize=no, menubars=no");
}

function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
		if (document.forms[formInst].elements[elementInst]) {
			document.forms[formInst].elements[elementInst].focus();
		}
	}
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

function checkcreditcard(object_value){
	if (object_value.length == 0)
		return false;
	var white_space = " -";
	var creditcard_string="";
	var check_char;

	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	if (creditcard_string.length < 13 || creditcard_string.length > 19)
		return false;

	if (creditcard_string.charAt(0) == "+")
		return false;

	if (!_CF_checkinteger(creditcard_string))
		return false;

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i));

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
				checkdigit++;

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;
}

var debugId = false;	

function walert(s){	window.status = s; }

function malert(s){
	if (debugId==1) alert(s);
	if (debugId==2) walert(s);
}

function setDebugId(v){
	// 1 alert // 2 status bar
	walert("debugId ("+v+")");
	debugId=v;
}

function getId(id) {
	return $('#'+id);
}

var lastId = 0;	
function statId(id){
	if (debugId) alert("statId "+id);
	if (!checkId(id)) return;
	display = $(id).css('display');
	opacity = $(id).css('opacity');
	//firelog("statId "+id+" display "+display+" opacity "+opacity);
	if (display=="none" || opacity==0) return 0;
	else return 1;
}

function hideId(id){
	if (debugId) alert("hideId "+id);
	if (!checkId(id)) return;
	$('#'+id).hide();
}

function showId(id,mode){
	if (debugId) alert("showId "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) lastId = id;
	$('#'+id).show();
}

function toggleId(id,mode){
	if (debugId) malert("toggleId "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode && lastId != id) hideId(lastId);
	$('#'+id).toggle();
}

function vislayer(){    
	this.lastId = '';
} 

vislayer.prototype.stat = function (id){
	if (!checkId(id)) return;
	opacity = $('#'+id).css('opacity');
	state   = $('#'+id).css('display');
	if (debugId) alert(id+" is display ["+state+"] opacity ["+opacity+"]");
	if (state=="block") return 1; else return 0;
}

vislayer.prototype.show = function (id,mode){
	if (debugId) malert("show "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) this.lastId = id;
	$('#'+id).show().css('opacity',1);
}

vislayer.prototype.hide = function (id){
	if (debugId) malert("hide "+id);
	if (!checkId(id)) return;
	$('#'+id).hide();
}

vislayer.prototype.toggle = function (id,mode){
	if (debugId) malert("toggle "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode && this.lastId != id) this.hide(this.lastId);
	if (this.stat(id)) this.hide(id); else this.show(id,mode);
}

vislayer.prototype.slideDown = function (id,mode){
	if (debugId) malert("slideDown "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) this.lastId = id;
	$('#'+id).slideDown("slow").css('opacity',1);
}

vislayer.prototype.slideUp = function (id){
	if (debugId) malert("slideUp "+id);
	if (!checkId(id)) return;
	$('#'+id).slideUp("slow");
}

vislayer.prototype.slideUpDown = function (id,mode){
	if (debugId) malert("slideUpDown "+id);
	if (!checkId(id)) return;
	realthis = this;
	$('#'+this.lastId).slideUp("slow", function () { realthis.slideDown(id,mode); } );
}

vislayer.prototype.faderIn = function (id,mode){
	if (debugId) malert("fadeIn "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	if (!mode) this.lastId = id;
	alert("last "+this.lastId);
	$('#'+id).fadeIn().css('opacity',1);
}

vislayer.prototype.faderOut = function (id){
	if (debugId) malert("faderOut "+id+" busy "+this.busy);
	if (!checkId(id)) return;
	$('#'+id).fadeOut("slow", function () { this.busy = false; malert("faderOut "+id+" busy "+this.busy); } );
}

vislayer.prototype.faderInOut = function (id,mode){
	if (typeof(this.busy) == "undefined") this.busy = false;
	if (debugId) malert("faderInOut "+id+" busy "+this.busy);
	if (!checkId(id)) return;
	if (this.busy) return;
	realthis = this;
	previousId = this.lastId;
	if (previousId == id) $('#'+id).fadeIn("slow");
	else {
		this.busy = true;
		$('#'+id).fadeIn("slow", function () { realthis.faderOut(previousId,mode); walert("busy "+this.busy); } );
	}
	if (!mode) this.lastId = id;
}

vislayer.prototype.slideToggle = function (id,mode){
	if (debugId) malert("slideToggle "+id);
	if (!checkId(id)) return;
	var mode = (mode == null) ? 0 : mode;
	// a panel is open, and its not this one // close it first
	if (this.stat(this.lastId) && this.lastId != id) {
		this.slideUpDown(id,mode);
	} else {
		if (this.stat(id)) this.slideUp(id); else this.slideDown(id,mode);
	}
}
