﻿function hideLandingPopUpWindow(id)
{
    //var myFx = new Fx.Style('overlayBackground', 'display').set('none');
    document.getElementById('overlayBackground').style.display='none';
    myFx = new Fx.Style('overlayBackground', 'opacity').set(0);
    document.getElementById(id).style.display='none';
    myFx = new Fx.Style(id, 'opacity').set(0);
}

function landingCheckZipcode()
{
      var re = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
      if($('txtZip').value.match(re))
      {
        $('txtZipTop').value = $('txtZip').value;
        
        //AJAX call to check zip code status
        var objAJAX = new Ajax('XML_CheckZip.aspx?z='+$('txtZip').value, {
            method: 'get',
            onSuccess: function(txt){
                //Check status
                if(txt=='pass')
                {
                    $('hdnZipState').value = 1;
                    window.open('Default.aspx','_self');
                }
                else
                {
                    $('hdnZipState').value = 2;                
                    if($('hdnUserType').value=='1')
                        window.open('Default.aspx','_self'); // hideLandingPopUpWindow('landingPopUpWindow');
                    else
                        window.open('Default.aspx','_self');
                }
            } //onSuccess
	     });
        objAJAX.request();
      } 
      else
      {
        alert("Invalid zip code.  Please try again.");
      }
}

function showLandingPopUpWindow(id)
{
    //Display, size and set opacity of overlay background
    var myFx = new Fx.Style('overlayBackground', 'height').set(window.getScrollHeight());
    document.getElementById('overlayBackground').style.display='block';
    myFx = new Fx.Style('overlayBackground', 'opacity').set(POPUP_BACKGROUND_OPACTIY);
    
    //Position popup window
    myFx = new Fx.Style(id, 'top').set(window.getScrollTop() + POPUP_WINDOW_HEIGHT);
    myFx = new Fx.Style(id, 'left').set((window.getScrollWidth()-$(id).getStyle('width').toInt()) / 2);
    
    //Set pop up window visibility and opacity
    document.getElementById(id).style.display='block';
    myFx = new Fx.Style(id, 'opacity').set(POPUP_WINDOW_OPACTIY);
    
    //Make window visible
    document.getElementById(id).style.display='block'; 
    document.getElementById('landingPopUpContainer').style.display='block';
    $(id).setOpacity(POPUP_WINDOW_OPACTIY);
    $('landingPopUpContainer').setOpacity(POPUP_WINDOW_OPACTIY);
    //$(id).getElement('div[class=popUpContainer]').setOpacity(0.85);
    //$(id).getElement('div[class=popUpWindowWideTopBar]').setOpacity(0.85);
    //$(id).getElement('div[class=popUpWindowWideLeftBar]').setOpacity(0.85);
    //$(id).getElement('div[class=popUpWindowWideRightBar]').setOpacity(0.85);
    myFx = new Fx.Style('landingPopUpWindowLeftBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    myFx = new Fx.Style('landingPopUpWindowRightBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    myFx = new Fx.Style('landingPopUpWindowWideTopBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    myFx = new Fx.Style('landingPopUpWindowWideBottomBar', 'opacity').set(POPUP_WINDOW_OPACTIY);
    
    //Adjust height of side bars
    //$('demoPopUpWindowLeftBar').setStyle('height', $(id).getElement('div[class=popUpContainer]').clientHeight);
    //$('demoPopUpWindowRightBar').setStyle('height', $(id).getElement('div[class=popUpContainer]').clientHeight);
    //$(id).getElement('div[class=popUpWindowWideLeftBar]').setStyle('height', $(id).getElement('div[class=popUpContainer]').clientHeight);
    myFx = new Fx.Style('landingPopUpWindowLeftBar', 'width').set(5); //$('demoPopUpContainer').clientHeight
    myFx = new Fx.Style('landingPopUpWindowRightBar', 'width').set(5);
    myFx = new Fx.Style('landingPopUpWindowLeftBar', 'height').set($('landingPopUpContainer').clientHeight); //$('demoPopUpContainer').clientHeight
    myFx = new Fx.Style('landingPopUpWindowRightBar', 'height').set($('landingPopUpContainer').clientHeight);
//alert($('demoPopUpContainer').clientHeight);
}


function initSamplesaintLanding()
{   
    //Set zip code
    if($('txtZip').value=='60648')
    {
        $('txtZip').value = '';
        $('txtZipTop').value = '';
    }
    else
    {
        $('txtZip').value = $('hdnZipCode').value;
        $('txtZipTop').value = $('hdnZipCode').value;
    }
    
    //Popup zipcode overlay
    if($('txtZip').value=='')
        showLandingPopUpWindow('landingPopUpWindow');
    
    //Check browser version, set variables
    //alert(navigator.appName+'****'+navigator.appVersion);
    if(navigator.appName.indexOf('Mac')!=-1||navigator.appVersion.indexOf('Mac')!=-1) {
        POPUP_WINDOW_OPACTIY = 1.0;
    }
    else {
        if(navigator.appName.indexOf('Internet Explorer')!=-1||navigator.appVersion.indexOf('Internet Explorer')!=-1)
            POPUP_WINDOW_OPACTIY = 0.92; //85
        else
            POPUP_WINDOW_OPACTIY = 0.95; //95
    }
    //alert(POPUP_WINDOW_OPACTIY);

}

window.addEvent('domready', initSamplesaintLanding);