String.prototype.empty = '';
String.prototype.startsWith = function ( /*String*/start ) {
    if ( start == null || start == '' )return false;
    return (this.indexOf(start) == 0);
}

String.prototype.endsWith = function ( /*String*/end ) {
    if ( end == null || end == '' )return false;

    var endL = end.length;
    var l = this.length;
    if ( l < endL )return false;
    var offset = l - endL;

    return (this.lastIndexOf(end) == offset )
}


String.prototype.trim = function () {
    if ( this == null || typeof(this) == 'undefined' )return this;
    var tmp = this.replace(/^\s+/g, "");
    return tmp.replace(/\s+$/g, "");
}


String.prototype.equals = function( /*Object*/obj ) {
    if ( obj == null ) {
        return (this == obj);
    }
    return this == obj.toString();
}

String.prototype.isEmpty = function() {
    if ( this == null )return true;
    return this.equals(String.empty);
}

String.prototype.replaceAll = function( oldStr, newStr ) {
    return this.split(oldStr).join(newStr);
}

String.prototype.replaceAllIgnoreCase = function( oldStr, newStr ) {
    return this.toLowerCase().split(oldStr.toLowerCase()).join(newStr);
}

String.prototype.containsIgnoreCase = function( /*String*/ strToSearch ) {
    if ( strToSearch != null && typeof(strToSearch).equals("string") ) {
        if ( !strToSearch.isEmpty() ) {

            return  this.toUpperCase().contains(strToSearch.toUpperCase());
        }
        return false;
    }
    return false;

}

String.prototype.contains = function( /*String*/ strToSearch ) {

    if ( strToSearch != null && typeof(strToSearch).equals("string") ) {
        if ( !strToSearch.isEmpty() ) {
            return this.indexOf(strToSearch) != -1;
        }
        return false;
    }
    return false;
}


String.prototype.countOf = function(pattern){
                var ar = this.split(pattern);
                return ar.length-1;
}


Client = new function() {
    this.screen = parseInt(window.screen.height, 10);
    this.OPERA = 'OPERA';
    this.IE = 'IE';
    this.FIREFOX = 'FIREFOX';
    this.SAFARI = 'SAFARI';
    this.MOZ = 'MOZILLA';
}

Browser = new function() {
    /*private prop*/
    var u = new String(navigator.userAgent), d = document;

 
    this.ie = (/MSIE /.test(u) && !u.containsIgnoreCase(Client.OPERA))?true:false;
    this.ns4 = typeof d.layers != "undefined";
    this.dom = typeof d.getElementById != "undefined";
    this.safari = /Safari/.test(u);
    this.moz = /Gecko/.test(u) && !(u.containsIgnoreCase(Client.SAFARI) || u.containsIgnoreCase(Client.OPERA));
    this.firefox = /Gecko/.test(u) && !(u.containsIgnoreCase(Client.SAFARI) || u.containsIgnoreCase(Client.OPERA)) && u.containsIgnoreCase(Client.FIREFOX);
    this.mie = /MSIE /.test(u) && /Mac/.test(u);
    this.opera = u.containsIgnoreCase(Client.OPERA);
    this.o7 = /Opera 7/.test(u);
    this.o8 = /Opera\/8.0/.test(u);
    /*OS*/
    this.win9x = /Win9/.test(u) || /Windows 9/.test(u);
    this.winNT = /Windows NT 5.1/.test(u);

};



/*workaround for fireFox*/
function collapseElement(/*HTMLElement*/ element ) {
    if ( element.className.toLowerCase().indexOf("elementcollapsed") == -1 )
        element.className += ' elementcollapsed';
}
function uncollapseElement(/*HTMLElement*/  element ) {
    element.className = element.className.replaceAllIgnoreCase('elementcollapsed', '');
}
// end workaround

function getObj( id ) {
    return document.getElementById(id);
}


// creatge event hander and dispath for HTMLElement when use FF
try {
    HTMLElement.prototype.click = function() {
        var evt = this.ownerDocument.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
    }
} catch( e ) {
    ;
}

/*customize Event.KEYDOWN with my handle */
if ( !Browser.ie ) {
        window.captureEvents(Event.KEYDOWN);
        window.onkeydown = keyhandler;
    } else {
        document.onkeydown = keyhandler;
 }

/*my custom handle*/
function keyhandler( e ) {

    if ( document.all ) {
        e = event;
    }

    var code = e.keyCode;
    //capture correct code from different browser
    if ( code == 13 ) {
        var el = null;
        if(Browser.ie){
            el = e.srcElement;
        }else{
            el = e.target;
        }
        // test if source is body do nothing
        if(el.tagName.toUpperCase()=="HTML"){
			return false;
        }
        // if source is button do nothing
        if (el!=null &&  el.type != null){
			var type  = el.type.toUpperCase();
			if(type != 'BUTTON' &&   !(type=="IMAGE" && el.tagName.toUpperCase()=="INPUT" ) ) {
				// event ==> fire	
			 if(eventFire.getTarget()!=null){
                    eventFire.getTarget().focus();
                    eventFire.fire();
                    return false;
                }
                else{
                    return false;
                }
			}
        }
    }

}

/* EventFire Object
	use to configure  custom event
	fire event on Enter pressed

  */
function _fire(){
  if(this.getTarget()!=null){
		//	alert('click ' + this.getTarget().id)
		this.getTarget().click();
  }
}
function _setSource(/*HTMLElement*/objSource){
	this._source = objSource;
}

function _getSource(){
	return this._source;
}

function _setTarget(/*HTMLElement*/objTarget){
	this._target = objTarget;
}

function _getTarget(){
	return this._target;
}

function EventFire(){
	/*private prop*/
	this._source = null;
	this._target = null;
	/*getter and setter*/
	this.setSource = _setSource;
	this.getSource = _getSource;
	this.setTarget = _setTarget;
	this.getTarget = _getTarget;
	/*public method*/
	this.fire = _fire;
}

/*globla object*/

var eventFire = new EventFire();

/*wrapper to set event*/
function setMyCustomEvent(/*HTMLElement*/objSource,/*HTMLElement*/objTarget){
//alert('setter ' + objTarget.id)
	eventFire.setSource(objSource);
	eventFire.setTarget(objTarget);
}

// apre la finestra in modalità modale per l'inserimento dell'abstract content
function ModalWindow(sUrl)
	{ 
		return window.showModalDialog(sUrl,null,"dialogWidth:800px;dialogHeight:600px;scroll: auto;") 
}


//Sezione per il funzionamento dei flash dopo l'applicazione della patch di windows xp
//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;
}

function ScrollAll()
{
	ObjHdPos = document.getElementById("HdPos");
	if (ObjHdPos!=null) 
	{
		var currentpos = ObjHdPos.value;
		window.scroll(0,currentpos);
	}
}
function SetPosition()
{
	var currentpos;
	if (document.all)
		currentpos=IECompatBody().scrollTop;
	else
		currentpos=window.pageYOffset;
		
	ObjHdPos = document.getElementById("HdPos");
	if (ObjHdPos!=null) ObjHdPos.value = currentpos;
}	
	
	
function IECompatBody()
{
	return (document.compatMode!="BackCompat")? document.documentElement : document.body
}	

function setSecureAction()
{
	var actionURL="";
	actionURL+="https://";
	actionURL+=location.host;
	if (location.pathname=="/") actionURL+="/default.aspx"; else actionURL+=location.pathname;
	actionURL+=location.search;
	//var objForm = document.forms['frmMain'];
	//objForm.action = actionURL;
	document.forms[0].action=actionURL;	
}	

function ChangePIC(imgName)
{
	if(imgName!="" && document.all("prodImage")!=null)
	{
		document.all("prodImage").src = imgName
	}		
}		

// per evitare che il validatore del w3c restituisca errori sui tag <embed> nel doctype xhtml 1.0 transitional
// iniettiamo il codice per il video all'interno di un div fissato all'interno del controllo che lo renderizza
//

/*
function CreateVideoX (videoSrc, w, h, clsID, autoS, showC, uiMode, codeB, idVideo)
{
    var showControl;
	if(showC=='0')
	    showControl = "False";
	else
	    showControl = "True";

    var autoStart;
	if(autoS=='0')
	    autoStart = "False";
	else
	    autoStart = "True";
	
	var string = ''+ 
		'<object id="'+idVideo+'" name="'+idVideo+'" width="'+w+'" height="'+h+'" classid="'+clsID+'" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="'+codeB+'">'+				
		'<param name="URL" value="'+videoSrc+'" />'+
		'<param name="ShowControls" value="'+showControl+'" />'+
		'<param name="AutoStart" value="'+autoStart+'" />'+
		'<embed id="'+idVideo+'" src="'+videoSrc+'" width="'+w+'" height="'+h+'" type="application/x-mplayer2" AutoStart="'+autoS+'" ShowControl='+showC+'" />'+
		'</object>';

    document.write(string);    
}
 */
/*
function addVideo (contentID, videoSrc, w, h, clsID, autoS, showC, uiMode, codeB, idVideo) 
{
    obj = document.getElementById(contentID);
    var showControl;
    
    if(showC=='0')
        showControl = "False";
    else
        showControl = "True";
    
    var autoStart; 
    
    if(autoS=='0')
        autoStart = "False"; 
    else 
        autoStart = "True";
 
    var v = ''+
 
    '<object id="'+idVideo+'" width="'+w+'" height="'+h+'" classid="'+clsID+'" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="'+codeB+'">'+
 
    '<embed src="'+videoSrc+'" name="'+idVideo+'" width="'+w+'" height="'+h+'" type="application/x-mplayer2" AutoStart="'+autoS+'" fullScreen="False" uiMode="'+uiMode+'" />'+
 
    '<param name="filename" value="'+videoSrc+'" />'+
 
    '<param name="ShowControls" value="'+showControl+'" />'+
 
    '<param name="AutoStart" value="'+autoStart+'" />'+
 
    '</object>'; 
    
    return v;
}
 
function createPlayer2(contentID, videoSrc, w, h, clsID, autoS, showC, uiMode, codeB, idVideo) 
{
    var out = addVideo(contentID, videoSrc, w, h, clsID, autoS, showC, uiMode, codeB, idVideo);
    var obj=document.createElement(out);
    document.getElementById(contentID).appendChild(obj);
}

*/

function addVideo (contentID, videoSrc, w, h, clsID, autoS, showC, uiMode, codeB, idVideo) {
	obj = document.getElementById(contentID);
	
	var showControl;
	if(showC=='0')
	    showControl = "False";
	else
	    showControl = "True";

    var autoStart;
	if(autoS=='0')
	    autoStart = "False";
	else
	    autoStart = "True";
	    	
	obj.innerHTML = ''+

		'<object id="'+idVideo+'" width="'+w+'" height="'+h+'" classid="CLSID:'+clsID+'" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="'+codeB+'">'+
		'<embed  src="'+videoSrc+'" name="'+idVideo+'" width="'+w+'" height="'+h+'" type="application/x-mplayer2" AutoStart="'+autoS+'" fullScreen="False" uiMode="'+uiMode+'" />'+
		'<param name="url" value="'+videoSrc+'" />'+
		'<param name="ShowControls" value="'+showControl+'" />'+
		'<param name="AutoStart" value="'+autoStart+'" />'+
		'</object>';
   // alert(obj.innerHTML);		
}


//
//
//
function clickButton(e, buttonid)
{
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);

      if (bt)
      {
          if (evt.keyCode == 13)
          {
                bt.click();
                return false;
          }
      }
}


	function getPars(strKey, strValue)
	{
		        return strKey + "=" + strValue + "&";
	}
	
	function accodeQueryParameters(strKey, strValue)
	{
	    return "&" + strKey + "=" + strValue;
	}




	function injectFlashObject(targetDivId, objectId, swfPath, width, height, allowfullscreen, flashvars) {

	    if (swfPath.indexOf(".swf") == -1) {
	        swfPath += ".swf";
	    }
	    var html = "<object id=\"" + objectId + "\" type=\"application/x-shockwave-flash\" data=\"" + swfPath + "\" width=\"" + width + "\" height=\"" + height + "\" menu=\"false\"><param name=\"movie\" value=\"" + swfPath + "\" /><param name=\"menu\" value=\"false\" /> <param name=\"allowfullscreen\" value=\"" + allowfullscreen + "\" /><param name=\"flashvars\" value=\"" + flashvars + "\" /></object>";

	    jQuery("#" + targetDivId).html(html);
	}
