var sito_title = 'Comune di Castelnuovo Rangone - Sito Ufficiale'
var sito_url = 'http://www.comune.castelnuovo-rangone.mo.it'
var sito_dominio = 'comune.castelnuovo-rangone.mo.it'

// antispam (almeno ci proviamo!)
function scrivi(nome) {
    	document.location = "mailto:" + nome + "@" + sito_dominio;
}

// defult status
defaultStatus = sito_title

// variabile random
var numero_random = (Math.random()*1000);

// tira fuori dal frameset
if (window != top) top.location = location;

// javascript:PopUPThis('imm/1.jpg');
function PopUPThis(img) {
	var fpop = window.open("","nome","width=100,height=100,menubar=no,toolbar=no,resizable=no,scrollbars=no");
	fpop.document.write('<html>\n');
	fpop.document.write('<head>\n');
	fpop.document.write('<title>' + sito_title + '</title>\n');  
	fpop.document.write('</head>\n');
	fpop.document.write('<script language=\'JavaScript\' type="text/javascript">\n');  
	fpop.document.write('function fitPic() {\n');  
	fpop.document.write('	var NS = (navigator.appName=="Netscape")?true:false;\n');
	fpop.document.write('	iWidth  = (NS)?window.innerWidth:document.body.clientWidth;\n');
	fpop.document.write('	iHeight = (NS)?window.innerHeight:document.body.clientHeight;\n');  
	fpop.document.write('\n');
	fpop.document.write('	var l = Math.floor((screen.availWidth  - document.images[0].width)/2);\n');
	fpop.document.write('	var a = Math.floor((screen.availHeight - document.images[0].height)/2);\n');
	fpop.document.write('\n');
	fpop.document.write('	iWidth  = document.images[0].width  - iWidth;\n');
	fpop.document.write('	iHeight = document.images[0].height - iHeight;\n');
	fpop.document.write('	window.resizeBy(iWidth, iHeight-1);\n');
	fpop.document.write('\n');
	fpop.document.write('	window.moveTo(l, a);\n');
	fpop.document.write('\n');
	fpop.document.write('	self.focus();\n');
	fpop.document.write('}\n');	
	fpop.document.write('</script>\n');
	fpop.document.write('<body style="margin:0px;" onLoad="fitPic();">\n');  
	fpop.document.write('<a href="javascript:self.close()"><img src="' + img + '" border="0" galleryimg="no" alt="Close"></a>\n');  
	fpop.document.write('</body>\n');
	fpop.document.write('</html>\n');
	fpop.document.close();
}

// pop up NO SCROLL
function winnoscroll(pag,w,h,nome) {
  var l = Math.floor((screen.availWidth-w)/2); 
  var a = Math.floor((screen.availHeight-h)/2);
  fin = window.open(pag,nome,"width="+w+",height="+h+",menubar=no,toolbar=no,resizable=no,scrollbars=no,left=" + l + ",top=" + a);
}

// pop up CON SCROLL
function winscroll(pag,w,h,nome) {
  var l = Math.floor((screen.availWidth-w)/2); 
  var a = Math.floor((screen.availHeight-h)/2);
  fin = window.open(pag,nome,"width="+w+",height="+h+",menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=" + l + ",top=" + a);
}

// funzione per scopri copri pezzi di codice
function scopri(a) {
	if(document.getElementById(a).style.display != 'block') {
		document.getElementById(a).style.display = 'block';
	} else {
		document.getElementById(a).style.display = 'none';
	}
}

// funzione per rub_row
function rub_row(rid) {	
	scopri('rub_row_s_'+rid);	
	scopri('rub_row_f_'+rid);
}

function rub_el(rid) {	
	document.getElementById('l_i_DESC').style.display = 'none';	
	for (var l=65; l <= 90; l++)	 
		if (document.getElementById('l_i_'+String.fromCharCode(l))) document.getElementById('l_i_'+String.fromCharCode(l)).style.display = 'none';	
  
	document.getElementById('l_i_'+rid).style.display = 'block';	
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

//Bookmark Page

//
isIE = isIE4 = isIE5 = isIE6 = isIE7 = isNS = isNS4 = isNS6 = isNS7 = isNS8 = isFlash5 = isFlashMX = false;

// Browser Detection
if(navigator.appName.indexOf('Netscape') == 0) isNS = true;
if(navigator.appName.indexOf('Microsoft') == 0) isIE = true;
isUNIX = (window.navigator.appVersion.indexOf("X11") != -1) ||
         (window.navigator.appVersion.indexOf("Linux") != -1) ||
         (window.navigator.appVersion.indexOf("SunOS") != -1) ||
         (window.navigator.appVersion.indexOf("IRIX") != -1) ||
         (window.navigator.appVersion.indexOf("HP-UX") != -1);
isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
isWindows = navigator.userAgent.indexOf("Windows 95") != -1 ||
            navigator.userAgent.indexOf("Windows 98") != -1 ||
            navigator.userAgent.indexOf("Windows NT") != -1;
isMacIE = (isMac && isIE);

// Netscape Version
if(isNS) {
  v = parseInt(navigator.appVersion);
  if(v == 4) {
    isNS4 = true;
  } else if(v == 5) {
    p = navigator.userAgent.lastIndexOf('/');
    v = parseInt(navigator.userAgent.substr(p+1));
    eval("isNS" + v + " = true");
  }
}

// Internet Explorer Version
if(isIE) {
  v = parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+5));
  eval("isIE" + v + " = true");
}


//Bookmark Page

function addbookmark() { 
  var bookmarktitle = sito_title;
  var bookmarkurl = sito_url;
  var netscape
  var macintosh
  netscape="Attenzione! Per aggiungere questa pagina ai Preferiti premere CTRL+D.\n\nPer aggiungere questa pagina alla Sidebar di Netscape, premi OK alla schermata successiva.\n\nAttention! To Bookmark this page please click the page you would like to bookmark and press CTRL+D. If you would like to add this page to your Netscape Sidebar, please click OK on the next window which appears.";
  macintosh="Attenzione! Per aggiungere ai Preferiti questa pagina premere CTRL+D.\n\nAttention! To Bookmark this page please click the page you would like to bookmark and press CTRL+D.";

  if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
    window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
  } else if (isMac) {
    alert(macintosh);
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  }
}



///////////////////////////////////////////////////////////////////////////////////////////////////////

// AC Run Active Content
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////

// cambia lingua
// le cartelle devono essere di 2 lettere 
// si passa il nome della cartella (es: it, en, es, fr, de, ecc)
function cl(quale){
	var lunghezza = sito_url.length 
	var tuttoUrl = String ( document.location ) 
	var lingua = "/" + tuttoUrl.slice ( lunghezza + 1, lunghezza + 3 ) + "/"
	var nuovoUrl = tuttoUrl.replace( lingua , "/" + quale + "/" ) 
	document.location = nuovoUrl;
}


function swimgph(q,d) {
	document.getElementById('iph'+q+'s').src = '/immagini/ph_'+q+'_s_'+d+'.gif';	
}

//o

function openD(theURL) {
  var l = Math.floor((screen.availWidth-580)/2); 
  var a = Math.floor((screen.availHeight-400)/2);
  window.open(theURL,'cv_news',"width=580,height=400,menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=" + l + ",top=" + a);
}

function openNI(dd) {
  var l = Math.floor((screen.availWidth-580)/2); 
  var a = Math.floor((screen.availHeight-400)/2);
  window.open('/dd_ni.htm?ID='+dd,'cv_news_i',"width=580,height=400,menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=" + l + ",top=" + a);
}

function PopupPic(sPicURL) { 
  /*window.open("/popup.htm?"+sPicURL, "", "resizable=0,HEIGHT=10,WIDTH=10");*/
  PopUPThis(sPicURL);  
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve contenere un numero tra '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è un campo obbligatorio.\n'; }
  } if (errors) alert('ATTENZIONE!\nSi sono verificati i seguenti errori:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}


function trim(strText) {
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function isFilled(object,idx) {
var str = trim(object.value);
   if (str.length > 0) return true;
   else {
      window.alert(msg[idx]);
      object.focus();
      return false;
  }
}

function isSelected(object,idx) {
var str = trim(object.value);
   if (str != "-1")  return true;
   else {
      window.alert(msg[idx]);
      object.focus();
      return false;
  }
}

function isNumber(object,idx) {
var str = trim(object.value);
   if ((str.length > 0) && (numCheck(str))) return true;
   else {
      window.alert(msg[idx]);
      object.focus();
      return false;
  }
}

function isEmail(object,idx) {
var str = trim(object.value);
   if (emailCheck(str)) return true;
   else {
      window.alert(msg[idx]);
      object.focus();
      return false;
  }
}


function isChecked(object,idx) {	
   if (object.checked) return true;
   else {
      window.alert(msg[idx]);
      object.focus();
      return false;
  }
}


function atLeastOneChecked(theForm,object,idx) {
  var nb;
  var chk;

  chk=false

  nb = theForm.elements.length;
  for (var i=0;i<nb;i++) {
    var e = theForm.elements[i];
    if (object == e.name) {
      if (e.checked) chk=true;
    }
  }

  if (chk)  return true;
   else {
      window.alert(msg[idx]);
      return false;
  }
}


function numCheck(argvalue) {

  if (argvalue.length == 0)
    return false;

  for (var n = 0; n < argvalue.length; n++)
    if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
      return false;

  return true;

}


function emailCheck(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  var retSize = customSplit(argvalue, "@", "arrayString");

  if (arrayString[1].indexOf(".") == -1)
    return false;
  else if (arrayString[1].indexOf(".") == 0)
    return false;
  else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }

  return true;

}


function customSplit(strvalue, separator, arrayName) {
  var n = 0;

  if (separator.length != 0) {
    while (strvalue.indexOf(separator) != -1) {
      eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
      strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
          strvalue.length+1);
      n++;
    }
    eval("arr" + n + " = strvalue;");
    arraySize = n+1;
  }
  else {
    for (var x = 0; x < strvalue.length; x++) {
      eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
      n++;
    }
    arraySize = n;
  }

  eval(arrayName + " = new makeArray(arraySize);");

  for (var i = 0; i < arraySize; i++)
    eval(arrayName + "[" + i + "] = arr" + i + ";");

  return arraySize;
}


function makeArray(IntarrSize) {

  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";

  return this;

}

/*---*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}




