add_today_date = function(box){
	var prog_date = $('progress_inspection_date').value;
	re = /\//g;
	prog_date = prog_date.replace(re,"-");
	var old = box.value;
	box.value = (old == '')	? prog_date : old;
	box.disabled = (box.disabled ==	true) ?	false : true;}

change_final_valuf = function(box){
	var fd = box.previousSibling;
	var sd = fd.previousSibling.previousSibling;
	var r = '' + sd.value +	":" + fd.value;
	box.value = r; }

change_final_value = function(box){
	re = /\//g;
	var v =	"";
	var a =	box.previousSibling;
	var b =	a.previousSibling.previousSibling;
	var c =	b.previousSibling.previousSibling;
	v = c.value + ":" + b.value + ":" + a.value;
	v = v.replace(re,"-");
	box.value = v;}

change_final_value_new = function(box){
	var v =	"";
	var a = prev(box,'text');
	var b = prev(prev(a,'text'),'text');
	var c = prev(prev(b,'text'),'text');
	v = c.value + ":" + b.value + ":" + a.value;
	box.value = v;}

cfvinsp	= function(box, count){
	if(!box)return;
	var v =	"";
	var a =	box;
	while(count-- > 0){
		if(prev(a,'text')) v = (prev(a,'text')).value +	":"	+ v;
		a = prev(a,'text');
	}
	v = v.substring(0,v.length - 1);
	re = /\//g;
	v = v.replace(re,"-");
	box.value = v;
}

target = function(x){
	if(!x)return;
	return (/finalvalue/.test(x.className))	? x	: target(x.nextSibling);
}

prev = function(ob, t){
	var other = (t == 'text') ? 'file' : t ;
	if(!ob || !ob.previousSibling) return;
	if(ob.previousSibling.type == t || ob.previousSibling.type == other) return ob.previousSibling;
	return prev(ob.previousSibling, t);
}

dates_with_ticks = function(){
	var fs = document.getElementsByTagName('input');
	for(var	i = 0; i < fs.length;	i++){
		var c = fs[i];
		if(/tick/.test(c.className)){
			c.onclick = function(){	
				add_today_date(this.nextSibling);
				var nx = this.nextSibling;
				if(nx.className=='fdate') change_final_value(target(this)); 
				if(nx.className=='sfdate') change_final_valuf(target(this)); 
			} 
		}
		if(/sfdate/.test(c.className))
			c.onblur = c.onchange = function(){change_final_valuf(target(this))};	
		if(/^fdate/.test(c.className) || /title/.test(c.className))
			c.onblur = c.onchange = function(){change_final_value(target(this))};
	}
}

do_histories = function(){
	if(!$('report')) return;
	var ls = document.getElementsByTagName('input');
	var	kids = toArray(ls);
	kids = kids.filter(function(x){return /history/.test(x.className)});
	kids.map(function(x){
		if(x.addEventListener) x.addEventListener("submit",function(){cfvinsp(target(x))});
		x.onchange = function(){cfvinsp(target(x))}
		x.onpropertychange = function(){cfvinsp(target(x))}})
}

showhide = function(thing){
	var	ob = document.getElementById(thing);
	var	state = ob.style.display;
	ob.style.display = (state == 'none') ? 'block' : 'none'; 
}

toggleheight = function(x,a,b){
		x.style.height = (x.style.height == a) ? b : a 
}

disableme	=	function(x){
	var	ob = $(x);
	var	s	=	ob.disabled;
	ob.disabled	=	(s ==	true)	?	false	:	true;	
}

boolable = function(obj){
	var	ob = document.getElementById(obj);
	ob.disabled	=	!ob.disabled;
}

add_image	=	function(){
	$('images').innerHTML +=	"<div>New	Image	Here</div>"; 
}

confirm_other	=	function(){
	document.register.confirm.pattern	=	document.register.email.innerHTML;
}
switchover = function(x){
	x.innerHTML = (x.innerHTML ==	'yes') ? 'no'	:	'yes'; }

var	IE = document.all?true:false

boolable = function(obj){
	var	ob = document.getElementById(obj);
	ob.disabled	=	!ob.disabled;	}

show_me_big_back = function(x){
	if(!x) return	0;
	var	im = x.src.replace(/s_/,'m_');
	show_me_big(im,	$('bigdisplay'));	}

show_me_big	= function(imge, loc){
	if(!loc) return	0;
	imge = imge.replace(/s_/,'m_');
	loc.innerHTML =	"<img src='" + imge	+	"' />";	
}
var	ac = 0;

bin_an_extra = function(){
	var	xslst	=	$('extras');
	xslst.removeChild(xslst.lastChild);
}
add_an_extra = function(){
	ac++;
	var ndiv =  "<div class='puta'>";
	ndiv += "<input class='title_'	type='text'	value=''/>";
	ndiv += "<input class='tick_started'	type='checkbox'/>";
	ndiv += "<input	class='fdate'	type='text'	disabled value=''/>";
	ndiv += "<input	class='tick_finished'	type='checkbox'/>";
	ndiv += "<input	class='fdate'	type='text'	disabled value=''/>";
	ndiv += "<input	class='finalvalue' type='hidden' name='extras" + ac	+	"' value=''/></div>";
	var	exdiv	=	$('extras');
	exdiv.innerHTML += ndiv;
	dates_with_ticks();
}
historytoggle = function(){ 
	if(!$('historymask'))return;
	var shorter=(document.addEventListener) ? '250px' : '230px';
	$('historymask').style.height=shorter;
	$('htoggle').onclick = function(){
		$('historymask').style.overflow='hidden';
		$('historymask').style.height = ($('historymask').style.height == '') ? shorter : '';
		return false;
	}

}
selectall = function(lst){ lst.map(function(x){ x.checked = 1 - x.checked; })}

formboxes = function(){
	if(!($('fchecker')) )return;
	var bxs = toArray(document.getElementsByTagName('input'));
	bxs = bxs.filter(function(x){ return /aform/.test(x.className)});
	$('fchecker').onclick = function(){selectall(bxs)};
}

sheeties = function(){
	if(!$('nprint')) return;
	$('nprint').onclick = function(){ 
		window.print();
		return false;
	}
	if(!$('gprint')) return;
	$('gprint').onclick = function(){ 
		$('normalprint').href='styles/print_gfx.css';
		window.print(); 
		return false;}
}		
	
ims_with_text = function(){
	var kids = toArray(document.getElementsByTagName('input'));
	kids = kids.filter(function(x){return /image/.test(x.className)});
	kids.map(function(x){x.onblur = x.onchange = function(){cfvinsp(target(x), 2)}});
}
	
do_histories = function(){
	if(!$('report')) return;
	var ls = document.getElementsByTagName('input');
	var kids = toArray(ls);
	kids = kids.filter(function(x){return /history/.test(x.className)});
	kids.map( function(x){x.onchange = function(){cfvinsp(target(x), 4)}} )
}
check_histories = function(){
	if(!$('report')) return;
	var ls = document.getElementsByTagName('input');
	var kids = $A(ls);
	kids = kids.filter(function(x){return /history/.test(x.className)});
	kids.map(function(x){cfvinsp(target(x), 4)});
}

printclient = function(id){
	window.frames['hideprint'].focus();
	window.frames['hideprint'].print();
}
do_client_print = function(){
	if(!$('clientprint'))return;
	$('clientprint').onclick = function(){printclient($('clientprint').getAttribute('contract_id'))}};

fpselector = function(){
	if(!$('dropper'))return;
	var thing = document.getElementsByTagName('select')[0];
	thing.onchange = function(){ $('dropper').submit() };
}
do_titles = function(){
	var lst = $T('a',$('gallery'));
	lst = lst.filter(function(x){return /title/.test(x.className)});
	lst.map(function(x){toggle(x.nextSibling);x.onclick=function(){toggle(this.nextSibling);return false;}})
}
reportlisteners = function(){
	if(!$('report'))return;
	$('report').onsubmit = function(){
		var kids = toArray(document.getElementsByTagName('input'));
		kids = kids.filter(function(x){ return /history/.test(x.className) });
		kids.map(function(x){cfvinsp(target(x),4)});
	}
}
servicecaller = function(){
	if(!$('callback')) return;
	var lst = $A(document.getElementsByTagName('a'))
	lst = lst.filter(function(x){return /showserviceform/.test(x.className)});
	lst = lst.map(function(x){
		x.onclick = function(){
			if(window.showModalDialog) 
				window.showModalDialog("http://www.paradorownersclub.com/services.php?s="+x.innerHTML,"","status:no;center:yes;dialogHeight:520px;dialogWidth:325px;resizable:0");
			if(!window.showModalDialog){ 
				var left = screen.width/2 - 152;
				var top = screen.height/2 - 255;
				window.open("http://www.paradorownersclub.com/services.php?s="+x.innerHTML,"","height=510,width=295,resizable=0,left="+left+",top="+top);
			}
		}
	})
}

function cats_and_subs(){
	if(!$('category_id')) return false;
	$('category_id').onchange=function(){
		callserver('catdrop.php?id=' + this.options[this.selectedIndex].value,$('subs'));
	}
}
function show_cats_and_subs(){
	var mcats = $T('h3').filter(function(x){return /mcat/.test(x.className)});
	var scats = $T('h3').filter(function(x){return /scat/.test(x.className)});
	var allcats = mcats.concat(scats);
	allcats.map(function(x){x.style.cursor='pointer'});
	allcats.map(function(x){
		x.onclick=function(){
			var w = this.innerHTML;
			var w = w.replace(/\+/,"++");
			var w = w.replace(/\-/,"--");
			var w = w.replace(/\+\+/,"-");
			var w = w.replace(/\-\-/,"+");
			this.innerHTML = w;
			toggle(this.nextSibling);
			if(/mcat/.test(x.className))
				mcats.map(function(z){if(x != z) z.nextSibling.style.display='none'});
			if(/scat/.test(x.className))
				scats.map(function(z){if(x != z) z.nextSibling.style.display='none'});
			return false;
		}
	});
}
addLoadEvent(cats_and_subs);
addLoadEvent(show_cats_and_subs);
addLoadEvent(servicecaller);
addLoadEvent(fpselector);
addLoadEvent(dates_with_ticks);
addLoadEvent(do_histories);
addLoadEvent(historytoggle);
addLoadEvent(sheeties);
addLoadEvent(formboxes);
addLoadEvent(ims_with_text);
addLoadEvent(do_client_print);
addLoadEvent(do_titles);
addLoadEvent(reportlisteners);
addLoadEvent(function(){if($('nifty2')) Rounded("div#nifty2","eef","#fff",'small')});
