setTimeout("document.getElementById(\"fixme\").style.position=\"absolute\";document.getElementById(\"fixme\").style.top=\"0\";document.getElementById(\"fixme\").style.left=\"0\";document.getElementById(\"fixme\").style.height=\""+document.documentElement.clientHeight+"\";",100);

//onerror=handleErr;
var txt="";
var abeadeschis=true;
function handleErr(msg,url,l){
	var reloaded=readcookie("didactrounivreloaded");reloaded++;
	if(abeadeschis==true){
		if(reloaded==5){
			alert("Datorita conexiunii instabile la internet, pagina nu s-a putut incarca complet. Navigarea pe acest site ar putea fi perturbata.");
		}else if(reloaded<5){
			setcookie("didactrounivreloaded",reloaded,(1200));
			document.body.style.display='none';
			window.location.reload();
			/*txt="There was an error on this page.\n\n";
			txt+="Error: " + msg + "\n";
			txt+="URL: " + url + "\n";
			txt+="Line: " + l + "\n\n";
			txt+="Click OK to continue.\n\n";
			alert(txt);*/
		}
	}
	setTimeout("abeadeschis=false;",500);
	return true;
}
//BrowserDetect.browser
//BrowserDetect.version
//BrowserDetect.OS
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

var browser=navigator.appName;
var version=navigator.appVersion;
if(version.length>50){version="6.0";}

// #################################################################
// ## dopost function: Posts Data to a website and writes the     ##
// ##                  HTML of that site into a div.              ##
// ## parms:                                                      ##
// ##       -url        -> url of the controller.                 ##
// ##       -parameters -> parameters that you post.              ##
// ##       -successdiv -> id of the div where the html should    ##
// ##                      be displayed.						  ##
// #################################################################

/************************** EXAMPLE POST ********************************* 
	function doProjAdd(){
		var poststr = "projname=" + encodeURI( document.getElementById("proj_new").value ) +
                  "&aktion=" + encodeURI( "projadd" );
    	dopost('controller_admin.jsp', poststr,"msgDIV");
	}  
**************************************************************************/                                                        


var http_request = false;
var msg_div = "";
var loaddiv = "";
var loadce = "";
var loadcum = "";
var nextaction = "";
searchnew=1;

   function postajax(url, parameters,successdiv){
	   if(httpbusy==true){
		   setTimeout("postajax('"+url+"','"+parameters+"','"+successdiv+"')",200);//alert("iar");
			return;
	   }else{
		   disablepage();
		   httpbusy=true;
		   favicon.change("ico-animat.gif");
		   
		   var loadingdiv=loaddiv;
		   if(loadingdiv == ''){loadingdiv='loading';}
		   
		   var loadmotiv=loadce;	//MOTIVUL CARE SE INCARCA INAINTE DE FUNCTIE
			if(loadmotiv !== ''){document.getElementById(loadingdiv).innerHTML=loadmotiv;}
			document.getElementById(loadingdiv).style.visibility = "visible";
			
		  document.getElementById("loading").style.visibility = "visible";
		  msgdiva=successdiv;
		  
		  http_request = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 http_request = new XMLHttpRequest();
			 if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {
				   http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  }
		  if (!http_request) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
		  
		  msg_div = successdiv;
		  
			  http_request.onreadystatechange = alertContents;
			  http_request.open('POST', url, true);
			  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			  http_request.setRequestHeader("Content-length", parameters.length);
			  http_request.setRequestHeader("Connection", "close");
			  http_request.send(parameters);
	   }
   }

   function alertContents() {
   		// ================= INFO @ http_request.readyState ================================ \\
		// 0  	The object has not yet started initializing (uninitialized).				 \\
		// 1 	The object is initializing, but no data is being read (loading).			 \\
		// 2 	Data is being loaded into the object and parsed (loaded).                    \\
		// 3 	Parts of the object's data has been read and parsed, so the object model is  \\
		//		available. However, the complete object data is not yet ready (interactive). \\
		// 4 	The object has been loaded, its content parsed (completed).                  \\
		// ================================================================================= \\
		
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			
			var loadtitlu=loadcum;
			var loadmotiv=loadce;
            if(loadmotiv !== ''){document.getElementById(loadingdiv).innerHTML=loadmotiv;}
			httpbusy=false;
		 	enablepage();//alert(nextaction);
		 	if(nextaction !== ""){
				var nextaction2=nextaction;
				nextaction="";
				eval(nextaction2);
			}
			favicon.change("ico.png");
			
			document.getElementById(msg_div).innerHTML = result;      
            document.getElementById("loading").style.visibility = "hidden";
			loadcum="";
         } else {
            alert('A intervenit o eroare cu cererea. Va rugam sa reincercati');
			enablepage();
			favicon.change("ico.png");
			document.getElementById("loading").style.visibility = "hidden";
			loadcum="";
         }
      }
	  loadce='';
   }
   
   
var xmlHttp = creazaXmlHttp();

function creazaXmlHttp() 
   { 
   var xmlHttp; 
   // pentru IE 
   if(window.ActiveXObject) 
      { 
      try 
         { 
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
         } 
      catch (e) 
         { 
         xmlHttp = false; 
         } 
      } 
   //Pt Mozilla sau alte browsere
   else 
      { 
      try 
         { 
         xmlHttp = new XMLHttpRequest(); 
         } 
      catch (e) 
         { 
         xmlHttp = false; 
         } 
      }
   if (!xmlHttp)
      alert("XMLHttpRequest could not be created."); 
   else 
      return xmlHttp; 
   } 

/*
Acesta functie preia numerele introduse in input-uri si le trimite php-ului pentru calculare
*/



httpbusy=false;

function ajax(adresa,msgdiv){
	if(httpbusy==true){
		setTimeout("ajax('"+adresa+"','"+msgdiv+"')",100);
		return;
	}else{
		disablepage();
		httpbusy=true;
		
		favicon.change("ico-animat.gif");
		
		var loadingdiv=loaddiv;
		if(loadingdiv == ''){loadingdiv='loading';}
	
		var loadmotiv=loadce;	//MOTIVUL CARE SE INCARCA INAINTE DE FUNCTIE
		var loadtitlu=loadcum;if(loadtitlu == ""){loadtitlu="Incarcare ";}
		if(loadmotiv !== ''){document.getElementById(loadingdiv).innerHTML=loadtitlu+loadmotiv+"...";}
		
		document.getElementById(loadingdiv).style.visibility = "visible";
	   msgdiva=msgdiv;
	   // verificam daca xmlHttp este liber 
	   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
		  { 
		  //obtinem cele doua valori ale numerelor
		  // executam script-ul php de adunare trimitand cele doua numere ca paramentri prin get
		  xmlHttp.open("GET", adresa, true);
		  //definim functia care se va ocupa de manipularea rezultatului primit de la script-ul php 
		  xmlHttp.onreadystatechange = gestioneazaRezultat;
		  // trimitem cererea catre server 
		  xmlHttp.send(null);
		  }
		}
   }

   
function gestioneazaRezultat(){ 
   // daca rezultatul este obtinut 
   if (xmlHttp.readyState == 4) 
      { 
      // status = 200 arata faptul ca cerea a fost rezoltata cu success 
      if (xmlHttp.status == 200) 
         { 
         // extragem rezultatul 
         var raspuns = xmlHttp.responseText;
         //modificam div-ul rezultat cu rezultatul 
         document.getElementById(msgdiva).innerHTML = raspuns ;
         
         var loadingdiv=loaddiv;
    	 if(loadingdiv == ''){loadingdiv='loading';}
         
		 var loadmotiv=loadce;	//MOTIVUL CARE SE INCARCA INAINTE DE FUNCTIE
		var loadtitlu=loadcum;if(loadtitlu == ""){loadtitlu="Incarcare ";}
		if(loadmotiv !== ''){document.getElementById(loadingdiv).innerHTML=loadtitlu+loadmotiv+"...";}
		 httpbusy=false;
		 enablepage();
		 if(nextaction != ""){//alert(nextaction);
				var nextaction2=nextaction;
				nextaction="";
				eval(nextaction2);
			}
		favicon.change("ico.png");loadcum="";
      } 
   }
   loadce='';
}

function disablepage(){
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
	document.getElementById('fixme').style.display='';
	document.getElementById('fixme').style.height=myHeight;
}
function enablepage(){
	document.getElementById('fixme').style.display='none';
}

function togglechat(){
	loadcum="Toggle";
	loadce=" chat";
	nextaction="document.getElementById(\"chatoption\").innerHTML=document.getElementById(\"raspuns\").innerHTML;chatenabled=!chatenabled;var f = document.getElementById(\"checkchat\");document.getElementById(\"checkchat\").src=f.src;";
	ajax("togglechat.didact&mod=1","raspuns");
}

function setcookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
	+ ";expires="+expire.toGMTString();
}

function readcookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}



	function changecss(theClass,element,value) {
	//Last Updated on May 21, 2008
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }

	  if(!added){
	  if(document.styleSheets[S].insertRule){
			  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
	  }
	 }
	}


function checkall(frm1) {
	var aa = document.getElementById(frm1);
	var checked = true;
	for (var i =0; i < aa.elements.length; i++) 
	{
	 aa.elements[i].checked = checked;
	}
}


function checknone(frm1) {
	var aa = document.getElementById(frm1);
	var checked = false;
	for (var i =0; i < aa.elements.length; i++) 
	{
	 aa.elements[i].checked = checked;
	}
}

function toggle(idcasuta){
	var bb = idcasuta;
	var aa = document.getElementById(bb);
	if(aa.checked==true){aa.checked=false;}else{aa.checked=true;}
	document.getElementById(idcasuta).checked=aa.checked;
}

function printsel(frm1,campselectie,formsave){
	var nr=0;
	var aa = document.getElementById(frm1);
	var selectie="";
	for (var i =0; i < aa.elements.length; i++){
		if(aa.elements[i].checked == true && aa.elements[i].name.indexOf('chs')>-1 ){
			if(selectie != ''){selectie+='|';}
			selectie += aa.elements[i].name.replace(/chs/g,"");
			nr+=1;
		}
	}
	if(nr==0){alert('Selecteaza cel putin un rand pentru printare.');}else{
		var url=parseurl(window.location.href);
		//setcookie('selectie',selectie,3600*24*365*1000);
		document.getElementById(campselectie).value=selectie;
		//alert(readcookie("selectie"));
		document.getElementById(formsave).action=url["protocol"]+"://"+url["authority"]+"/"+url["path"]+"&mod=4";
		document.getElementById(formsave).submit();
	}
}

function savesel(frm1,campselectie,formsave){
	var nr=0;
	var aa = document.getElementById(frm1);
	var selectie="";
	for (var i =0; i < aa.elements.length; i++){
		if(aa.elements[i].checked == true && aa.elements[i].name.indexOf('chs')>-1 ){
			if(selectie != ''){selectie+='|';}
			selectie += aa.elements[i].name.replace(/chs/g,"");
			nr+=1;
		}
	}
	if(nr==0){alert('Selecteaza cel putin un rand pentru salvare.');}else{
		var url=parseurl(window.location.href);
		//setcookie('selectie',selectie,3600*24*365*1000);
		document.getElementById(campselectie).value=selectie;
		//alert(readcookie("selectie"));
		document.getElementById(formsave).action=url["protocol"]+"://"+url["authority"]+"/"+url["path"]+"&mod=2";
		document.getElementById(formsave).submit();
	}
}

function parseurl(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};
    
    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }
    
    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }
    
    return uri;
}

function delmesaje(frm1){
	var nr=0;var cookieexistent='';
	var aa = document.getElementById(frm1);
    for (var i =0; i < aa.elements.length; i++){
		if(aa.elements[i].checked == true && aa.elements[i].name.indexOf('uid')>-1 ){
			if(cookieexistent != ''){cookieexistent+='!';}
			cookieexistent+=aa.elements[i].name.replace('uid','');
            nr+=1;
		}
	}
	if(nr==0){alert('Nu ai selectat nici un mesaj.');}else if(confirm('Mesajele selectate vor fi sterse definitiv. Esti sigur ca stergi mesajele selectate?')==1){location.href='mesajedel.didact&id='+cookieexistent+'&tip='+document.getElementById('tip').value+'&option='+document.getElementById('option').value;}else{return false;}
}

	function changeImgSize(objectId,newWidth,newHeight) {
	  imgString = 'theImg = document.getElementById("'+objectId+'")';
	  eval(imgString);
	  oldWidth = theImg.width;
	  oldHeight = theImg.height;
	  if(newWidth>0){
	   theImg.width = newWidth;
	  }
	  if(newHeight>0){
	   theImg.height = newHeight;
	  }

	}

	function changeColor(theObj,newColor){
	  eval('var theObject = document.getElementById("'+theObj+'")');
	  if(theObject.style.backgroundColor==null){theBG='white';}else{theBG=theObject.style.backgroundColor;}
	  if(theObject.style.color==null){theColor='black';}else{theColor=theObject.style.color;}
	  //alert(theObject.style.color+' '+theObject.style.backgroundColor);
      switch(theColor){
	    case newColor:
		  switch(theBG){
			case 'white':
		      theObject.style.color = 'black';
		    break;
			case 'black':
			  theObject.style.color = 'white';
			  break;
			default:
			  theObject.style.color = 'black';
			  break;
		  }
		  break;
	    default:
		  theObject.style.color = newColor;
		  break;
	  }
	}

function refresh(){
	setTimeout('location.reload(true);',2000);
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function validatemail(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function is_numeric(mixed_var){return !isNaN( mixed_var );}

function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	var spaces = words.length;
	for(var x = 1; x<spaces; ++x){
		words = words.replace(character, "");
	}
	return words;
}

function trimfaratag(cuvant){
	cuvant=stripCharacter(cuvant,"<br>");
	cuvant=stripCharacter(cuvant,"<br/>");
	cuvant=stripCharacter(cuvant,"<br />");
	cuvant=stripCharacter(cuvant,"&nbsp;");
	cuvant=stripCharacter(cuvant,"<h1>");
	cuvant=stripCharacter(cuvant,"<h2>");
	cuvant=stripCharacter(cuvant,"<h3>");
	cuvant=stripCharacter(cuvant,"<h4>");
	cuvant=stripCharacter(cuvant,"<h5>");
	cuvant=stripCharacter(cuvant,"<h6>");
	cuvant=stripCharacter(cuvant,"</h1>");
	cuvant=stripCharacter(cuvant,"</h2>");
	cuvant=stripCharacter(cuvant,"</h3>");
	cuvant=stripCharacter(cuvant,"</h4>");
	cuvant=stripCharacter(cuvant,"</h5>");
	cuvant=stripCharacter(cuvant,"</h6>");
    cuvant=trim(cuvant);
    return cuvant;
}

function str_ireplace ( search, replace, subject ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Martijn Wieringa
    // +      input by: penutbutterjelly
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Jack
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: str_ireplace('l', 'l', 'HeLLo');
    // *     returns 1: 'Hello'
 
    var i, k = '';
    var searchl = 0;
 
    search += '';
    searchl = search.length;
    if (!(replace instanceof Array)) {
        replace = new Array(replace);
        if (search instanceof Array) {
            // If search is an array and replace is a string,
            // then this replacement string is used for every value of search
            while (searchl > replace.length) {
                replace[replace.length] = replace[0];
            }
        }
    }
 
    if (!(search instanceof Array)) {
        search = new Array(search);
    }
    while (search.length>replace.length) {
        // If replace has fewer values than search,
        // then an empty string is used for the rest of replacement values
        replace[replace.length] = '';
    }
 
    if (subject instanceof Array) {
        // If subject is an array, then the search and replace is performed
        // with every entry of subject , and the return value is an array as well.
        for (k in subject) {
            subject[k] = str_ireplace(search, replace, subject[k]);
        }
        return subject;
    }
 
    searchl = search.length;
    for (i = 0; i < searchl; i++) {
        reg = new RegExp(search[i], 'gi');
        subject = subject.replace(reg, replace[i]);
    }
 
    return subject;
}

// Favicon.js - Change favicon dynamically [http://ajaxify.com/run/favicon].
// Copyright (c) 2006 Michael Mahemoff. Only works in Firefox and Opera.
// Background and MIT License notice at end of file, see the homepage for more.

// USAGE:
// * favicon.change("/icon/active.ico");  (Optional 2nd arg is new title.)
// * favicon.animate(new Array("icon1.ico", "icon2.ico", ...));
//     Tip: Use "" as the last element to make an empty icon between cycles.
//     To stop the animation, call change() and pass in the new arg.
//     (Optional 2nd arg is animation pause in millis, overwrites the default.)
// * favicon.defaultPause = 5000;

var favicon = {

// -- "PUBLIC" ----------------------------------------------------------------

defaultPause: 2000,

change: function(iconURL, optionalDocTitle) {
  clearTimeout(this.loopTimer);
  if (optionalDocTitle) {
    document.title = optionalDocTitle;
  }
  this.addLink(iconURL, true);
},

animate: function(iconSequence, optionalDelay) {
  this.preloadIcons(iconSequence);
  this.iconSequence = iconSequence;
  this.sequencePause = (optionalDelay) ?  optionalDelay : this.defaultPause;
  favicon.index = 0;
  favicon.change(iconSequence[0]);
  this.loopTimer = setInterval(function() {
    favicon.index = (favicon.index+1) % favicon.iconSequence.length;
    favicon.addLink(favicon.iconSequence[favicon.index], false);
  }, favicon.sequencePause);
},

// -- "PRIVATE" ---------------------------------------------------------------

loopTimer: null,

preloadIcons: function(iconSequence) {
  var dummyImageForPreloading = document.createElement("img");
  for (var i=0; i<iconSequence.length; i++) {
    dummyImageForPreloading.src = iconSequence[i];
  }
},

addLink: function(iconURL) {
  var link = document.createElement("link");
  link.type = "image/x-icon";
  link.rel = "shortcut icon";
  link.href = iconURL;
  this.removeLinkIfExists();
  this.docHead.appendChild(link);
},

removeLinkIfExists: function() {
  var links = this.docHead.getElementsByTagName("link");
  for (var i=0; i<links.length; i++) {
    var link = links[i];
    if (link.type=="image/x-icon" && link.rel=="shortcut icon") {
      this.docHead.removeChild(link);
      return; // Assuming only one match at most.
    }
  }
},

docHead:document.getElementsByTagName("head")[0]
}

function iconchangeload(){
	favicon.change('ico-animat.gif');
}
function resetfavicon(){
	favicon.change('ico.png');
}
function intval( mixed_var, base ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
 
    var tmp;
 
    var type = typeof( mixed_var );
 
    if(type == 'boolean'){
        if (mixed_var == true) {
            return 1;
        } else {
            return 0;
        }
    } else if(type == 'string'){
        tmp = parseInt(mixed_var * 1, 10);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if(type == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}


function date ( format, timestamp ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
    // +      parts by: Peter-Paul Koch (http://www.quirksmode.org/js/beat.html)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: MeEtc (http://yass.meetcweb.com)
    // +   improved by: Brad Touesnard
    // +   improved by: Tim Wiel
    // +   improved by: Bryan Elliott
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: David Randall
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   derived from: gettimeofday
    // %        note 1: Uses global: php_js to store the default timezone
    // *     example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400);
    // *     returns 1: '09:09:40 m is month'
    // *     example 2: date('F j, Y, g:i a', 1062462400);
    // *     returns 2: 'September 2, 2003, 2:26 am'
    // *     example 3: date('Y W o', 1062462400);
    // *     returns 3: '2003 36 2003'
    // *     example 4: x = date('Y m d', (new Date()).getTime()/1000); // 2009 01 09
    // *     example 4: (x+'').length == 10
    // *     returns 4: true
 
    var jsdate=(
        (typeof(timestamp) == 'undefined') ? new Date() : // Not provided
        (typeof(timestamp) == 'number') ? new Date(timestamp*1000) : // UNIX timestamp
        new Date(timestamp) // Javascript Date()
    ); // , tal=[]
    var pad = function(n, c){
        if( (n = n + "").length < c ) {
            return new Array(++c - n.length).join("0") + n;
        } else {
            return n;
        }
    };
    var _dst = function (t) {
        // Calculate Daylight Saving Time (derived from gettimeofday() code)
        var dst=0;
        var jan1 = new Date(t.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
        var june1 = new Date(t.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
        var temp = jan1.toUTCString();
        var jan2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
        temp = june1.toUTCString();
        var june2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
        var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
        var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
 
        if (std_time_offset === daylight_time_offset) {
            dst = 0; // daylight savings time is NOT observed
        }
        else {
            // positive is southern, negative is northern hemisphere
            var hemisphere = std_time_offset - daylight_time_offset;
            if (hemisphere >= 0) {
                std_time_offset = daylight_time_offset;
            }
            dst = 1; // daylight savings time is observed
        }
        return dst;
    };
    var ret = '';
    var txt_weekdays = ["Sunday","Monday","Tuesday","Wednesday",
        "Thursday","Friday","Saturday"];
    var txt_ordin = {1:"st",2:"nd",3:"rd",21:"st",22:"nd",23:"rd",31:"st"};
    var txt_months =  ["", "January", "February", "March", "April",
        "May", "June", "July", "August", "September", "October", "November",
        "December"];
 
    var f = {
        // Day
            d: function(){
                return pad(f.j(), 2);
            },
            D: function(){
                var t = f.l();
                return t.substr(0,3);
            },
            j: function(){
                return jsdate.getDate();
            },
            l: function(){
                return txt_weekdays[f.w()];
            },
            N: function(){
                return f.w() + 1;
            },
            S: function(){
                return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th';
            },
            w: function(){
                return jsdate.getDay();
            },
            z: function(){
                return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0;
            },
 
        // Week
            W: function(){
                var a = f.z(), b = 364 + f.L() - a;
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;
 
                if(b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
                    return 1;
                } 
                if(a <= 2 && nd >= 4 && a >= (6 - nd)){
                    nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                    return date("W", Math.round(nd2.getTime()/1000));
                }
                return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
            },
 
        // Month
            F: function(){
                return txt_months[f.n()];
            },
            m: function(){
                return pad(f.n(), 2);
            },
            M: function(){
                var t = f.F();
                return t.substr(0,3);
            },
            n: function(){
                return jsdate.getMonth() + 1;
            },
            t: function(){
                var n;
                if( (n = jsdate.getMonth() + 1) == 2 ){
                    return 28 + f.L();
                }
                if( n & 1 && n < 8 || !(n & 1) && n > 7 ){
                    return 31;
                }
                return 30;
            },
 
        // Year
            L: function(){
                var y = f.Y();
                return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0;
            },
            o: function(){
                if (f.n() === 12 && f.W() === 1) {
                    return jsdate.getFullYear()+1;
                }
                if (f.n() === 1 && f.W() >= 52) {
                    return jsdate.getFullYear()-1;
                }
                return jsdate.getFullYear();
            },
            Y: function(){
                return jsdate.getFullYear();
            },
            y: function(){
                return (jsdate.getFullYear() + "").slice(2);
            },
 
        // Time
            a: function(){
                return jsdate.getHours() > 11 ? "pm" : "am";
            },
            A: function(){
                return f.a().toUpperCase();
            },
            B: function(){
                // peter paul koch:
                var off = (jsdate.getTimezoneOffset() + 60)*60;
                var theSeconds = (jsdate.getHours() * 3600) +
                                 (jsdate.getMinutes() * 60) +
                                  jsdate.getSeconds() + off;
                var beat = Math.floor(theSeconds/86.4);
                if (beat > 1000) {
                    beat -= 1000;
                }
                if (beat < 0) {
                    beat += 1000;
                }
                if ((String(beat)).length == 1) {
                    beat = "00"+beat;
                }
                if ((String(beat)).length == 2) {
                    beat = "0"+beat;
                }
                return beat;
            },
            g: function(){
                return jsdate.getHours() % 12 || 12;
            },
            G: function(){
                return jsdate.getHours();
            },
            h: function(){
                return pad(f.g(), 2);
            },
            H: function(){
                return pad(jsdate.getHours(), 2);
            },
            i: function(){
                return pad(jsdate.getMinutes(), 2);
            },
            s: function(){
                return pad(jsdate.getSeconds(), 2);
            },
            u: function(){
                return pad(jsdate.getMilliseconds()*1000, 6);
            },
 
        // Timezone
            e: function () {
/*                var abbr='', i=0;
                if (this.php_js && this.php_js.default_timezone) {
                    return this.php_js.default_timezone;
                }
                if (!tal.length) {
                    tal = timezone_abbreviations_list();
                }
                for (abbr in tal) {
                    for (i=0; i < tal[abbr].length; i++) {
                        if (tal[abbr][i].offset === -jsdate.getTimezoneOffset()*60) {
                            return tal[abbr][i].timezone_id;
                        }
                    }
                }
*/
                return 'UTC';
            },
            I: function(){
                return _dst(jsdate);
            },
            O: function(){
               var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
               t = (jsdate.getTimezoneOffset() > 0) ? "-"+t : "+"+t;
               return t;
            },
            P: function(){
                var O = f.O();
                return (O.substr(0, 3) + ":" + O.substr(3, 2));
            },
            T: function () {
/*                var abbr='', i=0;
                if (!tal.length) {
                    tal = timezone_abbreviations_list();
                }
                if (this.php_js && this.php_js.default_timezone) {
                    for (abbr in tal) {
                        for (i=0; i < tal[abbr].length; i++) {
                            if (tal[abbr][i].timezone_id === this.php_js.default_timezone) {
                                return abbr.toUpperCase();
                            }
                        }
                    }
                }
                for (abbr in tal) {
                    for (i=0; i < tal[abbr].length; i++) {
                        if (tal[abbr][i].offset === -jsdate.getTimezoneOffset()*60) {
                            return abbr.toUpperCase();
                        }
                    }
                }
*/
                return 'UTC';
            },
            Z: function(){
               return -jsdate.getTimezoneOffset()*60;
            },
 
        // Full Date/Time
            c: function(){
                return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P();
            },
            r: function(){
                return f.D()+', '+f.d()+' '+f.M()+' '+f.Y()+' '+f.H()+':'+f.i()+':'+f.s()+' '+f.O();
            },
            U: function(){
                return Math.round(jsdate.getTime()/1000);
            }
    };
 
    return format.replace(/[\\]?([a-zA-Z])/g, function(t, s){
        if( t!=s ){
            // escaped
            ret = s;
        } else if( f[s] ){
            // a date function exists
            ret = f[s]();
        } else{
            // nothing special
            ret = s;
        }
        return ret;
    });
}

function max() {
    // http://kevin.vanzonneveld.net
    // +   original by: Onno Marsman
    // +    revised by: Onno Marsman
    // +    tweaked by: Jack
    // %          note: Long code cause we're aiming for maximum PHP compatibility
    // *     example 1: max(1, 3, 5, 6, 7);
    // *     returns 1: 7
    // *     example 2: max([2, 4, 5]);
    // *     returns 2: 5
    // *     example 3: max(0, 'hello');
    // *     returns 3: 0
    // *     example 4: max('hello', 0);
    // *     returns 4: 'hello'
    // *     example 5: max(-1, 'hello');
    // *     returns 5: 'hello'
    // *     example 6: max([2, 4, 8], [2, 5, 7]);
    // *     returns 6: [2, 5, 7]
 
    var ar, retVal, i = 0, n = 0;
    var argv = arguments, argc = argv.length;
 
    var _obj2Array = function(obj) {
        if (obj instanceof Array) {
            return obj;
        } else {
            var ar = [];
            for (var i in obj) {
                ar.push(obj[i]);
            }
            return ar;
        }
    }; //function _obj2Array
    
    var _compare = function(current, next) {
        var i = 0, n = 0, tmp = 0;
        var nl = 0, cl = 0;
        
        if (current === next) {
            return 0;
        } else if (typeof current == 'object') {
            if (typeof next == 'object') {
               current = _obj2Array(current);
               next    = _obj2Array(next);
               cl      = current.length;
               nl      = next.length;
               if (nl > cl) {
                   return 1;
               } else if (nl < cl) {
                   return -1;
               } else {
                   for (i = 0, n = cl; i<n; ++i) {
                       tmp = _compare(current[i], next[i]);
                       if (tmp == 1) {
                           return 1;
                       } else if (tmp == -1) {
                           return -1;
                       }
                   }
                   return 0;
               }
            } else {
               return -1;
            }
        } else if (typeof next == 'object') {
            return 1;
        } else if (isNaN(next) && !isNaN(current)) {
            if (current == 0) {
               return 0;
            } else {
               return (current<0 ? 1 : -1);
            }
        } else if (isNaN(current) && !isNaN(next)) {
            if (next==0) {
               return 0;
            } else {
               return (next>0 ? 1 : -1);
            }
        } else {
            if (next==current) {
               return 0;
            } else {
               return (next>current ? 1 : -1);
            }
        }
    }; //function _compare
    
    if (argc === 0) {
        throw new Error('At least one value should be passed to max()');
    } else if (argc === 1) {
        if (typeof argv[0] === 'object') {
            ar = _obj2Array(argv[0]);
        } else {
            throw new Error('Wrong parameter count for max()');
        }
        if (ar.length === 0) {
            throw new Error('Array must contain at least one element for max()');
        }
    } else {
        ar = argv;
    }
    
    retVal = ar[0];
    for (i=1, n=ar.length; i<n; ++i) {
        if (_compare(retVal, ar[i])==1) {
            retVal = ar[i];
        }
    }
    
    return retVal;
}