﻿// JScript File

function getWinWidth() {
    isNav = (document.all) ? false : true;
    isIE = (document.all) ? true : false;
    if (isNav && !isIE)
        return(window.innerWidth);
    else if (isIE && !isNav)
        return(document.documentElement.clientWidth);
    else
        return(100);
}

function getWinHeight() {
    isNav = (document.all) ? false : true;
    isIE = (document.all) ? true : false;
    if (isNav && !isIE)
        return(window.innerHeight);
    else if (isIE && !isNav)
        return(document.documentElement.clientHeight);
    else
        return(100);
}

function apriPopup(id){
	var theURL = '/dettaglioDealer.aspx?id=' + id + '&type=pos&win=popup'
	winPopup(theURL,'newWin',830,450,'yes')
}

function visLocation(id){
	var theURL = '/dettaglioLocation.aspx?id=' + id + '&type=pos&win=popup'
	winPopup(theURL,'newWin',830,450,'yes')
}

function visSurvey(id){
	var theURL = '/questionari/visQuery.aspx?id=' + id + '&win=popup'
	winPopup(theURL,'visSurvey',830,450,'yes')
}

function visQuestionario(id){
	var theURL = '/questionari/visQuestionario.aspx?idQuest=' + id + '&win=popup'
	winPopup(theURL,'visQuestionario',830,450,'yes')
}

function dettaglioPhotoSurvey(idRecord){
	var theURL = '/photoCompetitors/dettaglioPhoto.aspx?idFoto=' + idRecord + '&win=popup';
	winPopup(theURL,'dettaglioPhotoSurvey',940,710,'yes')
}   

function visPhotoSurvey(idRecord){
	var theURL = '/questionari/visPhoto.aspx?photo=' + idRecord
	winPopup(theURL,'visPhotoSurvey',940,710,'yes')
}   

function visDetailSurvey(sessionId,idDomanda,index){
	var theURL = '/analysis/detail.aspx?win=popup&idDom=' + idDomanda + '&sessionId=' + sessionId + '&index=' + index
	winPopup(theURL,'visDetailSurvey',940,710,'yes')
}   

function visInsiemeFotoPos(id){
	var theURL = '/insiemeFotoPos.aspx?id=' + id + '&win=popup'
	winPopup(theURL,'visInsiemeFotoPos',830,450,'yes')
}
function visDettaglioFotoPos(id){
	var theURL = '/dettaglioFotoPos.aspx?id=' + id + '&win=popup'
	winPopup(theURL,'visDettaglioFotoPos',640,480,'yes')
}

function visDettaglioFotoPosFotoStore(id){
	var theURL = '/dettaglioFotoPos.aspx?idStore=' + id + '&win=popup'
	winPopup(theURL,'visDettaglioFotoPos',640,480,'yes')
}

function visListaPos(id){
	var theURL = '/anagraficaPdv.aspx?daFormatore=si&win=popup&type=pos&Queryparams=False|0||pos|0|0||no|no|1|' + id + '|0|0||0|0|0|0|0|0|'
	winPopup(theURL,'visListaPos',830,450,'yes')
}

function visListaPosAgenti(id){
	var theURL = '/anagraficaPdv.aspx?source=agenti&win=popup&type=pos&Queryparams=False|0||pos|0|0||no|no|1|' + id + '|0|0||0|0|0|0|0|0|'
	winPopup(theURL,'visListaPosAgenti',830,450,'yes')
}

function visEditPos(id){
	var theURL = '../inserisciPdV.aspx?idPdv=' + id + '&type=pos&Queryparams=False|0||pos|0|0||no|no|1|0|0|0&back=javascript:parent.close();'
	winPopup(theURL,'visEditPos',830,450,'yes')
}
function visDettaglioUtente(id){
	var theURL = '/dettaglioFormatore.aspx?type=f&idUtente=' + id + '&win=popup'
	winPopup(theURL,'visDettaglioUtente',830,450,'yes')
}

function visElencoPersonSuPdv(idpdv){
	var theURL = '../fieldSpecialist/anagraficaPersonByArea.aspx?idpdv=' + idpdv + '&win=popup'
	winPopup(theURL,'visElencoPersonSuPdv',830,450,'yes')
}

function accredito(idUser){
	var theURL = '/fieldSpecialist/accredito.aspx?idUtente=' + idUser + '&win=popup'
	winPopup(theURL,'accredito',830,450,'yes')
}


var isOpenWindow = false;
var mw;
function winPopup(theURL,winName,wSize,hSize,scroll) {
       if (isOpenWindow) {
		    if (!mw.closed){
			    mw.close();
		    }
        } 
        var xMax = screen.width, yMax = screen.height;
        var xOffset = (xMax - wSize)/2, yOffset = (yMax - hSize)/2;
	    if (navigator.appname == 'Netscape'){
		    mw = window.open(theURL,winName,'screenX='+wSize+',screenY='+hSize+',scrollbars='+scroll+',statusbar=no,resizable=yes,top='+yOffset+',left='+xOffset+'');
	    }
	    else {
		    mw = window.open(theURL,winName,'width='+wSize+',height='+hSize+',scrollbars='+scroll+',statusbar=no,resizable=yes,top='+yOffset+',left='+xOffset+'');
        }
        mw.focus();
        isOpenWindow = true;
}

function KEYWORD_popup(theURL,winName,wSize,hSize,scroll) {
       if (isOpenWindow) {
		if (!mw.closed){
			mw.close();
		}
        } 
        var xMax = screen.width, yMax = screen.height;
        var xOffset = (xMax - wSize)/2, yOffset = (yMax - hSize)/2;
	if (navigator.appname == 'Netscape'){
		mw = window.open(theURL,winName,'screenX='+wSize+',screenY='+hSize+',scrollbars='+scroll+',statusbar=no,resizable=yes,top='+yOffset+',left='+xOffset+'');
	}
	else {
		mw = window.open(theURL,winName,'width='+wSize+',height='+hSize+',scrollbars='+scroll+',statusbar=no,resizable=yes,top='+yOffset+',left='+xOffset+'');
        }
        mw.focus();
        isOpenWindow = true;
}

function checkLength(obj,maxLength,sDescr) {
	var sMax = "max_" + obj.id;
	var sCounter = "cnt_" + obj.id;
	var maxAllowed = maxLength;
	var regexp = /'/gi;
    var matches = obj.value.match(regexp);
	if  ( (matches !== undefined)  && (matches !== null)  && (matches.length>0)  )
		maxAllowed = maxLength - matches.length;
	if  (obj.value.length > maxAllowed) {
		obj.value = obj.value.substr(0,maxAllowed);
		alert("WARNING  \n excedeed allowed characters limit!!! \n Text truncated at " + maxAllowed + " chars.");   //[" + sDescr + "]
	}
	document.getElementById(sMax).value=maxAllowed-obj.value.length;
	document.getElementById(sCounter).value=obj.value.length;
}