// JavaScript Document

///////////////////////////////////
//disabilita tasto destro
function clickIE4() {
	if (event.button == 2) {
		alert('Copyright � Audrey Hepburn Children\'s Fund Official Site');
		return false;
	}
}

function clickNS4(e) {
	if (document.layers || document.getElementById && !document.all) {
		if (e.which == 2 || e.which == 3) {
			alert('Copyright � Audrey Hepburn Children\'s Fund Official Site');
			return false;
		}
	}
}

if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown = clickNS4;
} else if (document.all && !document.getElementById) {
	document.onmousedown = clickIE4;
}

function msg_copy() {
	alert('Dear Visitor, please note that all the images of audreyhepburn.com are copyrighted.\nIf you\'d like to share our images with others, please simply send them to this page.\nThank you.');
	return false;
}

//document.oncontextmenu=new Function("return false")
document.oncontextmenu = msg_copy;
// /////////////////////////////////

// varibili per galleria selezionata
var selectedGallery = ''; // galleria selezionata
var selectedParag = ''; // paragrafo selezionato

/* ________________ MENU_____________________ */

function menu(idM, idTip, idTipMenuSub, idModulo, p1) {

	with (document.form_menu) {
		idMenu.value = idM;

		idMenuSub.value = '';
		idParagrafo.value = '';

		action = '/menu/index.php';

		switch (idTip) {
		case '1':
			//3 colonne
			action = '/menu/index.php';
			switch (idTipMenuSub) {
			case '5':
				//paragrafi
				action = '/menu/index.php';
				break;
			case '6':
				//modulo
				switch (idModulo) {
				case '1':
					//news
					action = '/news/index.php';
					break;
				case '2':
					//search
					action = '/search/index.php';
					break;
				}
				break;
			}
			break;
		case '2':
			//2 colonne
			action = '/menu/index02.php';
			break;
		case '3':
			//link
			action = '/menu/index03.php';
			break;
		case '4':
			//link
			action = '/menu/index04.php';
			break;
		}

		submit();
	}
}
function menuSub(idM, idTipMenuSub, idModulo) {
	with (document.form_menu) {
		idMenu.value = idM;
		idMenuSub.value = idM;
		idParagrafo.value = '';

		action = '/menu/index.php';

		switch (idTipMenuSub) {
		case '5':
			//paragrafi
			action = '/menu/index.php';
			break;
		case '6':
			//modulo
			switch (idModulo) {
			case '1':
				//news
				action = '/news/index.php';
				break;
			case '2':
				//search
				action = '/search/index.php';
				break;
			}
			break;
		}

		submit();
	}
}
function menuPar(idP, idM, idMs) {
	with (document.form_menu) {
		idMenu.value = idM;
		idMenuSub.value = idMs;
		idParagrafo.value = idP;

		action = '/menu/index.php';
		submit();
	}
}

function loadGallery02(idM, p2) {
	document.form_menu.idMenu.value = idM;
	document.form_menu.page.value = '';

	var parametri = formCollection(document.form_menu);

	getCode("/menu/gallery02.php", "main_left_center", parametri, "", "", "",
			"");
}

function navigaGallery01(idP, myPage, p1, p2) {
	var parametri = "";
	// carico lista
	with (document.form_menu) {
		idParagrafo.value = idP;
		page.value = myPage;

		parametri = formCollection(document.form_menu);

		getCode("/menu/gallery01.php", 'main_center', parametri, "", "", "", "");
	}
}

function loadGallery01List(idP, p2) {
	document.form_menu.idParagrafo.value = idP;
	document.form_menu.page.value = '';

	var parametri = formCollection(document.form_menu);

	getCode("/menu/gallery01.php", "main_center", parametri, "", "", "", "");
}

function loadMedia01List(idP, urlVideo, idVideo) {
	document.form_menu.idParagrafo.value = idP;
	document.form_menu.idMedia.value = idVideo;
	document.form_menu.page.value = '';

	var parametri = formCollection(document.form_menu);
	getCode("/menu/media01.php", "main_center", parametri, "play_video('"
			+ urlVideo + "');", "", "", "");
	// getCode("/menu/media01.php", "main_center", parametri, "","","","");
}

function navigaMedia01_OOOOLLLLDDDD(idP, myPage, p1, p2) {
	var parametri = "";
	// carico lista
	with (document.form_menu) {
		idParagrafo.value = idP;
		page.value = myPage;

		parametri = formCollection(document.form_menu);

		getCode("/menu/media01.php", 'main_center', parametri, "", "", "", "");
	}
}

function navigaMedia01(idP, urlVideo, idVideo, p1) {
	var parametri = "";
	// carico lista
	with (document.form_menu) {
		idParagrafo.value = idP;
		idMedia.value = idVideo;
		page.value = '';

		parametri = formCollection(document.form_menu);

		getCode("/menu/media01.php", 'main_center', parametri, "play_video('"
				+ urlVideo + "');", "", "", "");
	}
}

function play_video(video) {
	//alert(video);
	var so = new SWFObject(
			"/FLV_player/FLV_player_liquido.swf?auto_start=false&video="
					+ video, "mymovie", "300", "220", "8", "");
	so.addParam("quality", "best");
	so.addParam("wmode", "transparent");
	so.addParam("salign", "t");
	so.write("gallery_video", "<br /><br /><br />");
}

function newsCat(idNc, goTo, idM, idMs) {
	var strErr = '';
	var parametri = '';
	var idTip = '';
	with (document.form_menu) {

		if (strErr != '') {
			alert(strErr);
		} else {

			idNews_categoria.value = idNc;
			idMenu.value = idM;
			idMenuSub.value = idMs;
			// alert(idParagrafo.value);

			action = goTo;
			submit();

		}

	}
}

function nl_signup(idNc, idM, idMs) {
	var strErr = '';
	var parametri = '';
	var idTip = '';
	with (document.form_menu) {

		if (strErr != '') {
			alert(strErr);
		} else {

			idNews_categoria.value = idNc;
			idMenu.value = idM;
			idMenuSub.value = idMs;
			// alert(idParagrafo.value);

			action = '/newsletter/nl_signup.php';
			submit();

		}

	}
}

function nl_archive(idNc, idM, idMs) {
	var strErr = '';
	var parametri = '';
	var idTip = '';
	with (document.form_menu) {

		if (strErr != '') {
			alert(strErr);
		} else {

			idNews_categoria.value = idNc;
			idMenu.value = idM;
			idMenuSub.value = idMs;
			// alert(idParagrafo.value);

			action = '/newsletter/nl_archive.php';
			submit();

		}

	}
}

function loadNewsGallery01(idN, p2) {
	document.form_menu.idNews.value = idN;
	document.form_menu.page.value = '';

	var parametri = formCollection(document.form_menu);

	getCode("/news/gallery01.php", "main_center", parametri, "", "", "", "");
}

function resetPage(tipoPage, p1) {
	switch (tipoPage) {
	case 1:
		document.getElementById("main_center").innerHTML = '';
		break;
	}
}

function navigaNewsGallery01(idN, myPage, p1, p2) {
	var parametri = "";
	// carico lista
	with (document.form_menu) {
		idNews.value = idN;
		page.value = myPage;

		parametri = formCollection(document.form_menu);

		getCode("/news/gallery01.php", 'main_center', parametri, "", "", "", "");
	}
}

function set(elem, p1, p2) {
/*
	with (document) {
		if (document.getElementById(elem)) {
			document.getElementById(elem).className = 'seePicture_on';
			if (selectedGallery != '' && selectedGallery != elem && selectedGallery!=null){
				document.getElementById(selectedGallery).className = 'seePicture';
		    }
			selectedGallery = elem;
		}
	}
	*/
}

function set_parag(elem, p1, p2) {
	with (document) {
		getElementById(elem).className = 'submenuLeft_on';
		if (selectedParag != '' && selectedParag != elem)
			getElementById(selectedParag).className = 'submenuLeft_off';
		selectedParag = elem;
	}
}

function searchInSite(idM, p1, p2) {
	var strErr = '';
	with (document.form_menu) {

		if (searchkey.value == '') {
			alert('Attention! You must specify a key search!');
			return false;
		} else {
			idMenu.value = idM;
			idMenuSub.value = idM;
			idParagrafo.value = '';

			action = '/search/index.php';

			submit();
		}
	}

}

function checkKeySubmit(idM, p1, p2) {
	var strErr = '';
	alert('aaaaaaaaaaaaaaaaaaaa');
	with (document.form_menu) {

		alert('== ' + searchkey.focus());

		if (!searchkey.focus()) {
			alert('premuto');
			/* searchInSite(idM,p1,p2); */
		}
		//alert('aaa');
	}
}

function swapimage(img, imgA) {
	with (document) {
		getElementById(img).src = imgA;
	}
}

function setCheckbox01(idNlC, template, p1) {
	var myArr;
	var trovato = false; // se true elemento esiste in array

	with (document.form_menu) {
		//alert('1=='+idNewsletterCategoria.value);
		myArr = idNewsletterCategoria.value.split(',');

		// alert('lunghezza='+myArr.length);
		for ( var i = 0; i < myArr.length; i++) { //scorro array
			// alert(myArr[i]+' - '+idNlC);
			if (myArr[i] == idNlC) {
				trovato = true
				// elemento esiste quindi toglierlo
				myArr.splice(i, 1);
				// setto img checkbox a off
				swapimage('checkBox_' + idNlC,
						'/template/' + template + '/images/checkbox_off.gif');
				swapimage('checkBox_all',
						'/template/' + template + '/images/checkbox_off.gif');
			}
		}

		if (!trovato) { //elemento non esiste quindi metterlo
			myArr.push(idNlC);
			// setto img checkbox a on
			swapimage('checkBox_' + idNlC,
					'/template/' + template + '/images/checkbox_on.gif');
		}

		//ricompongo stringa
		idNewsletterCategoria.value = myArr.join(',');

		// alert('2=='+idNewsletterCategoria.value);
	}

}

function setCheckbox01_all(template, p1) {
	var myArr = new Array();
	var trovato = false; // se true elemento esiste in array

	with (document.form_menu) {
		//alert('1=='+idNewsletterCategoria.value);
		idNewsletterCategoria.value = '';

		// alert('lunghezza='+myArr.length);
		for ( var i = 0; i < areaArr.length; i++) { //scorro array
			if (areaArr[i] != '') {
				myArr.push(areaArr[i]);
				// setto img checkbox a on
				swapimage('checkBox_' + areaArr[i],
						'/template/' + template + '/images/checkbox_on.gif');
			}
		}

		swapimage('checkBox_all',
				'/template/' + template + '/images/checkbox_on.gif');

		// ricompongo stringa
		idNewsletterCategoria.value = myArr.join(',');

	}

}

function checkForm_sigup() {
	var strErr = '';
	var parametri = '';

	with (document.form_menu) {
		//nome
		setElementStyle('nome', 'input_nl', '', '');
		if (nome.value == '') {
			strErr += 'The field \'Name\' is required!\n';
			setElementStyle('nome', 'input_nl_error', '', '');
		} else {
			nome.value = injection_strip(nome.value);
		}

		//cognome
		setElementStyle('cognome', 'input_nl', '', '');
		if (cognome.value == '') {
			strErr += 'The field \'Family Name\' is required!\n';
			setElementStyle('cognome', 'input_nl_error', '', '');
		} else {
			cognome.value = injection_strip(cognome.value);
		}

		//email
		setElementStyle('email', 'input_nl', '', '');
		setElementStyle('email_confirm', 'input_nl', '', '');
		// if (email.value=='') email.value=injection_strip(email.value);
		if (!checkEmailFormat(email.value)) {
			strErr += 'The field \'E-mail\' does not have a correct format!\n';
			setElementStyle('email', 'input_nl_error', '', '');
		} else if (email.value != email_confirm.value) {
			strErr += 'The fields \'E-mail\' and \'Confirm E-mail\' do not match!\n';
			setElementStyle('email', 'input_nl_error', '', '');
			setElementStyle('email_confirm', 'input_nl_error', '', '');
		}

		//area d'interesse
		if (idNewsletterCategoria.value == '') {
			strErr += 'You must select at least an area of interest!\n';
		}

		if (strErr != '') {
			alert(strErr);
		} else {
			parametri = formCollection(document.form_menu);

			// controllo se esiste gi� l'email
			// getCall('/user/email_double_check.php', '', parametri,
			// 'alert(aj_return);insertNluser();', true, '', '');
			getCode("/user/email_double_check.php", 'area_hide', parametri,
					"insertNluser();", "", "", "");

		}
	}
}

function insertNluser() {
	var aj_return = document.getElementById("area_hide").innerHTML;

	var parametri = formCollection(document.form_menu);
	if (aj_return == 'OK') {
		//inserisco nuovo utente
		getCall('/newsletter/nl_user_insert.php', 'content_signup', parametri,
				'', false, '', '');
		document.getElementById("msg_registration_ok").innerHTML = 'Please check your email box to confirm registration.Remember to check your unwanted mail / spam mailbox as well.';
		document.getElementById("msg_registration_ok").style.display = 'block';
	} else {
		alert('The email is already included in our archive!');
	}
}

function loadNewsletterGallery01(idNl, p2) {
	document.form_menu.idNewsletter.value = idNl;
	document.form_menu.page.value = '';

	var parametri = formCollection(document.form_menu);

	getCode("/newsletter/gallery01_archivio.php", "main_center", parametri, "", "", "", "");
}

function nl_archive_view(idNl, p1) {
	var miaFinestraFront = '';
	document.form_menu.idNewsletter.value = idNl;
	miaFinestraFront = window
			.open(
					'',
					'miaFinestraFront',
					'width=800,height=800,scrollbars=yes,location=no,status=no,toolbar=no,resizable=no');

	if (idNl > 1) {
		document.form_menu.action = '/newsletter/template/001/newsletter.php';
	} else {
		document.form_menu.action = '/newsletter/template/001/newsletter_old.php';
	}
	document.form_menu.target = 'miaFinestraFront';
	document.form_menu.submit();
	document.form_menu.target = '';

	miaFinestraFront.focus();
}

function loadGallerySearch(idM, p2) {
	document.form_menu.idMenu.value = idM;
	document.form_menu.page.value = '';

	var parametri = formCollection(document.form_menu);

	getCode("/search/gallery.php", "main_left_center", parametri, "", "", "",
			"");
}

function search_goto_paragraph(idM, idPar, p1) {
	with (document.form_menu) {
		idMenu.value = idM;
		idMenuSub.value = idM;
		idParagrafo.value = idPar;
		issearch.value = '1';

		action = '/menu/index.php#par_' + idPar;

		submit();
	}
}

function search_goto_menu(idM, idTip, idTipMenuSub, idModulo, p1) {

	with (document.form_menu) {
		idMenu.value = idM;

		idMenuSub.value = '';
		idParagrafo.value = '';

		action = '/menu/index.php';

		switch (idTip) {
		case '1':
			//3 colonne
			action = '/menu/index.php';
			switch (idTipMenuSub) {
			case '5':
				//paragrafi
				action = '/menu/index.php';
				break;
			case '6':
				//modulo
				switch (idModulo) {
				case '1':
					//news
					action = '/news/index.php';
					break;
				case '2':
					//search
					action = '/search/index.php';
					break;
				}
				break;
			}
			break;
		case '2':
			//2 colonne
			action = '/menu/index02.php';
			break;
		case '3':
			//link
			action = '/menu/index03.php';
			break;
		case '4':
			//link
			action = '/menu/index04.php';
			break;
		}

		submit();
	}
}

function injection_strip(input) {
	var text = input;
	text = text.replace(/\n/m, "<br />"); // new line to br
	text = text.replace(/\r/m, "<br />"); // return to br
	text = text.replace(/\<\?/gi, " "); // php
	text = text.replace(/\?\>/gi, " "); // php
	text = text.replace(/\<\?php/gi, " "); // php
	text = text.replace(/\<\%/gi, " "); // asp
	text = text.replace(/\%\>/gi, " "); // asp
	text = text.replace(/\%00/m, " "); // null removal
	text = text.replace(/\\00/m, " "); // unicode removal
	text = text.replace(/\&#/g, " "); // &# removal (# allowed for inline CSS)
	text = text.replace(/\&lt/gi, " "); // &lt removal
	text = text.replace(/\(\'/, " "); // (' removal
	text = text.replace(/\'\)/, " "); // ') removal
	text = text.replace(/(\/*)/, " "); // comments script obfuscation
	text = text.replace(/!\[CDATA/gi, " "); // script obfuscation
	text = text.replace(/javascript/gi, " "); // script instance
	text = text.replace(/\<script\>/gi, " "); // script instance
	text = text.replace(/\<\/script\>/gi, " "); // script instance
	text = text.replace(/\<script/gim, " "); // script instance
	text = text.replace(/on(.*)\B[(.*)="]/gi, " "); // Event handlers
	text = text.replace(/on(.*)\B[(.*)=(.*)]/gi, " "); // Event handlers
	text = text.replace(/eval\((.*)\)/gi, " "); // Eval stuff
	text = text.replace(/fromCharCode/gi, " "); // fromCharCode
	text = text.replace(/getElementBy(.*)/gi, " "); // getElementBy
	text = text.replace(/!--/gi, " "); // SSI
	text = text.replace(/\<!/gi, " "); // html
	text = text.replace(/\<meta/gi, " "); // html
	text = text.replace(/\<base/gi, " "); // html
	text = text.replace(/\<style/gi, " "); // html
	text = text.replace(/\<ilayer/gi, " "); // html
	text = text.replace(/\<iframe/gi, " "); // html
	text = text.replace(/\<frame/gi, " "); // html
	text = text.replace(/\<embed/gi, " "); // html
	text = text.replace(/\<link/gi, " "); // html
	text = text.replace(/\<import/gi, " "); // html
	text = text
			.replace(
					/(vbscript(.*)\b[(*):]_|data(.*)\b[(*):]|base64(.*)\b[(*):]_|expression(.*)\b[(*):]|urn(.*)\b[(*):])/gi,
					" ");
	text = text
			.replace(
					/(binding(.*)\b[(*):]_|moz-binding(.*)\b[(*):]|behavior(.*)\b[(*):])/gi,
					" ");
	text = text.replace(
			/(window|document|style)._(location|cookie|images|frames)/gi, " ");

	// document.getElementById('output').innerHTML = text;

	return text;
}

function set_meta_info(title, keywords, description) {
	/*
	alert(title+","+ keywords+","+ description);
	document.title = title;
	// Iterate through the array, listing them all
	// Update only the Title meta tag
	var metatags = document.getElementsByTagName("meta");
	for (cnt = 0; cnt < metatags.length; cnt++)
	{
		// Update the Title meta tag
		
		if (metatags[cnt].getAttribute("name") == "Description") {
			alert(metatags[cnt].setAttribute("content"));
			//metatags[cnt].setAttribute("content", description);
		}
		
		if (metatags[cnt].getAttribute("name") == "Keywords") {
			alert(metatags[cnt].setAttribute("content"));
			//metatags[cnt].setAttribute("content", keywords);
		}

	}
	 */
}
