//Workaround per l'inserimento dinamico di elementi in firefox
if( typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement ) {
	HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) { 
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function (where,txtStr) {
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

function ShowProductLine(id_product_line)
{
	//var arr_linee_prodotti=['1','2','3'];
	//document.getElementById('intro').style.visibility='hidden';
	document.getElementById('intro').style.display='none';
	for(var i=0;i<(arr_linee_prodotti.length);i++)
	{
		//document.getElementById('div_linea_prodotto_'+arr_linee_prodotti[i]).style.visibility='hidden';
		document.getElementById('div_linea_prodotto_'+arr_linee_prodotti[i]).style.display='none';
		document.getElementById('li_linea_prodotto_'+arr_linee_prodotti[i]).className='';
	}
	if(id_product_line=='intro')
	{
		//document.getElementById('intro').style.visibility='visible';
		document.getElementById('intro').style.display='block';
	}else{
		//document.getElementById('div_linea_prodotto_'+id_product_line).style.visibility='visible';
		document.getElementById('div_linea_prodotto_'+id_product_line).style.display='block';
		document.getElementById('li_linea_prodotto_'+id_product_line).className='selected';
	}
}

function IsNumeric(strString)
   {
   var strValidChars = "0123456789.-/ ";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

var whitespace = " \t\n\r";
function isEmail(s){
	if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")){ 
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
function isWhitespace(s){
	var i;
	if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}


function preferiti()
{
	var ua=navigator.userAgent.toLowerCase();
	var isKonq=(ua.indexOf('konqueror')!=-1);
	var isSafari=(ua.indexOf('webkit')!=-1);
	var isMac=(ua.indexOf('mac')!=-1);
	var buttonStr=isMac?'Command/Cmd':'CTRL';
	
	if(window.external && (!document.createTextNode ||
	  (typeof(window.external.AddFavorite)=='unknown'))) {
		window.external.AddFavorite(location.href,document.title); // IE
	} else if(window.sidebar){ // firefox
		window.sidebar.addPanel(document.title, location.href,"");
	} else if(isKonq) {
	} else if(window.opera) {
	  alert('Per aggiungere questa pagina nei preferiti premere '+buttonStr+' + D');
	} else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
	  alert('Per aggiungere questa pagina nei preferiti premere '+buttonStr+' + D');
	} else if(!window.print || isMac) { // IE5/Mac e Safari 1.0
	}
} 

function SearchKeyword(keyword)
{
	if(keyword)
	{
		if(document.getElementById('query'))
		{
			document.getElementById('query').value='"'+keyword+'"';
			if(document.getElementById('query'))
			{
				document.getElementById('search_form').submit();
			}
		}
	}
}

function selectAllInput(elm)
{
    if (elm)
    {
        elm.focus();
        elm.select();
    }
}


function stampa(){
	print();
	//window.close();
}

function CambiaLingua(){
	var combo_lingua=document.getElementById('language');
	var sel_lingua=combo_lingua.selectedIndex;
	var valore=combo_lingua.options[sel_lingua].value;
	if(valore)
	{
		setCookieLanguage(valore)
		document.location="http://www.marposs.com/index.php/"+valore;
	}
}

function setCookieLanguage(language){
	if(language != ''){
		var dataOggi = new Date()
		var dataExpires = new Date()
		var durataGiorniCookieLanguage=30;
		dataExpires.setTime(dataOggi.getTime() + 24 * durataGiorniCookieLanguage * 3600000);
		document.cookie = 'Marposs_Language'+'='+escape(language)+''+'; path=/'+'; expires='+dataExpires.toGMTString();
	}
}

function RedirToUrl(url,timeout) {
	//es:
	//RedirToUrl("http://www.marposs.com/contact.php/eng","5");
	timeout=timeout*1000;
	timerID = setTimeout(function(){window.location=url;},timeout);
}
