﻿// File JScript

function image_swap(ImageID, Image) 
{
	document.getElementById(ImageID).src = Image;
}


function text_swap(ObjID, ClsName) 
{
    //alert (document.getElementById(ObjID).className);
	document.getElementById(ObjID).className = ClsName;
}

function gotoUrl(Url)
{
    window.location.href = Url;
}


function isRequired(ObjIDS, alertMsg)
{
    //alert (ObjIDS);
    var ObjID = ObjIDS.split(";");
    var DivID = "";
    for (i=0;i<=ObjID.length-1;i++)
    {
        if (document.getElementById(ObjID[i]).value == "")
        {
            DivID = "DV_" + ObjID[i].substring(3);
            //alert(DivID);
            if (document.getElementById(DivID)) 
                {Msg = alertMsg.replace("{0}",document.getElementById(DivID).innerHTML)}
            else
                {Msg = alertMsg.replace("{0}. ","")}
            alert(Msg);
            document.getElementById(ObjID[i]).focus();
            return false;
        }
    }
}

function showAlert(alertMsg)
{
    alert(alertMsg);
}

function StartMetaSearch(BaseUrl, Web, SearchMode, txtId, dropField){
	var el = document.getElementsByTagName('input');
	var Qry = '&Qry=';
	var Grp = '&Grp=';
	var id = '';
	var txtSearch = '';
	for (i=0; i<el.length; i++){
	if (el[i].type=='checkbox'){
		if (el[i].id.indexOf('chkGrp_') != -1) {
			if (el[i].checked) {Grp = Grp  + el[i].id.replace('chkGrp_', '')  + ',';};
	}
		if (el[i].id.indexOf('chkQry_') != -1) {
			if (el[i].checked){Qry  = Qry + el[i].id.replace('chkQry_', '')  + ',';};
	}
	}
	}
	ctl = document.getElementById(txtId)
	if (ctl.value !='') {
		if (SearchMode=='SIMPLE') {
		txtSearch = '&txtSimple=' + ctl.value
	} else {
		txtSearch = '&txtAdvanced1=' + ctl.value + '&dropField1=' + dropField
	}
	if (Qry != '&Qry=' || Grp != '&Grp=') {
		var w = window.open('','METASRC');
		w.location = 'http://' + BaseUrl + '/DCsearch/MetaSearch.aspx?Web=' + Web + '&SEARCHMODE=' + SearchMode + txtSearch + Grp + Qry;
		w.focus();
		} else {
		alert('Nessun archivio selezionato');
	}
	} else {
		alert('Immettere il testo da cercare');
	}
}


function StartOpacSearch(Version, Mode, CodWeb, CodBib, ServerUrl, ANYId, TITId, AUId, SOId)
{
	//CodWeb='DEMO';
	//ServerUrl = 'NT40';
	
	switch (Mode)
	{
	    case 'S':
	        ctlANY = document.getElementById(ANYId + CodWeb + CodBib)
	        if (ctlANY.value !='') {
		        var w = window.open('','OPAC');
		        if (Version == "5") {
		        if (ServerUrl.indexOf('/')>0) {
		               w.location = 'http://' + ServerUrl + '/opac.aspx?web=' + CodWeb + '&SRC=SSMP&TXT=' + ctlANY.value
		        } else {
		               w.location = 'http://' + ServerUrl + '/bw5net/opac.aspx?web=' + CodWeb + '&SRC=SSMP&TXT=' + ctlANY.value
		        }
		        } else {
		        w.location = 'http://' + ServerUrl + '/bwnet/default.asp?page=ListREC&ListMode=IDX&QRM=META&opac=' + CodWeb + '&opac=' + CodBib + '&ANY=' + ctlANY.value
		        }
		        w.focus();
	        } else {
		        alert('Immettere il testo da cercare');
	        }
	    break;
	    
	    case 'A':
	        ctlTIT = document.getElementById(TITId + CodWeb + CodBib)
	        ctlAU = document.getElementById(AUId + CodWeb + CodBib)
	        ctlSO = document.getElementById(SOId + CodWeb + CodBib)
	        if (ctlTIT.value != '' || ctlAU.value != '' || ctlSO.value != '' ) 
	        {
		        var w = window.open('','OPAC');
		        if (Version == "5") {
		        if (ServerUrl.indexOf('/')>0) {
		            w.location = 'http://' + ServerUrl + '/opac.aspx?web=' + CodWeb + '&SRC=SBAS&TIT=' + ctlTIT.value + '&AU=' + ctlAU.value + '&SO=' + ctlSO.value
		        } else {
		            w.location = 'http://' + ServerUrl + '/bw5net/opac.aspx?web=' + CodWeb + '&SRC=SBAS&TIT=' + ctlTIT.value + '&AU=' + ctlAU.value + '&SO=' + ctlSO.value
		        }
		        } else {
		        w.location = 'http://' + ServerUrl + '/bwnet/default.asp?page=ListREC&ListMode=IDX&QRM=META&opac=' + CodWeb + '&codbib=' + CodBib + '&TIT=' + ctlTIT.value + '&AU=' + ctlAU.value + '&SO=' + ctlSO.value
		        }
		        w.focus();
		    } else {
		        alert('Immettere il testo da cercare');
	        }
	    
	    break;
	}
}


function fnTrapKD(btnId, e){
    btn = document.getElementById(btnId);
	var key =  window.event ? window.event.keyCode : e.which;
	if (key == 13)
	{ 
		if (navigator.userAgent.indexOf("Firefox") == -1) {
			e.returnValue=false;
			e.cancel = true;
			btn.click();
		} else {
			correctSubmitHandler(e);
			btn.click();
		}
	} 
}

function correctSubmitHandler(e)
{
	if (e && e.preventDefault)
		e.preventDefault();
	return false;
}


function ResizeShowImage() {
	if (document.getElementById("imgMain").height >  window.screen.width){
		y = window.screen.height - 60;
	} else {
		y = document.getElementById("imgMain").height;
	}
	if (window.document.getElementById("imgMain").width > window.screen.width){
		x = window.screen.width  - 60;
	} else {
		x = document.getElementById("imgMain").width;
	}
	resizeTo(x+50,y+240);
	return;
}



function PageQuery(q) {
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
    for(var i=0; i < this.q.split("&").length; i++) {
    this.keyValuePairs[i] = this.q.split("&")[i];
    }
}

this.getKeyValuePairs = function() { return this.keyValuePairs; }

this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
var keyval = this.keyValuePairs[j].split("=")[0];
if(keyval.toLowerCase() == s.toLowerCase())
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}
