var is_win;
var is_mac;
var is_unix;
var client_pc = navigator.userAgent.toLowerCase();
var client_ver = parseInt(navigator.appVersion);
var is_ie = ((client_pc.indexOf("msie") != -1) && (client_pc.indexOf("opera") == -1));
var is_win = (navigator.appVersion.indexOf("win") != -1);
var is_mac = (navigator.appVersion.indexOf("mac") != -1);

if( !is_mac && !is_win ) is_unix = true;
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var ns6=document.getElementById&&!document.all?1:0
window.defaultStatus = "";
var menudelay = 500;
var delayflag;

if (ie4) {
	if (navigator.userAgent.indexOf('MSIE 5')>0) {
		ie5 = true;
	} else {
		ie5 = false; }
} else {
	ie5 = false;
}

function preloadImages()
{ 
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p)
		{
			d.MM_p=new Array();
		}
    	var i,j=d.MM_p.length,a=preloadImages.arguments; 
    	for(i=0; i<a.length; i++)
    	{
    		if (a[i].indexOf("#")!=0)
	    	{ 
	    		d.MM_p[j]=new Image; 
	    		d.MM_p[j++].src=a[i];
	    	}
    	}
	}
	
}

function reIm() { 
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function fiOb(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=fiOb(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function chIm() { 
  var i,j=0,x,a=chIm.arguments; document.sr=new Array; for(i=0;i<(a.length-1);i+=2)
   if ((x=fiOb(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+1];}
}

function shLa() {
  var i,p,v,obj,args=shLa.arguments;
  for (i=0; i<(args.length-1); i+=2) if ((obj=fiOb(args[i]))!=null) { v=args[i+1];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function shNa(nmbr) // show specified rollover&layer and hide others
{
	sh_args = new Array();
	reIm();
	for (i=1; i<=6 ; i++)
	{
		shLa('lay'+i, (i==nmbr)?'show':'hide');
	}		
	chIm('nav'+nmbr,root_path+'img/butstr.gif',1);
}

function rePa() // reset Page
{
	reIm();
	for (i=1; i<=6 ; i++)
	{
		shLa('lay'+i, 'hide');
	}		
}

function reDe() // reset Page after Delay
{
	delayflag = window.setTimeout("rePa()", 500);
}

function noRe() // delete Timeout for rePa()
{
	window.clearTimeout(delayflag);
}

function f1(id, show){
id2 = id;
show2 = show;
if(NS4){
	if(show2 == true)
	vis = "show";
	else
	vis = "hide";
	
	if(document.layers[id2].visibility != vis){
	if(vis == 'hide')
		delayflag = setTimeout("eval('f2(id2,show2)')", menudelay);
	else
		f2(id2,show2);
	}
}else if(IE4){
	if(show2 == true)
	vis = "visible";
	else
	vis = "hidden";
	if(document.all[id2].style.visibility != vis){
	if(vis == 'hidden')
		delayflag = window.setTimeout("eval('f2(id2,show2)')", menudelay);
	else
	f2(id2,show2);
}
}
}

function f2(id, show){
if(NS4){
if(show){
clearTimeout(delayflag);
document.layers[id].visibility = "show";
}else{
document.layers[id].visibility = "hide";
}
}else if(IE4){
if(show){
clearTimeout(delayflag);
document.all[id].style.visibility = "visible";
}else{
document.all[id].style.visibility = "hidden";
}
}
}

function h(htext){
window.status = htext;
}
function hf(objName, newText)
{
  status=newText;
  document.bon_returnValue = true;
  var obj = fiOb(objName); 
  if (obj) obj.value = newText;
}
function set_bg(obj)
{
	obj.style.backgroundColor = 'FFCCCC';
}
function unset_bg(obj)
{
	obj.style.backgroundColor = '';
}
function f3(layerID, imageID, newImage){
if(NS4){
cmd = "document."+ layerID +".document."+ imageID +".src = '/media/"+ newImage +".gif'";
eval(cmd);
}else if(IE4){
document.images[imageID].src = "/media/" + newImage + ".gif";
}
}
function f4(layerID, imageID, newImage){
if(NS4){
cmd = "document."+ layerID +".document."+ imageID +".src = newImage";
eval(cmd);
}else if(IE4){
document.images[imageID].src = newImage ;
}
}
function x(layerid,id){
if(document.layers){
temp = eval("document."+ layerid +".document."+ id);
}else if(document.all){
temp = eval(id + ".style");
}
temp.backgroundColor = "#000000";
}
function y(layerid,id){
if(document.layers){
temp = eval("document."+ layerid +".document."+ id);
}else if(document.all){
temp = eval(id + ".style");
}
temp.backgroundColor = "#cd0000";
}
function m(url){
window.location.href=url;
}
function sc(ta) 
{
	if (ta.createTextRange) ta.cp = document.selection.createRange().duplicate();
}
function opclw(pgc,u,W,H,X,Y,n,b,x,m,r) {
	var CWIN=window.open(u,n,'width='+W+',height='+H+',scrollbars=yes,resizable=yes',true);
	CWIN.moveTo(50,50);
	CWIN.focus();
}

/**
 * deletes all options from select box
 *
 * @param	obj		Object of select box
 */ 
function delete_opt_val(obj)
{
	// terminate condition
	if(obj == null)
	{
		return false;	
	}	
	
	for( i = obj.options.length; i >= 0; i--)
	{
		obj.options[i] = null;
	}
	
	return true;
	
}	// eo delete_opt_val()

function hex2num(hex) 
{
	if(hex.charAt(0) == "#") 
	{ 
		hex = hex.slice(1);
	}
	
	var value = new Array(3);
	
	var result = hex.match(/\brgb\b\((\d+)[, ]+(\d+)[, ]+(\d+)\)/i);
	
	if( result )
	{
		value[0] = result[1];
		value[1] = result[2];
		value[2] = result[3];
		return value;
	}
	
	hex = hex.toUpperCase();
	var hex_alphabets = "0123456789ABCDEF";
	
	var k = 0;
	var int1,int2;
	for(var i=0;i<6;i+=2) 
	{
		int1 = hex_alphabets.indexOf(hex.charAt(i));
		int2 = hex_alphabets.indexOf(hex.charAt(i+1));
		value[k] = (int1 * 16) + int2;
		k++;
	}
	return(value);
}

function num2hex(triplet) 
{
	var hex_alphabets = "0123456789ABCDEF";
	 var hex = '';
	 var int1,int2;
	 for(var i=0;i<3;i++) {
	  int1 = triplet[i] / 16;
	  int2 = triplet[i] % 16;
	
	  hex += hex_alphabets.charAt(int1) + hex_alphabets.charAt(int2); 
	 }
	 return(hex);

}

function clean_hex(str) 
{
	if(str.charAt(0) == "#") 
	{ 
		return(str.slice(1));
	}
	
	var result = str.match(/\brgb\b\((\d+)[, ]+(\d+)[, ]+(\d+)\)/i);
	
	if( result )
	{
		var value = new Array(3);
		value[0] = result[1];
		value[1] = result[2];
		value[2] = result[3];
		return num2hex(value);
	}
	else
	{
		return str;
	}
}


bon_fade_color_timeout = 0;

function indicate_change(obj_id, blink_step, start_hex, stop_hex, steps, delay, color_background, invoke_step) 
{
	var obj = fiOb(obj_id);
 	if(!obj) 
	{
		return false;
	}
	
	if(!steps) steps= 100;
	if(!delay) delay = 25;
	if(!start_hex) start_hex = "FF6600";
	if(!color_background) color_background = "background";
	if(!stop_hex) 
	{
		if(!obj.original_backgroundColor && obj.style.backgroundColor)
		{
			obj.original_backgroundColor = clean_hex(obj.style.backgroundColor);
		}
		
		if (!obj.original_color && obj.style.color)
		{
			obj.original_color = clean_hex(obj.style.color);
		}		
		
		if(color_background == "background")
		{
			stop_hex = obj.original_backgroundColor;
		}
		else
		{
			stop_hex = obj.original_color;
		}
	}
	
	stop_hex = clean_hex(stop_hex);
	start_hex = clean_hex(start_hex);
	
	
	if(!blink_step) blink_step = 0;
	var blink_delay = 500;
	
	var start_num	= hex2num(start_hex);
 	var stop_num 	= hex2num(stop_hex);
	
	for(var i=0;i<3;i++) 
	{
		start_num[i] 	= Number(start_num[i]);
	 	stop_num[i] 	= Number(stop_num[i]);
	}
	
	if(!invoke_step)
	{
		window.clearTimeout(bon_fade_color_timeout);
		this_invoke_step = 1;
		obj.start_orig = start_num;
		
		if(color_background == "background")
		{
			obj.bg_triple_step = new Array();
		}
		else
		{
			obj.color_triple_step = new Array();
		}
		for(var i=0;i<3;i++) 
		{
			if(color_background == "background")
			{
				obj.bg_triple_step[i] = (obj.start_orig[i] + (start_num[i] > stop_num[i] ? -1 * stop_num[i] : stop_num[i])) /steps ;
			}
			else
			{
				obj.bg_triple_step[i] = (obj.start_orig[i] + (start_num[i] > stop_num[i] ? -1 * stop_num[i] : stop_num[i])) /steps ;
			}
		}
	}
	else
	{
		var this_invoke_step = invoke_step + 1;
	}
	
	if(blink_step > 0)
	{
		color_hex = blink_step % 2 ? start_hex : stop_hex;
		//alert(color_hex);
		if(color_background == "background") 
		{
			obj.style.backgroundColor = '#' + color_hex;
		} 
		else 
		{
			obj.style.color = '#' + color_hex;
		}
		
		bon_fade_color_timeout = window.setTimeout("indicate_change('"+obj_id+"', " + (--blink_step) + ",'"+start_hex+"','"+stop_hex+"',"+steps+","+delay+",'"+color_background+"', " + this_invoke_step +")", blink_delay);
		return true;
	}
	
	
	if(color_background == "background")
	{
		var triple_step = obj.bg_triple_step;
	}
	else
	{
		var triple_step = obj.color_triple_step;
	}


	var diff;

	for(var i=0;i<3;i++) 
	{
		diff = Math.abs( Math.round( triple_step[i] * this_invoke_step ));
		
		if(diff == 0)
		{
			diff=1;
		}
		
  		if (start_num[i] < stop_num[i]) 
		{
   			start_num[i] = obj.start_orig[i] + diff;
   			if(start_num[i] > stop_num[i]) 
			{
				start_num[i] = stop_num[i];
			}
  		}
  		else if(start_num[i] > stop_num[i]) 
		{
   			start_num[i] = obj.start_orig[i] - diff;
			if(start_num[i] < stop_num[i]) 
			{
				start_num[i] = stop_num[i];
			}
		}
	}

	start_hex = num2hex(start_num);
 	if(color_background == "background") 
	{
		obj.style.backgroundColor = '#' + start_hex;
 	} 
	else 
	{
 		obj.style.color = '#' + start_hex;
	}

	if((start_num[0] == stop_num[0]) && (start_num[1] == stop_num[1]) && (start_num[2] == stop_num[2])) 
	{
		return true;
	}
	
	bon_fade_color_timeout = window.setTimeout("indicate_change('"+obj_id+"', 0,'"+start_hex+"','"+stop_hex+"',"+steps+","+delay+",'"+color_background+"', " + this_invoke_step +")",delay);
}


