var highlightcolor="#F3E7DB"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}


  state = "html"; 

  function e_text(){
    if(state == "text") return;
    c_html = document.getElementById('content_html');
    c_text = document.getElementById('content_text');
    c_html.style.display="none"; 
    c_text.innerHTML = c_html.value; 
    c_text.style.display=""; 
    state = "text"; 
  }

  function e_html(){
    if(state == "html") return; 
    c_html = document.getElementById('content_html');
    c_text = document.getElementById('content_text');
    c_html.style.display=""; 
    c_html.value = c_text.innerHTML; 
    c_text.style.display="none"; 
    state = "html"; 
  }

  function e_h3(){
    c_html = document.getElementById('content_html');
    c_text = document.getElementById('content_text');
    if(state == "text"){
      c_text.focus();
      c_text.document.execCommand("FontSize",false,"3");
      c_text.document.execCommand("Bold",false,"bold");
      c_text.focus();
    }
  }
  
  function e_image(){
    c_html = document.getElementById('content_html');
    c_text = document.getElementById('content_text');
    if(state == "text"){
      c_text.focus();
      c_text.document.execCommand("InsertImage",true,"");
      c_text.focus();
    }    
  }

  function e_link(){
    c_html = document.getElementById('content_html');
    c_text = document.getElementById('content_text');
    if(state == "text"){
      c_text.focus();
      c_text.document.execCommand("CreateLink",true,"");
      c_text.focus();
    }    
  }

  function e_bold(){
    c_html = document.getElementById('content_html');
    c_text = document.getElementById('content_text');
    if(state == "text"){
      c_text.focus();
      c_text.document.execCommand("Bold",false,"bold");
      c_text.focus();
    }
  }

  function faq(f){
    if(f.faq_add.checked){
       f.faq_q.disabled = 0;  
       f.faq_a.disabled = 0;
    }else{
       f.faq_q.disabled = 1; 
       f.faq_a.disabled = 1; 
    } 
  }
    function checkBucket(f){
      if(f.make_bucket.checked){
        nextSection();
      }else if(f.make_component.checked){
        openSection(opened + 2);
      }else{
        openSection(opened + 3);
      }
    }

    function checkComponent(f){
      if(f.make_component.checked){
        nextSection();
      }else{
        openSection(opened + 2); 
      }
    }

    function openSection(section){
      if(opened > 0){closeSection(opened); t=1000; }else{ t = 1; }
      if(opened != section){
        opened = section; 
        sect = new CA_Object("section" + section); 
        sect.css.visibility="visible"; 
        setTimeout('sect.resizeToOverflow(5,1)',t); 
      }else{ opened = 0; }
    }

    function nextSection(){
      if(opened < max){openSection(opened + 1); }else{ opened = max + 1; }
    }

    function closeSection(section){
      sectc = new CA_Object("section"+section); 
      sectc.h = sect.h;
      sectc.resizeElasticTo(parseInt(sect.w),1,5,1); 
    }

    function checkIt(){
      if(opened == max + 1){ return true; }else{ return false; }
   }
	
   function popUp(URL)
   {
      day = new Date();
      id = day.getTime();
      eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400,left = 600,top = 400');");
   }

   function openSectionHighlight(section)
   {
      for (i = 1; i < max + 1 ; i++)
      {
         dom = eval('document.all.sect' + i + '.style');
         if (i == section)
            dom.color = "#cc6600";
         else
            dom.color = "#585858";
      }
   }
   
   function getDayOfTheWeek(dateStr)
   {
      if (dateStr == "" || dateStr.length != 8)
         return "";
         
      firstSlash = dateStr.indexOf('/');
      if (firstSlash != 2)
         return "";
         
      secondSlash = dateStr.indexOf('/', firstSlash + 1);
      if (secondSlash != 5)
         return "";
      
      dateArr = dateStr.split('/');
      date = new Date('20' + dateArr[2], dateArr[0] - 1, dateArr[1]);
      return date.getDay();
   }
   
   function SubmitForm()
   {
      var ret = true;
      if (document.forms[0].email.value == "")
      {
         alert("Please enter your email.");
         document.forms[0].email.focus();
         return;
      }

      document.forms[0].submit();
   }