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);
}

//<!> 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";
}
