// General functions used in Componennts
function checkKey(evt,str){
	var charCode = (evt.which) ? evt.which : event.keyCode
	var re=new RegExp("^["+str+"]$");
	return charCode<31 || re.test(chr(charCode));
}

function getAbsX(obj){
	var result = 0;
	while(obj!=null){
		result+=obj.offsetLeft;
		obj=obj.offsetParent;
	}
	return result;
}

function getAbsY(obj){
	var result = 0;
	while(obj!=null){
		result+=obj.offsetTop;
		obj=obj.offsetParent;
	}
	return result;
}

//SSToolTip Component
//created by Sebastian Serban, v3.0 (12.09.2007)
function SSToolTip(obj,title,content,width,fixed){
	if(typeof(SSTT)=='undefined'){
		SSTT=document.createElement('div');
		document.body.appendChild(SSTT);
		SSTT.id='SSToolTip';
		SSTT.style.display="none";
		SSTT.style.position="absolute";
		SSTT.style.zIndex=10010;
		SSTT.style.left=0;
		SSTT.style.top=0;
		document.onmousemove = function(e){
			if(SSTT_move){
				if(e=e ? e : window.event){
					var x=e.pageX ? e.pageX : e.x+document.body.scrollLeft;
					var y=e.pageY ? e.pageY : e.y+document.body.scrollTop;
					x+=20;
					y+=20;
					var tipWidth=document.getElementById("tooltiptable").clientWidth+4;
					if(x+tipWidth>document.body.clientWidth){
						x=document.body.clientWidth-tipWidth;
					}
					if(y+SSTT.clientHeight>document.body.scrollTop+document.body.clientHeight){
						y=document.body.scrollTop+document.body.clientHeight-SSTT.clientHeight;
						if(y<document.body.scrollTop){
							y=document.body.scrollTop;
						}
					}
					SSTT.style.left = x;
					SSTT.style.top = y;
					if(SSTT_stopafterfirst){
						SSTT_move=0;
					}
				}
			}
		}
		SSTT.hide=function(){
			this.style.display='none';
			SSTT_move=0;
		}
	}
	title=unescape(title);
	if(content==undefined){
		SSTT.innerHTML='<table id="tooltiptable" cellPadding="0" cellSpacing="0"><tr><td style="padding:0 4px">'+title+'</td></tr></table>';
	}else{
		content=unescape(content);
		if(width==undefined){
			width="";
		}
		SSTT.innerHTML='<!--[if IE]><iframe id="SSTT_iframe" style="position:absolute;z-index:-100;filter:\'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\';"></iframe><![endif]--><table style="border:solid 1px #36c;background:#fff;opacity:0.85;filter:alpha(opacity=85) progid:DXImageTransform.Microsoft.Shadow(color=#333333,direction=135,strength=2,enabled=true);width:'+width+';" id="tooltiptable" cellpadding="1" cellspacing="0">'+(title!="" ? '<tr><td style="background:#36c;color:#fff;padding:0 4px"><b>'+title+'</b></td></tr>' : '')+'<tr valign=top><td style="padding:0 4px">'+content+'</td></tr></table>';
	}
	SSTT.style.display = "";
	var iframe=document.getElementById('SSTT_iframe');
	if(iframe!=null){
		iframe.style.width=SSTT.offsetWidth;
		iframe.style.height=SSTT.offsetHeight;
	}
	obj.onmouseout=function(){
		SSTT.hide();
	}
	SSTT_move=1;
	SSTT_stopafterfirst=fixed;
	document.onmousemove();
}

//XMLHTTP OBject
var xmlhttp=false;
/*@cc_on @*/
/*@if(@_jscript_version>=5)
//JScript gives us Conditional compilation, we can cope with old IE versions.
//and security blocked creation of the objects.
try{
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
	try{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}catch(E){
		xmlhttp=false;
	}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

sendAndLoad=function(url,callback,method){
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if(@_jscript_version>=5)
	//JScript gives us Conditional compilation, we can cope with old IE versions.
	//and security blocked creation of the objects.
	try{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp=false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined'){
		try{
			xmlhttp=new XMLHttpRequest();
		}catch(e){
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest){
		try{
			xmlhttp=window.createRequest();
		}catch(e){
			xmlhttp=false;
		}
	}
	if(xmlhttp){
		if(method==null){
			method="GET";
		}
		try{
			xmlhttp.open(method,url,true);
			if(callback){
				xmlhttp.onreadystatechange=function(){
					if(xmlhttp.readyState==4){
						callback(xmlhttp.status==200 ? xmlhttp.responseText : false);
					}
				}
			}
			xmlhttp.send(null);
		}catch(e){
		}
	}
}


//SSColorPicker Component
//created by Sebastian Serban, v1.0 (11.09.2007)
function SSColorPicker(obj,color,callback){
	if(typeof(SSCP)=='undefined'){
		SSCP_in=0;
		SSCP_intID=0;
		SSCP_alpha=100;
		SSCP=document.createElement('div');
		document.body.appendChild(SSCP);
		SSCP.id='SSColorPicker';
		SSCP.style.visibility="hidden";
		SSCP.style.position="absolute";
		SSCP.style.zIndex=10001;
		SSCP.style.backgroundColor="#000";
		SSCP.style.left=0;
		SSCP.style.top=0;
		var html='<!--[if IE]><iframe id="SSCP_iframe" style="position:absolute;z-index:-100;filter:\'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\';"></iframe><![endif]--><table cellpadding=0 cellspacing=0 border=1 bordercolor=1 style="border:solid 1px #000000;border-collapse:collapse;background:#000;filter:progid:DXImageTransform.Microsoft.Shadow(color=#efefef,direction=135,strength=1,enabled=true);" onmouseover="SSCP_in=1" onmouseout="SSCP_in=0"><tr><td colspan=18><div id="SSCP_preview" style="cursor:pointer;width:50px;height:19px;background-color:#fff;float:left;" onclick="SSCP.setColor(document.getElementById(\'SSCP_value\').value)"></div><span style="color:#fff;margin-left:10px">#</span><input id=SSCP_value maxlength=6 value="ffffff" style="width:60px;height:19px;margin-left:1px;" onblur="this.value=this.value.replace(/[^0-9a-fA-F]/g,\'\');" onkeypress="if(document.all ? (window.event.keyCode==13) : (arguments[0].which==13)){SSCP.setColor(this.value)};return checkKey(event,\'0-9a-fA-F\')" onkeyup="SSCP.previewColor(this.value,1)"></td></tr>';
		for(var i=0;i<12;i++){
			html+='<tr>';
			for(var j=0;j<18;j++){
				var c=(0x330000*(Math.floor(j/6))+(0x3300*(j%6))+0x33*(i%6)+(i>=6 ? 0x990000 : 0)).toString(16).toUpperCase();
				while(c.length<6){
					c="0"+c;
				}
				html+='<td style="border:solid 1px #000000;padding-left:13px;height:13px;background-color:#'+c+'" onmouseover="SSCP.previewColor(\''+c+'\');" onclick="SSCP.setColor(\''+c+'\')"></td>';
			}
			html+='</tr>';
		}
		html+='<tr>';
		var custom=[0xff0000,0x00ff00,0x0000ff,0xffff00,0xff00ff,0x00ffff,0x333333,0x444444,0x555555,0x666666,0x777777,0x888888,0x999999,0xaaaaaa,0xbbbbbb,0xcccccc,0xdddddd,0xeeeeee];
		for(i=0;i<custom.length;i++){
			c=custom[i].toString(16).toUpperCase();
			while(c.length<6){
				c="0"+c;
			}
			html+='<td style="border:solid 1px #000000;padding-left:13px;height:13px;background-color:#'+c+'" onmouseover="SSCP.previewColor(\''+c+'\');" onclick="SSCP.setColor(\''+c+'\')"></td>';
		}
		html+='</tr>';
		html+='</table>';
		setTimeout(function(){
			var iframe=document.getElementById('SSCP_iframe');
			if(iframe!=null){
				iframe.style.width=SSCP.offsetWidth;
				iframe.style.height=SSCP.offsetHeight;
			}
			SSCP.style.visibility="visible";
			SSCP.style.display="none";
		},1);
		SSCP.innerHTML=html;
		SSCP.hide=function(){
			clearInterval(SSCP_intID);
			SSCP_intID=setInterval(function(){
				SSCP_alpha-=20;
				setAlpha(SSCP,SSCP_alpha);
				if(SSCP_alpha<=0){
					SSCP.style.display="none";
					clearInterval(SSCP_intID);
				}
			},50)
		}
		SSCP.previewColor=function(value,skipInput){
			value=value.replace(/#/g,'');
			while(value.length<6){
				value="0"+value;
			}
			document.getElementById('SSCP_preview').style.backgroundColor="#"+value;
			if(!skipInput){
				document.getElementById('SSCP_value').value=value;
			}
		}
		SSCP.setColor=function(value){
			value=value.replace(/#/g,'');
			while(value.length<6){
				value="0"+value;
			}
			this.hide();
			SSCP.callback(value.toUpperCase());
		}
		document.onmouseup=new Function('if(!SSCP_in){SSCP.hide()}');
		window.onresize=new Function('if(SSCP.style.display==""){SSCP.hide()}');
	}

	setTimeout(function(){
		SSCP_alpha=0;
		setAlpha(SSCP,SSCP_alpha);
		SSCP.style.display='';
		SSCP.callback=callback;
		var x=getAbsX(obj)+obj.clientWidth;
		var y=getAbsY(obj);
		var w=SSCP.clientWidth+2;
		if(x+w>document.body.clientWidth){
			x=document.body.clientWidth-w;
		}
		if(y+SSCP.clientHeight>document.body.scrollTop+document.body.clientHeight){
			y=document.body.scrollTop+document.body.clientHeight-SSCP.clientHeight;
			if(y<document.body.scrollTop){
				y=document.body.scrollTop;
			}
		}
		SSCP.style.left=x
		SSCP.style.top=y
		SSCP.previewColor(color);
		clearInterval(SSCP_intID);
		SSCP_intID=setInterval(function(){
			SSCP_alpha+=20;
			setAlpha(SSCP,SSCP_alpha);
			if(SSCP_alpha>=100){
				clearInterval(SSCP_intID);
			}
		},50)
	},1);
}

//SSDate Component
//created by Sebastian Serban, v1.0 (11.09.2007)
function SSDate(obj,value,callback){
	if(typeof(SSD)=='undefined'){
		SSD_in=0;
		SSD_intID=0;
		SSD_alpha=100;
		SSD=document.createElement('div');
		document.body.appendChild(SSD);
		SSD.id='SSColorPicker';
		SSD.style.visibility="hidden";
		SSD.style.position="absolute";
		SSD.style.zIndex=10001;
		SSD.style.backgroundColor="#000";
		SSD.style.left=0;
		SSD.style.top=0;
		var html='<!--[if IE]><iframe id="SSD_iframe" style="position:absolute;z-index:-100;filter:\'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\';"></iframe><![endif]--><table cellpadding=0 cellspacing=0 border=1 bordercolor=1 style="border:solid 1px #000000;border-collapse:collapse;background:#000;filter:progid:DXImageTransform.Microsoft.Shadow(color=#efefef,direction=135,strength=1,enabled=true);" onmouseover="SSD_in=1" onmouseout="SSD_in=0"><tr><td colspan=18><div id="SSD_preview" style="cursor:pointer;width:50px;height:19px;background-color:#fff;float:left;" onclick="SSD.setColor(document.getElementById(\'SSD_value\').value)"></div><span style="color:#fff;margin-left:10px">#</span><input id=SSD_value maxlength=6 value="ffffff" style="width:60px;height:19px;margin-left:1px;" onblur="this.value=this.value.replace(/[^0-9a-fA-F]/g,\'\');" onkeypress="if(document.all ? (window.event.keyCode==13) : (arguments[0].which==13)){SSD.setColor(this.value)};return checkKey(event,\'0-9a-fA-F\')" onkeyup="SSD.previewColor(this.value,1)"></td></tr>';
		for(var i=0;i<12;i++){
			html+='<tr>';
			for(var j=0;j<18;j++){
				var c=(0x330000*(Math.floor(j/6))+(0x3300*(j%6))+0x33*(i%6)+(i>=6 ? 0x990000 : 0)).toString(16).toUpperCase();
				while(c.length<6){
					c="0"+c;
				}
				html+='<td style="border:solid 1px #000000;padding-left:13px;height:13px;background-color:#'+c+'" onmouseover="SSD.previewColor(\''+c+'\');" onclick="SSD.setColor(\''+c+'\')"></td>';
			}
			html+='</tr>';
		}
		html+='<tr>';
		var custom=[0xff0000,0x00ff00,0x0000ff,0xffff00,0xff00ff,0x00ffff,0x333333,0x444444,0x555555,0x666666,0x777777,0x888888,0x999999,0xaaaaaa,0xbbbbbb,0xcccccc,0xdddddd,0xeeeeee];
		for(i=0;i<custom.length;i++){
			c=custom[i].toString(16).toUpperCase();
			while(c.length<6){
				c="0"+c;
			}
			html+='<td style="border:solid 1px #000000;padding-left:13px;height:13px;background-color:#'+c+'" onmouseover="SSD.previewColor(\''+c+'\');" onclick="SSD.setColor(\''+c+'\')"></td>';
		}
		html+='</tr>';
		html+='</table>';
		setTimeout(function(){
			var iframe=document.getElementById('SSD_iframe');
			if(iframe!=null){
				iframe.style.width=SSD.offsetWidth;
				iframe.style.height=SSD.offsetHeight;
			}
			SSD.style.visibility="visible";
			SSD.style.display="none";
		},1);
		SSD.innerHTML=html;
		SSD.hide=function(){
			clearInterval(SSD_intID);
			SSD_intID=setInterval(function(){
				SSD_alpha-=20;
				setAlpha(SSD,SSD_alpha);
				if(SSD_alpha<=0){
					SSD.style.display="none";
					clearInterval(SSD_intID);
				}
			},50)
		}
		SSD.previewColor=function(value,skipInput){
			value=value.replace(/#/g,'');
			while(value.length<6){
				value="0"+value;
			}
			document.getElementById('SSD_preview').style.backgroundColor="#"+value;
			if(!skipInput){
				document.getElementById('SSD_value').value=value;
			}
		}
		SSD.setColor=function(value){
			value=value.replace(/#/g,'');
			while(value.length<6){
				value="0"+value;
			}
			this.hide();
			SSD.callback(value.toUpperCase());
		}
		document.onmouseup=new Function('if(!SSD_in){SSD.hide()}');
		window.onresize=new Function('if(SSD.style.display==""){SSD.hide()}');
	}

	setTimeout(function(){
		SSD_alpha=0;
		setAlpha(SSD,SSD_alpha);
		SSD.style.display='';
		SSD.callback=callback;
		var x=getAbsX(obj)+obj.clientWidth;
		var y=getAbsY(obj);
		var w=SSD.clientWidth+2;
		if(x+w>document.body.clientWidth){
			x=document.body.clientWidth-w;
		}
		if(y+SSD.clientHeight>document.body.scrollTop+document.body.clientHeight){
			y=document.body.scrollTop+document.body.clientHeight-SSD.clientHeight;
			if(y<document.body.scrollTop){
				y=document.body.scrollTop;
			}
		}
		SSD.style.left=x
		SSD.style.top=y
		SSD.previewColor(color);
		clearInterval(SSD_intID);
		SSD_intID=setInterval(function(){
			SSD_alpha+=20;
			setAlpha(SSD,SSD_alpha);
			if(SSD_alpha>=100){
				clearInterval(SSD_intID);
			}
		},50)
	},1);
}

