/* This notice must be untouched at all times.

Farbverlauf.js	v. 1.0
The latest version is available at http://www.asp-tools.de/Tools/Farbverlauf/Farbverlauf.aspx

Copyright (c) Hans Hüller -  click the web. - Germany. All rights reserved.
Created 01. 02. 2007 by Hans Hüller

LICENSE: LGPL
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For more details on the GNU Lesser General Public License, see http://www.gnu.org/copyleft/lesser.html
*/
function MakeFarbverlauf(TheName, SFH, EFH, MyTyp, HV){var dgE=document.getElementById(TheName);if(dgE==null){alert('FEHLER:\n\nObjekt-Name "'+TheName+'" ist nicht im HTML-Code vorhanden\noder der Script-Aufruf vor diesem platziert.')}var P_AbsoluteRelative='', MyLeft='', MyTop='', MyWidth='', MyHeight='',MyZindex=0;if(MyTyp==undefined){MyTyp=0}if(HV==undefined){HV=0}if(dgE.style.position!=''){P_AbsoluteRelative='position:'+dgE.style.position+';'}else{P_AbsoluteRelative='position:absolute;'; dgE.style.position='absolute'}if(dgE.style.left!=''){MyLeft='left:'+dgE.style.left+';'}else{MyLeft='left:'+dgE.offsetLeft+'px;'}if(dgE.style.top!=''){MyTop='top:'+dgE.style.top+';'}else{MyTop='top:'+dgE.offsetTop+'px;'}if(dgE.style.width!=''){MyWidth='width:'+dgE.style.width+';'}else{MyWidth='width:'+dgE.offsetWidth+'px;'}if(dgE.style.height!=''){MyHeight=dgE.style.height.toLowerCase().replace(/[px%]+/,'')}else{MyHeight=dgE.offsetHeight}if(MyHeight<1){return}if(dgE.style.zIndex==''){dgE.style.zIndex=1}MyZindex=dgE.style.zIndex-1;SFH=SFH.toLowerCase().replace('#','');EFH=EFH.toLowerCase().replace('#','');if(SFH==''&&EFH==''){return}if(SFH==''&&EFH!=''){SFH=EFH}if(EFH==''&&SFH!=''){EFH=SFH}if(SFH.length+EFH.length!=12||/([\da-f])/.test(SFH+EFH)==false){alert('Fehlerhafter Wert im Farb-Start-Wert oder Farb-End-Wert\nin der Funktion "MakeFarbverlauf"');return}var S1=parseInt(SFH.substring(0,2),16), S2=parseInt(SFH.substring(2,4),16), S3=parseInt(SFH.substring(4,6),16);var E1=parseInt(EFH.substring(0,2),16), E2=parseInt(EFH.substring(2,4),16), E3=parseInt(EFH.substring(4,6),16);var DIV='<div style="position:absolute;'+MyLeft+MyTop+MyWidth+'height:'+MyHeight+'px;z-index:'+MyZindex+'">';if(SFH==EFH){document.write(DIV.replace('">', ';background-color:#'+SFH+'"></div>'));return}dgE.style.backgroundColor='transparent';var A=0;if(HV==0){A=MyHeight}else{A=dgE.offsetWidth}var i,F=new Array();for(i=0;i<A;i++){switch(MyTyp){case 0:F[i]=hex(Math.round(S1+(E1-S1)*i/(A-1)))+hex(Math.round(S2+(E2-S2)*i/(A-1)))+hex(Math.round(S3+(E3-S3)*i/(A-1)));break;case 1:F[i]=hex(Math.round(S1+(E1-S1)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2))) + hex(Math.round(S2+(E2-S2)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2))) + hex(Math.round(S3+(E3-S3)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2)));break;case 2:if(A/2>i){F[i]=hex(Math.round(S1+(E1-S1)*i/(A-1)))+hex(Math.round(S2+(E2-S2)*i/(A-1)))+hex(Math.round(S3+(E3-S3)*i/(A-1)));}else{F[i]=hex(Math.round(E1+(S1-E1)*i/(A-1)))+hex(Math.round(E2+(S2-E2)*i/(A-1)))+hex(Math.round(E3+(S3-E3)*i/(A-1)));}break;case 3:if(A/2>i){F[i]=hex(Math.round(S1+(E1-S1)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2))) + hex(Math.round(S2+(E2-S2)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2))) + hex(Math.round(S3+(E3-S3)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2)));}else{F[i]=hex(Math.round(E1+(S1-E1)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2))) + hex(Math.round(E2+(S2-E2)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2))) + hex(Math.round(E3+(S3-E3)*((Math.sin((-Math.PI/2)+Math.PI*i/(A-1))+1)/2)));}break;default:alert('Mögliche erlaubte Typen:\n\n0 = Linear\n1 = Trigonometrisch\n2 = Linear-Round\n3 = Trigonometrisch-Round');return;}if(HV==0){DIV+='<div style="height:1px;background-color:#'+F[i]+';z-index:'+MyZindex+'"></div>'}else{DIV+='<div style="position:absolute;'+'left:'+i+'px;width:1px;height:'+MyHeight+'px;background-color:#'+F[i]+';z-index:'+MyZindex+'"></div>';}}document.write(DIV+'</div>')}	
function hex(x){var hd=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];return isNaN(x)?"00":hd[(x-x%16)/16]+hd[x%16];}
