function $(id) { return document.getElementById(id) }

function addEvent(obj, type, fn){
  if (obj.addEventListener)
    obj.addEventListener(type, fn, false);
  else if (obj.attachEvent){
    obj["e"+type+fn] = fn;
    obj[type+fn] = function(){obj["e"+type+fn](window.event);}
    obj.attachEvent("on"+type, obj[type+fn]);
  }
}

/* class */
function addClass(el,c) { el.className += " " + c; }
function removeClass(el, c) { el.className = el.className.replace(new RegExp(c,"g"),""); }

// -- run
function run()
{
	// run with threads for faster load
	setTimeout(serviceLoginBox,20);
	setTimeout(serviceNlBox,0);
	//flashFix();
}

function flashFix()
{
	var objects=document.getElementsByTagName('object');
	var attrs, params, originalAttr, originalParams;
	for( var i=0; i<objects.length; i++)
	{
		attrs = params = originalAttr = originalParams = '';
		originalAttr=objects[i].attributes; 
		originalParams=objects[i].parentNode.getElementsByTagName('param'); 
		for(var j=0;j<originalAttr.length;j++){attrs+=originalAttr[j].name+'="'+originalAttr[j].value+'" '+"\n";}
		for(var j=0;j<originalParams.length;j++){params+='<param name="'+originalParams[j].name+'" value="'+originalParams[j].value+'"/>'+"\n"}
		objects[i].outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+attrs+'>'+params+'</object>';
	}
}

addEvent(window,"load",run);

function serviceLoginBox()
{
	var spellLoginFormChecked = 0;
	
	var form = $("login_box");
	if(!form)
		return;
		
	// click on label
	var labels = form.getElementsByTagName("label");
	for( var i = 0; i < labels.length; i++ )
	{
		if(labels[i].className.indexOf("field") != -1 )
		{
			if($(labels[i].htmlFor).value == "")
			{
				labels[i].style.display = "block";
				labels[i].onclick = function(e)
				{
					e=e||event;
					hideDirectly($(this.htmlFor));
					e.cancelBubble = true;
					return false;
				}
			}
			else
			{
				labels[i].style.display = "none";
			}
		}
	}
	// keyboard navigation
	var inputs = form.getElementsByTagName("input");
	for( var i = 0; i < inputs.length; i++ )
	{
		if(inputs[i].className.indexOf("text") != -1 )
		{
			if(inputs[i].value!="")	hideDirectly(inputs[i]);
			inputs[i].onfocus = hide;
			inputs[i].onclick = hide;
		}
	}
	
	function hide()
	{
		hideDirectly(this);
	}
	
	function hideDirectly(input)
	{
		var label = input.previousSibling;
		if(label && label.nodeName.toLowerCase() == "label" && label.className.indexOf("hide") == -1)
		{
			input.previousSibling.className = "hide";
			input.focus();
		}
	}
	
	// do it twice becouse of firefox autocomplete
	if( spellLoginFormChecked == 0)
	{
		spellLoginFormChecked = 1;
		window.setTimeout("serviceLoginBox()", 5 ); 
	}
}

 /*	index.xml */ 
 function tabChange(tabId) 
 {
 	var listItems = document.getElementById("tab_list").getElementsByTagName("li");
	for(var i=0; i<listItems.length; i++) {

		if(tabId-1 == i) listItems[i].className="active";
		else listItems[i].className="";
	} 
	var tabs= document.getElementById("tabs").childNodes; 
 	var j=1;
	for(var i=0; i<tabs.length; i++) {	
		if(tabs[i].nodeName=='DIV')
		{
			if(tabId == j)	tabs[i].className="active";
			else tabs[i].className="";
			j++;
		}
	} 	   
 }
 
 /* Advanced Search */
 function deselect(div)
 {
 	var eList = div.childNodes;
 	for(var i=0; i<eList.length; i++) {
 		if(eList[i].nodeName.toUpperCase()=='INPUT'&& eList[i].type.toUpperCase()=='CHECKBOX')
 			eList[i].checked=false;
 		else
 		{
 			deselect(eList[i]); 		
 		}
 	}
 	return null;
 }
 

 function serviceNlBox()
{
	var form = $("nl_box");
	if(!form) return;

	var input = form.elements["email"];
	if(!input) return;
	
	var defaultValue = input.value;
	input.onfocus = inputOn;
	input.onblur = inputOff;

	form.onsubmit = function()
	{
		return checkEmail(input.id,"Please enter a valid email address.");
	}
	
	function inputOn()
	{
		if(this.value == defaultValue) this.value = "";
		return true;
	}
	
	function inputOff()
	{
		if(this.value == "") this.value = defaultValue;
		return true;	
	}
}
 
function PopupWindow(url,width,height,name){
    if (name==null){
      name = new String(Math.round(Math.random()*10000000));
    }

    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2 - 18;

    var win = window.open(url,name,"toolbar=no,location=no,directories=no,"+
      "status=no,menubar=no,scrollbars=no,resizable=no,"+
      "copyhistory=no, width="+width+",height="+height+",left="+left+",top="+top);
}

function showSearchByStyle(element) {
	element.style.display='none';	
	var elementList = element.parentNode.childNodes;
	
	for(var i=0; i<elementList.length; i++) {
		element = elementList[i]; 
		if(element.nodeName=='UL')
		{
			var liElemnts = element.childNodes;			
			for(var j=0; j<liElemnts.length; j++) {
				if(liElemnts[j].nodeName=='LI'){				
					liElemnts[j].style.display='list-item';
				}
			}	
		}
	}
	return false;
}

function hideSearchByStyle() {
	var elementList = document.getElementById('search_by_style').childNodes;
	
	for(var i=0; i<elementList.length; i++) {
		element = elementList[i]; 
		if(element.nodeName=='UL')
		{
			var liElemnts = element.getElementsByTagName('LI');	
			
			for(var j=3; j<liElemnts.length; j++) {
				liElemnts[j].style.display='none';									
			}	
		}
		
		if(element.nodeName=='A')
			element.style.display='inline';
	}		
}

/**
 * 	Shows popup help window.
 */ 
function popup(title,width,height)
{
	if (!width) width = 350;
	if (!height) height = 450;

    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2 - 18;

    var win = window.open('/misc/popup.xml?' + title,'popup',"toolbar=no,location=no,directories=no,"+
      "status=no,menubar=no,scrollbars=yes,resizable=yes,"+
      "copyhistory=no, width="+width+",height="+height+",left="+left+",top="+top);
     if (win) win.focus();
}

/**
 * Format price
 */ 
function formatPrice(d)
{
	var d2 = Math.floor(d);
	var s = "" + ((d*100-d2*100));	
	if (s.length>2) s=s.substr(0,2);
	else while (s.length<2) s="0"+s;
	
	var s1=""+d2;
	if (s1.length>3) s1=s1.substr(0,s1.length-3) + "." + s1.substr(s1.length-3,s1.length)
	return s1+"."+s; 
}		

/**
 * Some Fun ;-)
 */ 
function FadeObject(element,fromColor,toColor)
{
	this.e = element;
	this.c1 = fromColor;
	this.c2 = toColor;
	this.steps = 10;
	this.repeats = 3;


	this._steps = this.steps;
	var r1 = hextorgb(this.c1);
	var r2 = hextorgb(this.c2);
	r1[0] = (r2[0]*1.0-r1[0])/this.steps;
	r1[1] = (r2[1]*1.0-r1[1])/this.steps;
	r1[2] = (r2[2]*1.0-r1[2])/this.steps;
	this.c1 = r2;
	this.v = r1;
}

FadeObject.prototype = {
		
		fade : function() 
		{
			if (this.steps>0)
			{
				var s = '';
				s += (this.c1[0]-Math.ceil(this.v[0]*this.steps));
				s += ',';
				s += (this.c1[1]-Math.ceil(this.v[1]*this.steps));
				s += ',';
				s += (this.c1[2]-Math.ceil(this.v[2]*this.steps));
				
				this.e.style.backgroundColor = "rgb(" + s + ")";
				this.steps--;
				CCallWrapper.asyncExecute(new CCallWrapper(this, 20, 'fade'));
				return;
			}
			this.e.style.backgroundColor = "rgb(" + this.c1[0] + "," + this.c1[1] + "," + this.c1[2] + ")";
			if (this.repeats > 1)
			{
				this.repeats--;
				this.steps = this._steps;
				if (this.reverse) this.reverseMode=this.reverseMode*-1;
				CCallWrapper.asyncExecute(new CCallWrapper(this, 20, 'fade'));
			}
		}
	};


		
		
		
		
function hextorgb(n1,n2,n3,n4,n5,n6) {

	var n1,n2,n3,n4,n5,n6;
	if (n1.length==6)
	{
		n2 = replacevals(n1.charAt(1));
		n3 = replacevals(n1.charAt(2));
		n4 = replacevals(n1.charAt(3));
		n5 = replacevals(n1.charAt(4));
		n6 = replacevals(n1.charAt(5));
		n1 = replacevals(n1.charAt(0));
	}
	else
	{
		n1 = replacevals(n1);
		n2 = replacevals(n2);
		n3 = replacevals(n3);
		n4 = replacevals(n4);
		n5 = replacevals(n5);
		n6 = replacevals(n6);
	}
		var returnval = ((16 * n1) + (1 * n2));
		var returnval1 = 16 * n3 + n4;
		var returnval2 = 16 * n5 + n6;
		return [((16 * n1) + (1 * n2)),((16 * n3) + (1 * n4)),((16 * n5) + (1 * n6))];
}

function replacevals(n) {

if (n == "a") { n = "10"; }
if (n == "b") { n = "11"; }
if (n == "c") { n = "12"; }
if (n == "d") { n = "13"; }
if (n == "e") { n = "14"; }
if (n == "f") { n = "15"; }

return n

}

function replacevalsreverse(thenum) {
 if (thenum == 10) { thenum = "a"; }
 if (thenum == 11) { thenum = "b"; }
 if (thenum == 12) { thenum = "c"; }
 if (thenum == 13) { thenum = "d"; }
 if (thenum == 14) { thenum = "e"; }
 if (thenum == 15) { thenum = "f"; }

 return thenum;
}

function rgbtohex(num1, num2, num3) {
return calc10to16(num1) + calc10to16(num2) + calc10to16(num3);

}

function calc10to16(num) {
if (num < 16) {
 var thenum = replacevalsreverse(num);
 return thenum;
 }
else {
 var themod=num % 16;
 var thenum=((num-themod) / 16);
 thenum = replacevalsreverse(thenum)
 themod = replacevalsreverse(themod)

 return ""+thenum+themod
}
}


