﻿// JScript File

function ClientBack() {
	h = window.history;
	if (h.length) { // if there is a history
		h.back();     // equivalent to clicking back button
	}
}

function getValueByRadioList(radioList) {
	if (!radioList) return
	for (var i = 0; i < radioList.length; i++) {
		if (radioList[i].checked)
			return radioList[i].value;
	}
}

function goToCatalog(famiglia) {
	var isScooterFamily = (famiglia.toLowerCase().indexOf('scooter') > -1);
	var basePath = "/scooter/";
	if (!isScooterFamily) basePath = "/moto/";
	if (document.getElementsByName('tipo')[0].checked) {
		document.location = basePath + 'nuovo.aspx?famiglia=' + famiglia;
	} else {
		document.location = basePath + 'usato.aspx?famiglia=' + famiglia;
	}
}


function infoRequest(scheda) {
	if (scheda) {
		getObj('DIVmotoInfoRequest').style.display = '';
		getObj('DIVmotoScheda').style.display = 'none';
	} else {
		getObj('DIVmotoScheda').style.display = '';
		getObj('DIVmotoInfoRequest').style.display = 'none';
	}
}

function addToFavorites() {
	var urlAddress = "http://www.motoservice.net";
	var pageName = "Motoservice";
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(pageName, urlAddress, "");
	} else if (window.external) { // IE Favorite
		window.external.AddFavorite(urlAddress, pageName);
	} else if (window.opera && window.print) { // Opera Hotlist
		alert("Siamo spiacenti! Il tuo browser non sembra supportare questa funzione.");
	} else {
		alert("Siamo spiacenti! Il tuo browser non sembra supportare questa funzione.");
	}
}

function addPageToFavorites(ProductName) {
	var urlAddress = document.location;
	var pageName = "Motoservice - " + ProductName;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(pageName, urlAddress, "");
	} else if (window.external) { // IE Favorite
		window.external.AddFavorite(urlAddress, pageName);
	} else if (window.opera && window.print) { // Opera Hotlist
		alert("Siamo spiacenti! Il tuo browser non sembra supportare questa funzione.");
	} else {
		alert("Siamo spiacenti! Il tuo browser non sembra supportare questa funzione.");
	}
}

function getObj(name) {
	return document.getElementById(name)
}

function CheckChecked(source, arguments) {
	if (document.getElementById("ctl00_ContentPlaceHolder1_accetto_privacy").checked) {
		arguments.IsValid = true;
		return true
	} else {
		arguments.IsValid = false;
		return false
	}
}

//controlla il codice da trascrivere per il CustomValidator per il campo anti-spam
function CheckCodiceTrascritto(source, arguments) {
	if (arguments.Value + "" == "12345") {
		arguments.IsValid = true;
		return true
	} else {
		arguments.IsValid = false;
		return false
	}
}


function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}



function getHeight(obj) {
	if (document.getBoxObjectFor) {
		var bo = document.getBoxObjectFor(obj);
		return bo.height;
	}
	else if (obj.getBoundingClientRect) {
		var rect = obj.getBoundingClientRect();
		return rect.bottom - rect.top;
	}
}

function getWidth(obj) {
	if (document.getBoxObjectFor) {
		var bo = document.getBoxObjectFor(obj);
		return bo.width;
	}
	else if (obj.getBoundingClientRect) {
		var rect = obj.getBoundingClientRect();
		return rect.right - rect.left;
	}
}


function MoveOnContent(obj, e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	endXobj = findPosX(obj) + getWidth(obj);
	if ((posx - findPosX(obj) > 0) && (posx - findPosX(obj) < 20)) {
		obj.scrollLeft = obj.scrollLeft - 10;
		setTimeout("", 50);
	}
	if ((posx < endXobj) && (posx > endXobj - 40)) {
		obj.scrollLeft = obj.scrollLeft + 10;
		setTimeout("", 50);
	}

}

function popPrivacy() {
	window.open("/azienda/privacy.aspx?popUp=true", "pricacy", "height=400,width=300,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}


function inputEuro_onkeyPress(objInput, e) {
	var strPress, strCharPermitted;
	var key;
	if (window.event) {
		key = event.keyCode
	} else {
		key = e.charCode;
		if (key == 0) return;
		//if (!isNumCode(key)) return;
	}
	key = String.fromCharCode(key);
	if (key.length == 0) return;
	if (!isEuroProgress(objInput.value + key)) {
		if (window.event) { //IE
			window.event.returnValue = false;
			window.event.keyCode = null;
		} else { //Firefox
			e.preventDefault();
		}
	}
}

function isEuroProgress(data) {
	if (data.length == 0) return true
	var rez = /^[\+|\-]{0,1}$/;
	if (rez.test(data)) {
		return true
	}
	rez = /^[\+|\-]{0,1}[\d]*$/;
	if (rez.test(data)) {
		return true
	}
	rez = /^[\+|\-]{0,1}[\d]*[[\,|\.]?$/;
	if (rez.test(data)) {
		return true
	}
	rez = /^[\+|\-]{0,1}[\d]*[[\,|\.]?[\d]{1,2}]?$/;
	if (rez.test(data)) {
		return true
	}
	return false
}

function isNumCode(Data) {
	numChars = ".0123456789";

	var isNum = true;
	var index = 0;
	while ((index < Data.length) && (isNum)) {
		isNum = (numChars.indexOf(Data.charAt(index)) != -1);
		index++;
	}
	return isNum;
}

function resetSubmitControl() {
	document.form.onsubmit = null;
}

function hideOrUnhideChildElement(obj, elementName) {
	if (!obj.hasChildNodes()) return;
	var obz;
	obz = getSubObj(obj, elementName);
	if (obz == undefined)
		return
	if (obz.style.display == 'none') {
		obz.style.display = '';
		obj.src = '/images/bx-minus.gif';
	} else {
		obz.style.display = 'none';
		obj.src = '/images/bx-plus.gif';
	}
}

function hideOrUnhideNextElement(obj, elementName) {
	var obz;
	obz = getObjSibling(obj, elementName);
	if (obz == undefined)
		return
	if (obz.style.display == 'none') {
		obz.style.display = '';
		obj.src = '/images/bx-minus.gif';
	} else {
		obz.style.display = 'none';
		obj.src = '/images/bx-plus.gif';
	}
}

function getSubObj(obj, elementName) {
	var oobj = obj.childNodes;
	for (var i = 0; i < oobj.length; i++) {
		if (oobj[i].tagName != null) {
			if (oobj[i].tagName.toLowerCase() == elementName.toLowerCase()) {
				return oobj[i];
			}
		}
	}
}

function getObjSibling(masterObj, tagNamez) {
	var objtmp = masterObj.nextSibling;
	if (objtmp.tagName != undefined) {
		if (objtmp.tagName.toLowerCase() == tagNamez.toLowerCase()) {
			return objtmp;
		}
	}
	return getObjSibling(objtmp, tagNamez);
}

function printVeicolo() {
	var url = window.document.URL + "";
	url = url.replace("#", "");
	url = url + "&popUp=true";
	window.open(url, "scheda", "height=600,width=760,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}
