/*Funzione setFocus iSValidator */
function isSetFocus(CtrlId)
{
	var Ctrl = document.getElementById(CtrlId);
	if ((Ctrl != null) && (Ctrl.focus != null)) {  
		Ctrl.focus();
	}
}

/*Funzione aprire calendario*/
function fn_OpenCalendar(nomeInput, Magg)
{	
	url="../../Controls/Misc/Calender.aspx?Magg=" + Magg + "&formname=aspnetForm." + nomeInput
	//url=<%= PageUtilities.GetFullPath("~/Controls/Misc/Calender.aspx")%> + "?Magg=" + Magg + "&formname=aspnetForm." + nomeInput
	calendar_window=window.open(url,'calendar_window','width=210,height=240,left=430px,top=450px');
	calendar_window.focus()
}

/* Function to prepare focus on the coupon */
/* This is never called from within the coupon, but we use parent.FocusOnCoupon() instead */
function FocusOnCoupon(scrollHandle, getScrollAreaHandle, removeScrollAreaHandle)
{
   // This is the ID of the iframe to search for:
   var frmCouponID = 'divFrmCoupon';
   
   // Get reference to coupon
   var frmCoupon = $('div#' + frmCouponID);
   
   // Remove the siblings. Not the message box...
   frmCoupon.siblings('div').not('div#divCouponMessage').hide();
   
   // Also remove the riserva iframe.
   $('iframe#frmScoRiserva').hide();
   
   // Store the original "top" position of the coupon.
   var originalFrameTop = frmCoupon.position().top;
   
      
   // Get the least amount of space needed to enable the scrolling of the coupon and the scrolling of the bets within the coupon.
   var minimumHeightRequired = frmCoupon.height() - getScrollAreaHandle() + 100;
   
   
   // If the (window height - the original frame top) is less than the minimum height required, then return and do not enable scroll.
   //alert($(window).width());
   if ((minimumHeightRequired > $(window).height() - originalFrameTop) ||
      ($(window).width() < 1024))
   {
        // Now set the top margin to 0...
        frmCoupon.css("margin-top", "0px");
        
        // Remove the scroll area.
        removeScrollAreaHandle();
        
        // Unbind the scroll event!
        $(window).unbind('scroll');
       
        return;
   }
   
   
   // If the screen size is LESS than the coupon's height, then we need to keep on the scrolling, 
   // and introduce the mousewheel.
   if ($(window).height() < frmCoupon.position().top + frmCoupon.height())
   {
        if (scrollHandle != null)
        {
            scrollHandle($(window).height(), originalFrameTop, frmCoupon.height());
        }
   }
   
    // Hook the scroll event.
    $(window).scroll(function()
    {
        DoScroll(frmCoupon, originalFrameTop);
    });
    
    // Call the do scroll for the first time.
    DoScroll(frmCoupon, originalFrameTop);
}

function DoScroll(frmCoupon, originalFrameTop)
{
    // Compute the amount to scroll:
    var moveAmount = $(window).scrollTop() - originalFrameTop;
    
    // If the move amount is negative, then set it to 0
    if (moveAmount < 0)
    {
        // 
        moveAmount = 0;
    }
    else
    {
        moveAmount += 10;
    }
    
    // The animation moves the margin position.
    frmCoupon.animate({marginTop:moveAmount+"px"}, {queue: false, duration: 350});
}

         

/* Function to prepare unfocus the coupon and reset. */
/* This is never called from within the coupon, but we use parent.UnFocusOnCoupon() instead */
function UnFocusOnCoupon()
{
   // This is the ID of the iframe to search for:
   var frmCouponID = 'divFrmCoupon';
   
   // Get reference to coupon
   var frmCoupon = $('div#' + frmCouponID);
   
   // Show the siblings. Not the message box...
   frmCoupon.siblings('div').not('div#divCouponMessage').show();
   
   // Also show the riserva iframe.
   $('iframe#frmScoRiserva').show();
   
   // Now set the top margin to 0...
   frmCoupon.css("margin-top", "0px");
      
   // Unbind the scroll event!
   $(window).unbind('scroll');
}


/* Funzione per aggiungere un IDQuota al Coupon */
function AddCoupon(IDQuota)
{
    
	var frm
	if (window.parent.frames["frmCoupon"])
		frm = window.parent.frames["frmCoupon"];
	else
	
	frm = window.parent.document.getElementById("frmCoupon").contentWindow;
	frm.document.getElementById("hidIDQuota").value = IDQuota;
	frm.document.getElementById("btnHide").click();
}

/* Funzione per caricare un Coupon dall'ID Coupon */
function LoadCoupon(IDCoupon,Stampa)
{
	var frm

	if (window.parent.frames["frmCoupon"])
		frm = window.parent.frames["frmCoupon"];
	else
		frm = window.parent.document.getElementById("frmCoupon").contentWindow;

	frm.document.getElementById("HidIDCoupon").value = IDCoupon;
	frm.document.getElementById("HidStampaCoupon").value = Stampa;
	frm.document.getElementById("btnHideLoadCoupon").click();
}

function AddCouponBF(IDQuota){
	var frm

	if (window.parent.frames["frmCoupon"])
		frm = window.parent.frames["frmCoupon"];
	else
		frm = window.parent.document.getElementById("frmCoupon").contentWindow;

	frm.document.getElementById("hidIDQuota").value = IDQuota;
	frm.document.getElementById("btnHideBF").click();
}

/* Funzione per sel/deselezionare la quota presente nel coupon nelle tabelle delle quote Action = sel/des */
function selezionaQuota(IDQuota, Action)
{	
    
	var hidden = window.parent.$('input.hiddenIframeList');
	if (hidden.length > 0){
		var elencoFrame = hidden.val().split("|");
		var frm;
	
		for (var i = 0 ; i< elencoFrame.length; i++){
			frm = window.parent.document.getElementById(elencoFrame[i]);
			if (frm != null)
			{
			var td = frm.contentWindow.document.getElementById("TDQuota" + IDQuota);
			//var link = frm.contentWindow.document.getElementById("lnkQuota§" + IDQuota);
			//var link = frm.contentWindow.document.getElementById("boldQuota" + IDQuota);
				
		
			if (td != null){
				//if(td.style.backgroundImage != 'url(../Images/QuotaModificata.gif)'){
					if (Action == 'sel'){
						if (td.className == 'OddsOddMultipla')
							td.className = "OddsOddSelMultipla";
						else if (td.className == 'OddsOddUnica')
							td.className = "OddsOddSelUnica";
						else if (td.className == 'OddsOdd')
							td.className = "OddsOddSel";
						else if (td.className == 'OddsOddParticolare')
							td.className = "OddsOddSelParticolare";
						else if (td.className == 'OddsOddNMultipla')
							td.className = "OddsOddNMultiplaSel";
						//link.style.color = "#FFFFFF"
					}
					else{
						if (td.className == 'OddsOddSelMultipla')
							td.className = "OddsOddMultipla";
						else if (td.className == 'OddsOddSelUnica')
							td.className = "OddsOddUnica";
						else if (td.className == 'OddsOddSel')
							td.className = "OddsOdd";
						else if (td.className == 'OddsOddSelParticolare')
							td.className = "OddsOddParticolare";
						else if (td.className == 'OddsOddNMultiplaSel')
							td.className = "OddsOddNMultipla";
					}
				}
			}
		}	
	}
}

function getKeyPress(e)
{
    if (e == null)
        return -1;
    
    var evt = e || window.event;
    var keyPressed = evt.which || evt.keyCode;
    return keyPressed;
}

/* Funzione per impostare il button di default */
function fnTrapKD(e, txt, btn)
{
	var objTXT;
	objTXT = document.getElementById(txt);
	if (objTXT == null) return false

	var objBTN;
	objBTN = document.getElementById(btn);
	if (objBTN == null) return false
	
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	if (e && code) {
		if (code == 13) {
			e.returnValue=false;
			e.cancel = true;
			objBTN.click();

			return false;
		}
	}

	return true;
}

function setSaldo(saldo)
{  
	try{
	    
		parent.document.getElementById("ctl00_AreaRiservata_lblSaldo").innerHTML = saldo;
		
	}
	catch (ex){
		return false;
	}
} 

function setSaldoBonus(saldo)
{
	try{
		parent.document.getElementById("AreaRiservata_lblSaldoBonus").innerHTML = saldo;
	}
	catch (ex){
		return false;
	}
} 

function showHideElement(elementName, nomeImgIcona)
{
	var ctrl = document.getElementById(elementName);
	if (ctrl == null) return
	
	var ctrlImg = document.getElementById(nomeImgIcona);

	if (ctrl.style.display == 'none'){
		ctrl.style.display = 'inline'
		if (ctrlImg != null) ctrlImg.src="../App_Themes/Default_Black/images/Games/ico_close.gif";
	}else{
		ctrl.style.display = 'none'
		if (ctrlImg != null) ctrlImg.src="../App_Themes/Default_Black/images/Games/ico_open.gif";
	}
}

//Funzione che effettua il replace del separatore decimale (Usato in coupon e Quote.aspx per Scommesse Combo)
function replaceSeparator(event, sDecimalSeparator, sObjImportoGiocato)
{
	if (getKeyPress(event) == 190 || getKeyPress(event) == 110 || getKeyPress(event) == 180 || getKeyPress(event) == 188){
		var oImportoGiocato = document.getElementById(sObjImportoGiocato);
		if (sDecimalSeparator == ","){
			oImportoGiocato.value =  oImportoGiocato.value.replace(".",",");
		} else {
			oImportoGiocato.value =  oImportoGiocato.value.replace(",",".");
		}
	}
}

//Funzion per assegnare los tile al bottone (on Mouse Over  e on Mouse out)
function RollIn(button,classname){
    button.className = classname;
}

function RollOut(button,classname){
    button.className = classname;
}