function toggle_tab(tabv,dtabv,tabd, dtabd) {
    var e_tabv = document.getElementById(tabv);
    var e_dtabv = document.getElementById(dtabv);
    var e_tabd = document.getElementById(tabd);
    var e_dtabd = document.getElementById(dtabd);
    e_tabv.className="selected";
    e_tabd.className="unselected";
    e_dtabv.className="show";
    e_dtabd.className="hide";
}

function toggle_unit(me,id_obj,tot) {
	disattivaLink();
	me.className="active";
	nascondiUnita(tot);
	var elem = document.getElementById(id_obj);
	elem.className="view_unit";
}

function disattivaLink() {
	var links=document.getElementById('lista_unita').getElementsByTagName('a');
	for(var i=0;i<links.length;i++){
    	links[i].className="none";
    }
}

function nascondiUnita(tot) {
	for(var i=1;i<=tot;i++){
		var elem = document.getElementById("unita"+i);
		elem.className="hidden_unit";
    }
}	

function toggle(obj) {
	var node = obj.nextSibling;
	alert(node.className);
	node.className=(node.className=="hide"?"show":"hide");
}

function toggle_obj(obj) {
	var node = document.getElementById(obj);
	node.className=(node.className=="hide"?"show":"hide");
	return(false);
}

function reset_field(obj, tipo) {
		switch(tipo) {
			case 'data':
				if (obj.value == 'dd/mm/yyyy')
					obj.value = "";
				break;
		}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
    }
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function TestSearch() {
    var form = document.getElementById("ricerca_case");
    if (form.tipologia.value=="0" &&  form.posizione.value=="0" &&  form.localita.value=="0" && form.postiletto.value=="0") {
        alert("Please, revise your search criteria by entering at least one field.");
        return(false);
    }
}	

function disattivaNews(active_news) {
	var newsp=document.getElementById('news').getElementsByTagName('div');
	for(var i=0;i<newsp.length;i++){
    	if (newsp[i].id=="news"+active_news) newsp[i].className="show";
	else newsp[i].className="hide";
    }
}

function loadimage(sorgente) {
    document["slideshow"].src=sorgente;
}

function printContent (content) {
    var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=650,height=600,left=100,top=25"; 
    var docprint = window.open("","",disp_setting);
    docprint.document.open(); 
    docprint.document.write('<html>');
    docprint.document.write('<head>');
    docprint.document.write('<title>Print page</title>');
	docprint.document.write('<style type="text/css">');
    docprint.document.write('body { font-size:100%; }');
	docprint.document.write('h1 { font-size:16px; }');
	docprint.document.write('h2 { font-size:14px; }');
	docprint.document.write('h3 { font-size:12px; }');
    docprint.document.write('p, td { font-size:11px; }');
    docprint.document.write('#foobar, #my_cal { display:none; }');
    docprint.document.write('</style>');
    docprint.document.write('</head>');
    docprint.document.write('<body onLoad="self.print()">');          
    docprint.document.write('<h1>PureItaly</h1>');          
    docprint.document.write(content);
    docprint.document.write('</body>');
    docprint.document.write('</html>'); 
    docprint.document.close(); 
    docprint.focus(); 
}

function printCol5() {
	printContent($('col5').innerHTML);
}

function printCol2() {
    var content = $('col2').innerHTML;
    if ($('services_div')) {
        content += '<table width="100%"><tr><td width="50%" valign="top"><h2>Services</h2>';
        content += $('services_div').innerHTML + '</td><td width="50%" valign="top">';
        if ($('access_div')) {
            content += '<h2>Facilities</h2>';
            content += $('access_div').innerHTML;
        }
        if ($('distances_div')) {
            content += '<h2>Distances</h2>';
            content += $('distances_div').innerHTML;
        }
		content += '</td></tr></table>';
    }
	printContent(content);
}

function clearAValue(event){
    var element = event.element();
    if (element.value == 'Dialling code') element.value = '';
	element.setStyle({'color':'#000000', 'font-style':'normal'});
}

function setAValue(event){
    var element = event.element();
    if (element.value == '') element.value = 'Dialling code';
	element.setStyle({'color':'#c0c0c0', 'font-style':'italic'});
}

function clearTValue(event){
    var element = event.element();
    if (element.value == 'Number') {
		element.setStyle({'color':'#000000'});
		element.value = '';
	}
}

function setTValue(event){
    var element = event.element();
    if (element.value == '') {
		element.setStyle({'color':'#c0c0c0'});
		element.value = 'Number';
	}
}

function clearPValue(event){
    var element = event.element();
    if (element.value == 'If yes, which type?') {
		element.setStyle({'color':'#000000'});
		element.value = '';
	}
}

function setPValue(event){
    var element = event.element();
    if (element.value == '') {
		element.setStyle({'color':'#c0c0c0'});
		element.value = 'If yes, which type?';
	}
}

function clearCValue(event){
    var element = event.element();
    if (element.value == 'Yes, please call me back between the hours of ...') {
		element.setStyle({'color':'#000000'});
		element.value = '';
	}
}

function setCValue(event){
    var element = event.element();
    if (element.value == '') {
		element.setStyle({'color':'#c0c0c0'});
		element.value = 'Yes, please call me back between the hours of ...';
	}
}

function submitForm(event){
	if ($('areacode') && $F('areacode') == 'Dialling code') $('areacode').value = '';
	if ($('areacode_mobile') && $F('areacode_mobile') == 'Dialling code') $('areacode_mobile').value = '';
	if ($('areacode_fax') && $F('areacode_fax') == 'Dialling code') $('areacode_fax').value = '';

	if ($('telefono') && $F('telefono') == 'Number') $('telefono').value = '';
	if ($('mobile') && $F('mobile') == 'Number') $('mobile').value = '';
	if ($('fax') && $F('fax') == 'Number') $('fax').value = '';

	if ($('type_pets') && $F('type_pets') == 'If yes, which type?') $('type_pets').value = '';

	if ($('time_tel') && $F('time_tel') == 'Yes, please call me back between the hours of ...') $('time_tel').value = '';
}

Event.observe(window, 'load', function() {
	if ($('areacode')) {
		$('areacode').setStyle({'color':'#c0c0c0'});
		$('areacode').observe('focus', clearAValue);
		$('areacode').observe('blur', setAValue);
	}
	if ($('areacode_mobile')) {
		$('areacode_mobile').setStyle({'color':'#c0c0c0'});
		$('areacode_mobile').observe('focus', clearAValue);
		$('areacode_mobile').observe('blur', setAValue);
	}
	if ($('areacode_fax')) {
		$('areacode_fax').setStyle({'color':'#c0c0c0'});
		$('areacode_fax').observe('focus', clearAValue);
		$('areacode_fax').observe('blur', setAValue);
	}
	
	if ($('telefono')) {
		$('telefono').setStyle({'color':'#c0c0c0'});
		$('telefono').observe('focus', clearTValue);
		$('telefono').observe('blur', setTValue);
	}
	if ($('mobile')) {
		$('mobile').setStyle({'color':'#c0c0c0'});
		$('mobile').observe('focus', clearTValue);
		$('mobile').observe('blur', setTValue);
	}
	if ($('fax')) {
		$('fax').setStyle({'color':'#c0c0c0'});
		$('fax').observe('focus', clearTValue);
		$('fax').observe('blur', setTValue);
	}

	if ($('type_pets')) {
		$('type_pets').setStyle({'color':'#c0c0c0'});
		$('type_pets').observe('focus', clearPValue);
		$('type_pets').observe('blur', setPValue);
	}

	if ($('time_tel')) {
		$('time_tel').setStyle({'color':'#c0c0c0'});
		$('time_tel').observe('focus', clearCValue);
		$('time_tel').observe('blur', setCValue);
	}

	if ($('richiedi')) {
		$('richiedi').observe('click', submitForm)
	}
})
