var isIE=false;
var skinColor;
var undoColor;
var undoObj;
var idz="skin_background";
if(navigator.appName.indexOf("Microsoft")!=-1) isIE=true;

function test(ev,obj) 
	{
	  //var tempDiv=document.getElementById(tagRef);
	  //tempDiv.style.background="#FF0000";
	  //alert (obj.id);
	  //alert (document.getElementById("p_mode").checked);
	  if(isIE) {ev.cancelBubble = true;}
	  else {ev.stopPropagation();}
	  idz=obj.id;
	  undoColor=obj.style.backgroundColor;
	  obj.style.backgroundColor=skinColor;
	  
	  //skinColor=obj.style.backgroundColor;
	  //if(skinColor.indexOf("rgb")!=-1)
	  //{
	  
	  //}
	  //document.getElementById("inputColor").value = skinColor.toUpperCase();
	}
function undo()
	{
	document.getElementById(idz).style.backgroundColor=undoColor;
	}
function resetColor()
	{
	alert("reset ! not implemented yet :-(");
	}
function selectBackground(val)
	{
	if(val=="win98")
		{
		this.document.getElementById('skin_background_img').style.backgroundImage="url('http://www.wavosaur.com/skin-your-saur/img/skin_background_img.png')";
		this.document.getElementById('wavosaur_bg_img').style.backgroundImage="url('http://www.wavosaur.com/skin-your-saur/img/wavosaur-img-bckgrd-98.png')";
		}
	if(val=="winXP")
		{
		this.document.getElementById('skin_background_img').style.backgroundImage="url('http://www.wavosaur.com/skin-your-saur/img/skin_background_img_XP.png')";
		this.document.getElementById('wavosaur_bg_img').style.backgroundImage="url('http://www.wavosaur.com/skin-your-saur/img/wavosaur-img-bckgrd-XP.png')";
		}
	}
	
function generate()
	{
		var background = document.getElementById('skin_background').style.backgroundColor;
		document.getElementById('background').value = rgb2hex(background);
		
		var grid = document.getElementById('skin_grid').style.backgroundColor;
		document.getElementById('grid').value = rgb2hex(grid);
		
		var selectionactive = document.getElementById('skin_selectionactive').style.backgroundColor;
		document.getElementById('selectionactive').value = rgb2hex(selectionactive);
		
		var sampleselected00 = document.getElementById('skin_sampleselected00').style.backgroundColor;
		document.getElementById('sampleselected00').value = rgb2hex(sampleselected00);
		
		var sampleselected01 = document.getElementById('skin_sampleselected01').style.backgroundColor;
		document.getElementById('sampleselected01').value = rgb2hex(sampleselected01);
		
		var backgroundsample = document.getElementById('skin_backgroundsample').style.backgroundColor;
		document.getElementById('backgroundsample').value = rgb2hex(backgroundsample);
		
		var sample00 = document.getElementById('skin_sample00').style.backgroundColor;
		document.getElementById('sample00').value = rgb2hex(sample00);
		
		var sample01 = document.getElementById('skin_sample01').style.backgroundColor;
		document.getElementById('sample01').value = rgb2hex(sample01);
		
		getIframeContent();
		document.getElementById('form2').submit();
	}
	
function rgb (r,g,b)
	{
	//var n = (r<<16) + (g<<8) + b;
	//return '#' + (r<16? '0':'') + n.toString(16);
	red = r.toString(16).length<2 ? '0' + r.toString(16):r.toString(16);
	green = g.toString(16).length<2 ? '0' + g.toString(16):g.toString(16);
	blue = b.toString(16).length<2 ? '0' + b.toString(16):b.toString(16);
	return '#' + red + green + blue;
	}
function rgb2hex(color)
	{
	if (color.substring(0,3)=="rgb") return eval(color);
	else return color;
	}
function load() //à degager
	{
	document.getElementById("loading").style.display="block";
	}
	
function loading()
	{
	IE  = window.ActiveXObject ? true : false;		
  	if(IE){
  			edoc = window.frames['upload'].document;
			edoc.getElementById('loading').style.zIndex="1";
  		  }
    else{
  			edoc = document.getElementById('upload').contentDocument;
			edoc.getElementById('loading').style.zIndex="1";						
		}
	}
	
function getIframeContent()
	{
	IE  = window.ActiveXObject ? true : false;
	name = "noimg";		
  	if(IE){
  			edoc = window.frames['upload'].document;
			if(edoc.getElementById('img_name')!=null) name = edoc.getElementById('img_name').value;
  			}	
    else {
  			edoc = document.getElementById('upload').contentDocument;			
			if(edoc.getElementById('img_name')!=null) name = edoc.getElementById('img_name').value;			
			}	
	document.getElementById("img").value = name;			
	}

function clearText()
	{
	document.getElementById("skin_name").value = "";
	}
	
function showtab1()
	{
	this.document.getElementById('tab1').style.display = "block";
	this.document.getElementById('tab2').style.display = "none";
	this.document.getElementById('titletab1').style.borderBottom = "solid 1px #d8d8d8";
	this.document.getElementById('titletab2').style.borderBottom = "solid 1px #999999";
	}
function showtab2()
	{
	this.document.getElementById('tab2').style.display = "block";
	this.document.getElementById('tab1').style.display = "none";
	this.document.getElementById('titletab2').style.borderBottom = "solid 1px #d8d8d8";
	this.document.getElementById('titletab1').style.borderBottom = "solid 1px #999999";
	}
