﻿var i=-273;
var ctrlanim;
var intHide;
var intShow;
var speed=15;
var lastctrl;

var previousscroll = -1;
var nextscroll = 1;
var newsdisplay = 0;
var xmlDoc;

var ctrProducts = 3;
var productArray = new Array();
productArray[0] = "TaxMania";
productArray[1] = "EDi";
productArray[2] = "XTaxes";

mainMenuManager = function(ctrl, anim) {
    if (ctrl.className == "menu_btn_unselected") {
        unselectbtn();
        hideAllPanels();
        ctrl.className = "menu_btn_selected";
        if (anim != 'default') {
            StopTheClock();
            Effect.SlideDown(anim, { duration: 0.7 });
        } else InitializeTimer();
    }

}

showMenu = function(){
	if (i<55)
	{
		i = i + speed;
		document.getElementById(ctrlanim).style.top = i + 'px';
	}
	else
		document.getElementById(ctrlanim).style.zIndex = 1;
}
	
hideMenu = function(){
	if (i>-273)
	{
		i=i-speed;
		document.getElementById(ctrlanim).style.top = i + 'px';
	}
}

hideAllPanels = function(){
    $('menu_about_slider').hide();
    $('menu_contact_slider').hide();
    $('menu_products_slider').hide();
    $('menu_solutions_slider').hide();
    $('menu_support_slider').hide();
    try {
        $('ctl00_ContentPlaceHolder1_pnl_invitation').hide();
    }
    catch (err) {
        //Handle errors here
    }
   
}

unselectbtn = function(){
	document.getElementById('menu_btn_welcome').className = "menu_btn_unselected";
	document.getElementById('menu_btn_products').className = "menu_btn_unselected";
	document.getElementById('menu_btn_solutions').className = "menu_btn_unselected";
	document.getElementById('menu_btn_support').className = "menu_btn_unselected";
	document.getElementById('menu_btn_about').className = "menu_btn_unselected";
	document.getElementById('menu_btn_contact').className = "menu_btn_unselected";
}

closeCurrentMenu = function(ctrl) {
    InitializeTimer();
    hideAllPanels();
    unselectbtn();
    document.getElementById('menu_btn_welcome').className = "menu_btn_selected";
}

txtEmptyMessage_onfocus = function(ctrl){
   if (document.getElementById(ctrl).style.fontStyle == 'italic'){
    document.getElementById(ctrl).value = "";
    document.getElementById(ctrl).style.fontStyle = "normal";
   }
}

txtEmptyMessage_onblur = function(ctrl, defaulttext){
    var s = new String(document.getElementById(ctrl).value);
    s=s.trim();
    if (document.getElementById(ctrl).style.fontStyle == 'normal' && s == ""){
        document.getElementById(ctrl).value = defaulttext;
        document.getElementById(ctrl).style.fontStyle = "italic";
    }
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

moveToPrevious = function() {
    if (previousscroll >= 0) {
        new Effect.Move('menu_side_scroller_imageBoxInside', { x: 983, y: 0, transition: Effect.Transitions.sinoidal });
        nextscroll = previousscroll + 1;
        previousscroll -= 1;
        offstateAllbtn();

        var n = nextscroll - 1;
        document.getElementById('menu_side_scroller_nav_' + n).src = 'images/onstate.gif';

    }
    InitializeTimer();
}

moveToNext = function(){
    if (nextscroll <=4){
        new Effect.Move('menu_side_scroller_imageBoxInside', { x: -983, y: 0, transition: Effect.Transitions.sinoidal });
        previousscroll = nextscroll - 1;
        nextscroll += 1;
        offstateAllbtn();
        
        var n = previousscroll + 1;
        document.getElementById('menu_side_scroller_nav_' + n).src = 'images/onstate.gif';
      
    }else
        clicklinkinsidescroll(0);
    InitializeTimer();
    
}

offstateAllbtn = function(){
    document.getElementById('menu_side_scroller_nav_0').src = 'images/offstate.gif';
    document.getElementById('menu_side_scroller_nav_1').src = 'images/offstate.gif';
    document.getElementById('menu_side_scroller_nav_2').src = 'images/offstate.gif';
    document.getElementById('menu_side_scroller_nav_3').src = 'images/offstate.gif';
    document.getElementById('menu_side_scroller_nav_4').src = 'images/offstate.gif';
   
}


clicklinkinsidescroll = function(val) {
    var linkstotal = 5;
    if (sringRight(document.getElementById('menu_side_scroller_nav_' + val).src, 20) == '/images/offstate.gif') {
        var i = 0;
        if (val > previousscroll + 1)
            i = -983 * (val - (previousscroll + 1));
        else
            i = 983 * ((previousscroll + 1) - val);
        new Effect.Move('menu_side_scroller_imageBoxInside', { x: i, y: 0, transition: Effect.Transitions.sinoidal });

        previousscroll = val - 1;
        nextscroll = val + 1;
        offstateAllbtn();
        document.getElementById('menu_side_scroller_nav_' + val).src = 'images/onstate.gif'


    }
    InitializeTimer();
}

stringLeft = function(str, n){
    if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);

}

sringRight = function(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);    
       }
}

setOpacity = function() {
    if (initopacity < 0)
        initopacity = 100;
    else{
        var Obj = document.getElementById('news');
	    Obj.style.opacity = initopacity/10;
	    Obj.style.filter = 'alpha(opacity=' + initopacity*10 + ')';
	    initopacity=-1;
	}
}

setNews = function() {
    if (window.XMLHttpRequest) {
        xmlDoc = new window.XMLHttpRequest();
        xmlDoc.open("GET", "news.xml", false);
        xmlDoc.send("");
        xmlDoc = xmlDoc.responseXML;
    }
    // IE 5 and IE 6
    else if (ActiveXObject("Microsoft.XMLDOM")) {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.load("news.xml");
    }

    var x = xmlDoc.getElementsByTagName("news");
    document.getElementById('news').innerHTML = x[newsdisplay].childNodes[0].nodeValue;

    setInterval("loadNewsInterval()", 5500);

    InitializeTimer();
}

loadNewsInterval = function(){
    var x=xmlDoc.getElementsByTagName("news");
    newsdisplay+=1;
    if (newsdisplay == x.length)
        newsdisplay = 0;
    document.getElementById('news').innerHTML = x[newsdisplay].childNodes[0].nodeValue;
}



openURLFromSlider = function() {
    switch (previousscroll + 1) {
        case 0:
            window.location = "http://www.cegsoft.com/goedi";
            break;
        case 2:
            window.location = "https://www.taxmania.com/Default.aspx";
            break;
        case 1:
            window.location = "http://www.tax.cegsoft.com";
            break;
        case 4:
            var ctrl = document.getElementById("menu_btn_solutions");
            mainMenuManager(ctrl, 'menu_solutions_slider');
            break;
    }
}

 previousProduct = function() {
 var lastproduct = productArray[ctrProducts - 1];
 for (i = ctrProducts - 1; i >= 0; i--) {
     if (i == 0)
         productArray[i] = lastproduct;
     else
         productArray[i] = productArray[i - 1];
 };
 setProductsinCarrousel();
 }

 nextProduct = function() {
     var lastproduct = productArray[0];
     for (i = 0; i <= ctrProducts - 1; i++) {
         if (i == ctrProducts - 1)
             productArray[i] = lastproduct;
         else
             productArray[i] = productArray[i + 1];
     };
     setProductsinCarrousel();
 }

 setProductsinCarrousel = function() {
    document.getElementById("product_c_previous").src = getProductimage("small", productArray[0]);
    document.getElementById("product_c_current").src = getProductimage("big", productArray[1]);
    setProductDescription(productArray[1]);
    document.getElementById("product_c_next").src = getProductimage("small", productArray[2]);

 }

 getProductimage = function(thesize, theproduct) {
     switch (theproduct) {
         case "TaxMania":
             if (thesize == "big")
                 return "images/taxbigcar.png";
             else
                 return "images/taxsmallcar.png";
             break;
         case "EDi":
             if (thesize == "big")
                 return "images/edibigcar.png";
             else
                 return "images/edismallcar.png";
             break;
         case "XTaxes":
             if (thesize == "big")
                 return "images/ETbigcar.png";
             else
                 return "images/ETsmallcar.png";
             break;
     }
 }

 hideAllDescriptions = function() {
     document.getElementById('edi_product_description').style.display = "none";
     document.getElementById('taxmania_product_description').style.display = "none";
     document.getElementById('xtaxes_product_description').style.display = "none";
 }

 setProductDescription = function(theproduct) {
     hideAllDescriptions();
     switch (theproduct) {
         case "TaxMania":
             document.getElementById('taxmania_product_description').style.display = "block";
             break;
         case "EDi":
             document.getElementById('edi_product_description').style.display = "block";
             break;
         case "XTaxes":
             document.getElementById('xtaxes_product_description').style.display = "block";
             break;
     }
 }

 redirectToProductPage = function() {
    switch (productArray[1]) {
        case "TaxMania":
            window.location.href = "http://www.taxmania.com";
            break;
        case "EDi":
            window.location.href = "http://edi.cegsoft.com";
            break;
        case "XTaxes":
            window.location.href = "http://tax.cegsoft.com";
            break;
  
     }

 }
 var secs
 var timerID = null
 var timerRunning = false
 var delay = 1000

 function InitializeTimer() {
     // Set the length of the timer, in seconds
     secs = 10
     StopTheClock()
     StartTheTimer()
 }

 function StopTheClock() {
     if (timerRunning)
         clearTimeout(timerID)
     timerRunning = false
 }

 function StartTheTimer() {
     if (secs == 0) {
         StopTheClock();
         moveToNext();
         InitializeTimer();       
     }
     else {
         //self.status = secs
         secs = secs - 1
         timerRunning = true
         timerID = self.setTimeout("StartTheTimer()", delay)
     }
 }

