

function createGradient(type) {


     objArray = getGradientObjects(type);
     if(!objArray.length) return;
         for(i=0;i<objArray.length;i++) {
            params = objArray[i].className.split(" ");

            if(objArray[i].offsetHeight<100)
            {
               colorPercentStep=.05;
            }
            else
            {
               colorPercentStep=.01;
            }

            colorArray = createColorPath(params[1],params[2], colorPercentStep);

            x=0;y=0;

            if(objArray[i].className.indexOf("roundcont_view")!=-1)y=100;

            if(params[3] == "horizontal") {
               w=Math.round(objArray[i].offsetWidth/colorArray.length);
               if(!w)w=1;
               h = objArray[i].offsetHeight;
             } else {

               if(objArray[i].className.indexOf("roundcont_view")!=-1)
               {
                    h = Math.round((objArray[i].offsetHeight-100)/colorArray.length);
               }
               else h = Math.round(objArray[i].offsetHeight/colorArray.length);
               if(!h) h =1;
               w = objArray[i].offsetWidth;
             }
             makeGrandParent(objArray[i]);
             tmpDOM = document.createDocumentFragment();

                         var count;


                            for(p=0;p<colorArray.length;p++) {
                               g = document.createElement("div");

                               if(document.all && !window.opera) {

                                   g.style.cssText="position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h+ "px;width:" + w + "px;background-color:rgb(" + colorArray[p][0] + "," + colorArray[p][1] + "," + colorArray[p][2] + ");";
                   }
                               else
                               {
                                   g.setAttribute("style","position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h+ "px;width:" + w + "px;background-color:rgb(" + colorArray[p][0] + "," + colorArray[p][1] + "," + colorArray[p][2] + ");");
                               }

                               var divID=objArray[i].id;

                               $(g).addClass(divID);
                               count=p;
                               params[3] == "horizontal"?x+=w:y+=h;
                               tmpDOM.appendChild(g);

                               if(y+h>objArray[i].offsetHeight)
                               {
                                   h=objArray[i].offsetHeight-y;
                               }

                               if(y>=objArray[i].offsetHeight || x >= objArray[i].offsetWidth) break;
                }

                            while(y<objArray[i].offsetHeight)
                            {
                               if(y+h>objArray[i].offsetHeight) h=objArray[i].offsetHeight-y;
                               g = document.createElement("div");
                               if(document.all && !window.opera) {
                                   g.style.cssText="position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h+ "px;width:" + w + "px;background-color:rgb(" + colorArray[count][0] + "," + colorArray[count][1] + "," + colorArray[count][2] + ");";
                               }
                               else
                               {
                                   g.setAttribute("style","position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h+ "px;width:" + w + "px;background-color:rgb(" + colorArray[count][0] + "," + colorArray[count][1] + "," + colorArray[count][2] + ");");

                               }

                               var divID=objArray[i].id;

                               $(g).addClass(divID);



                y+=h;
                tmpDOM.appendChild(g);
                          }

             objArray[i].appendChild(tmpDOM);
             tmpDOM = null;
         }

  }

  function getGradientObjects(type) {
  a = document.getElementsByTagName("*");
  objs = new Array();
  for(i=0;i<a.length;i++) {
      c = a[i].className;
      if(c != "") if(c.indexOf("gradient") == 0)
      {
           if(type==1 &&  c.indexOf("roundcont_view")!=-1 || type==2 && c.indexOf("roundcont_menu")!=-1 || type==3 && c.indexOf("roundcont_calendar")!=-1)
               objs[objs.length] = a[i];
      }
  }
  return objs;
  }

  function createColorPath(color1,color2,colorPercentStep) {
  colorPath = new Array();
  colorPercent = 1.0;

  do {
      colorPath[colorPath.length]=setColorHue(longHexToDec(color1),colorPercent,longHexToDec(color2));
      colorPercent-=colorPercentStep;
  } while(colorPercent>0);
  return colorPath;
  }

  function setColorHue(originColor,opacityPercent,maskRGB) {
  returnColor=new Array();
  for(w=0;w<originColor.length;w++) returnColor[w] = Math.round(originColor[w]*opacityPercent) + Math.round(maskRGB[w]*(1.0-opacityPercent));
  return returnColor;
  }

  function longHexToDec(longHex) {
  return new Array(toDec(longHex.substring(0,2)),toDec(longHex.substring(2,4)),toDec(longHex.substring(4,6)));
  }

  function toDec(hex) {
  return parseInt(hex,16);
  }

  function makeGrandParent(obj) {

      if(document.all && !window.opera) {
          disp = obj.currentStyle.display;
      }
      else{
          disp = document.defaultView.getComputedStyle(obj,'').display;
      }

  disp == "block"?nSpan = document.createElement("div"):	nSpan = document.createElement("span");
  mHTML = obj.innerHTML;
  obj.innerHTML = "";
  nSpan.innerHTML = mHTML;
      if(document.all && !window.opera) {

          nSpan.style.cssText="position:relative;z-index:10;";
      }
      else{
          nSpan.setAttribute("style","position:relative;z-index:10;");
      }
  obj.appendChild(nSpan);
   }

  function buildURL(locationStr,id, strAttr, inputValue){

                            if(strAttr.indexOf(",")!=-1)
                            {

                                 var regexp = /,\b/;
                                 var attrArray = strAttr.split(regexp);
                                 for(t=0;t<attrArray.length;t++)
                                 {
                                     locationStr+="objectType="+id+"&attribute=" +attrArray[t]+
                                                  "&condition=12&dictionaryValue=&textValue="
                                                   +encodeURI(inputValue);
                                     if(t<attrArray.length-1) locationStr+="&";

                                 }
                            }
                            else
                            {
                               locationStr+="objectType="+id+"&attribute=" +strAttr+
                                                  "&condition=12&dictionaryValue=&textValue="
                                                   +encodeURI(inputValue);
                            }

                            return locationStr;

  }

  function ssSubmit() {

                     var elements = document.getElementsByTagName('input');
                     var attrs = document.getElementById("typeSearchId").value;
                     var locationStr;
                     var isAnyParam=false;
                     var i, elm;

                     if (attrs != "0")
                     {
                         var id, inTextAttr, inHeaderAttr, index1,index2;
                         locationStr="search.do?";
                         index1=attrs.indexOf("|");
                         index2=attrs.lastIndexOf("|");
                         inputSearchInHeaderValue=document.getElementById("1804282193").value;
                         inputSearchInText=document.getElementById("1804282196");

                         if(index1!=index2)
                         {
                            id=attrs.substring(0,index1);
                            inHeaderAttr=attrs.substring(index1+1,index2);
                            inTextAttr=attrs.substring(index2+1);

                         }
                         else
                         {
                            id=attrs.substring(0,index1);
                            inHeaderAttr=attrs.substring(index1+1);
                         }

                         if(inputSearchInHeaderValue!="")
                         {

                            locationStr=buildURL(locationStr, id, inHeaderAttr, inputSearchInHeaderValue);
                            isAnyParam=true;
                         }

                         if(inputSearchInText.style.display!="none"&& inputSearchInText.value!="")
                         {
                            if(isAnyParam) locationStr+="&";
                            locationStr=buildURL(locationStr, id, inTextAttr, inputSearchInText.value);
                            if(!isAnyParam)isAnyParam=true;
                         }
                     }
                     else
                     {
                         locationStr="generalSearch.do?";
                         for( i=0; i<elements.length;i++)
                         {
                             elm=elements.item(i);
                             if(elm.type == "text" && elm.value!="")
                             {
                                 if(isAnyParam) locationStr+="&";
                                 locationStr+="attribute="+elm.id+"&condition=12&dictionaryValue=&textValue="
                                 + encodeURI(elm.value);
                                 isAnyParam=true;
                             }

                         }

                     }

                     if(isAnyParam) window.location=locationStr;
   }


  function showTextInput(typeSearch)
  {
       var attrs = typeSearch.value;
       var inputSearchInText=document.getElementById("1804282196");
       var inputSearchInTextLabel=document.getElementById("label_1804282196");

       if (attrs != "0" && attrs.indexOf("|")==attrs.lastIndexOf("|")){
            inputSearchInText.style.display="none";
            inputSearchInTextLabel.style.display="none";
       }
       else{
            inputSearchInText.style.display="";
            inputSearchInTextLabel.style.display="";
       }
  }


  function fillFormWithValues(objectType,inputHeaderValue,inputTextValue)
  {
     if(objectType!=null)
     {
       if(inputHeaderValue!="") document.getElementById("1804282193").value=inputHeaderValue;

       var attrsSelect= document.getElementById("typeSearchId");

       for(i=0; i < attrsSelect.options.length;i++){

           if(attrsSelect.options[i].value.indexOf(objectType)!=-1){

               var option = attrsSelect.options[i];
               option.selected=true;
               var inputSearchInText=document.getElementById("1804282196");
               if(option.value.indexOf("|")==option.value.lastIndexOf("|")) inputSearchInText.style.display="none";
               else if(inputTextValue!="") inputSearchInText.value=inputTextValue;

           }
       }

    }

  }


function enterKey(event)
 {
    if((event.keyCode == 0xA)||(event.keyCode == 0xD))
       {
          ssSubmit();return false;
       }
}


$("#calendar").ready(function(){

   $("#calendar").click(function(event) {
       onCalendarClickAction();
   })

   var menu2active=$("#gradient_calendar .menu2active")
   var calendarLink=$("#calendar");


   if(calendarLink.hasClass("menu1inactive_last")&&menu2active.length!=0)
   {
        var calendarMenuInActive=$(".calendarMenuInActive")
        if(calendarMenuInActive.length!=0)
        {
            calendarLink.addClass("menu1active");
            calendarLink.removeClass("menu1inactive_last");
            calendarMenuInActive.removeClass("calendarMenuInActive").addClass("calendarMenuActive")
            var calendarGradientDivs=$(".gradient_calendar")
            if(calendarGradientDivs.length!=0) calendarGradientDivs.remove()
            createGradient(3);

        }
   }
})



function onCalendarClickAction() {
       var calendarMenuActive=$(".calendarMenuActive")
       if(calendarMenuActive.length!=0)
       {
          calendarMenuActive.removeClass("calendarMenuActive").addClass("calendarMenuInActive")
          var calendarLink=$("#calendar");
          calendarLink.addClass("menu1inactive_last");
          calendarLink.removeClass("menu1active");
       }
       else
       {
            var calendarMenuInActive=$(".calendarMenuInActive")
	        if(calendarMenuInActive.length!=0)
	        {
		        calendarMenuInActive.removeClass("calendarMenuInActive").addClass("calendarMenuActive")

                var menu1active=$(".menu1active")

	        if(menu1active.length!=0)
	        {
		        menu1active.removeClass("menu1active").addClass("menu1inactive")
	        }
                var calendarLink=$("#calendar");
                calendarLink.removeClass("menu1inactive_last");
                calendarLink.addClass("menu1active");

                var menu2inactive=$(".menu2inactive")
	        if(menu2inactive.length!=0)
	        {
		        menu2inactive.css("display","none")
	        }

	        var menu2active=$(".menu2active")
	        if(menu2active.length!=0)
	        {
		        menu2active.css("display","none")
	        }

	    }
       }

       var menuGradientDivs=$(".gradient_menu")
       if(menuGradientDivs.length!=0) menuGradientDivs.remove()
       createGradient(2);
       var calendarGradientDivs=$(".gradient_calendar")
       if(calendarGradientDivs.length!=0) calendarGradientDivs.remove()
       createGradient(3);

       $('#calendar').unbind('click');
       $("#calendar").bind('click', function(event) {

           onCalendarClickAction();
       })
}



