strBasePath = "http://www.sapere.it/tca/MainApp"
//strBasePath = "http://194.244.21.234/tca/MainApp"

function openTimeline() {
	window.open("/tca/minisite/scuola/timeline/timeline.html",'remote',"width=761,height=451,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0");
}

function writeImage() {
	//to be implemented
}
function CPForGo(sName,sAttr) {
	q=sName.lastIndexOf(".")
	sExt=sName.substr(q+1,sName.length-q-1)
	sName=sName.substr(0,q)
	go(sExt,sName,sAttr)
}

function URLForGo(sURL) {
	sAbsPath = strBasePath + "?srvc=dcmnt&url=";
	document.location=sAbsPath + sURL;
}

function goLemma(page_id) {
  if (page_id.indexOf(",") != -1) {
    option = page_id.split(",");
    sAbsPath = strBasePath + "?srvc=vr&url=/" + option[1] + "/" + option[0] + "_1";
  }
  else {
    sAbsPath = strBasePath + "?srvc=vr&url=/" + channel + "/" + page_id + "_1";
  }
  document.location=sAbsPath;
}

function goExternal(strURL) {
	if(strURL.indexOf("tca/minisite") != -1) {
		window.open(strURL).focus();
	}
	else {
		location = strURL;
	}
}


function goAtlante(strURL){
  sAbsPath = strBasePath + "?srvc=jsp&name=atlante/contentHolder&content=" + strURL;
  if(strURL != "#"){
    document.location=sAbsPath;
  }
}


// vertical reference links.
function goVR(strURL) {
	sAbsPath = strBasePath + "?srvc=vr&url=" + strURL
	document.location = sAbsPath;
}


// Writes the local banner.
function writeBannerLocal() {
	strLink = "http://www.sapere.it";
	var intNum = Math.floor(Math.random() * 10);
	var strHTML = '';
	strHTML += '<a href="' + strLink + '">';
	strHTML += '<img src="/images/banner_local_' + intNum + '.gif" border="0" alt="">';
	strHTML += '</a>';
	document.write(strHTML);
}


// Creates banner regarding of branch value.

function writeBannerBig() {
	var strType = "";
	switch(branch) {
		case "/docroot/tc/geografia":
			strType = "viag&modn=viag";
			break;
		case "/docroot/tc/medicina":
			strType = "salu&modn=salute";
			break;
		case "/docroot/tc/sport":
			strType = "spor&modn=sport";
			break;
		case "/docroot/tc/scuola":
			strType = "scuo";
			break;
		default:
			strType = "genr";
	}
	document.write('<IFRAME SRC="http://adv.sapere.it/adv/adserver?type=html&site=sape&adsize=468x60&subsite=home" WIDTH=468 HEIGHT=60 MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR="#000000">')
	document.write('<SCRIPT LANGUAGE="JavaScript1.1" SRC="http://adv.sapere.it/adv/adserver?type=js&site=sape&adsize=468x60&pos=1&subsite=home"></SCRIPT>')
	document.write('</IFRAME>')
}


// Creates banner regarding of branch value.
function writeBannerSmall() {
	var strType = "";
	switch(branch) {
		case "/docroot/tc/geografia":
			strType = "viag&modn=viag";
			break;
		case "/docroot/tc/medicina":
			strType = "salu&modn=salute";
			break;
		case "/docroot/tc/sport":
			strType = "spor&modn=sport";
			break;
		case "/docroot/tc/scuola":
			strType = "scuo";
			break;
		default:
			strType = "genr";
	}
	document.write('<IFRAME SRC="http://adv.sapere.it/adv/adserver?type=html&site=sape&adsize=120x60&pos=11&subsite=home" WIDTH=120 HEIGHT=60 MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR="#000000">')
	document.write('<SCRIPT LANGUAGE="JavaScript1.1" SRC="http://http://adv.sapere.it/adv/adserver?type=js&params.richmedia=yes&site=sape&adsize=120x60&pos=11&subsite=home"></SCRIPT>')
	document.write('</IFRAME>')
}


sImgFol="/images/" //images folder

// array of images path in images folder (without .gif extension)
aImg=new Array ("canali_top/arte","canali_top/geografia","canali_top/medicina","canali_top/musica_e_spettacolo","canali_top/scienze_e_tecniche","canali_top/sport","canali_top/scuola","canali_top/giornale_del_sapere","leftmenu_hp/scienza","leftmenu_hp/tecnologia","leftmenu_hp/terra_e_universo","leftmenu_hp/animali_e_piante","leftmenu_hp/storia_e_societa","leftmenu_hp/scienze_umane","leftmenu_hp/letteratura_e_media","leftmenu_hp/arte_e_architettura","leftmenu_hp/spettacolo","leftmenu_hp/sport_e_hobby","leftmenu_hp/guida_visuale","canali_top/storia")

//index for branch
aBr=new Array ("","/arte","/geografia","/medicina","/musica","/scienza","/sport","/storia")


for (i=0;i<aBr.length;i++) {
  iBI=i-1
  if(branch=="/docroot/tc"){
    break;
  }
  else if(branch.indexOf(aBr[i])>0){
    break;
  }
  iBI = -1
}

// array of the image objects for caching
aoImg=new Array(aImg.length)


// caching loop
for (i=0;i<aImg.length;i++) {
  aoImg[i]=new Image()
  aoImg[i].src=sImgFol + aImg[i] + "_on.gif"
}

// for onmouseovers
function imgon(pic) {
  document.images["pic" + pic].src = sImgFol + aImg[pic] + "_on.gif"
}

// for onmouseouts
function imgoff(pic) {
  if (pic!=iBI) { document.images["pic" + pic].src = sImgFol + aImg[pic] + ".gif" }
}



//----- OPEN ENLARGED ------
function OpenEnlarged(path,credit) {
windowprops = "top=0,left=0,resizable=yes" + ",width=" + (screen.width-12) + ",height=" + screen.height;
wid=window.open("","enlarged",windowprops)
wid.document.open()
wid.document.write("<html>\n<head>\n<title>" + credit + "</title>\n</head>\n<body bgcolor=\"#ffffff\" topmargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">\n")
wid.document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\">\n<tr>\n<td width=\"50%\"></td>")
wid.document.write("<td align=\"center\" valign=\"middle\"><img src=\"" + path + "\" alt=\"" + credit + "\"><p>")
wid.document.write("<span style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000;\"><i>" + credit + "</i></span>")
wid.document.write("</td>\n<td width=\"50%\"></td>\n</tr>\n</table>")
wid.document.write("\n</body>\n</html>")
wid.document.close()
}

function showQuery(sCQuery) {
iQCut=15
if (sCQuery.length>iQCut) {
	sCQuery=sCQuery.substring(0,iQCut) + "..."
}
document.write (sCQuery)
}


// Cookie
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));



function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "; path=/" : ("; path=/")) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}



function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}




// SEARCH FUNCTIONS
function goSearch(strPhrase) {
  window.location.href = '/SearchWeb/results.jsp?q=%28+CONTENTS%3A%28'+escape(strPhrase)+'%29+OR+TITLE%3A%28'+escape(strPhrase)+'%29%29+AND+%28+type%3A%22Enciclopedie%2FEnciclopedia+generale%22+%29&oqs=+CONTENTS%3A%28'+escape(strPhrase)+'%29+OR+TITLE%3A%28'+escape(strPhrase)+'%29';; 
}


function submitSearchSimpleState(frm) {
	var checkList = new String();
	var formList = GetCookie('advancedSearchState');
	var firstSeparator = "@";
	var secondSeparator = "|";

        // Aggiunta automatica asterisco per limitazione Altavista
        if ((frm.query.value.indexOf("**") == -1) && (frm.query.value.indexOf("*") > 0)) {
	  frm.query.value = frm.query.value.substring(0,frm.query.value.indexOf("*")) + "*" + frm.query.value.substring(frm.query.value.indexOf("*"),frm.query.value.length);
	}

	checkList +=frm.query.value+"@";
	checkList +=frm.dove.selectedIndex+"@";
	i = 1;

	if ( formList == null ) {
		formList = new String("@0@1|1|1|1|0|0|0|0|0|0|");
	}

	var queryText= formList.substring(0, formList.indexOf(firstSeparator));

	formList = formList.substring(formList.indexOf(firstSeparator) + firstSeparator.length, formList.length);
	checkList +=formList.substring(formList.indexOf(firstSeparator) + firstSeparator.length, formList.length);
	SetCookie('advancedSearchState', checkList);
	var formList = GetCookie('advancedSearchState');
	return;
}



function submitSearchAdvancedState(frm) {
	var checkList = new String();
	checkList +=frm.query.value+"@";
	checkList +=frm.dove.selectedIndex+"@";
	for (var j = 1; j <= 10; j++) checkList +=(eval("frm.check" + j).checked == true)?"1|":"0|";
	SetCookie('advancedSearchState', checkList);

	var formList = GetCookie('advancedSearchState');
	return;
}



function readSearchStateAdvanced() {
	var formList = GetCookie('advancedSearchState');
	var firstSeparator = "@";
	var secondSeparator = "|";
	i = 1;

	if ( formList == null ) {
		formList = new String("@0@1|1|1|1|0|0|0|0|0|0|");
	}

	var queryText= formList.substring(0, formList.indexOf(firstSeparator));
	document.search.query.value = queryText;

	formList = formList.substring(formList.indexOf(firstSeparator) + firstSeparator.length, formList.length);
	var comboBox= formList.substring(0, formList.indexOf(firstSeparator));
	document.search.dove.selectedIndex = comboBox;

	var checkBoxList= formList.substring(formList.indexOf(firstSeparator) + firstSeparator.length, formList.length);
	while(checkBoxList.indexOf(secondSeparator) != -1) {
		checkBox = checkBoxList.substring(0, checkBoxList.indexOf(secondSeparator));
		eval("document.search.check" + i).checked = (checkBoxList.substring(0, checkBoxList.indexOf(secondSeparator)) == "1")?true:false;
		checkBoxList = checkBoxList.substring(checkBoxList.indexOf(secondSeparator) + secondSeparator.length, checkBoxList.length);
		i++;
	}
	DeleteCookie('advancedSearchState');
}
function readSearchStateSimple() {
	var formList = GetCookie('advancedSearchState');
	var firstSeparator = "@";
	var secondSeparator = "|";
	i = 1;

	if ( formList == null ) {
		formList = new String("@0@1|1|1|1|0|0|0|0|0|0|");
	}

	var queryText= formList.substring(0, formList.indexOf(firstSeparator));
	document.search.query.value = queryText;

	formList = formList.substring(formList.indexOf(firstSeparator) + firstSeparator.length, formList.length);
	var comboBox= formList.substring(0, formList.indexOf(firstSeparator));
	document.search.dove.selectedIndex = comboBox;

	DeleteCookie('advancedSearchState');
}

function submitToAdvancedSearch(searchForm) {
	loc = new String(document.location.search);	//possible parameters of the url
	if(searchForm.query.value == ""){
		if(document.location.href.indexOf("MainApp") == -1){
			//static home page
			path = document.location.protocol + "//" + document.location.host + "/tca/MainApp?formtype=advanced";
			document.location = path;
		}
		else if(loc == ""){
			//home page no parameters after "/tca/MainApp"
			path = document.location + "?formtype=advanced";
			document.location = path;
		}
		else if (loc != ""){
		   if(loc.search("formtype=simple") != -1){
				//a channel since the url has parameters or the home page with formtype=advanced
				page = document.location.href;
				newpage = page.replace(/simple/i, "advanced");
				document.location = newpage;
			}
			else{
				path = document.location + "&formtype=advanced";
				document.location = path;
			}
		}
	}
	else{
		submitSearchSimpleState(searchForm);
		searchForm.action = "/search/AdvancedSearch";
		searchForm.submit();
	}
}

function submitToSimpleSearch(aSearchForm) {
	loc = new String(document.location.search);
	if(aSearchForm.query.value == ""){
		if(loc.search("formtype=advanced") != -1){
			page = document.location.href;
			newpage = page.replace(/advanced/i, "simple");
			document.location = newpage;
		}
		else if(loc.search("formtype=advanced") == -1){
			page = document.location.href;
			document.location = page;
		}
	}
	else{
		submitSearchAdvancedState(aSearchForm);
		aSearchForm.action = "/search/SimpleSearch";
		aSearchForm.submit();
	}
}


// functions for popupwindows.
function addpar(type)
{
	oLink=new String(document.location);
	aLoc=oLink.split("?");
	return aLoc[0] + "?" + "tmpl=" + type + ((aLoc.length<2)?"":"&"+aLoc[1])
}

function openPopWindow(type,winName,features)
{
    window.open(addpar(type), winName, features);
}
function openURLForwardPopWindow(winName,features)
{
    oLink=new String(document.location);
    aLoc = oLink.split("?");
    if (aLoc.length > 1) {
	aLoc[1] = escape(aLoc[1]);
    }
    window.open('/tca/MainApp?srvc=jsp&name=mail/URLForward&drazURL=' + aLoc[0] + ((aLoc.length<2)?"":"&drazQuery="+aLoc[1]), winName, features);
}

function callZipServlet()
{
    oLink=new String(document.location);
    aLoc=oLink.split("?");
    document.location = "/tca/ZipServlet.jsp?what=" + aLoc[0] + ((aLoc.length<2)?"":"&"+aLoc[1]);
}

// functions for search redirection
function submitFormDetailPage(indexName,fromParameter, toParameter) {
	document.detailPage.indexName.value = indexName;
	document.detailPage.from.value = fromParameter;
	document.detailPage.to.value = toParameter;
	document.detailPage.submit();
	return;
}

// function for search from mm gallery
function goMMsearch(frm) {
	frm.action = '/SearchWeb/mm.jsp';
	return true;
}

// open visual index
function openVisualIndex() {
	window.open("/gr/VisualIndexServlet?rand="+Math.random(),'Mapa',"height=500,width=700,resizable=yes,menubar=yes,status=yes");
}




