
function isNetscape()
{
browser_ie = browser_nn = browser_nn6 = platform_win = platform_mac = false;
navigator.appName == "Microsoft Internet Explorer" ? browser_ie = true : navigator.appName == "Netscape" ? parseInt(navigator.appVersion.charAt(0),10) >= 5 ? browser_nn6 = true : browser_nn = true : null;
navigator.userAgent.indexOf('Win') == -1 ? platform_mac = true : platform_win = true;

return browser_nn || browser_nn6;
}

function isMac()
{
browser_ie = browser_nn = browser_nn6 = platform_win = platform_mac = false;
navigator.appName == "Microsoft Internet Explorer" ? browser_ie = true : navigator.appName == "Netscape" ? parseInt(navigator.appVersion.charAt(0),10) >= 5 ? browser_nn6 = true : browser_nn = true : null;
navigator.userAgent.indexOf('Win') == -1 ? platform_mac = true : platform_win = true;

return platform_mac;
}

function checkRFCEmail(email)
{
var reg1 = /^.*\<[a-zA-Z0-9\-\._]+\@[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}\>$|^[a-zA-Z0-9\-\._]+\@[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}$/;
return reg1.test(email);
}

function isFirefox()
{
var browser_firefox = (navigator.userAgent.indexOf("Firefox/") >=0) ? true : false;
return browser_firefox;
}


function IEVersion()
{
agent=navigator.userAgent;
ver=agent.replace(/(.*)MSIE (\d*.\d*);(.*)/gi,"$2");
return parseFloat(ver);
}

//---------------------------------------------
// setParameter()
//---------------------------------------------
// in:	(sParam)	parametro da cercare
//			(sValue)	valore da impostare
//			(sURL)		URL
// out:	la stringa di search
function setParameter(sParam, sValue, sURL){
	var rxParam=new RegExp(sParam+"=");

	//Ottieni la stringa di search
	var nPos=sURL.search(/\?/);
	var sSearch="?open";
	if (nPos>=0){	sSearch=sURL.substr(nPos); }

	//Se non è stato trovato il parametro, aggiungilo
	if ((nPos=sSearch.search(sParam))==-1){	return sSearch+"&"+sParam+"="+sValue;	}

	//Ottieni la coda se esiste
	var sBuf=sSearch.substr(nPos);
	var sTail="";
	if(sBuf.search(/&/)!=-1){ sTail=sBuf.substr(sBuf.search(/&/)); }

	//Imposta il parametro
	return sSearch.substr(0,nPos)+sParam+"="+sValue+sTail;
}

// Torna il valore selezionato da una select list di un dato form
  function getSelectedValue(formname, selectname) {
    //len = eval("document." + formname + "." + selectname + ".length");
    len = document.forms[formname].elements[selectname].length;
    //alert(len);
    for (var i = 0; i < len; i ++) {
      if (document.forms[formname].elements[selectname].options[i].selected == true)
        return document.forms[formname].elements[selectname].options[i].value;
    }//end for i
    return null;
  }//end function getSelectedValue(...)

  // Torna il nome selezionato da una select list di un dato form
  function getSelectedText(formname, selectname) {
    len = document.forms[formname].elements[selectname].length;
    for (var i = 0; i < len; i ++) {
      if (document.forms[formname].elements[selectname].options[i].selected == true)
        return document.forms[formname].elements[selectname].options[i].text;
    }//end for i
    return null;
  }//end function getSelectedText(...)

  // Torna l'indice del valore selezionato da una select list di un dato form
  function getSelectedIndex(formname, selectname) {
    len = document.forms[formname].elements[selectname].length;
    for (var i = 0; i < len; i ++) {
      if (document.forms[formname].elements[selectname].options[i].selected == true)
        return i;
    }//end for i
    return null;
  }//end function getSelectedIndex(...)

// torna il nome della pagina passato come parametro
// es: www.arscolor.com/test.asp?id=45 torna 'test.asp'
function getPageName(stringa)
  {

  stringa.match(/[^\?]*\/([^\?]*)(\?)?[^\?]*$/);
  return RegExp.$1;

  }

function queryString()
{
var i;

name=arguments[0];

if (arguments.length==2)
    target=arguments[1];
else
	target=self;

query=target.location.search;
query=query.substr(1);

params=new Array();
params=query.split("&");

for (valore="",i=0;i<params.length;i++)
{
v=params[i];
pos=v.indexOf("=");
if (v.substring(0,pos)==name)
{
valore=unescape(v.substr(pos+1).replace(/\+/gi, " "));
break;
}
}

return valore;
}//end function

function openPopup()
{

Page=arguments[0];
Name=arguments[1];
w=parseInt(arguments[2]);
h=parseInt(arguments[3]);

          if (arguments.length>4)
             sb=arguments[4];
         else
                 sb='yes';

          if (arguments.length>5)
             rsz=arguments[5];
         else
                 rsz='yes';

      mywidth = w;
      myheight = h;
      x = (screen.width - mywidth)/2;
      y = (screen.height - myheight)/2;
      newwin = window.open(Page, Name, "scrollbars=" + sb + ",resizable=" +
rsz + ",left="+x+",top="+y+",width=" + w + ",height=" + h );
      newwin.creator=self;
}


function popImageExtra(imageURL,imageTitle,AutoClose,oTimeClose,extraHTML){
	//really not important (the first two should be small for Opera's sake)
	PositionX = 10;
	PositionY = 10;
	defaultWidth  = 600;
	defaultHeight = 400;
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function getRefToDivMod( divID, oDoc ) {\n'+
			'if( !oDoc ) { oDoc = document; }\n'+
			'if( document.layers ) {\n'+
			'if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {\n'+
			'for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {\n'+
			'y = getRefToDivNest(divID,oDoc.layers[x].document); }\n'+
			'return y; } }\n'+
			'if( document.getElementById ) { return oDoc.getElementById(divID); }\n'+
			'if( document.all ) { return oDoc.all[divID]; }\n'+
			'return document[divID];\n'+
		'}\n'+
		'function resizeWinTo() {\n'+
			'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
			'if( !document.images[0].height || window.doneAlready ) { return; }\n'+ //in case images are disabled
			'var oH = getRefToDivMod( \'myID\' ); if( !oH ) { return false; }\n'+
			'var oW = oH.clip ? oH.clip.width : oH.offsetWidth;\n'+
			'var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }\n'+
			'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
			'window.doneAlready = true;\n'+ //for Safari and Opera
			'if(document.getElementsByTagName) {\n'+
				'for( var l = document.getElementsByTagName(\'a\'), x = 0; l[x]; x++ ) {\n'+
					'if(l[x].className==\'makeright\'&&!l[x].style.position){\n'+
						'l[x].style.position=\'relative\';\n'+
						'l[x].style.left=(document.images[0].width-(l[x].offsetWidth+l[x].offsetLeft))+\'px\';\n'+
			'}}}\n'+
			'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
			'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
			'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
			'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
			'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
			'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
			'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
			'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
			'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
			'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
			(oTimeClose?('window.setTimeout(\'window.close()\','+oTimeClose+');\n'):'')+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0" id="myID">'):('<div style="position:absolute;left:0px;top:0px;" id="myID">'))+
		'<img src='+imageURL.replace(" ","%20")+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(extraHTML?extraHTML:'')+(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}
