// common yui utility used ilėn all the page
var DomObj=YAHOO.util.Dom // short cut instance onj
var EventObj=YAHOO.util.Event
var conObj=YAHOO.util.Connect

var interceptLink = function(e) { 
    EventObj.preventDefault(e);
    xInfo=DomObj.getRegion(this).right
	yInfo=DomObj.getRegion(this).top // get y and
	objLogin=document.getElementById('loginBox');  
	showLoginBox(e);
	DomObj.setY(objLogin,parseInt(yInfo)+25);
	DomObj.setX(objLogin,parseInt(xInfo)-140); 
 } 
  
 var hideLoginBox = function(e) { 
     EventObj.preventDefault(e);
	 objLogin=document.getElementById('loginBox');
	 DomObj.setStyle(objLogin, "display", "none");  
 } 
  
 var showLoginBox = function(e) { 
     EventObj.preventDefault(e);
	 objLogin=document.getElementById('loginBox');
	 DomObj.setStyle(objLogin, "display", "block");  
 } 
 
 
 function onMenuBarBeforeRender(p_sType, p_sArgs, p_oMenu) {
     this.getItem(0).cfg.setProperty("submenu", { id:"smigroupItem", itemdata: oSubmenuData["smigroupItem"] });
     this.getItem(1).cfg.setProperty("submenu", { id:"prodottiItem", itemdata: oSubmenuData["prodottiItem"] });
     this.getItem(2).cfg.setProperty("submenu", { id:"newsItem", itemdata: oSubmenuData["newsItem"] });
	 this.getItem(3).cfg.setProperty("submenu", { id:"contattiItem", itemdata: oSubmenuData["contattiItem"] });
     this.getItem(4).cfg.setProperty("submenu", { id:"mediaItem", itemdata: oSubmenuData["mediaItem"] });
     if(oSubmenuData["serviceItem"])this.getItem(5).cfg.setProperty("submenu", { id:"serviceItem", itemdata: oSubmenuData["serviceItem"]  });
 }

				
				
 YAHOO.example.onMenuBarAvailable = function(p_oEvent) {
	// Instantiate and render the menu bar
    var oMenuBar = new YAHOO.widget.MenuBar("headerTopMenu", { autosubmenudisplay:true, showdelay:150, hidedelay:750, lazyload:true });
        // Subscribe to the "beforerender" event
    oMenuBar.beforeRenderEvent.subscribe(onMenuBarBeforeRender, oMenuBar, true);
    oMenuBar.render();
	  
}
      //  set  the image path
YAHOO.widget.MenuBarItem.prototype.IMG_ROOT = serverPath+"js/yui/assets/";
YAHOO.widget.MenuBarItem.prototype.SUBMENU_INDICATOR_IMAGE_PATH = "menuarorght8_hov_1.gif"; 
YAHOO.widget.MenuBarItem.prototype.SELECTED_SUBMENU_INDICATOR_IMAGE_PATH = "menuarorght8_hov_1.gif"; 
YAHOO.widget.MenuBarItem.prototype.DISABLED_SUBMENU_INDICATOR_IMAGE_PATH = "menuarorght8_hov_1.gif";
	 
YAHOO.widget.MenuItem.prototype.IMG_ROOT = serverPath+"js/yui/assets/";
YAHOO.widget.MenuItem.prototype.SUBMENU_INDICATOR_IMAGE_PATH = "menuarorght8_hov_1.gif"; 
YAHOO.widget.MenuItem.prototype.SELECTED_SUBMENU_INDICATOR_IMAGE_PATH = "menuarorght8_hov_1.gif"; 
YAHOO.widget.MenuItem.prototype.DISABLED_SUBMENU_INDICATOR_IMAGE_PATH = "menuarorght8_hov_1.gif";
	
EventObj.onAvailable("headerTopMenu", YAHOO.example.onMenuBarAvailable);
EventObj.onAvailable("cvFooterBar", initCV);

//HTTP REQUEST FUNCTION
var args;
var sUrl = serverPath+"includes/functions/ajax.php";
var objCombo;
var divMainCont;
var divHttp;
var mode='html';

var handleSuccess = function(o){
   	if(o.responseText !== undefined){
       if(mode=='formValidation') {
             if(o.responseText=='OK') {
                hideContainer(divHttp)
                divHttp.innerHTML =''
                disableForm=false
                
             }
             else  {
               divHttp.innerHTML =o.responseText
               showContainer(divHttp)
               disableForm=true;
             }
       }
	   else if(mode!='html'){ 
	       myDataTxt = eval(o.responseText);
       		   populateComboBox(myDataTxt);
	   }
	   else {
         divHttp.innerHTML =o.responseText
	   }
 	}

};

var handleFailure = function(o){
	if(o.responseText !== undefined){
		alert('Enable to load XML data');
	}
};

var callback = {
   success:handleSuccess,
   failure:handleFailure,
   argument:args
};


function makeRequest(){
   var request = conObj.asyncRequest('POST', sUrl, callback, postData);
}

function updateCombo(Id,IdCombo,funzione){
	if(document.getElementById(Id)){
		valore=document.getElementById(Id).value  // get combo value
		objCombo=document.getElementById(IdCombo) // get combo obj
        boxFinderHandler(Id,valore)
		objTxt=objCombo.options[0].text           // get   combo   first item text label
		removeOption(objCombo)					//  clear  combo
		postData="funzione="+funzione+"&Azienda=''&Id="+valore
		sUrl = serverPath+"includes/functions/ajaxXML.php";
		divHttp=document.getElementById(IdCombo+'Box');
		mode='combo';
		insertOption(objCombo,'',objTxt)
		if(valore!=0)makeRequest()
	} 
 }
 
 

 function populateComboBox(dataList){
   for(i=0;i<dataList.length;i++){
      insertOption(objCombo,dataList[i].a,dataList[i].b)
   }
 }
 
 
// validate  the box finder object 
function validazioneBoxFinder(msg,objCombo){
	if(document.getElementById(objCombo).value!=''  || document.getElementById('packList').value!=''){
		formObject = document.getElementById('productFinder');
		curForm='productFinder';   
		conObj.setForm(formObject); 
		postData="remote=1";
		sUrl = serverPath+"includes/cat.inc.php";
		updateMainContainer()
		mode='html';	
	}
	else alert(msg)
	return false;
}

function  boxFinderHandler(IdCombo,valore){
  if(IdCombo!='companyList')return
  else if(valore=='smi'){
     DomObj.setStyle('packListBox', 'display', 'block');
  }
  else {
     DomObj.setStyle('packListBox', 'display', 'none');
     document.getElementById('packList').value=''
  }
  
  if(valore=='smiform'){
     DomObj.setStyle('capacityListBox', 'display', 'block');
  }
  else {
     DomObj.setStyle('capacityListBox', 'display', 'none');
     document.getElementById('capacityList').value=''
  }

}

function validazioneBoxService(msg,objCombo){
	if(document.getElementById(objCombo).value!=''){
		formObject = document.getElementById('serviceFinder');
		curForm='serviceFinder';   
		conObj.setForm(formObject); 
		postData="remote=1";
		sUrl = serverPath+"includes/blocks/service_helpdesk_footer.inc.php";
		updateMainContainer()
		mode='html';	
	}
	else alert(msg)
	return false;
}


// validate  the box contatti object 
function validazioneBoxContatti(msg,objCombo){
	if(document.getElementById(objCombo).value!=''){
        myAzienda=document.getElementById(objCombo).value
        if(myAzienda=='smi'){
          openMap('smigroup')
        }
        else if(myAzienda=='smipack')location.href='/profilo.php?article=smipack_vendita'
        return true;
	}
	else {
       alert(msg)
       return false;
    }
}



function validazioneBoxPosition(msg,objCombo){
	formObject = document.getElementById('jobFinder');
	curForm='jobFinder';   
	conObj.setForm(formObject); 
	postData="remote=1";
	sUrl = serverPath+"includes/modules/jobs/jobopp.inc.php";
	updateMainContainer()
	mode='html';	
}


/*****************  valido i campi della   form  **********/





var curX
var curY
var curStyle

function updateVideo(video,videoTitle,Obj){
	postData="remote=1&video="+video+"&videoTitle="+videoTitle;
	sUrl = serverPath+"includes/modules/media/video_player.inc.php";
    updateContainer(Obj)
  	mode='html';
    
}


function updateImageGallery(IdSerie,Idmediacategoria,Azienda,Obj,galleryTitle){
	postData="remote=1&IdSerie="+IdSerie+"&Idmediacategoria="+Idmediacategoria+"&companyList="+Azienda+"&Title="+galleryTitle;
	sUrl = serverPath+"includes/modules/media/imgGallery.inc.php";
    updateContainer(Obj)

  	mode='html';
    
}

	
 
function updateMainContainer(){
    divHttp=document.getElementById('contentBoxCenter');
	divHttp.innerHTML=''; 
	showWaitBox(divHttp);
	makeRequest()
}


function updateContainer(obj){
    divHttp=document.getElementById(obj);
	divHttp.innerHTML=''; 
  	//showWaitBox(divHttp);
	makeRequest()
}


function clearContainer(obj){
    document.getElementById(obj).innerHTML='';
	
}

 
 
 function showWaitBox(objTarget){
    objTarget.innerHTML='<center><div id="waitingBox" align="center"><img src="/smigroup/images/grid-loading.gif" border="0"><br><br>.....Loading.....</div></center>';
 }
 
 
 
//init Cv form
function initCV(){
  mostraForm('CVPersona')
}


function rollout(obj) {
	obj.className=obj.className.replace(new RegExp(" sfhover\\b"), "");
}

function rollon (obj){
   obj.className+=" sfhover";
}




// event handler  for   online editor

var load = function(carousel, start, last) {
    var oi=DomObj.getElementsByClassName('carousel-list','ul')
    DomObj.setStyle(oi,'width','10000px')
	for(var i=start;i<=last;i++) {
		carousel.addItem(i, fmtItem(newsArticleList[i-1]));
	}
}



var initOnlineEditor = function() {

   var editorDiv=DomObj.getElementsByClassName('bodyTextEditor','div')
   EventObj.addListener(editorDiv, 'click', activeEditor);
}

var activeEditor = function() {
  lingua=this.getAttribute('lang');
  page=this.getAttribute('page')
  url="/cms/cms/cmsEditor.php?Id_sez=webpage&Id_sub="+page+"&mode=edit&online=1&lang="+lingua
  location.href=url 
}





// function to manage  the  video this  clear the video div
var handleClick = function(e) {
    videoBox=DomObj.getElementsByClassName('videoBoxStyle','div')
    if(videoBox[0]){
        for(i=0;i<videoBox.length;i++){
          videoBox[i].innerHTML='';
      }
    }
};
EventObj.addListener(window, 'load', initOnlineEditor);





