﻿var panelWidth = 345;
var rootPath = "";

function SetRootPath(path)
{
	rootPath = path;
}

function YamitoCalc_status() {
    this.homepage = true;
    this.noofpages = 5;
    this.slideshow = false;
    this.form = false;
    this.cms = false;
    this.logo = false;
    this.hosting = true;
    this.updates = true;
    this.sedomain = true;
    this.periodlength = 3;
    this.paylater = false;
    this.invoice = "month";
    this.pFirst = 0;
    this.pNext = 0;
}

var YamitoCalc_StatusObj = new YamitoCalc_status();

jQuery(document).ready(function () {
    jQuery('.YamitoCalc .panel').hide();
    jQuery('.YamitoCalc #panel1').show();
    jQuery('.YamitoCalc').width(panelWidth);
    jQuery('.YamitoCalc .panelWrapper').width(panelWidth * 3);
    jQuery('.YamitoCalc .panel').width(panelWidth);
    //var startHeight = jQuery('.YamitoCalc #panel1').height();
    //jQuery('.YamitoCalc .YamitoCalc_content').height(startHeight);

    InitYamitoCalcTooltips();
	
	this.homepage = jQuery('#YamitoCalc_HomePage').val();
	this.noofpages = jQuery('#YamitoCalc_NoOfPages').val();
	this.slideshow = jQuery('#YamitoCalc_Slideshow').val() == "true";
	this.form = jQuery('#YamitoCalc_Form').val() == "true";
	this.cms = jQuery('#YamitoCalc_CMS').val() == "true";
	this.logo = jQuery('#YamitoCalc_Logo').val() == "true";
	this.hosting = jQuery('#YamitoCalc_Hosting').val() == "true";
	this.updates = jQuery('#YamitoCalc_Updates').val() == "true";
	this.sedomain = jQuery('#YamitoCalc_SEDomain').val() == "true";
	this.periodlength = jQuery('#YamitoCalc_PeriodLength').val();
	this.paylater = jQuery('#YamitoCalc_PayLater').val() == "true";
	this.invoice = jQuery('#YamitoCalc_Invoice').val();
	
    UpdateYamitoCalcPrice();
	
	GoToNext(0);
});

function InitYamitoCalcTooltips() {
    jQuery('.YamitoCalc .info.homepage').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #homepage').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.design').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #design').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.consultation').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #consultation').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.noofpages').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #noofpages').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.slideshow').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #slideshow').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.form').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #form').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.cms').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #cms').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.logo').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #logo').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.hosting').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #hosting').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.email').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #email').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.support').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #support').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.updates').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #updates').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.sedomain').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #sedomain').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.periodlength').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #periodlength').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.invoice').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #invoice').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .info.paylater').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #paylater').html();
            },
            showURL: false
        }
    );

        jQuery('.YamitoCalc .error').tooltip(
        {
            bodyHandler: function () {
                return jQuery('.tooltips #error').html();
            },
            showURL: false
        }
    );


}

function UpdateYamitoCalcStatuses() {
    if (YamitoCalc_StatusObj.homepage) {
        jQuery(".YamitoCalc #imgHomepage").attr("src", rootPath + "img/on.png");
        jQuery(".YamitoCalc .homepagesub").show();
		jQuery('#YamitoCalc_HomePage').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgHomepage").attr("src", rootPath + "img/off.png");
        jQuery(".YamitoCalc .homepagesub").hide();
		jQuery('#YamitoCalc_HomePage').val("false");
    }

    if (YamitoCalc_StatusObj.slideshow) {
        jQuery(".YamitoCalc #imgSlideShow").attr("src", rootPath + "img/on.png");
		jQuery('#YamitoCalc_Slideshow').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgSlideShow").attr("src", rootPath + "img/off.png");
		jQuery('#YamitoCalc_Slideshow').val("false");
    }

    if (YamitoCalc_StatusObj.form) {
        jQuery(".YamitoCalc #imgForm").attr("src", rootPath + "img/on.png");
		jQuery('#YamitoCalc_Form').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgForm").attr("src", rootPath + "img/off.png");
 		jQuery('#YamitoCalc_Form').val("false");
    }

    if (YamitoCalc_StatusObj.cms) {
        jQuery(".YamitoCalc #imgCMS").attr("src", rootPath + "img/on.png");
 		jQuery('#YamitoCalc_CMS').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgCMS").attr("src", rootPath + "img/off.png");
  		jQuery('#YamitoCalc_CMS').val("false");
   }

    if (YamitoCalc_StatusObj.logo) {
        jQuery(".YamitoCalc #imgLogo").attr("src", rootPath + "img/on.png");
 		jQuery('#YamitoCalc_Logo').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgLogo").attr("src", rootPath + "img/off.png");
  		jQuery('#YamitoCalc_Logo').val("false");
   }

    if (YamitoCalc_StatusObj.hosting) {
        jQuery(".YamitoCalc #imgHosting").attr("src", rootPath + "img/on.png");
        jQuery(".YamitoCalc .hostingsub").show();
  		jQuery('#YamitoCalc_Hosting').val("true");
   }
    else {
        jQuery(".YamitoCalc #imgHosting").attr("src", rootPath + "img/off.png");
        jQuery(".YamitoCalc .hostingsub").hide();
  		jQuery('#YamitoCalc_Hosting').val("false");
    }

    if (YamitoCalc_StatusObj.updates) {
        jQuery(".YamitoCalc #imgUpdates").attr("src", rootPath + "img/on.png");
  		jQuery('#YamitoCalc_Updates').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgUpdates").attr("src", rootPath + "img/off.png");
   		jQuery('#YamitoCalc_Updates').val("false");
   }

    if (YamitoCalc_StatusObj.sedomain) {
        jQuery(".YamitoCalc #imgSeDomain").attr("src", rootPath + "img/on.png");
   		jQuery('#YamitoCalc_SEDomain').val("true");
   }
    else {
        jQuery(".YamitoCalc #imgSeDomain").attr("src", rootPath + "img/off.png");
  		jQuery('#YamitoCalc_SEDomain').val("false");
    }

    if (YamitoCalc_StatusObj.paylater) {
        jQuery(".YamitoCalc #imgPayLater").attr("src", rootPath + "img/on.png");
   		jQuery('#YamitoCalc_PayLater').val("true");
    }
    else {
        jQuery(".YamitoCalc #imgPayLater").attr("src", rootPath + "img/off.png");
   		jQuery('#YamitoCalc_PayLater').val("false");
   }
   
   if (YamitoCalc_StatusObj.homepage && YamitoCalc_StatusObj.hosting) {
		jQuery(".YamitoCalc .hostingsub.homepagesub").show();
   }
   else{
		jQuery(".YamitoCalc .hostingsub.homepagesub").hide();
   }
}

function UpdateYamitoCalcPrice() {
    var periods = 12;
    var pFirst = 9700;
    var pNext = 0;

    var offert = false;

	if (YamitoCalc_StatusObj.homepage)
	{
	    if (YamitoCalc_StatusObj.noofpages >= 40)
        offert = true;
	
	    if (YamitoCalc_StatusObj.cms) {
			pFirst = pFirst + 10000;
			pFirst = pFirst + Math.max(((YamitoCalc_StatusObj.noofpages - 5) * 295), 0);
		}
		else {
			var po5 = YamitoCalc_StatusObj.noofpages - 5;
			if (po5 > 0) {
				var po8 = YamitoCalc_StatusObj.noofpages - 8;
				if (po8 > 0) {
					pFirst = pFirst + (3 * 995) + (po8 * 395);
				}
				else {
					pFirst = pFirst + (po5 * 995)
				}
			}
		}
		
		if (YamitoCalc_StatusObj.slideshow)
			pFirst = pFirst + 1495;

		if (YamitoCalc_StatusObj.form)
			pFirst = pFirst + 995;

	}
	else {
		pFirst = 0;
	}
	
    if (YamitoCalc_StatusObj.hosting) {
        pNext = 1999;
        if (YamitoCalc_StatusObj.updates)
            pNext = pNext + 1000;

        if (YamitoCalc_StatusObj.cms)
            pNext = pNext + 1000;
			
		if (YamitoCalc_StatusObj.homepage)
		{
			pFirst = pFirst - 1000;
			pFirst = pFirst + (pNext*(YamitoCalc_StatusObj.periodlength-1));

			periods = YamitoCalc_StatusObj.periodlength * 12;
			if (YamitoCalc_StatusObj.periodlength > 1 && YamitoCalc_StatusObj.paylater) {
				periods = periods - 12;
			}
		}
		else
			pFirst = pNext;
    }

    if (YamitoCalc_StatusObj.logo)
        pFirst = pFirst + 2990;

    if (YamitoCalc_StatusObj.hosting && YamitoCalc_StatusObj.sedomain) {
        pFirst = (pFirst * 0.99);
        pNext = (pNext * 0.99) ;
    }

    pFirst = Math.ceil(pFirst / periods);
    pNext = Math.ceil(pNext / 12);
    
    YamitoCalc_StatusObj.pFirst = pFirst;
    YamitoCalc_StatusObj.pNext = pNext;

	jQuery('#YamitoCalc_pFirst').val(pFirst);
	jQuery('#YamitoCalc_pNext').val(pNext);
	jQuery('#YamitoCalc_Periods').val(periods);

    if (YamitoCalc_StatusObj.paylater && YamitoCalc_StatusObj.periodlength > 1 && YamitoCalc_StatusObj.hosting) {
        jQuery(".YamitoCalc #divSecondPeriod").show();
        jQuery(".YamitoCalc #divNextPeriod").show();

        jQuery(".YamitoCalc #pl1").text("12");
        jQuery(".YamitoCalc #pFirst").text(0);

        jQuery(".YamitoCalc #pl2").text(12 + periods);
        jQuery(".YamitoCalc #pSecond").text(pFirst);

        jQuery(".YamitoCalc #plTot").text(12 + periods);
        jQuery(".YamitoCalc #pNext").text(pNext);
    }
    else if (YamitoCalc_StatusObj.hosting) {
        jQuery(".YamitoCalc #divSecondPeriod").hide();
        jQuery(".YamitoCalc #divNextPeriod").show();

        jQuery(".YamitoCalc #pl1").text(periods);
        jQuery(".YamitoCalc #pFirst").text(pFirst);

        jQuery(".YamitoCalc #plTot").text(periods);
        jQuery(".YamitoCalc #pNext").text(pNext);
    }
    else {
        jQuery(".YamitoCalc #divSecondPeriod").hide();
        jQuery(".YamitoCalc #divNextPeriod").hide();

        jQuery(".YamitoCalc #pl1").text(periods);
        jQuery(".YamitoCalc #pFirst").text(pFirst);
    }

    jQuery(".YamitoCalc #pFirst_tot").text(pFirst * periods);
    jQuery(".YamitoCalc #pNext_tot").text(pNext * 12);

    if (offert) {
        jQuery(".YamitoCalc #divIsNotOffer").hide();
        jQuery(".YamitoCalc #divIsOffer").show();
    }
    else {
        jQuery(".YamitoCalc #divIsNotOffer").show();
        jQuery(".YamitoCalc #divIsOffer").hide();
    }
}

function Toogle_YamitoCalc_Setting(setting) {
    if (setting != 'noofpages' &&
        setting != 'periodlength' &&
        setting != 'invoice') {
        YamitoCalc_StatusObj[setting] = !YamitoCalc_StatusObj[setting];
        UpdateYamitoCalcStatuses();
    }
    else {
        if (setting == 'noofpages') {
            YamitoCalc_StatusObj[setting] = jQuery(".YamitoCalc #selNoOfPages").val();
			jQuery('#YamitoCalc_NoOfPages').val(jQuery(".YamitoCalc #selNoOfPages option:selected").text());
        }
        else if (setting == 'periodlength') {
            YamitoCalc_StatusObj[setting] = jQuery(".YamitoCalc #selPeriodLength").val();
			jQuery('#YamitoCalc_PeriodLength').val(jQuery(".YamitoCalc #selPeriodLength").val());
        }
        else if (setting == 'invoice') {
            YamitoCalc_StatusObj[setting] = jQuery(".YamitoCalc #selInvoice").val();
			jQuery('#YamitoCalc_Invoice').val(jQuery(".YamitoCalc #selInvoice option:selected").text());
        }
    }

    UpdateYamitoCalcPrice();

    var nextHeight = jQuery('.YamitoCalc #panel2 .panel_content .contentFader').outerHeight();
	if (nextHeight > 0)
		jQuery('.YamitoCalc #panel2 .panel_content').animate({ height: nextHeight }, 600, "easeInOutExpo");

    nextHeight = jQuery('.YamitoCalc #panel3 .panel_content .contentFader').outerHeight();
	if (nextHeight > 0)
		jQuery('.YamitoCalc #panel3 .panel_content').animate({ height: nextHeight }, 600, "easeInOutExpo");
}

function GoToNext(current) {
   	if (jQuery('.YamitoCalc #panel' + (current) + ' .panel_content').length>0) {      
    	var currentHeight = jQuery('.YamitoCalc #panel' + (current) + ' .panel_content').height();
	}
	else
	{
		var currentHeight = 0;
	}
	
	aimgcopy = jQuery('.YamitoCalc #panel' + (current + 1) + ' .panel_content').clone(); 
	jQuery('#divYamitoCalc_offSite').append(aimgcopy);
	aimgcopy.css("height", "");
	aimgcopy.children(".contentFader").show();
	var nextHeight = aimgcopy.height();	
	aimgcopy.remove();
    
	jQuery('.YamitoCalc #panel' + (current + 1) + ' .panel_content').height(currentHeight);
    jQuery('.YamitoCalc #panel' + current + ' .contentFader').fadeOut(500, function() {
		jQuery('.YamitoCalc #panel' + current).hide();
		jQuery('.YamitoCalc #panel' + (current + 1)).show();
		jQuery('.YamitoCalc #panel' + (current + 1) + ' .contentFader').fadeIn(500, "easeInOutExpo");
	});
    jQuery('.YamitoCalc #panel' + (current + 1) + ' .panel_content').animate({ height: nextHeight }, 1500, "easeInOutExpo");
}



function GoToBack(current) {
   	if (jQuery('.YamitoCalc #panel' + (current) + ' .panel_content').length > 0) {      
    	var currentHeight = jQuery('.YamitoCalc #panel' + (current) + ' .panel_content').height();
	}
	else
	{
		var currentHeight = 0;
	}
	
	aimgcopy = jQuery('.YamitoCalc #panel' + (current - 1) + ' .panel_content').clone(); 
	jQuery('#divYamitoCalc_offSite').append(aimgcopy);
	aimgcopy.css("height", "");
	aimgcopy.children(".contentFader").show();
	var nextHeight = aimgcopy.height();	
	aimgcopy.remove();
    
	jQuery('.YamitoCalc #panel' + (current - 1) + ' .panel_content').height(currentHeight);
    jQuery('.YamitoCalc #panel' + current + ' .contentFader').fadeOut(500, function() {
		jQuery('.YamitoCalc #panel' + current).hide();
		jQuery('.YamitoCalc #panel' + (current - 1)).show();
		jQuery('.YamitoCalc #panel' + (current - 1) + ' .contentFader').fadeIn(500, "easeInOutExpo");
	});
	jQuery('.YamitoCalc #panel' + (current - 1) + ' .panel_content').animate({ height: nextHeight }, 1500, "easeInOutExpo");    
}
