﻿var jBox;
var CloseNotifyMeTimer=10;
var CloseNotifyMeInterval;
var NotifyMeProductID=0;

function LoadBuyButton(pid,pm,div) {    
    if(pid<=0){
        jQuery("#" + div).html("");
    }
    else {    
        jQuery.get("/products/GetStockStatus.aspx?pid=" + pid + "&pm=" + pm + "&t="+(new Date()).getTime(),function(data) {			        
            jQuery("#" + div).html(data);
        });
    }    
}

function subscribe(sid,lid) {
	if (	
		(jQuery("#txtNotifyMeName").val()=="")||
		(jQuery("#txtNotifyMeEmail").val()=="")||
		(!/^[-+.\w]*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(jQuery("#txtNotifyMeEmail").val()))
	) {
		if(lid==2) {
		    // German
			alert ("Alle Felder müssen ausgefüllt werden. Bitte füllen Sie die mit einem Sternchen (*) gekennzeichneten Felder korrekt aus.");			
		}
		else if(lid==4) {
		    // French
			alert ("Tous les champs sont obligatoires. Complétez correctement tous les champs comportant un astérisque (*).");			
		}
		else if(lid==5) {
		    // Italian
			alert ("Tutti i campi sono obbligatori. Compilare correttamente i campi contrassegnati da un asterisco (*).");			
		}
		else if(lid==6) {
		    // Polish
			alert ("Wszystkie pola są wymagane. Wypełnij poprawnie wszystkie pola oznaczone gwiazdką (*).");			
		}
		else if(lid==7) {
		    // Spanish
			alert ("Todos los campos son obligatorios. Rellene todos los campos marcados con un asterisco (*) correctamente.");			
		}
		else {
			alert ("All fields are mandatory. Please fill in all fields marked with an asterisk (*) correctly.");
		}

		return false;
	}
    
    jQuery.get("/products/SubscribeNotifyMe.aspx?sid="+sid+"&pid="+NotifyMeProductID+"&name="+jQuery('#txtNotifyMeName').val()+"&email="+jQuery('#txtNotifyMeEmail').val(), function(data) {        
        if(data=='ok') {
            jQuery("#subscriptionform").hide();
            jQuery("#ThankYouForm").show();
            jQuery("#spanTimer").html("10");
            CloseNotifyMeTimer=10;
            CloseNotifyMeInterval=setInterval(NotifyMeTimer,1000);
        }
        else {
		    if(lid==2) {
		        // German
			    alert ("Bei der Bearbeitung Ihrer Anfrage ist ein Problem aufgetreten. Bitte aktualisieren Sie diese Seite und versuchen Sie es später erneut. Entschuldigen Sie die Umstände.");			
		    }
		    else if(lid==4) {
		        // French
			    alert ("Nous avons rencontré quelques problèmes en essayant de traiter votre demande. S'il vous plaît rafraîchir cette page ou réessayez plus tard. Désolé pour les désagréments causés.");			
		    }
		    else if(lid==5) {
		        // Italian
			    alert ("Abbiamo riscontrato alcuni problemi mentre elaboravamo la richiesta. Si prega di ricaricare la pagina o di riprovare piu' tardi. Ci scusiamo per il disagio.");			
		    }
		    else if(lid==6) {
		        // Polish
			    alert ("Wystąpiły problemy podczas przetwarzania Państwa żądania. Proszę odświeżyć tę stronę lub spróbować ponownie później. Przepraszamy za wszelkie niedogodności.");			
		    }
		    else if(lid==7) {
		        // Spanish
			    alert ("Hemos tenido algunos problemas al intentar procesar su solicitud. Por favor, actualiza la página o inténtalo de nuevo más tarde. Perdón por las molestias causadas.");			
		    }
		    else {
			    alert ("We encountered some problems while trying to process your request. Please refresh this page or try again later. Sorry for any inconvenience caused.");
		    }
		}
    });
}

function NotifyMeTimer() {    
    if(CloseNotifyMeTimer==0) {
        clearInterval(CloseNotifyMeInterval);
        jBox.hide(cleanUp);
        setTimeout(clearNotifyMeForm,1000);
    }
    else {
        jQuery("#spanTimer").html(CloseNotifyMeTimer--);
    }    
}

function cleanUp() {
    if(navigator.appVersion.indexOf("MSIE")>0) {
        document.getElementById("NotifyMeIFrame").style.display="none";
    }
}

function clearNotifyMeForm() {    
    CloseNotifyMeTimer=10;
    clearTimeout(clearNotifyMeForm);
    jQuery("#ThankYouForm").hide();
    jQuery("#txtNotifyMeName").val("");
    jQuery("#txtNotifyMeEmail").val("");
    jQuery("#subscriptionform").show();
}

function ShowNofifyMeHint (ctl, pdtName) {
    var leftpos = 0
    var toppos = 0
    var width = 0
    var height = 0

    width = ctl.offsetWidth
    height = ctl.offsetHeight

    var aTag = ctl
    do {
	    leftpos += aTag.offsetLeft;
	    toppos += aTag.offsetTop;
	    aTag = aTag.offsetParent;
    } while(aTag.tagName!="BODY");

    document.getElementById("divNotifyMeHint").style.left=(leftpos + width + 20) + "px";
    document.getElementById("divNotifyMeHint").style.top=(toppos - ((document.getElementById("divNotifyMeHint").offsetHeight-ctl.offsetHeight)/2)) + "px";    
    document.getElementById("divNotifyMeHint").style.visibility = "visible";    
    document.getElementById("pdtName").innerHTML = " <b>" + pdtName + "</b> ";
}

function HideNofifyMeHint () {
    document.getElementById("divNotifyMeHint").style.visibility = "hidden";
}

function ShowNotifyMeLightBox(pdtName,pdtId) {
    NotifyMeProductID = pdtId;
    jQuery("#pdtName2").html(pdtName);
    jQuery("#pdtName3").html(pdtName);
    jBox = new Boxy(jQuery("#NotifyMeLightBox"), {show: true, closable: true, modal: true, title: ""});    
    
    if(navigator.appVersion.indexOf("MSIE")>0) {
        document.getElementById("NotifyMeIFrame").style.left=jBox.getPosition()[0]+"px";
        document.getElementById("NotifyMeIFrame").style.top=jBox.getPosition()[1]+"px";
        document.getElementById("NotifyMeIFrame").style.width=jBox.getSize()[0]+"px";
        document.getElementById("NotifyMeIFrame").style.height=jBox.getSize()[1]+"px";
        document.getElementById("NotifyMeIFrame").style.display="block";
    }
}
