/* begin Page */
var  bTranslate=false;
var idLang  = 0;
var IsDebug = false;

function SetIdLang(lang)
{
	switch(lang)
	{
		case 'it-IT':idLang=1;
			break;
		case 'es-ES':idLang=2;
			break;
		case 'de-DE':idLang=3;
			break;
		case 'fr-FR':idLang=4;
			break;
		default:idLang=0;
	}
}

function ShowLogOff()
{
	try
	{
		if ($('#dnn_dnnLOGIN_cmdLogin').text().indexOf('Accedi')==-1 &&
			$('#dnn_dnnLOGIN_cmdLogin').text().indexOf('Login')==-1)
		{
			$('#dnn_dnnLOGIN_cmdLogin').css('display','block');
		}
	}
	catch(err)
	{
		
	}
}

function ManageTabs(idLang)
{
	$('li[id*="LiveTab"] a').each(function()
	{
		//alert(this.text);
		try
		{
			if ($(this).text().indexOf('|')!=-1)
			{
				var ar = $(this).text().split('|');
				if (ar.length>idLang)
				{
					var currText = ar[idLang];
					$(this).text(currText);
				}
				else 
					$(this).text(ar[0]);
			}
		}
		catch(err)
		{
			
		}
	}
	);
}

function ManageDownloadButton()
{
	try
	{
		if ($('.livetabsimagicledefault').length!=0)
		{
			if ($('.downloadbutton').length!=0)
			{
				if (document.title.indexOf('ImagicleCare')==0)
				{
					//nascondo download per ImagicleCare
					$('.downloadbutton').css('display','none');
				}
				else 
				{
					var offset = 10;
					if (jQuery.browser.msie) offset=-2;
					//contam:posiziono il bottone download in base alle coordinate del tab
					$('.downloadbutton').css('top',$('.livetabsimagicledefault').position().top-offset);
					$('.downloadbutton').css('display','block');
				}
			}
		}
		else //se non ho tab non posso posizionare il bottone
		{
			if ($('.downloadbutton').length!=0)
				$('.downloadbutton').css('display','none');
		}
	}
	catch(err)
	{
	
	}
}

$(document).ready(function()
{
	ShowLogOff();
	var sUrl = document.location.href;
	
	$('IMG[src*="crumb.gif"]').attr('alt','breadcrumb arrow')
	
	
	if (sUrl.indexOf('dnn.imagicle.com')!=-1)
	{
		if (document.location.pathname.length>0)
			document.location.href="http://www.imagicle.com" + document.location.pathname;
		else 
			document.location.href="http://www.imagicle.com";
	}

	/* fix, nascondo registrati su area partner*/
	if (document.title.indexOf('Partner')!=-1)
	{
		$('#dnn_ctr1246_Login_cmdRegister').hide();
	}
	
	//nascondo i punti interrogativi delle registrazioni
	$('img[id*=Login]').hide();
	
	/*fix durante fine registrazione appare captcha*/
	if (sUrl.indexOf('Register')>0)
	{
		if ($('#dnn_ctr_ctl01_imgIcon').attr('src').indexOf('ok')>0)
		{
			$('#dnn_ctr_ManageUsers_trCaptcha').hide();
		}
	}
	ManageTabs(idLang);
	ManageDownloadButton();
	
	if (sUrl.indexOf('DEBUG')!=-1)
	{
		IsDebug = true;
		try
		{
		}
		catch(err)
		{}
	}
	try
	{
		//gestione novità lifestyle
		$('*[id="dnn_dnnNAV_ctldnnNAVt403"]').css('color','#F46700').css('font-weight','bold');
	}
	catch(err)
	{}
});


function getQueryString(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function getTipoLead(lang) 
{
    var tipoLead = getQueryString("IAM");

    if (lang != null && lang == 'en-US')
    {
        switch (tipoLead) {
        case "1":
            return "final customer";
        case "2":
            return "imagicle partner";
        case "3":
            return "potential reseller";
        case "4":
            return "";
        default:
            return "";
        }
    }
    else    {    
        switch (tipoLead) {
        case "1":
            return "Cliente finale";
        case "2":
            return "Distributore";
        case "3":
            return "Rivenditore";
        case "4":
            return "Altro";
        default:
            return "Rivenditore";
        }
    }
}

function WindowScroll(win, x, y) {
    if (win)
        win.scroll(x,y);
}

function WindowScroll(x, y) {
    if (this.parent.window.location.href != this.window.location.href && WindowScroll) 
        this.parent.window.scroll(x, y);
    else
        this.window.scroll(x, y);
}


function DisableSubmit(nomeElemento) {
    if ($('input[name=' + nomeElemento + ']').length > 0)
        $('input[name=' + nomeElemento + ']').attr('disabled', 'disabled');
} 
function EnableSubmit(nomeElemento) {
    if ($('input[name=' + nomeElemento + ']').length > 0)
        $('input[name=' + nomeElemento + ']').attr('disabled', '');
}