// Questo file contiene funzioni.
// Il linguaggio utilizzato è Javascript
//
// change image's source
function change_gif(imageFile, imageSource) {
	document [imageSource].src = imageFile;
	}

// formatting the loadtime of image
function format_time(string, start, lenght) {
	return string.substring(0, 6);
	}

// create dynamic windows for a zoom in
function windows_open(image_name, image_width, image_height, image_path) {
	var w = window.open("", "WindowImage", "resizable,status,width="+(image_width+20)+",height="+(image_height+90)+"");
	var d= w.document;

	var w_chiudi="'Chiudere / Schliessen'";
	var w_null="''";

	d.write('<html>');
	d.write('<head>');
	d.write('<title>Zoom In</title>');
	d.write('</head>');
	d.write('<body background="' + image_path + '/sfondo_window.gif" bgcolor="#EFD6C6">');
	d.write('<img src="' + image_path + image_name + '" width="' + image_width +
					    '" height="' + image_height +
					    '" alt="" border="0">');
	d.write('<br>');
	d.write('<br>');
	d.write('<table>');
	d.write('<tr>');
	d.write('<td width=25></td>');
	d.write('<td><a href="javascript:void(0)" onMouseOver="window.status= ' + w_chiudi + '; return true" onMouseOut="window.status= ' + w_null + '; return true" onclick="window.close(); return true">');
	d.write('<img src="' + image_path + '/m_chiudi_off.gif" width=134 height=43 alt="" border="0" name="m_chiudi">');
	d.write('</a></td>');
	d.write('</tr>');
	d.write('</table>');
	d.write('</body>');
	d.write('</html>');
	d.close();
	return true;
}


function WriteLastModified ()
{
//	return "Updated: " + lutext;
}

// Open the window descriptor
function fn_desc_win (language) {
	if (language=='D') window.open("./abc/pages/uber_uns.html", "WindowImage", "resizable,status,width=600,height=490,top=100,left=50");
	else window.open("./abc/pages/chi_siamo.html", "WindowImage", "resizable,status,width=600,height=440,top=100,left=350");
};

// Open the window navigator
function open_next_window (fixed_path, content_name, content_language) {
	var d= window.document;
	d.write('<frameset  rows="119,*" framespacing="0" border="false" frameborder="0" >');
	if (content_language=='D') d.write('    <frame name="bottom" src="' + fixed_path + '/buttom_d.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="no">');
	else d.write('    <frame name="bottom" src="' + fixed_path + '/buttom_i.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="no">');
	d.write('    <frameset  cols="99,*" framespacing="0" border="false" frameborder="0" >');
	d.write('        <frame name="left" src="' + fixed_path + '/left.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="no">');
	d.write('        <frame name="content" src="'+ content_name + '" marginwidth="0" marginheight="0" scrolling="auto" frameborder="no">');
	d.write('    </frameset>');
	d.write('</frameset>');
}

// Controlli sull'input
function ctrlObbligo(myform, language) {
	if (myform.name.value=="") {
		(language=='I') ? alert ("Attenzione, immettere cognome  !") : alert ("Achtung, Namen einfuegen !");
		return false;
	}
	if (myform.vorname.value=="") {
		(language=='I') ? alert ("Attenzione, immettere nome !") : alert ("Achtung, Vornamen einfuegen !");
		return false;
	}
	if (myform.strasse.value=="") {
		(language=='I') ? alert ("Attenzione, immettere indirizzo !") : alert ("Achtung, Strasse einfuegen !");
		return false;
	}
	if (myform.plz.value=="") {
		(language=='I') ? alert ("Attenzione, immettere NAP !") : alert ("Achtung,  PLZ einfuegen !");
		return false;
	}
	if (myform.ort.value=="") {
		(language=='I') ? alert ("Attenzione, immettere località !") : alert ("Achtung, Ort einfuegen !");
		return false;
	}

	myform.submit();
}

// Open the window descriptor
function fnOpenDesignPage (DesignUrl) {
	window.open(DesignUrl, "WEBDesign", "noresizable,status,width=540,height=253,top=100,left=350");
};



function WriteLastModified () {

	var browser = navigator.appName;
	var version = navigator.appVersion
	var ver1 = version.substring(0, 1)
	if (browser == 'Netscape')  return "";

	var lutime;
	var ludm;
	var ludd;
	var ludy;

	var pStrMesi = "January#February#March#April#May#June#July#August#September#October#November#December#";
	monthName = new Array(12);
	monthName = pStrMesi.split("#");

	lutime = unescape(document.lastModified);

    function writeData () {
		if (ludy.length==2) {
			(ludy >= 90) ? yearNow = 19: yearNow = 20;
		} else yearNow ="";
		return "Last update: " + ludd+". "+ monthName[parseInt(ludm-1)] +" "+ yearNow + ludy +" ";;
	}

	if (lutime.length == 19) { // mm/dd/yyyy hh:mm:ss  Netscape 4 and higher, Internet Explorer 5
		ludm = lutime.substring(0,2);
		ludd = lutime.substring(3,5);
		ludy = lutime.substring(6,10);
		return writeData();
	} else {
		if (lutime.length == 17) { // mm/dd/yy hh:mm:ss	Netscape 3 and higher, Internet Explorer 4
			ludm = lutime.substring(0,2);
			ludd = lutime.substring(3,5);
			ludy = lutime.substring(6,8);
			return writeData();
		} else {
			return "";
		}
	}

}

var message='Right button disabled !';
function click(e) {

	if (document.all) {
		if (event.button == 2) {
			alert(message);
			return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
			alert(message);
			return false;
		}
	}
}


//------------------------------------------------------------------------------
//  to return on Object's list
//------------------------------------------------------------------------------
function returnToList() {
	if (top.frames[1].document.objForm.lngObject.value == 'I') {
		top.frames[2].location='/abc/php/lista_immobili.phtml';
	} else {
		top.frames[2].location='/abc/php/liste_immobilie.phtml';
	}
}
//------------------------------------------------------------------------------
//  open the formular for selected object
//------------------------------------------------------------------------------
function openFormular() {

	if (top.frames[1].document.objForm.lngObject.value == 'I') {
		top.frames[2].location='../form_i.html';
	} else {
		top.frames[2].location='../form_d.html';
	}
}

function zoomImage(image_name, image_width, image_height, image_path)
{ 	// create dynamic windows for a zoom in
	var w = window.open("", "WindowImage");
	var d= w.document;

	d.write('<html>');
	d.write('<head>');
	d.write('<title>Zoom In</title>');
	d.write('<style>');
	d.write('BODY { color: aqua; FONT-FAMILY: verdana; FONT-SIZE: 10pt; FONT-WEIGHT: normal; TEXT-DECORATION: none} ');
	d.write('</style>');
	d.write('</head>');
	d.write('<body background="' + image_path + '/sfondo.gif" bgcolor="#EFD6C6"><center>');
	d.write('<img src="' + image_path + image_name + '" width="' + image_width +
					    '" height="' + image_height +
					    '" alt="" border="1">');
	d.write('<br><font size="-2">Foto vergrössert&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please wait to loading ...</font>');
	d.write('</center></body>');
	d.write('</html>');
	d.close();
	return true;
}

	  //------------------------------------------------------------------------------
	  //  Open the object's description
	  //------------------------------------------------------------------------------
function openObject(nObjekt, languageObjekt) {
	var wO = window.open("", "content");
	var d = wO.document;
	d.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
	d.write('<html>');
	d.write('<head>');
	d.write('  <title>Immobilienvermittlung</title>');
	d.write('</head>');
	d.write('<frameset rows="30, *, 30" framespacing="0" frameborder="no" border="0">');
	d.write('  <frame name="header_obj" src="/abc/pages/objects/obj_testa.html" marginwidth="0" marginheight="0" scrolling="no">');
	d.write('  <frame name="object"     src="/abc/php/open_obj.phtml?objnr='+nObjekt+'&objlanguage='+languageObjekt+'" marginwidth="0" marginheight="0" scrolling="auto">');
	d.write('  <frame name="foot_obj"   src="/abc/pages/objects/obj_piede.html" marginwidth="0" marginheight="0" scrolling="no">');
	d.write('</frameset>');
	d.write('<noframes>');
	d.write('  <body>');
	d.write('    <P>This page is designed to be viewed by a browser which supports');
	d.write('       Netscape\'s Frames extension. This text will be shown by browsers');
	d.write('       which do not support the Frames extension.</P>');
	d.write('  </body>');
	d.write('</noframes>');
	d.write('</html>');
}


//============================================================================================================
//	Value must be not null
//============================================================================================================
function mustNotNull(formName, inputName, fehler_text) {

	eval ("var inputValue = document."+ formName +"." + inputName + ".value");
	if (inputValue.length<1) {
		alert (fehler_text);
		eval (formName + "." + inputName + ".focus()");
		eval (formName + "." + inputName + ".select()");
		return false;
	}
	return true;
}
//============================================================================================================
//	Value must be eMail address
//============================================================================================================
function mustNumber(formName, inputName, fehler_text) {
	eval ("var inputValue = document." + formName + "." + inputName + ".value");
	var filter=/^[0-9]$/;
	if (inputValue.length == 0 ) return true;
	if (filter.test(inputValue))
		return true;
	else
		alert (fehler_text);
    eval (formName + "." + inputName + ".focus()");
		eval (formName + "." + inputName + ".select()");
    return false;
}

//============================================================================================================
//	Value must be eMail address
//============================================================================================================
function mustEMail(formName, inputName, fehler_text) {
	eval ("var inputValue = document." + formName + "." + inputName + ".value");
	if (inputValue.length == 0 ) return true;


	var firstPart = inputValue.substr(0, inputValue.indexOf("@"));
	var secondPart = inputValue.substr((inputValue.indexOf("@")+1));


	if (secondPart.indexOf(".")<1)
	{
		alert (fehler_text);
		eval (formName + "." + inputName + ".focus()");
		eval (formName + "." + inputName + ".select()");
		return false;
	}
	else
	{
		return true;
	}

}
//============================================================================================================
//	Value must be data
//============================================================================================================
function mustData(formName, inputName, fehler_text, formatData) {
	eval ("var inputValue = document." + formName + "." + inputName + ".value");
	if (!chkdate(inputValue, formatData.toUpperCase())) {
		alert (fehler_text);
		eval (formName + "." + inputName + ".focus()");
		eval (formName + "." + inputName + ".select()");
		return false;
	}
	return true;
}
//============================================================================================================
//	Ctrl second data must > first data
//============================================================================================================
function ctrlData (formName, p_dFrom, p_dTo, fehler_text) {
	var fErr = 0;
	var dFrom = new Array;
	var dTo = new Array;
	eval ("dFrom = document." + formName + "." + p_dFrom + ".value.split(\".\")");
	eval ("dTo = document." + formName + "." + p_dTo + ".value.split(\".\")");
	data_from = new Date(dFrom[2], dFrom[1], dFrom[0]);
	data_to = new Date(dTo[2], dTo[1], dTo[0]);
	if (data_to < data_from) {
	 	alert (fehler_text);
    	return false;
	}
	return true;
}
function fromToday (formName, p_dFrom, fehler_text) {
	var fErr = 0;
	var dFrom = new Array;
	eval ("dFrom = document." + formName + "." + p_dFrom + ".value.split(\".\")");
	data_from = new Date(dFrom[2], (dFrom[1]-1), dFrom[0]);
	d_today = new Date();
	data_today = new Date(d_today.getYear(), (d_today.getMonth()), d_today.getDate());
	if (data_from < data_today ) {
	 	alert (fehler_text);
	    	return false;
	}
	return true;
}

function dataToday (formName, p_dFrom, p_dTo, fehler_text) {
	var fErr = 0;
	var dFrom = new Array;
	var dTo = new Array;
	eval ("dFrom = document." + formName + "." + p_dFrom + ".value.split(\".\")");
	eval ("dTo = document." + formName + "." + p_dTo + ".value.split(\".\")");
	data_from = new Date(dFrom[2], dFrom[1], dFrom[0]);
	data_to = new Date(dTo[2], dTo[1], dTo[0]);
	if (data_to < data_from) {
	 	alert (fehler_text);
    	return false;
	}
	return true;
}
//============================================================================================================
//	Value format data
//============================================================================================================
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) return true;
	} else {
		if ((intYear % 4) == 0) return true;
	}
	return false;
}
function formatData (objName, strDatestyleIN) {

	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var allMonth ="Jan#Feb#Mar#Apr#May#Jun#Jul#Aug#Sep#Oct#Nov#Dec"
	var strMonthArray = allMonth.split("#");

	var strDatestyle=strDatestyleIN.toUpperCase();

	strDate = objName.value;
	if (strDate.length < 1) {
		return true;
	}

	if (strDate.length < 4) {
		return false;
	}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			} else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}

	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}

	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}

	// MON/DD/YYYY, US style
	if (strDatestyle == "MON/DD/YYYY") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	intday = parseInt(strDay, 10);
	intMonth = parseInt(strMonth, 10);
	for (i = 0;i<12;i++) {
		if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
			intMonth = i+1;
			strMonth = strMonthArray[i];
			i = 12;
		}
	}
	intYear = parseInt(strYear, 10);


//
//  DD.MM.YYYY = 01.01.1999
//  D.M.YYYY   = 1.1.1999
//  DD.MON.YYYY = 01.Jan.1999
//  D.MON.YYYY = 1.Jan.1999
//
	if (strDatestyle == "MON/DD/YYYY") {
		datefield.value = strMonthArray[intMonth-1] + "/" + strDay+"/" + strYear;
	} else if (strDatestyle == "MON/D/YYYY") {
		datefield.value = strMonthArray[intMonth-1] + "/" + intday+"/" + strYear;
	} else if (strDatestyle == "DD.MON.YYYY") {
		datefield.value = strDay + "." + strMonthArray[intMonth-1] + "." + strYear;
	} else if (strDatestyle == "D.MON.YYYY") {
		datefield.value = intday + "." + strMonthArray[intMonth-1] + "." + strYear;
	} else if (strDatestyle == "DD.MM.YYYY") {
		datefield.value = strDay + "." + strMonth + "." + strYear;
	} else if (strDatestyle == "D.M.YYYY") {
		datefield.value = intday + "." + intMonth + "." + strYear;
	}

	if (datefield.value.length < 8) {
		alert("Datum, ungültige Format !");
		return false;
	}

	return true;

}

//============================================================================================================
// Controllo su campo Data
//============================================================================================================
function chkdate(strDate, strDatestyle) {
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var allMonth ="Jan#Feb#Mar#Apr#May#Jun#Jul#Aug#Sep#Oct#Nov#Dec"
	var strMonthArray = allMonth.split("#");

	if (strDate.length < 1) {
		return true;
	}
	if (strDate.length < 4) {
		return false;
	}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) return false;
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}

	if ((strDay.length + strMonth.length + strYear.length ) < 6) {
		return false;
	}

	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}

	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}


	if ((strDay.length>2) || (strDay.length==0)) {
		return false;
	}
	if ((strMonth.length>2) || (strMonth.length==0)) {
		return false;
	}
	if ((strYear.length!=2) && (strYear.length!=4)) {
		return false;
	}


	// MON/DD/YYYY, US style
	if (strDatestyle == "MON/DD/YYYY" || strDatestyle == "MON/D/YYYY") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}


	intday = parseInt(strDay, 10);
	if (isNaN(intday)) return false;

	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) return false;
	}

	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) return false;

	if (intMonth>12 || intMonth<1) return false;
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) return false;
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) return false;

	if (intMonth == 2) {
		if (intday < 1) return false;
		if (LeapYear(intYear) == true) {
			if (intday > 29) return false;
		} else {
			if (intday > 28) return false;
		}
	}

	return true;
}


function insert_copyright() {
	var dToday = new Date()
	yToday = dToday.getFullYear();
	document.write('<center>');
	document.write('    <span style="font-size:10px">Copyright &copy;, Imotours-abc 1995-' + yToday + '. All right reserved.</span>');
	document.write('</center>');
}