var h="/html/homepage/";
var url = document.location.protocol +'//' + document.location.host +'/webapp/wcs/stores/mediaworld/include/TESTajax_home.jsp?';
function start(){
delcookie();
StickyAd.load();
}
var startingUrl = document.location.protocol+'//' + document.location.host + '/webapp/wcs/stores/servlet/';
var emptyList = '<select id="capcombo"><option value="-1">-</option></select>';
function AJAXCall(strURL, strSubmit, strResultFunc, elemId, imgdir) {
   var immagine = '<img height="30px" src="'+imgdir+'/ajax-loader.gif\"></td>';
   if(imgdir != null && imgdir != '' && imgdir != 'undefined') putHtml(elemId, immagine);	
   var xmlHttpReq = false;
   if(window.XMLHttpRequest) { // Mozilla/Safari
		xmlHttpReq = new XMLHttpRequest();
		if (navigator.appVersion.indexOf("MSIE 7") < 0 && navigator.appVersion.indexOf("MSIE 8") < 0 && navigator.appVersion.indexOf("MSIE 9") < 0) {
			xmlHttpReq.overrideMimeType('text/xml');
		}
   }
   else if (window.ActiveXObject) { // IE
      xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
   }
    // Timeout to abort in 10 seconds 
	var xmlHttpTimeout = setTimeout(ajaxTimeout, 15000); 
	function ajaxTimeout(){ 
	xmlHttpReq.abort(); 
	}
   xmlHttpReq.open('POST', startingUrl + strURL + strSubmit, true);
   xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpReq.onreadystatechange = function() {
      if(xmlHttpReq.readyState==4) {
         if((elemId!=null)&&(elemId!="")) eval(strResultFunc+'(elemId,xmlHttpReq.responseText);');
         else eval(strResultFunc+'(xmlHttpReq.responseText);');
         }
   }
   xmlHttpReq.send(startingUrl + strURL + strSubmit);
   delete xmlHttpReq;   
   window.scrollTo(0,0);
}

function putSelectHtml(id,txt) {
	select_innerHTML(getElement(id),txt);
}

function putHtml(id,txt) {
	getElement(id).innerHTML=txt;
}

function showHtml(id,txt) {
var css = document.URL.substr(0,document.URL.indexOf('webapp'))+"html/css_new/style.css";
getElement(id).innerHTML=getCss(css)+txt;}

function delcookie(){
	//Imposto la scadenza dei cookies ad un giorno indietro per ottenere la loro eliminazione
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli-1*24*60*60*1000);
	UTCstring = Today.toUTCString();		
	//Imposto il path dei cookies da cancellare uguale a quello di creazione
	path=";path=/webapp/wcs/stores/servlet"; 
	//Elimino i cookies
	document.cookie="sid=;expires="+UTCstring+path;
	document.cookie="sitopunti=;expires="+UTCstring+path;
	//Ritorno su MDW non essendoci più i cookie
}
	
function getPageRequest(url){
	var page_request = false;
	if (window.XMLHttpRequest)
		page_request = new XMLHttpRequest();
	if(window.XMLHttpRequest) {
   		page_request = new XMLHttpRequest();
		if (navigator.appVersion.indexOf("MSIE 7") < 0 && navigator.appVersion.indexOf("MSIE 8") < 0 && navigator.appVersion.indexOf("MSIE 9") < 0) {
			page_request.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) {
   		page_request = new ActiveXObject("Microsoft.XMLHTTP");
	} else return false
	return page_request;
}

function ajaxinclude(url){
 var pr = GetCall(getPageRequest(url),url);
 if (window.location.href.indexOf("http")==-1 || pr.status==200)
 document.write(pr.responseText)
}
	 
function GetCall(pr,url){
 	pr.open('GET', url, false);
	pr.send(null);
	return pr;	 
}
	 
function getContent(url) {
	return GetCall(getPageRequest(url),url).responseText;
}	 
     
function getCss(url){
	return '<style rel=\"stylesheet\" type=\"text/css\">\n'+getContent(url)+'</style>';
}
function getElement(id) { return document.getElementById(id); }

	 	var StickyAd = {
		load:function() {
			if(top.document.body) {
				window.onscroll = StickyAd.reLoad;
				window.onresize = StickyAd.reLoad;
				this.reLoad();
				getElement("StickyAdLayerTop").style.display="block";
				getElement("StickyAdLayer").style.display="block";
			}
		},
		reLoad:function() {
		var t = getElement("StickyAdLayerTop");
		var b = getElement("StickyAdLayer");
			t.style.top = 0;			
			b.style.top = 93 + top.document.body.scrollTop + (Math.max(1, 6 - top.document.body.scrollTop));
			if (top.document.body.clientWidth > 1024) {
				t.style.left = 1002;
				t.style.visibility = "visible";
				b.style.left = 995;
				b.style.visibility = "visible";				
			}
			else {
				t.style.left = 0;
				t.style.visibility = "hidden";
				b.style.left = 0;
				b.style.visibility = "hidden";
			}
		}
	}
	
	function select_innerHTML(objeto,innerHTML){
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span");
    innerHTML = innerHTML.toUpperCase();
    alert(innerHTML);
    selTemp.innerHTML = innerHTML
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}

function getSelectedValue(obj){
var opzioni = obj.options;
var lunghezza = opzioni.length;
var answer = "";
var unOpzione;
for(var i = 0; i < lunghezza; i++){
	unOpzione = opzioni[i];
	if(unOpzione.selected) answer += unOpzione.value;
} 
return answer
}

function putEmptyList(id){
putHtml(id,emptyList);
}
