﻿
function aggiungiCarrello(id, qta) {
//    document.formElencoArticoli.action = "carrello.aspx?f=1&a=" + id + "&qta=" + qta + "#" + id ;
//    document.formElencoArticoli.method = "POST";
//    document.formElencoArticoli.submit();
    window.location.href = 'carrello.aspx?f=1&a=' + id + '&qta=' + qta + "#" + id;
    alert('carrello.aspx?f=1&a=' + id + '&qta=' + qta + "#" + id);
    return true;
}

function showLogin() {
    $('loginForm').setStyle('display', 'block');
    myLoginForm.slideIn();
    myLoginCommands.slideOut();
    return false;
}

function hideLogin() {
    myLoginForm.slideOut();
    myLoginCommands.slideIn();
    return false;  
}

//function submitForm(theInput, e) {
//    var key;
//    e = e || window.event;
//    key=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
////    if (window.event)
////        key = window.event.keyCode; //IE
////    else
////        key = e.which; //firefox
//    
//    if (key == 13)
//    {
//        //alert('0k');
//        // document.forms[0].submit();
//        //__doPostBack('ctl00$Login1$LoginLinkButton','')
//        //__doPostBack('ctl00$Contenuti$Login1$LoginLinkButton','')
//        //document.aspnetForm.submit();
//        
//        return false;
//    }
//}

 function openGestioneFile (field_name, url, type, win) {

    // alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

    var cmsURL = '/Amministrazione/GestioneFile.aspx'      // script URL
    var searchString = window.location.search;  // possible parameters
    if (searchString.length < 1) {
        // add "?" to the URL to include parameters (in other words: create a search string because there wasn't one before)
        searchString = "?";
    }

    // newer writing style of the TinyMCE developers for tinyMCE.openWindow

    tinyMCE.openWindow({
        file : cmsURL + searchString + "&type=" + type + "tinyMCE=1&compact=1", // PHP session ID is now included if there is one at all
        title : "File Browser",
        width : 620,  // Your dimensions may differ - toy around with them!
        height : 600,
        close_previous : "no"
    }, {
        window : win,
        input : field_name,
        resizable : "yes",
        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        editor_id : tinyMCE.selectedInstance.editorId
    });
    return false;
  }

function openGestioneFile2(inputControl) {
    url = "/amministrazione/GestioneFile.aspx"
    var type = "files"
    url += searchString() + "&type=" + type + "&tinyMCE=0&compact=1&sourceControl=" + URLEncode(inputControl.name) + "&link=" + URLEncode(inputControl.value);
    openAdminWindow(url, "gestioneFile2");
    return false;
}

function openGestioneViaggi() {
    url = "/amministrazione/GestioneViaggi.aspx"
    url += searchString() + "&compact=1";
    openAdminWindow(url, "gestioneViaggi");
    return false;
}

function searchString() {
    var searchString = window.location.search;  // possible parameters
    if (searchString.length < 1) {
        // add "?" to the URL to include parameters (in other words: create a search string because there wasn't one before)
        searchString = "?";
    }
    return searchString;
}

function openAdminWindow(url, nome)  {
    
    // alert(inputUrl.name);
    
    var html, width, height, x, y, resizable, scrollbars, url, name, win, modal, features;
    
    width = 930;
    height = 650;
    
	x = parseInt(screen.width / 2.0) - (width / 2.0);
	y = parseInt(screen.height / 2.0) - (height / 2.0);

	resizable = "yes";
	scrollbars = "yes";
	
    modal = "modal";
					
    win = window.open(url, nome, "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=" + modal + ",minimizable=" + resizable + ",modal=" + modal + ",width=" + width + ",height=" + height + ",resizable=" + resizable, false);
    
    if (win == null) {
        alert("Attenzione, la finestra non è stata visualizzata. Disabilitare il blocco pop-up!");
        return;
    }
    
    if (win.opener == null) win.opener = self;

    try {
        win.resizeTo(width, height);
    } catch(e) {
    // Ignore
    }

    win.focus();
}

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++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
            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)); 
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

