var lang = "undefined";
var conv = "undefined";
var cod_ag = "undefined";

function Querystring(){
// get the query string, ignore the ? at the front.
var querystring=location.search.substring(1,location.search.length);
// parse out name/value pairs separated via &
var args = querystring.split('&');
// split out each name = value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=');
		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		name = temp.join(' ');
		temp = unescape(pair[1]).split('+');
		value = temp.join(' ');
		this[name]=value;
	}
	this.get=Querystring_get;
 }
function Querystring_get(strKey,strDefault){
	var value=this[strKey];
	if (value==null)
	{
		value=strDefault;
	}
	return value;
 } 
function dispW() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
 }
function dispH() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
 }

// JavaScript Document
prenota = function(){
	maxH = dispH()-60;
	if (maxH < 520) maxH = 520;

	var qs = new Querystring()
	if (conv == "undefined") conv = qs.get("conv","");
	if (cod_ag == "undefined") cod_ag = qs.get("cod_ag","");
	if (lang == "undefined") lang = qs.get("lang","");

	// Display an external page using an iframe
	var src = "http://"+account_url+"/catalogo_noleggio/registrazione/login.asp?ref=http://"+account_url+"/catalogo_noleggio/ncc/Servizi-on-line.asp";
	if (conv != "") src+="&conv="+conv;
	if (cod_ag != "") src+="&cod_ag="+cod_ag;
	if (lang != "") src+="&lang="+lang;

	$.modal('<iframe src="' + src + '" height='+maxH+'+"px" width="825px" style="border:0">', {
		containerCss:{
			backgroundColor:"#fff",
			borderColor:"#fff",
			height:maxH,
			padding:0,
			width:825
		},
		overlayClose:false,
		autoPosition:true
	});
}
$().ready(function() {
	$("a[href^='http://www.gd-soft.it']").each(function(){
			lang = $(this).attr("lang");
			conv = $(this).attr("conv");
			cod_ag = $(this).attr("cod_ag");
			$(this).removeAttr("target");
			$(this).attr('href', 'javascript:prenota();');
	});

	$("a[href^='http://www.etransfer.it']").each(function(){
			lang = $(this).attr("lang");
			conv = $(this).attr("conv");
			cod_ag = $(this).attr("cod_ag");
			$(this).removeAttr("target");
			$(this).attr('href', 'javascript:prenota();');
	})

	$("a[href^='http://"+account_url+"']").each(function(){
			lang = $(this).attr("lang");
			conv = $(this).attr("conv");
			cod_ag = $(this).attr("cod_ag");
			$(this).removeAttr("target");
			$(this).attr('href', 'javascript:prenota();');
	})

});
