/*
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=oScripts[i].src.toLowerCase();
  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.toLowerCase();
    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()
  { 
  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","#ffffe0","#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:default;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+".onRemoveColor();"+this.oName+".currColor='';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='white 1px solid'\" style=\"cursor:default;padding:1px;border:white 1px solid;font-family:verdana;font-size:10px;color:black;line-height:9px;\" align=center valign=top unselectable=on>x</td></tr>"+
    "</table></td>";
    sHTMLColor+= "<td colspan=7 unselectable=on style='border:none;padding:0px;'>"+
        "<table style='margin:1px;width:117px;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;cursor:default;font-family:verdana;font-size:9px;color:black;line-height:9px;padding:1px\" align=center valign=top nowrap unselectable=on>"+getText("More Colors...")+"</td></tr>"+
        "</table></td>";
    sHTMLColor+= "</tr>";
  
  sHTMLColor+= "</table>";      
  sHTMLColor+="</td></tr></table>";
  document.write(sHTMLColor);
  }
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;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.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);
    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();};};
    }