// ############# - GETELEMENTBYID - #############
function getObj(itemId) {
	return document.getElementById(itemId);
}
// ################### - FINE - ###################

// ############# - JS TRIM - #############
function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

// ################### - FINE - ###################

// ################### - FINE - ###################

// ############# - BROWSER DETECT - #############
// BROWSER TYPE		= BrowserDetect.browser
// BROWSER VERSION	= BrowserDetect.version
// OPERATVE SYSTEM	= 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: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			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();

if (BrowserDetect.browser == 'Explorer')  {
	if (BrowserDetect.version == 7) {
		var BrowserType = 'msie7';
	} else {
		var BrowserType = 'msie';
	}
} else if (BrowserDetect.browser == 'Firefox') {
	var BrowserType = 'firefox';
} else {
	var BrowserType = '';
}
// ################### - FINE - ###################


function openPage(URL) {
	window.location.href = URL;
}


/*
function screenResizer(action) {
	
	coverObj = document.getElementById('login_cover');
	
	if (action==0) {
		if (document.documentElement.scrollWidth > document.documentElement.clientWidth) {
			coverObj.style.width = document.documentElement.scrollWidth +'px';
		} else {
			coverObj.style.width = '100%'
		}
		
		if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
			coverObj.style.height = document.documentElement.scrollHeight +'px';
		} else {
			coverObj.style.height = '100%'
		}
		coverObj.style.display ='block';
	} else {
		coverObj.style.display ='none';
		coverObj.style.width = '100%';
		coverObj.style.height = '100%';
	}
	hideElements(action);
}

function coverOpen(action) {
	if (BrowserDetect.browser == 'Explorer') {
		window.setTimeout('screenResizer('+ action +')', 0);
	} else {
		screenResizer(action);
	}
}

function loginOpen(action, theURL) {
	if (action==0) {
		coverOpen(action);
		setTimeout("showLoginForm()", 300);
	}
}

function loginClose(URL) {
	if (effettua_login) {
		window.location.href = URL;
	} else {
		screenResizer(1);
		document.getElementById('login_form').style.display = 'none';
	}
	
}

function showLoginForm() {
	loginObj = document.getElementById('login_form');
	if (loginObj.style.display == 'none') {
		loginObj.style.display='block';
		loginOpen(0);
	}
}

function actionOnLoginCover() {
	if (document.getElementById('login_cover').style.display != 'none') {
		loginOpen(0);
	}
}
*/

function switchLoginRegTable() {
	regTableObj = document.getElementById('id_registration_table');
	loginTableObj = document.getElementById('id_login_table');
	if (loginTableObj.style.display == '') {
		loginTableObj.style.display = 'none';
		regTableObj.style.display = '';
	} else {
		loginTableObj.style.display = '';
		regTableObj.style.display = 'none';
	}
}
function scrollPageUp(idItem, action) {
	var ScrollTopLength = document.body.scrollTop;
	if (ScrollTopLength == 0) {
	
		if (window.pageYOffset) {
			ScrollTopLength = window.pageYOffset;
		} else {
			ScrollTopLength = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	
	var scrollIntval;
	if (ScrollTopLength > 0) {
		window.scrollBy (0, -5);
		//scrollIntval = window.setTimeout('scrollPageUp('+ idItem +','+ action +')', 1);
		scrollPageUp(idItem ,action);
	} else {
		//window.clearInterval(scrollIntval);
		showIframeList(idItem, action);
	}
}
function openContattaInserz(idItem, action) {
	if (action==1) {
		document.getElementById('frame_id_form').style.display = '';
		scrollPageUp(idItem, action);
	} else {
		window.frame_name_form.document.getElementById('outer_contatta_div').className = 'flash_form';
		setTimeout('changeBG()', 1000);
	}
}

function changeBG() {
	window.frame_name_form.document.getElementById('outer_contatta_div').className = 'bg_empty_form';
}

function showIframeList(idItem, action) {
	window.open('/contatta_inserzionista/?ida='+ idItem ,'frame_name_form');
	checkIframeLoad();
}

var checkIntval;
onloadVar = false;
function checkIframeLoad() {
	if (onloadVar) {
		window.clearInterval(checkIntval);
		window.frame_name_form.document.getElementById('outer_contatta_div').className = 'flash_form';
		onloadVar = false;
	} else {
		checkIntval = window.setTimeout('checkIframeLoad()', 500);
	}
}


function checkItem(itemCheck) {
	objCheck = getObj(itemCheck);
	if (objCheck.checked == true) {
		objCheck.checked = false;
	} else {
		objCheck.checked = true;
	}
}

function fnSelect(objId) {
	fnDeSelect();
	if (document.selection) {
		var range = document.body.createTextRange();
		range.moveToElementText(document.getElementById(objId));
		range.select();
	}
	else if (window.getSelection) {
		var range = document.createRange();
		range.selectNode(document.getElementById(objId));
		window.getSelection().addRange(range);
	}
}
function fnDeSelect() {
	if (document.selection) {
		document.selection.empty(); 
	} else if (window.getSelection) {
		window.getSelection().removeAllRanges();
	}
}

var currentRegion = false;
function openDropDownRegione(itemObj, regione_id, e) {
	
	selectedClass = 'regione_button selected';
	notSelectedClass = 'regione_button';
	
	var aObj = document.getElementsByTagName('a');
	for (var i=0;i<aObj.length;i++) {
		if (aObj[i].className == selectedClass) {
			aObj[i].className = notSelectedClass;
		}
	}
	var divObj = document.getElementsByTagName('div');
	for (var i=0;i<divObj.length;i++) {
		if (divObj[i].className == 'dropdown') {
			divObj[i].style.display = 'none';
		}
	}
	
	itemObj.className = selectedClass;
	
	if (currentRegion == regione_id) {
		itemObj.className = notSelectedClass;
		document.getElementById(regione_id).style.display = 'none';
		if (!right_col_search) {
			if (BrowserType == 'msie') {
				document.getElementById('select_regioni').style.display = 'block';
				document.getElementById('select_regioni_input_txt').style.display = 'none';
				
				document.getElementById('select_disponibilita').style.display = 'block';
				document.getElementById('select_disponibilita_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_from').style.display = 'block';
				document.getElementById('select_eta_from_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_to').style.display = 'block';
				document.getElementById('select_eta_to_input_txt').style.display = 'none';
			}
		} else {
			if (BrowserType == 'msie') {
				document.getElementById('select_regioni').style.display = 'block';
				document.getElementById('select_regioni_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_from').style.display = 'block';
				document.getElementById('select_eta_from_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_to').style.display = 'block';
				document.getElementById('select_eta_to_input_txt').style.display = 'none';
			}
		}
		currentRegion = false;
	} else {
		itemObj.className = selectedClass;
		document.getElementById(regione_id).style.display = 'block';
		if (!right_col_search) {
			if (BrowserType == 'msie') {
				document.getElementById('select_regioni').style.display = 'none';
				document.getElementById('select_regioni_input_txt').style.display = 'block';
				
				document.getElementById('select_disponibilita').style.display = 'none';
				document.getElementById('select_disponibilita_input_txt').style.display = 'block';
				
				document.getElementById('select_eta_from').style.display = 'none';
				document.getElementById('select_eta_from_input_txt').style.display = 'block';
				
				document.getElementById('select_eta_to').style.display = 'none';
				document.getElementById('select_eta_to_input_txt').style.display = 'block';
			}
		} else {
			if (BrowserType == 'msie') {
				document.getElementById('select_regioni').style.display = 'none';
				document.getElementById('select_regioni_input_txt').style.display = 'block';
				
				document.getElementById('select_eta_from').style.display = 'none';
				document.getElementById('select_eta_from_input_txt').style.display = 'block';
				
				document.getElementById('select_eta_to').style.display = 'none';
				document.getElementById('select_eta_to_input_txt').style.display = 'block';
			}
		}
		currentRegion = regione_id;
	}
	e.cancelBubble = true;
}


function closeAllDropDown(region_id) {
	
	if (region_id) {
		selectedClass = 'regione_button selected';
		notSelectedClass = 'regione_button';
		
		var aObj = document.getElementsByTagName('a');
		for (var i=0;i<aObj.length;i++) {
			if (aObj[i].className == selectedClass) {
				aObj[i].className = notSelectedClass;
			}
		}
		var divObj = document.getElementsByTagName('div');
		for (var i=0;i<divObj.length;i++) {
			if (divObj[i].className == 'dropdown') {
				divObj[i].style.display = 'none';
			}
		}
		if (!right_col_search) {
			if (BrowserType == 'msie') {
				document.getElementById('select_regioni').style.display = 'block';
				document.getElementById('select_regioni_input_txt').style.display = 'none';
				
				document.getElementById('select_disponibilita').style.display = 'block';
				document.getElementById('select_disponibilita_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_from').style.display = 'block';
				document.getElementById('select_eta_from_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_to').style.display = 'block';
				document.getElementById('select_eta_to_input_txt').style.display = 'none';
			}
		} else {
			if (BrowserType == 'msie') {
				document.getElementById('select_regioni').style.display = 'block';
				document.getElementById('select_regioni_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_from').style.display = 'block';
				document.getElementById('select_eta_from_input_txt').style.display = 'none';
				
				document.getElementById('select_eta_to').style.display = 'block';
				document.getElementById('select_eta_to_input_txt').style.display = 'none';
			}
		}
		document.getElementById(region_id).style.display = 'none';
		currentRegion = false;
	}
	
	//openDropDownRegione(false, regione_id, false)
}




