MobiMultipleInstancesExtension = function () {
	this.pid = 0;
	this.uids = new Array();
}; 
// MobiMultipleInstancesExtension.prototype.pid  = 0; 
// MobiMultipleInstancesExtension.prototype.uids = new Array();

var mobiFieldLength = 10;
function linkLogo(){
	var el = document.getElementById('mobi_logo');
	if (el != null){
		el.onclick = function(){
			mobiRedirect('');
		}
	}
}
window.onload  = linkLogo;



function getProtocol(url){
	//var protocol = url.match(/(ht|f)tps?:/i)[0];
	var t = url.match(/(ht|f)tps?:/i);
	if (t == null){
		return '';
	}
	else{
		return t[0];
	}
}

function getUrl(){
	return window.location;
};

function getUrlItem( name, url ) {
	//url = typeof(url) != 'undefined' ? url : getUrl();
	if (url === undefined){
		url = getUrl();
	}
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );
	if( results == null )
		return "";
	else
		return results[1];
}

/*http://www.weberdev.com/get_example-4569.html*/
function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
} 

function setUrlItem( name, value, url ) {
	//url = typeof(url) != 'undefined' ? url : getUrl();
	if (url === undefined){
		url = getUrl();
	}
	var item = getUrlItem(name, url);
	var n = name+"="+value;
	var os = url+'';
	var regexS = name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var ns = os.replace(regex, n);

	return ns;
}

function getHash() {
  var hash = window.location.hash;
  return hash.substring(1); // remove #
}

function getHashItem( name ) {
	var hash = getHash();
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( hash );
	if( results == null )
		return "";
	else
		return results[1];
}

function setHashItem( name, value ) {
	var item = getHashItem(name);
	if (window.location.hash.length == 0){
		window.location.hash = "#?"+name+"="+value;
	}
	else if (item == ""){
		window.location.hash += "&"+name+"="+value;
	}
	else{
		var n = name+"="+value;
		var os = window.location.hash.substring(1);
		var regexS = name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var ns = os.replace(regex, n);
		window.location.hash = "#"+ns;
	}
}

/* 
gup function

http://www.netlobo.com/url_query_string_javascript.html
*/
function gup( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function hide(element){
	cn = element.className;
	element.className = cn.replace(" hover", "");
}

//<!> ExtJS has to be loaded
function mobiHtmlDecode(s){
	return Ext.util.Format.htmlDecode(s);
}
function mobiHtmlDecode2(s)
{
	var str = s;
	
	// str = str.replace(/br\//g, '');
	
	
	// str = str.replace(/\&amp;/g, "\&");
	// str = str.replace(/\&gt;/g,'>');
	// str = str.replace(/\&lt;/g,'<');
	// str = str.replace(/\&quot;/g, "\"");
	// str = str.replace(/\&#039;/g, "\'");
	
	
	str = str.replace(/&amp;/g, "&");
	str = str.replace(/&gt;/g,'>');
	str = str.replace(/&lt;/g,'<');
	str = str.replace(/&quot;/g, "\"");
	str = str.replace(/&#039;/g, "\'");
	
	// var str = s.replace(/&amp;/g, '%26').replace(/&lt;/g, '%3C').replace(/&gt;/g, '%3E');
	
	// var symbols = {
      // '@': '%40',
      // '%26amp%3B': '%26',
      // '*': '%2A',
      // '+': '%2B',
      // '/': '%2F',
      // '%26lt%3B': '%3C',
      // '%26gt%3B': '%3E'
   // };
   // return escape(s).replace(/([@*+/]|%26(amp|lt|gt)%3B)/g, function (m) { return symbols[m]; });

  
	// s = s.replace(/&(lt|gt);/g, function (strMatch, p1){
		// return (p1 == "lt")? "<" : ">";
	// });
	// var s = s.replace(/<\/?[^>]+(>|$)/g, "");

  return str;
}



//<!> ExtJS has to be loaded
function intToMonth(s, l){
	var n = parseFloat(s);
	
	if (l === undefined){
		l = 0;
	}
	if ( l == 0){
		if(Date.shortMonthNames[n-1]){
			return Date.shortMonthNames[n-1];
		}
	}
	else if (l == 1){
		if(Date.monthNames[n-1]){
			return Date.monthNames[n-1];
		}
	}
	return '';
	
}

//<!> ExtJS has to be loaded
function mobiRedirect(url){
	if (Ext.isIE){
		window.open('http://'+window.location.host+'/'+url, "_self");
	}
	else{
		window.location = url;
	}
};

function show(element){
	element.className += " hover";
}

// http://www.ejeliot.com/blog/109
function loadScript(sScriptSrc, oCallback) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('script');
	oScript.type = 'text/javascript';
	oScript.src = sScriptSrc;
	// most browsers
	oScript.onload = oCallback;
	// IE 6 & 7
	oScript.onreadystatechange = function() {
		if (this.readyState == 'complete') {
			oCallback();
		}
	}
	oHead.appendChild(oScript);
}

// http://stackoverflow.com/questions/4413590/javascript-get-array-of-dates-between-2-dates
Date.prototype.addDays = function(days) {
   var dat = new Date(this.valueOf())
   dat.setDate(dat.getDate() + days);
   return dat;
}

Date.prototype.retrDays = function(days) {
   var dat = new Date(this.valueOf())
   dat.setDate(dat.getDate() - days);
   return dat;
}

function getDates(startDate, stopDate) {
  var dateArray = new Array();
  
  // On souhaite comparer seulement sur la date au format YYYY/MM/DD
  var currentDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
  var stDate = new Date(stopDate.getFullYear(), stopDate.getMonth(), stopDate.getDate());
  while (currentDate <= stDate) { 
	dateArray.push(currentDate)
	currentDate = currentDate.addDays(1);
  }
  return dateArray;
}

function sameDate(date1, date2){
	dateA = parseDate(date1);
	dateB = parseDate(date2);
	return ((dateA.getFullYear() == dateB.getFullYear()) && (dateA.getMonth() == dateB.getMonth()) && (dateA.getDate() == dateB.getDate()));
}

function resetHour(uneDate){ // Met l'heure à 0 
	dateTemp = parseDate(uneDate);
	return (new Date(dateTemp.getFullYear(), dateTemp.getMonth(), dateTemp.getDate()));
}

function parseDate(uneDate){
 var part = uneDate.split('T');
 var ymd = part[0].split('-');
var laDate = ymd[1]+'/'+ymd[2] + '/' + ymd[0] + ' ' + part[1];
return new Date(laDate);
}
