var d = document, xttip, xreq, xcur, xtarget, ximgtime, xmove, ymove, xconfigpop, xmenu, m_aboutus, m_product, m_simplicius, m_configurator, m_catalogue, m_ecommerce, m_techcenter, m_salesnetwork, m_download, m_helpdesk, vSeriesSparePart;
var m_Jan, m_Feb, m_Mac, m_Apr, m_May, m_Jun, m_Jul, m_Aug, m_Sep, m_Oct, m_Nov, m_Dec;
var m_Sunday, m_Monday, m_Tuesday, m_Wednesday,m_Thursday, m_Friday, m_Saturday;
var todayDay, todayMonth,m_language;
var m_Italy, m_ConfigProcessingrequestPlsWait;
//var months = new Array(m_Jan, m_Feb, m_Mac, m_Apr, m_May, m_Jun, m_Jul, m_Aug, m_Sep, m_Oct, m_Nov, m_Dec), days = new Array(m_Sunday, m_Monday, m_Tuesday, m_Wednesday,m_Thursday, m_Friday, m_Saturday);
var months = new Array('Jan', 'Feb', 'Mac', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var thour = '', tmin = '', tsec = '', tdaytext = '', tday = '', tmonth = '', tyear = '';
var dthour = 0, dtmin = 0, dtsec = 0, daytext = 0, dtday = 0, dtmonth = 0, dtyear = 0;
d.onmousemove = MouseUpdate;
//d.oncontextmenu = new Function("return false");

function MouseUpdate(e) {
    if (e == null) { e = window.event; }
	if (xttip != null) {
        if (xttip.innerHTML != '') { Tooltip.Show(e); }
	    else { xttip.style.visibility = 'hidden'; }
	}
}

var General = { 
    MultiLanguage: function(a, b, c, e, f, g, h, i, j, k, l, m , n, o, p, q, r, s, t, u, v) {
        m_Jan = a , m_Feb = b, m_Mac = c, m_Apr = e, m_May = f, m_Jun = g, m_Jul = h, m_Aug = i, m_Sep = j, m_Oct = k, m_Nov = l, m_Dec = m;
        m_Sunday = n, m_Monday = o, m_Tuesday = p, m_Wednesday = q, m_Thursday = r, m_Friday = s, m_Saturday = t;
        m_Italy = u , m_ConfigProcessingrequestPlsWait = v;
     },
    
    Language: function(a) {
       m_language = a;
    },
    
    Display: function(a, b) {
        if (b == 'x') { a.style.display = 'block'; }
        else { a.style.display = 'none'; }
    },
    
    DateTime: function(a, b, c) {
        var x = 'datetime';
        dtday = a.substring(0, 2);
        dtmonth = a.substring(3, 5) - 1;
        dtyear = a.substring(6, 10);
        dthour = parseInt(b.substring(0, 2), 10);
        dtmin = parseInt(b.substring(3, 5), 10);
        dtsec = parseInt(b.substring(6, 8), 10);
        daytext = c;
        
        General.DateTimeUpdate();
        setInterval("General.DateTimeUpdate()", 1000);
    },
    
    DateTimeUpdate: function() {
        var x = 'datetime';
        
        if (parseInt(dthour) == 23 && parseInt(dtmin) == 59 && parseInt(dtsec) == 59) { dthour = 0; dtmin = 0; dtsec = -1; General.DateTimeDays(); General.DateTimeText(); }
        if (parseInt(dtsec) == 59) { dtmin = parseInt(dtmin) + 1; dtsec = 0;} else { dtsec = parseInt(dtsec) + 1 } 
        if (parseInt(dtmin) == 60) { dthour = parseInt(dthour) + 1; dtmin = 0;}
        if (parseInt(dtsec) <= 9) { tsec = '0' + dtsec  } else { tsec = dtsec }
        if (parseInt(dtmin) <= 9) { tmin = '0' + dtmin  } else { tmin = dtmin }   
        if (parseInt(dthour) <= 9) { thour = '0' + dthour } else { thour = dthour }  

        tdaytext = General.DayText(daytext);  //days[daytext];
        tday = dtday;
        tmonth = General.MonthText(dtmonth);  //months[dtmonth];
        tyear = dtyear;

        var vDisplayText;
        
        switch (m_language){
            case 'en-GB','it-IT','fr-FR','pl-PL':
                    vDisplayText = tdaytext + ", " + tday + " " + tmonth + " " + tyear + " - " + thour + ":" + tmin + ":" + tsec + " (" + m_Italy + ")"; break;                
            case 'zh-CN':
                    vDisplayText = tdaytext + ", " + tyear + "/" + (dtmonth+1) + "/" + tday + " - " + thour + ":" + tmin + ":" + tsec + " (" + m_Italy + ")"; break;                
                default:
                    vDisplayText = tdaytext + ", " + tday + " " + tmonth + " " + tyear + " - " + thour + ":" + tmin + ":" + tsec + " (" + m_Italy + ")"; break;                
                }         
                
        d.getElementById(x).innerHTML = vDisplayText;
       
    },
    
    DateTimeDays: function() {
      if (dtmonth == 11 && dtday == 31) { dtmonth = 0; dtday = 1; dtyear = parseInt(dtyear) + 1; }
      else if (dtmonth == 1 && dtday == 28 && (dtyear % 4) == 1) { dtday = 1; }
      else if (dtmonth == 1 && dtday == 29 && (dtyear % 4) == 0) { dtday = 1; }
      else if ((dtmonth == 0 || dtmonth == 2 || dtmonth == 4 || dtmonth == 6 || dtmonth == 7 || dtmonth == 9 || dtmonth == 11) && dtday == 31) { dtday = 1; dtmonth = parseInt(dtmonth) + 1; }
      else if ((dtmonth == 1 || dtmonth == 3 || dtmonth == 5 || dtmonth == 8 || dtmonth == 10) && dtday == 30) { dtday = 1; dtmonth = parseInt(dtmonth) + 1; }
      else { dtday = parseInt(dtday) + 1; }
    },
    
    DateTimeText: function() {
          if (daytext == 6) { daytext = 1; }
             else { daytext = parseInt(daytext) + 1; }
      },
      
    DayText: function(a) {
          var vDayText;
          
            switch (a) {
                case '0':
                    vDayText = m_Sunday; break;
                case '1':
                    vDayText = m_Monday; break; 
                case '2':
                    vDayText = m_Tuesday; break; 
                case '3':
                    vDayText = m_Wednesday; break; 
                case '4':
                    vDayText = m_Thursday; break; 
                case '5':
                    vDayText = m_Friday; break;                
                case '6':
                    vDayText = m_Saturday; break;                
                default:
                    vDayText = a;break;        
                }         
                
              return  vDayText;                          
      } ,          

    MonthText: function(a) {
          var vMonthText;
          
            switch (a+1) {
                case 1:
                    vMonthText = m_Jan; break; 
                case 2:
                    vMonthText = m_Feb; break; 
                case 3:
                    vMonthText = m_Mac; break; 
                case 4:
                    vMonthText = m_Apr; break; 
                case 5:
                    vMonthText = m_May; break;                
                case 6:
                    vMonthText = m_Jun; break;    
                case 7:
                    vMonthText = m_Jul; break;
                case 8:
                    vMonthText = m_Aug; break;
                case 9:
                    vMonthText = m_Sep; break;
                case 10:
                    vMonthText = m_Oct; break;
                case 11:
                    vMonthText = m_Nov; break;
                case 12:
                    vMonthText = m_Dec; break;
                default:
                    vMonthText = a;break;        
                }         
                
              return  vMonthText;                          
      }                 
 }

var Browser = {
	Redirect: function(a) {
	    window.location = a;
	},
	
	ConfigPopup: function(a, b, c) {
	    var x, y;
        x = (screen.width - parseInt(b)) / 2;
	    y = (screen.height - (parseInt(c))) / 2;
	    xconfigpop = window.open(a, 'Configurator', 'resizable=1, width=' + b + ', height=' + c + ', top=' + y + ', left=' + x + '');
	},
	
	ConfigPopupClose: function() {
	    if (xconfigpop != null) { xconfigpop.close(); }
	    Configurator.CloseBlankScreen();
	},
	
    CenterPopup: function(a, b, c) {
	    var x, y;
        x = (screen.width - parseInt(b)) / 2;
	    y = (screen.height - (parseInt(c))) / 2;
	    xconfigpop = window.open(a, 'CenterPopup', 'resizable=1, width=' + b + ', height=' + c + ', top=' + y + ', left=' + x + '');
//        xconfigpop.document.open("text/html", "replace");
//        xconfigpop.document.write("<HTML><HEAD><TITLE>Vega S.r.l</TITLE></HEAD></HTML>");
//        xconfigpop.document.close();
	    return xconfigpop
	},

    CenterPopupEcommerce: function(a) {
	    var x, y = 0;
	    var b = 800; c = 600;
		var sh = screen.height;
		if (sh > 700) { c = sh - 100 };
        x = (screen.width - parseInt(b)) / 2;
	    xconfigpop = window.open(a, 'CenterPopup', 'resizable=1, width=' + b + ', height=' + c + ', top=' + y + ', left=' + x + '');
	    return xconfigpop
	},
	
    CenterPopupSimple: function(a, b, c) {
	    var x, y;
        x = (screen.width - parseInt(b)) / 2;
	    y = (screen.height - (parseInt(c))) / 2;
	    xconfigpop = window.open(a, 'CenterPopupSimple', 'resizable=0, scrollbars=0, width=' + b + ', height=' + c + ', top=' + y + ', left=' + x + '');
	    return xconfigpop
	},
	
	CenterPopupWithMenu: function(a, b, c) {
	    var x, y;
        x = (screen.width - parseInt(b)) / 2;
	    y = (screen.height - (parseInt(c))) / 2;
	    xconfigpop = window.open(a, 'CenterPopupWithMenu', ',menubar=1, scrollbars=1, resizable=1, width=' + b + ', height=' + c + ', top=' + y + ', left=' + x + '');
	   return xconfigpop
	}

}

var Mouse = {
    ChangeCSS: function(a, b, c, e, f) {
        if (b != '') { a.className = b; }
        if (c != '' && e != '') { 
            if (vSeriesSparePart == '') { xttip.innerHTML = ConfigTip.Tooltip(c, e); }
            else { xttip.innerHTML = ConfigTip.SparePartTip(c, e); }
        }
        else { if(xttip != null) { xttip.innerHTML = ''; } }
    },
    
    Visibility: function(a, b) {
        d.getElementById(a).style.display = b;
    },
    
    BestPrice: function(a) {
        if (a != '') { xttip.innerHTML = '<img src="/images/bestprice.gif" />'; }
        else { xttip.innerHTML = ''; }
    },
    
    OverCSS: function(a, b) {
        a.className = b;
    },
    
    OutCSS: function(a, b) {
        a.className = b;
    }
}

var Tooltip = {
    Show: function(e) {
        xttip.style.visibility = 'visible';
        if ((e.clientY) > (document.documentElement.clientHeight)) { xttip.style.top = (e.clientY + document.documentElement.scrollTop) + 'px'; }
        else { xttip.style.top = (e.clientY + document.documentElement.scrollTop) + 'px'; }
        xttip.style.left = (e.clientX + 20) + 'px'; 
    },
    
    Retrieve: function(a, b, c) {
        Ajax.Post('ax_tooltip.aspx?series=' + c + '&type=' + a + '&value=' + b, xttip, Ajax.Retrieve);
    }
}

var Search = {
    Init: function() {
        //d.getElementById('txtSearch').value = "";
        //Search.InActive();
    },
    
    Active: function() {
        if (d.getElementById('txtSearch').value == 'Search Term') {
            d.getElementById('txtSearch').className = 'search_with';
            d.getElementById('txtSearch').value = '';    
        }
    },
    
    InActive: function() {
        if (d.getElementById('txtSearch').value == '') {
            d.getElementById('txtSearch').className = 'search_without';
            d.getElementById('txtSearch').value = 'Search Term';
        }
    }
}

var NavMenu = {
    English: function() {
        m_aboutus = new Array('m_aboutus', '95px', '11px');
        m_product = new Array('m_product', '95px', '11px');
        m_simplicius = new Array('m_simplicius', '105px', '11px');
        m_configurator = new Array('m_configurator', '125px', '11px');
        m_catalogue = new Array('m_catalogue', '110px', '11px');
        m_ecommerce = new Array('m_ecommerce', '115px', '11px');
        m_techcenter = new Array('m_techcenter', '110px', '11px');
        m_salesnetwork = new Array('m_salesnetwork', '135px', '11px');
        /*'m_download = new Array('m_download', '90px', '11px');*/
        m_helpdesk = new Array('m_helpdesk', '93px', '11px');
        NavMenu.Settings();
    },
    
    Italian: function() {
        m_aboutus = new Array('m_aboutus', '95px', '11px');
        m_product = new Array('m_product', '95px', '11px');
        m_simplicius = new Array('m_simplicius', '105px', '11px');
        m_configurator = new Array('m_configurator', '125px', '11px');
        m_catalogue = new Array('m_catalogue', '105px', '11px');
        m_ecommerce = new Array('m_ecommerce', '110px', '11px');
        m_techcenter = new Array('m_techcenter', '125px', '11px');
        m_salesnetwork = new Array('m_salesnetwork', '130px', '11px');
        /*'m_download = new Array('m_download', '120px', '11px');*/
        m_helpdesk = new Array('m_helpdesk', '93px', '11px');
        NavMenu.Settings();
    },
    
    Chinese: function() {
        m_aboutus = new Array('m_aboutus', '102px', '11px');
        m_product = new Array('m_product', '110px', '11px');
        m_simplicius = new Array('m_simplicius', '110px', '11px');
        m_configurator = new Array('m_configurator', '110px', '11px');
        m_catalogue = new Array('m_catalogue', '110px', '11px');
        m_ecommerce = new Array('m_ecommerce', '110px', '11px');
        m_techcenter = new Array('m_techcenter', '110px', '11px');
        m_salesnetwork = new Array('m_salesnetwork', '110px', '11px');
        /*'m_download = new Array('m_download', '99px', '11px');*/
        m_helpdesk = new Array('m_helpdesk', '111px', '11px');
        NavMenu.Settings();
    },
    
    French: function() {
        m_aboutus = new Array('m_aboutus', '122px', '11px');
        m_product = new Array('m_product', '77px', '11px');
        m_simplicius = new Array('m_simplicius', '85px', '11px');
        m_configurator = new Array('m_configurator', '115px', '11px');
        m_catalogue = new Array('m_catalogue', '95px', '11px');
        m_ecommerce = new Array('m_ecommerce', '95px', '11px');
        m_techcenter = new Array('m_techcenter', '130px', '11px');
        m_salesnetwork = new Array('m_salesnetwork', '186px', '11px');
        /*m_download = new Array('m_download', '90px', '11px');*/
        m_helpdesk = new Array('m_helpdesk', '78px', '11px');
        NavMenu.Settings();
    },
   
    
    Settings: function() {
        var z; xmenu = new Array(m_aboutus, m_product, m_simplicius, m_configurator, m_catalogue, m_ecommerce, m_techcenter, m_salesnetwork, m_helpdesk);
        for (var x = 0; x < xmenu.length; x++) {
            z = xmenu[x];
            d.getElementById(z[0]).style.width = z[1];
            d.getElementById(z[0]).style.fontSize = z[2];
        }
    }
}

var addToCartWin;
var showWin;
var Cart = {
    Add: function(a) {
	    var width = 450;
	    var height = 180;
		addToCartWin = dhtmlwindow.open("AddToCart", "ajax", "/eCommerce/add_to_cart.aspx?code=" + a, "Vega S.r.l", "width=" + width + ",height=" + height + ",center=1,resize=0,scrolling=0")
    },
    
    AddViaCart: function(a) {
	    var width = 450;
	    var height = 180;
		addToCartWin = dhtmlwindow.open("AddToCart", "ajax", "/eCommerce/add_to_cart.aspx?code=" + a + "&type=cart", "Vega S.r.l", "width=" + width + ",height=" + height + ",center=1,resize=0,scrolling=0")    
    }
}

var Price = {
    GetOld: function(a) {
		var objGetPrice = d.getElementById('ctl00$cphContent$ctrlCheckPrice$btnGetPrice');

		if (objGetPrice) {
			d.getElementById('ctl00$cphContent$ctrlCheckPrice$hidOrderCode').value = a;
			objGetPrice.click();
		}
    },
    
    Get: function(a) {
	    var width = 500;
	    var height = 220;
		showWin = dhtmlwindow.open("CheckPrice", "ajax", "/eCommerce/check_price.aspx?code=" + a, "Vega S.r.l", "width=" + width + ",height=" + height + ",center=1,resize=0,scrolling=0")
    }
    
}
