/*
InnovaStudio Web Color Picker 1.3
© 2004-2005 INNOVA STUDIO (www.InnovaStudio.com). All rights reserved.
*/

/*** Localization ***/
var sLangDir="english";
var sScriptPathLang="";
try{if(LanguageDirectory)sLangDir=LanguageDirectory;}catch(e){;}
var oScripts=document.getElementsByTagName("script");
for(var i=0;i<oScripts.length;i++)
  {
  var sSrc= pagePath + "/" + oScripts[i].src;
  if(sSrc.indexOf("inc/inc/color_picker.js")!=-1)
    sScriptPathLang=oScripts[i].src.replace(/inc\/color_picker.js/ig,"")+"language/"+sLangDir+"/";
  }

if(sLangDir=="english")
  document.write("<scr"+"ipt src='"+sScriptPathLang+"color_lang.js'></scr"+"ipt>");
/*** /Localization ***/

var arrIColorPickerObjects=[];
function IColorPicker(sName,sParent)
  {
  this.oParent=sParent;
  if(sParent)
    {
    this.oName=sParent+"."+sName;
    this.oRenderName=sName+sParent;
    }
  else
    {
    this.oName=sName;
    this.oRenderName=sName;
    }
  arrIColorPickerObjects.push(this.oName);

  //[CUSTOM]
  var oScripts=document.getElementsByTagName("script");
  for(var i=0;i<oScripts.length;i++)
    {
    var sSrc=oScripts[i].src;
    if(sSrc.indexOf("inc/color_picker.js")!=-1)
      {
      this.url=sSrc.replace(/color_picker.js/,"color_picker.htm");
      }
    }

  this.onShow=function(){return true;};
  this.onHide=function(){return true;};
  this.onPickColor=function(){return true;};
  //this.onRemoveColor=function(){return true;};
  this.onRemoveColor=function(){this.color="";this.onPickColor();};//1.2

  this.onMoreColor=function(){return true;};
  this.show=showIColorPicker;
  this.hide=hideIColorPicker;
  this.hideAll=hideIColorPickerAll;
  this.color;
  this.customColors=[];
  this.refreshCustomColor=refreshICustomColor;
  this.isActive=false;
  this.align="left";
  this.currColor="#ffffff";//default current color
  this.RENDER=drawIColorPicker;
  }
function drawIColorPicker()
  {
	
 if(getById("dropIColor"+this.oRenderName))
 	return;
	
  var arrColors=[["#800000","#8B4513","#006400","#2F4F4F","#000080","#4B0082","#800080","#000000"],
        ["#FF0000","#DAA520","#6B8E23","#708090","#0000CD","#483D8B","#C71585","#696969"],
        ["#FF4500","#FFA500","#808000","#4682B4","#1E90FF","#9400D3","#FF1493","#A9A9A9"],
        ["#FF6347","#FFD700","#32CD32","#87CEEB","#00BFFF","#9370DB","#FF69B4","#DCDCDC"],
        ["#FFDAB9","#FFFEE0","#98FB98","#E0FFFF","#87CEFA","#E6E6fA","#DDA0DD","#FFFFFF"]]
  var sHTMLColor="<table id=dropIColor"+this.oRenderName+" style=\"z-index:1;display:none;position:absolute;border:#716F64 1px solid;cursor:default;background-color:#f3f3f3;padding:2px\" unselectable=on cellpadding=0 cellspacing=0 width=145px><tr><td unselectable=on style='border:none;padding:0px;'>"
  sHTMLColor+="<table align=center cellpadding=0 cellspacing=0 border=0 unselectable=on style='border:none;'>";
  for(var i=0;i<arrColors.length;i++)
    {
    sHTMLColor+="<tr>";
    for(var j=0;j<arrColors[i].length;j++) {
      sHTMLColor+= "<td onclick=\""+this.oName+".color='"+arrColors[i][j]+"';"+this.oName+".onPickColor();"+this.oName+".currColor='"+arrColors[i][j]+"';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#efefef 1px solid'\" style=\"cursor:pointer;padding:1px;border:#efefef 1px solid;\" unselectable=on>"+
       					"<table style='margin:0;width:13px;height:13px;background:"+arrColors[i][j]+";border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
        					"<tr>" + 
								"<td unselectable=on style='background:"+arrColors[i][j]+";border:none;padding:0px;'>" + 
								"</td>" + 
							"</tr>"+
       					"</table>" + 
					"</td>";
	}
    sHTMLColor+="</tr>";
    }

  //~~~ custom colors ~~~~
  sHTMLColor+="<tr><td colspan=8 id=idICustomColor"+this.oRenderName+" style='border:none;padding:0px;'></td></tr>";

  //~~~ remove color & more colors ~~~~
  sHTMLColor+= "<tr>";
  
  sHTMLColor+= "<td unselectable=on style='border:none;padding:0px;'>"+
    				"<table style='margin-left:1px;width:14px;height:14px;background:#f3f3f3;border:none;' cellpadding=0 cellspacing=0 unselectable=on>"+
    					"<tr>" + 
							"<td onclick=\""+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='white 1px solid'\" style=\"cursor:pointer;padding:1px;border:white 1px solid;font-family:verdana;font-size:10px;font-color:black;line-height:9px;\" align=center valign=top unselectable=on>" + 
								"x" +
							"</td>" +
						"</tr>" +
					"</table>" +
				"</td>";
	
  sHTMLColor+= "<td title=\"transparent\" onclick=\""+this.oName+".color='transparent';"+this.oName+".onPickColor();"+this.oName+".currColor='transparent';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#efefef 1px solid'\" style=\"cursor:pointer;padding:1px;border:#efefef 1px solid;\" unselectable=on>"+
   					"<table style='margin:0;width:13px;height:13px;border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
    					"<tr>" + 
							"<td unselectable=on style='background-image: url(\"images/transparent.png\"); border:none;padding:0px;'>" + 
							"</td>" + 
						"</tr>"+
   					"</table>" + 
				"</td>";
	
    sHTMLColor+= "<td colspan=6 unselectable=on style='border:none;padding:0px;'>"+
        "<table style='margin:1px;width:100%;height:16px;background:#f3f3f3;border:#f3f3f3 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
		"<tr><td id='"+this.oName+"moreIColTd' onclick=\""+this.oName+".onMoreColor();"+this.oName+".hideAll();modalDialogShow('"+this.url+"?" +this.oName+ "', 442, 380)\" onmouseover=\"this.style.border='#777777 1px solid';this.style.background='#8d9aa7';this.style.color='#ffffff'\" onmouseout=\"this.style.border='#efefef 1px solid';this.style.background='#f3f3f3';this.style.color='#000000'\" style=\"border:#efefef 1px solid;font-family:verdana;font-size:9px;font-color:black;line-height:9px;padding:1px; cursor: pointer;\" align=center valign=top nowrap unselectable=on>"+getText("More Colors...")+"</td></tr>"+
        "</table></td>";
    sHTMLColor+= "</tr>";

  sHTMLColor+= "</table>";
  sHTMLColor+="</td></tr></table>";
  
  var divElement = document.createElement("div");
  divElement.innerHTML = sHTMLColor;
  document.body.appendChild(divElement);
  
  }
function refreshICustomColor()
  {
  if(this.customColors.length==0)
    {
    document.getElementById("idICustomColor"+this.oRenderName).innerHTML="";
    return;
    }
  sHTML="<table cellpadding=0 cellspacing=0 width=100% style='border:none;'><tr><td colspan=8 style=\"font-family:verdana;font-size:9px;font-color:black;line-height:9px;padding:1px;border:none;\">"+getText("Custom Colors")+":</td></tr></table>"
  sHTML+="<table cellpadding=0 cellspacing=0 style='border:none;'><tr>";
  for(var i=0;i<this.customColors.length;i++)
    {
    if(i<22)
      {
      if(i==8||i==16||i==24||i==32)sHTML+="</tr></table><table cellpadding=0 cellspacing=0><tr>"
      sHTML+="<td onclick=\""+this.oName+".color='"+this.customColors[i]+"';"+this.oName+".onPickColor()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#efefef 1px solid'\" style=\"cursor:default;padding:1px;border:#efefef 1px solid;\" unselectable=on>"+
        " <table style='margin:0;width:13px;height:13px;background:"+this.customColors[i]+";border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
        " <tr><td unselectable=on style='background:"+this.customColors[i]+"border:none;padding:0px;'></td></tr>"+
        " </table>"+
        "</td>";
      }
    }
  sHTML+="</tr></table>";
  document.getElementById("idICustomColor"+this.oRenderName).innerHTML=sHTML;
  }
function showIColorPicker(oEl)
  {
  	
  this.RENDER();
	
  this.onShow();

  this.hideAll();

  var box=document.getElementById("dropIColor"+this.oRenderName);

  //remove hilite
  var allTds = box.getElementsByTagName("TD");
  for (var i = 0; i<allTds.length; i++) {
      allTds[i].style.border="#efefef 1px solid";
      if (allTds[i].id==this.oName+"moreIColTd") {
          allTds[i].style.border="#efefef 1px solid";
          allTds[i].style.background="#f3f3f3";
          allTds[i].style.color="#000000";
      }
  }

  box.style.display="block";
  var nTop=0;
  var nLeft=0;

  oElTmp=oEl;
  while(oElTmp.tagName!="BODY" && oElTmp.tagName!="HTML")
    {
    if(oElTmp.style.top!="")
      nTop+=oElTmp.style.top.substring(1,oElTmp.style.top.length-2)*1;
    else nTop+=oElTmp.offsetTop;
    oElTmp = oElTmp.offsetParent;
    }

  oElTmp=oEl;
  while(oElTmp.tagName!="BODY" && oElTmp.tagName!="HTML")
    {
    if(oElTmp.style.left!="")
      nLeft+=oElTmp.style.left.substring(1,oElTmp.style.left.length-2)*1;
    else nLeft+=oElTmp.offsetLeft;
    oElTmp=oElTmp.offsetParent;
    }

  if(this.align=="left")
    box.style.left=nLeft + "px";
  else//right
    box.style.left=(nLeft-143+oEl.offsetWidth) + "px";

  //box.style.top=nTop+1;//[CUSTOM]
  box.style.top=(nTop+1+oEl.offsetHeight) + "px";//[CUSTOM]

  this.isActive=true;

  this.refreshCustomColor();
  }
function hideIColorPicker()
  {
  this.onHide();

  var box=document.getElementById("dropIColor"+this.oRenderName);
  box.style.display="none";
  this.isActive=false;
  }
function hideIColorPickerAll()
  {
  for(var i=0;i<arrIColorPickerObjects.length;i++)
    {
    var box=document.getElementById("dropIColor"+eval(arrIColorPickerObjects[i]).oRenderName);
    if (box) {
		box.style.display = "none";
		eval(arrIColorPickerObjects[i]).isActive = false;
	}
    }
  }

var activeModalWin;
function modalDialogShow(url,width,height)
    {
    var left = screen.availWidth/2 - width/2;
    var top = screen.availHeight/2 - height/2;
    activeModalWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
    window.onfocus = function(){if (activeModalWin.closed == false){activeModalWin.focus();};};
    }