$(document).ready(function(){
		
	// first example
	$(".treeMenu").treeview({
		persist: "location",
		collapsed: true
		
	}); 
	
	
		selectedUl=$('.treeMenu .selected').parent().parent();
		if(selectedUl.css('display')=='none'){
			selectedUl.css('display','block');
			div=selectedUl.parent().find('div');
			selectedUl.parent().removeClass('expandable').addClass('collapsable');
			div.removeClass('expandable-hitarea').addClass('collapsable-hitarea');
		}
	
	$('.moreLink').click(function(){
		newWindow(this.href,500,400);
		return false;
	})
	
	});

               function newWindow(link,width,height){
                    window.open(link,"","height="+height+", width="+width+",menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,left=50,top=150")
               }

var cmd;
var _ifName;

function open_color_picker()
{
window.open("color_picker.htm","my_window","toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=330")
}

function setC(color) {

  document.getElementById(_ifName).contentWindow.document.execCommand(cmd, false, color);

}


function insert(id,ifName) {
_ifName=ifName;
 if ((id == "forecolor") || (id == "hilitecolor")) {
    cmd = id;
    if(cmd == "hilitecolor") {
     try {
          document.getElementById(ifName).contentWindow.document.execCommand("hilitecolor", false, "white");
        }  catch (e) { cmd = "backcolor"; }
    }
    open_color_picker();
 }
 else
 if (id == "createlink") {
    var url = prompt("URL:", "http://");
    if ((url != null) && (url != "")) {
      document.getElementById(ifName).contentWindow.document.execCommand("CreateLink",false,url);
    }
 }
 else 
 document.getElementById(ifName).contentWindow.document.execCommand(id, false, null);
 //document.getElementById("myif").contentWindow.focus();
 
}


function _select(selectname,ifName)
{
  var selIndex = document.getElementById(selectname).selectedIndex;
  if (selIndex != 0) {
    var selected = document.getElementById(selectname).options[selIndex].value;
    document.getElementById(ifName).contentWindow.document.execCommand(selectname, false, selected);
    document.getElementById(selectname).selectedIndex = 0;
  }
  document.getElementById(ifName).contentWindow.focus();
}

function viewSource(source,ifName)
{
  
  if(document.body.innerText) {
   
   if (source) {
   iHTML = document.getElementById(ifName).contentWindow.document.body.innerHTML;
   document.getElementById(ifName).contentWindow.document.body.innerText = iHTML;
   }
   else {
   iText = document.getElementById(ifName).contentWindow.document.body.innerText;
   document.getElementById(ifName).contentWindow.document.body.innerHTML = iText;
   }
  
  }
   else {


   if (source) {
    html = document.createTextNode(document.getElementById(ifName).contentWindow.document.body.innerHTML);
    document.getElementById(ifName).contentWindow.document.body.innerHTML = "";
    document.getElementById(ifName).contentWindow.document.body.appendChild(html);
  } else {
    html = document.getElementById(ifName).contentWindow.document.body.ownerDocument.createRange();
    html.selectNodeContents(document.getElementById(ifName).contentWindow.document.body);
    document.getElementById(ifName).contentWindow.document.body.innerHTML = html.toString();
  }
  
  }

}


function change_inner2(obj,id)
 {
  
	 	 arrayR=obj.src.split('/');
	 	document.getElementById(obj);
	 	 rootArray=new Array();
	 	 for(i=0;i<arrayR.length-1;i++)
	 	    rootArray[i]=arrayR[i];
	 	 
	 	  root=rootArray.join('/');   
	 	  root+="/";
	 	 
		 imgs1=Array('plus.gif','plusbottom.gif','plusupper.gif')	 
		 imgs2=Array('minus.gif','minusbottom.gif','minusupper.gif')	 
		 for(i=0;i<3;i++){
			  if(obj.src==root+imgs2[i]){
			      obj.src=root+imgs1[i];
			      
			  }
			  else
			  if(obj.src==root+imgs1[i]){
			      obj.src=root+imgs2[i];
			  }
		 }
   
      
 }

function change_inner(id)
 {
//if(document.getElementById('_'+id))
  if(document.getElementById('_'+id).innerHTML=="+")
    document.getElementById('_'+id).innerHTML="-";
  else
    if(document.getElementById('_'+id).innerHTML=="-")
      document.getElementById('_'+id).innerHTML="+";

 }

function dhtml_shortMenu_show(id,message)
   {
   	
  	if(document.getElementById(id))
     if(document.getElementById(id).innerHTML!="")
       {
         document.getElementById(id).innerHTML="";
       }
     else
      {
       document.getElementById(id).innerHTML=message;
      }
   	
   }
 function openElements(id){
 	id=id.toString();
 	array=id.split(0);
 	
 	code="<script>";
 	for(i=0;i<array.length;i++){
 		newArray=new Array();
 		
 		for(j=0;j<=i;j++)
 	      newArray[j]=array[j];
 	      newId=newArray.join(0);
 	    
 	   code+="try{";
 	   code+="dhtml_shortMenu_show("+newId+",item_"+newId+");"
 	   code+="change_inner2(img_"+newId+","+newId+");}catch(e){}";
 	   
 	 
 	   
 	    
 	 
 	  //open element
 	  
 	}
 	code+='</script>';
 	
 	document.writeln(code);
 	
 }
 
 
 function openCatElements(openable){
 	openable=openable.toString();
 	if(openable!=''){
 	array2=openable.split('-');
 	
 	code="<script>";
 	  for(j=0;j<array2.length;j++){
 	  	
 	  
   	   code+="dhtml_shortMenu_show("+array2[j]+",cats_item_"+array2[j]+");"
 	   code+="change_inner2(cats_img_"+array2[j]+","+array2[j]+");";

 	  }
 	
 	code+='</script>';
 	
 	document.writeln(code);
 	}
 	
 }
 
  function openBrandsElements(openable){
 	openable=openable.toString();
 	
 	if(openable!=''){
 	array2=openable.split('-');
 	
 	code="<script>";
 	  for(j=0;j<array2.length;j++){
 	  	
	   	   code+="dhtml_shortMenu_show("+array2[j]+",brands_item_"+array2[j]+");"
	   	  
	 	   code+="change_inner2(brands_img_"+array2[j]+","+array2[j]+");";

 	  }
 	
 	code+='</script>';
 	
 	document.writeln(code);
 	}
 	
 }
   
function doNothing( ) {return true;}
//window.onerror = doNothing;

function del_goto(link){
               	  if(confirm('Sunteti sigur ca vreti sa stergeti?'))
                       window.location.href=link;
               }

               function newWindow(link,width,height){
                    window.open(link,"","height="+height+", width="+width+",menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=50,top=150")
               }
               function load() {
 				
                       if(document.getElementById("myIf")){
                          document.getElementById("myIf").contentWindow.document.designMode = "On";
                          document.getElementById("html").checked = false;
                       }
                      if(document.getElementById("myIf1")){
                          document.getElementById("myIf1").contentWindow.document.designMode = "On";
                          document.getElementById("html").checked = false;
                       }

               }

			   function submitForm(obj,ifName){
			      obj.eText.value= document.getElementById(ifName).contentWindow.document.body.innerHTML;
			      obj.submit();
			   }
			   
function addTable(ifName){
var rows = prompt("rows","");
var cols = prompt("cols","");
var border= prompt("border","");
var cellspacing= prompt("cell spacing","");
var cellpadding= prompt("cell padding","");
html='<table border='+border+' cellspacing='+cellspacing+' cellpadding='+cellpadding+'>';	
for(i=0;i<rows;i++){
	html+='<tr>';	
	for(j=0;j<cols;j++){
	html+='<td></td>';	
	}
	html+='</tr>';	
}
html+='</table>';	

	document.getElementById(ifName).contentWindow.document.execCommand('inserthtml',false,html);
}

