var dualLine_count = 1;
var point_count = 1;
var asset_count = 1;
var arrow_count = 1;
var broken_color = 'white';
var point_img = "components/controls/geo/visor/IconRender.aspx?color=";
var workdirno_color = 'black';
var workdirin_color = 'blue';
var workdirop_color = 'red';
var assetsVisible = true;
var routesVisible = true;
//Folgende Variablen werden durch generiertes JavaScript in JSVisorControl mit Werten aus Config überschrieben.
var thick = true;
var apexEveryPx = 35;


//Dreiecksberechnung

function toRad(degree) {
	if (!Number(degree)) {
		return 0;
	}
	return (degree * Math.PI) / 180;
}

function toDeg(radiant) {
	if (!Number(radiant)) {
		return 0;
	}
	return (radiant * 180) / Math.PI;
}

function getAngle(line_x, line_y, apex_x, apex_y) {
	var delta_x = apex_x - line_x;
	var delta_y = line_y - apex_y;
	var angle = toDeg(Math.atan(delta_y / delta_x));
	if (parseInt(apex_x) < parseInt(line_x)) {
		angle += 180;
	}
	return angle;
}

function pointDiffX(angle, angle_diff, axis_length) {
	return Math.ceil(Math.cos(toRad(angle + angle_diff)) * axis_length);
}

function pointDiffY(angle, angle_diff, axis_length) {
	return Math.ceil(Math.sin(toRad(angle + angle_diff)) * axis_length);
}

function getArrowEdges(line_x, line_y, apex_x, apex_y, angle_diff, axis_length) {
	var edge_1 = new Array(Number.NaN, Number.NaN);
	var edge_2 = new Array(Number.NaN, Number.NaN);
	var line_angle = getAngle(line_x, line_y, apex_x, apex_y);
	angle_diff = Math.abs(angle_diff);
	axis_length = Math.abs(axis_length);
	edge_1[0] = parseInt(apex_x) - pointDiffX(line_angle, angle_diff, axis_length);
	edge_1[1] = parseInt(apex_y) + pointDiffY(line_angle, angle_diff, axis_length);
	edge_2[0] = parseInt(apex_x) - pointDiffX(line_angle, -angle_diff, axis_length);
	edge_2[1] = parseInt(apex_y) + pointDiffY(line_angle, -angle_diff, axis_length);
	return new Array(new Array(apex_x, apex_y), edge_1, edge_2);
}

/*
 * Gibt aus, um welche Art von Steigung es sich bei der Linie handelt.
 * waagerecht: 0,
 * senkrecht: -2,
 * positive Steigung: 1,
 * negative Steigung: -1,
 */
function Gradient(x1, y1, x2, y2) {
	if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) return; //Fehler
/*
	 * Steigungsformel:
	 *	delta y
	 *	-------
	 *	delta x
	 *
	 * wobei normalerweise gilt:
	 *
	 *	y2 - y1
	 *	-------
	 *	x2 - x1
	 *
	 * Da der Ursprung des Elternelements aber die linke obere und nicht die linke untere Ecke ist,
	 * muss die Formel wie folgt umgeformt werden:
	 *
	 *	y2 - y1
	 *	-------
	 *	x1 - x2
	 *
	 * Außerdem gilt, wenn delta x = 0 ist, dann ist die Linie senkrecht. Dies muss vorher geprüft werden,
	 * da es ansonsten zu dem Fehler "Division durch Null" führen würde, was mathematisch nicht erlaubt ist.
	 */
	var delta_X = x1 - x2;
	if (delta_X == 0) return -2; //senkrecht
	var delta_Y = y2 - y1;
	var gradient = delta_Y / delta_X;
	var tmp = gradient;
	if (gradient > 0) gradient =  1;	//positive Steigung
	if (gradient < 0) gradient = -1;	//negative Steigung
	return gradient;
}

/*
 * Vertikale Verschiebung der inneren schmalen Linie auf der äußeren für:
 * waagerechte Linie: 2px,
 * positive Steigung: 1px,
 * negative Steigung: 3px,
 * seknrechte Linie: 2px.
 */
function getVertAdjustment(gradient) {
	switch(parseInt(gradient)) {
		case  0:	return 1; //ok
		case -2:	return 1; //ok
		case  1:	return 0; //ok
		case -1:	return 1; //ok
	}
}

/*
 * Horizontale Verschiebung der inneren schmalen Linie auf der äußeren für:
 * waagerechte Linie: 1px,
 * positive Steigung: 2px,
 * negative Steigung: 1px,
 * seknrechte Linie: 1px.
 */
function getHorAdjustment(gradient) {
	switch(parseInt(gradient)) {
		case  0:	return 0; //ok
		case -2:	return 0; //ok
		case  1:	return 0; //ok
		case -1:	return 0; //ok
	}
}

//Dicke der breiteren Linie abhängig vom Winkel, waagerechte und senkrechte 6px, schräge 7px,
function outerThick(gradient) {
	switch(parseInt(gradient)) {
		case  0:	return 6; //ok
		case -2:	return 6; //ok
		case  1:	return 7; //ok
		case -1:	return 7; //ok
	}
}


function getColor(color, routeColor, workDir) {
	var clr = color;
	if (routeColor != "auto" && routeColor != "no") {
		clr = routeColor;
	}
	if (workDir == 1) {
		clr = workdirno_color;
	} else if (workDir == 2) {
		clr = workdirin_color;
	} else if (workDir == 3) {
		clr = workdirop_color;
	}
	return clr;
}

/*
 * Zeichnet eine doppelte Linie von x1:y1 nach x2:y2. Painter ist ein Objekt des Typs jsGraphics,
 * das die Doppellinie zeichnet.
 *
 * color und border_color sind die Farben für Text und Rahmen, erlaubt sind
 * Farbnamen der 16er-Farbpalette sowie Farbcodes im Format "#rrggbb".
 *
 * Es wird die ID der gezeichneten Doppellinie zurückgegeben.
 */
function DualLine(ID, painter, x1, y1, x2, y2, color, borderColor, routeColor, workDir, p1Visible, p2Visible) {
	//alert("Punkt 1: " + p1Visible + "\nPunkt 2: " + p2Visible);
	if (!p1Visible && !p2Visible) {
		return null;
	}
	var id = ID;
	//alert(id);
	dualLine_count++;
	if (painter.obj != 'jsGraphics') {
		return null;
	}
	if ((x1 <= -500 && y1 <= -500) || (x2 <= -500 && y2 <= -500)){
		return;
	}
	painter.htm += '<div id="' + id + '" style="position:relative; cursor:pointer;">';
	painter.htm += '<div id="' + id + 'inner">';
	var gradient = Gradient(x1, y1, x2, y2);
	var x_adj = getHorAdjustment(gradient);
	var y_adj = getVertAdjustment(gradient);
	y1 += y_adj;
	y2 += y_adj;
	x1 += x_adj;
	x2 += x_adj;
	if (x1 == x2 && y1 == y2) {
		x2++;
	}
	painter.setColor(getColor(color, routeColor, workDir));
	painter.setStroke(2);
	painter.drawLine(x1, y1, x2, y2);
	painter.setColor(borderColor);
	divide(painter, x1, y1, x2, y2);
	painter.htm += '<\/div><\/div>';
	painter.setColor(color);
	return id;
}

function divide(painter, x1, y1, x2, y2) {
	var length = getLength(x1, y1, x2, y2);
	if (divideSection(length)) {
		var apex = getArrowApex(x1, y1, x2, y2);
		drawDirectionArrow(painter, x1, y1, apex[0], apex[1]);
		
		divide(painter, x1, y1, apex[0], apex[1]);
		divide(painter, apex[0], apex[1], x2, y2);
	}
}

function getLength(x1, y1, x2, y2) {
	var a2 = Math.pow(x2 - x1, 2);
	var b2 = Math.pow(y2 - y1, 2);
	var c = Math.sqrt(a2 + b2);
	return c;	
}

function divideSection(length) {
	length = Math.abs(length);
	return length > apexEveryPx * 2;
}

function getArrowApex(x1, y1, x2, y2) {
	var apex = new Array(Number.NaN, Number.NaN);
	apex[0] = (x2 + x1) / 2;
	apex[1] = (y2 + y1) / 2;
		
	apex[0] = Math.round(apex[0]);
	apex[1] = Math.round(apex[1]);
	//alert("Von:  " + x1.toString() + ":" + y1.toString() + "\nNach: " + x2.toString() + ":" + y2.toString() + "\nApex: " + apex[0].toString() + ":" + apex[1].toString() + "\nSections: " + count.toString());
	return apex;
}

function drawDirectionArrow(painter, line_x, line_y, apex_x, apex_y) {
	//Winkel alpha an der Spitze = 30°, Kantenlänge des Pfeils 20px.
	var edges = getArrowEdges(line_x, line_y, apex_x, apex_y, 40, 8);
	// Da die Funktion dieKoordinaten nach Punkten gebündelt zurückgibt, sie aber zum Zeichen nach x-
	// und y-Werten gebündelt werden müssen, wird hier umsortiert.
	var x_vals = new Array(edges[1][0], edges[0][0], edges[2][0]);
	var y_vals = new Array(edges[1][1], edges[0][1], edges[2][1]);
	painter.drawPolyLine(x_vals, y_vals);
}

function getTooltipString(tooltipName) {
	o = new Object();
	var title = this[tooltipName](1,true);	
	var tt = this[tooltipName](1,false);
	var ttStr = 'onmouseover=\"this.T_TITLE=\'';
	ttStr += title; 
	ttStr += '\';return escape(';
	ttStr += tooltipName;
	ttStr += '(\'\')';
	ttStr += ');\"';
	return ttStr;
}

/*
 * Zeichnet eine Punkt an x:y. Painter ist ein Objekt des Typs jsGraphics,
 * das den Punkt zeichnet.
 *
 * color und border_color sind die Farben für Text und Rahmen, erlaubt sind
 * Farbnamen der 16er-Farbpalette sowie Farbcodes im Format "#rrggbb".
 *
 * Es wird die ID des gezeichneten Punktes zurückgegeben.
 */
function Point(ID, painter, x, y, tooltip, color, isSmall, reason, visible) {
	if (!visible) {
		return null;
	}
	var id = ID;
	point_count++;
	if (painter.obj != 'jsGraphics') {
		return null;
	}
	painter.htm += '<div id=\"' + id
	 + '\" style="position:relative; cursor:pointer; z-index:100;">';
	var rtype = Math.round(reason);
	var doSmall = ((reason - rtype) * 10) == 0;
	rBorder = doSmall ? 9 : 15;
	rSize = doSmall ? 9 : 15;
	x -= parseInt(Math.round(rSize / 2) - 1);
	y -= parseInt(Math.round(rSize / 2) - 1);
	var iconStr = ' background-image:url(\'' + point_img + color
	 + '&size=' + rSize.toString() + '&r=' + rtype.toString() + '\');"';
	var ttStr = '<div style="position:absolute; top:'
	 + y.toString() + '; left:'
	 + x.toString() + '; width:';
	ttStr += rSize.toString() + '; height: '
	 + rSize.toString() + '; clip:rect(0px '
	 + rSize.toString() + 'px ' + rSize.toString() + 'px 0px);';
	ttStr += iconStr + ' ';
	ttStr += getTooltipString(tooltip) + ' >';
	painter.htm += ttStr;
	painter.htm += '<\/div><\/div>';
	return id;
}

/*
 * Zeichnet eine Einheitenbezeichnung an x:y (linke obere Ecke des Labels). Painter ist ein Objekt des Typs jsGraphics,
 * das die Doppellinie zeichnet.
 *
 * Parameter:
 * x und y sind die Koordinaten der linken oberen Ecke des Labels.
 * txt ist der Text, der in dem Label angezeigt werden soll.
 * txt_color, bg_color und border_color sind die Farben für Text, Hintergrund und Rahmen, erlaubt sind
 * Farbnamen der 16er-Farbpalette sowie Farbcodes im Format "#rrggbb".
 * font-size ist die Schriftgröße des Textes, Angabe CSS-konform
 * border-style ist die gleichnamige CSS-Eigenschaft des DIV-Tags
 *
 * Es wird die ID des gezeichneten Labels zurückgegeben.
 */
function AssetName(ID, painter, x, y, txt, tooltip, txt_color, font_size, bg_color, border_color, border_style) {
	var id = ID;
	asset_count++;
	if (painter.obj != 'jsGraphics') {
		return null;
	}
	painter.htm += '<div id="' + id + '" style="position:relative; z-index:600; cursor:pointer;" '
	 + getTooltipString(tooltip) + '>';
	painter.setColor(txt_color);
	painter.setFont("arial", font_size, Font.PLAIN);
	painter.drawStringBoxed(txt, x, y, bg_color, border_color, border_style);
	painter.htm += '<\/div>';
	return id;
}

/*
 * Zeichnet eine Einheitenbezeichnung an x:y (linke obere Ecke des Labels) mit Standardwerten. Painter ist ein Objekt des Typs jsGraphics,
 * das die Doppellinie zeichnet.
 *
 * Parameter:
 * x und y sind die Koordinaten der linken oberen Ecke des Labels.
 * txt ist der Text, der in dem Label angezeigt werden soll.
 * 
 * Zum Zeichnen wird die Funktion AssetName mit einer Standardformatierung aufgerufen. Die Werte können
 * in dieser Funktion angepasst werden, sind einzelne Texte mit anderen Werten gewünscht, sollte AssetName
 * direkt aufgerufen werden. Soll reiner Text ohne jegliche Formatierung gezeichnet werden, ist die Funk-
 * tion Text zu verwenden.
 *
 * Es wird die ID des gezeichneten Labels zurückgegeben.
 */
function AssetNameDefaults(ID, painter, x, y, txt, tooltip, border_color) {
	return AssetName(ID, painter, x, y, txt, tooltip, 'black', "7pt", "#ffffff", border_color, "dashed");
}

/*
 * Zeichnet eine Doppellinie von line_x:line_y nach apex_x:apex_y mit einer Pfeilspitze an apex_x:apex_y.
 * Painter ist ein Objekt des Typs jsGraphics, das den Punkt zeichnet.
 *
 * color und border_color sind die Farben für Text und Rahmen, erlaubt sind
 * Farbnamen der 16er-Farbpalette sowie Farbcodes im Format "#rrggbb".
 *
 * Es wird die ID des gezeichneten Punktes zurückgegeben.
 */
function ArrowLine(ID, painter, x, y, heading, color, lastArrowID, routeColor, workDir) {
	var id = ID;
	arrow_count++;
	if (painter.obj != 'jsGraphics' || parseInt(heading) == -500) {
		return null;
	}
	if (ID != lastArrowID) {
		return null;
	}
	var str = '<div id=\"' + id + '\" style="position:relative; cursor:pointer; z-index:0; visibility:';
	str += (ID == lastArrowID) ? "visible" : "hidden";
	//alert("Arrow ID: " + ID + "\nlast Arrow ID: " + lastArrowID + "\nRender: " + str);
	str += ';"><div style="position:absolute; top:';
	painter.htm += str;
	rSize = 13;
	x -= (2 * rSize)-1;
	y -= (2 * rSize)-3;
	var iconStr = ' background-image:url(\'' + point_img + getColor(color, routeColor, workDir) + '&size=' + rSize.toString() + '&arrow=true&degree=' + heading + '\');"';
	var ttStr = y.toString() + '; left:'
	 + x.toString() + '; width:';
	rSize *= 4;
	ttStr += rSize.toString() + '; height: '
	 + rSize.toString() + '; ';
	ttStr += iconStr + '>';
	painter.htm += ttStr;
	painter.htm += '<\/div><\/div>';
	return id;
}

function paint(painter) {
	if (painter.obj != 'jsGraphics') {
		return null;
	}
	painter.paint();
}

function clear(painter) {
	if (painter.obj != 'jsGraphics') {
		return null;
	}
	painter.clear();
}

function Asset(ID, X, Y, name, tooltip) {
	this.ID = ID;
	this.X = X;
	this.Y = Y;
	this.name = name;
	this.tooltip = tooltip;
	this.obj = "Asset";
}
	
function Route(container, id) {
	this.obj = "Route";
	this.parent = container;
	this.id = id;
	this.jg = new jsGraphics(this.parent);
	
	this.coords = new Array();
	this.color = 'black';
	this.borderColor = 'white';
	this.heading = 0;
	this.elements = new Array();
	
	this.setColor = new Function('color', 'this.color = color.toLowerCase(); this.jg.setColor(this.color);');
	this.setHeading = new Function('degree', 'this.heading = parseInt(degree);');
	this.asset = null;
	this.setAsset = function(id, x, y, name, tooltip) {
		this.asset = new Asset(id, x, y, name, tooltip);
	}
	this.renderRoute = true;
	this.routeColor = "auto";
	this.lastArrow = "";
	
	this.addCoord = function(ID, x, y, tooltip, isSmall, reason, workDir, heading, visible) {
		this.coords[this.coords.length] = new Array(ID, x, y, tooltip, isSmall, reason, workDir, heading, visible);
	}
	
	this.paint = function (color, renderRoute, lastArrow, routeColor) {
		this.setColor(color);
		this.renderRoute = renderRoute;
		this.routeColor = routeColor;
		this.lastArrow = ChangeIDType(lastArrow, "AL");
//		alert("Color: " + color + "\nRender Route: " + renderRoute + "\nLetzter Pfeil: " + lastArrow);
		this.calculate();
		paint(this.jg);
	}
	this.clear = function () {
		clear(this.jg);
		this.asset.ID = "";
		this.asset.X = Number.NaN;
		this.asset.Y = Number.NaN;
		this.asset.name = "";
		this.elements = new Array();
		this.heading = 0;
		this.color = 'black';
		this.coords = new Array();
	}
	this.calculate = function() {
		if (this.coords.length > 1) {
			for (i = 0; i < this.coords.length - 1; i++) {
				if (this.renderRoute && i < this.coords.length){
					this.elements[this.elements.length] = DualLine(
																												 ChangeIDType(this.coords[i+1][0], "L"),
																												 this.jg,
																												 this.coords[i][1],
																												 this.coords[i][2],
																												 this.coords[i+1][1],
																												 this.coords[i+1][2],
																												 this.color,
																												 this.borderColor,
																												 this.routeColor,
																												 this.coords[i][6],
																												 this.coords[i][8],
																												 this.coords[i+1][8]);
				}
			}
		}
		if (this.coords.length > 0) {
			for ( i = 0; i < this.coords.length; i++) {
				this.elements[this.elements.length] = Point(
																										this.coords[i][0],
																										this.jg,
																										this.coords[i][1],
																										this.coords[i][2],
																										this.coords[i][3],
																										this.color,
																										this.coords[i][4],
																										this.coords[i][5],
																										this.coords[i][8]);
				if (this.renderRoute) { 
					this.elements[this.elements.length] = ArrowLine(
																													ChangeIDType(this.coords[i][0], "AL"),
																													this.jg,
																													this.coords[i][1],
																													this.coords[i][2],
																													this.coords[i][7],
																													this.color,
																													this.lastArrow,
																													this.routeColor,
																													this.coords[i][6]);
				}
			}
		}
		if (this.asset != null) {
			this.elements[this.elements.length] = AssetNameDefaults(
																															this.asset.ID,
																															this.jg,
																															this.asset.X,
																															this.asset.Y,
																															this.asset.name,
																															this.asset.tooltip,
																															this.color);
		}
	}
}

function ChangeIDType(pointID, type) {
	var id = pointID.replace(/_P_/, "_" + type + "_");
	return id;
}

function showHideTruck(id, input) {
	var _id = id;
	if (id == "showHideCheck") {return;}
	if (input.type == 'checkbox') {
		vis = input.checked ? 'visible' : 'hidden';
		color = input.checked ? 'white' : broken_color;
		//Punkt
		var point = document.getElementById(id);
		if (point) {
			point.style.visibility = vis;
		} /*else if(checked) {
			alert("truck_out_of_sight");
	  }
	  if (document.getElementById(id + "outer")) {
			setOuterColor(document.getElementById(id + "outer"), color);
		}*/
	  //Linien
		point = null;
		var no_pos = id.lastIndexOf("_") + 1;
		var id_no = parseInt(id.substring(no_pos, id.length));
		var id_fraq = id.substring(0, no_pos);
  
	  //vorhergehende Linie
	  id_no++;
		point = document.getElementById(id_fraq + id_no.toString());
		id = _id.replace(/_P_/, "_L_");
		var line = document.getElementById(id);
		if ((input.checked
		 && point
		 && point.style.visibility == "hidden")
		 || !routesVisible) {//
			vis = "hidden";
		}
		if (line) {
			line.style.visibility = vis;
		}
  
		//nachfolgende Linie
		vis = input.checked ? 'visible' : 'hidden';
		point = null;
		line = null;
		old_id = id;
		id_no -= 2;
		id = id_fraq + id_no.toString();
		//alert(old_id + " => " + id);
		point = document.getElementById(id);
		id = id.replace(/_P_/, "_L_");
		line = document.getElementById(id);
		if ((input.checked
		 && point
		 && point.style.visibility == "hidden")
		 || !routesVisible) {//
			vis = "hidden";
		}
		if (line) {
			line.style.visibility = vis;
		}
		//benachbarte Punkte umfärben
		/*var color = "white";
		vis = input.checked ? 'visible' : 'hidden';
		//vorigen
		id_fraq = _id.substring(0, no_pos);
		id_no = parseInt(_id.substring(no_pos, _id.length));
 		id = id_fraq + (--id_no).toString() + "outer";
		var obj = document.getElementById(id);
		if (vis == "hidden") {
			color = broken_color;
			// TODO: 2. Nachbar in jeweilige Richtung auf Existenz und Sichtbarkeit prüfen und entsprechend die Farbe anpassen.
		}
		setOuterColor(obj, color);
		id_no += 2;
		id = id_fraq + id_no.toString() + "outer";
		obj = null;
		obj = document.getElementById(id);
		setOuterColor(obj, color);*/
		id = _id.replace(/_P_/, "_A_");
		obj = null;
		obj = document.getElementById(id);
		var vis2 = assetsVisible ? vis : "hidden";
		if (obj) {
			obj.style.visibility = vis2;
		}
		id = _id.replace(/_P_/, "_AL_");
		if (input.checked && routesVisible) {
			if (line && line.style.visibility == "visible") {
				vis2 = "hidden";
			} else {
				vis2 = "visible";
			}
		} else {
			vis2 = "hidden";
		}
		obj = null;
		obj = document.getElementById(id);
		if (obj) {
			obj.style.visibility = vis2;
		}
	}
}

function setOuterColor(obj, color) {
	if (obj && obj.hasChildNodes()) {
		var divs = obj.childNodes;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].nodeName == "DIV") {
				divs[i].style.backgroundColor = color;
			}
		}
	}
}

function showHideObjects(input, type) {
	if (input.type == 'checkbox'
	 && ((input.id.indexOf("showRoute") > -1)
	  || input.id.indexOf("showAssets") > -1)) {
		var obj = document.getElementById("jspaint");
		if (obj) {
			var divs = obj.childNodes;
			for (i = 0; i < divs.length; i++) {
				var div = divs[i];
				var regex = new RegExp("A\\d+_" + type + "_\\d+","");
				if (div.nodeName == "DIV" && regex.test(div.id)) {
					var id = div.id.replace(new RegExp("_" + type + "_", ""), "_P_");
					var no_pos = id.lastIndexOf("_") + 1;
					var id_no = parseInt(id.substring(no_pos, id.length));
					var id_fraq = id.substring(0, no_pos);
					if (input.checked) {
						// Einblenden
						var point = document.getElementById(id);
						var show = true;
						if (type == 'L') {
							if (point) {
								show = point.style.visibility == "visible";
							}
							point = null;
							id = id_fraq + (++id_no).toString();
							point = document.getElementById(id);
							if (show && point) {
								show = point.style.visibility == "visible";
							}
							if (show) {
								div.style.visibility = "visible";
							}
							routesVisible = true;
						} else if (type == 'A') {
							show = point.style.visibility == "visible";
							if (show) {
								div.style.visibility = "visible";
							}
							assetsVisible = true;
						}
					} else {
						// Ausblenden
						div.style.visibility = "hidden";
						if (type == 'L') {
							routesVisible = false;
						}
						if (type == 'A') {
							div.style.visibility = "hidden";
							assetsVisible = false;
						}
					}
				}
			}
		}
	}
}

function showHideAll(trucks, allChk) {
	var	id	= "";
	var inputs = document.getElementsByTagName("input");
	if	(allChk.type ==	'checkbox')	{
		for	(var i = 0;	i	< inputs.length; i++)	{
			if (inputs[i].getAttribute("type") ==	"checkbox")	{
				if(inputs[i].onclick)	{
					if (inputs[i].id.indexOf("showRoute") == -1
					 && inputs[i].id.indexOf("showAssets") == -1) {
						inputs[i].checked	= allChk.checked;
					}
					ke = inputs[i].onclick;
					ke = ke.toString();
					id = ke.substring(ke.indexOf("'")+1, ke.lastIndexOf("'"));
					if (id == "") {
						id = ke.substring(ke.indexOf("\"")+1, ke.lastIndexOf("\""));
					}			
					if (id != ""
					 && id != "showHideCheck") {
						showHideTruck(id, inputs[i]);
					}
				}
			}
		}
	}
}

