//import styles  
document.write(getCalendarStyles());

//init popup-calendar
var cal1x = new CalendarPopup("caldiv1");

//create dates for range
var theLastMonth = new Date();
var theNextMonth = new Date();
theLastMonth.setDate(theLastMonth.getDate()-30);
theNextMonth.setDate(theLastMonth.getDate()+30);

//convert dates to strings for addDisabledDates method
//getMonth returns 0-11, so needs an extra 1
theLastMonth = theLastMonth.getFullYear()+'-'+(theLastMonth.getMonth()+1)+'-'+theLastMonth.getDate();
theNextMonth = theNextMonth.getFullYear()+'-'+(theNextMonth.getMonth()+1)+'-'+theNextMonth.getDate();

//don't add disabled dates for numerology
//don't add disabled dates for birthday central
if(document.location.pathname.indexOf('numerology') == -1 && document.location.pathname != "/astrology/birthday-central/"){
    cal1x.addDisabledDates(null,theLastMonth);
    cal1x.addDisabledDates(theNextMonth, null);
}

if(document.location.pathname == "/astrology/birthday-central/")
{

    var threedaypad = new Date();
    threedaypad.setDate(threedaypad.getDate()+1);
    threedaypad = threedaypad.getFullYear()+'-'+(threedaypad.getMonth()+1)+'-'+threedaypad.getDate();
    cal1x.addDisabledDates(threedaypad, null);
    cal1x.addDisabledDates(null,theLastMonth);

}


//dhod only goes one day ahead
if(document.location.pathname.indexOf('daily-horoscope') == 11)
{
    var threedaypad = new Date();
    threedaypad.setDate(threedaypad.getDate()+2);
    threedaypad = threedaypad.getFullYear()+'-'+(threedaypad.getMonth()+1)+'-'+threedaypad.getDate();
    cal1x.addDisabledDates(threedaypad, null);
    cal1x.addDisabledDates(null,theLastMonth);
    cal1x.offsetX = 10;

}

cal1x.setReturnFunction("datePicked");
    
function datePicked(y,m,d){
    var newUrl = document.location.pathname;
    
    //ensure m and d are in proper form for scopeDay
    m = new String(m);
    d = new String(d);
    if(m.length == 1){ m = "0"+m; }
    if(d.length == 1){ d = "0"+d; }
        
    
    //add question mark for potential query strings
    newUrl += '?';
    
    //parse query strings out into an object
    var GET = new Object();    
    var query = window.location.search;        
    //shift off leading question mark    
    query = query.substring(1);    
    var pairs = query.split('&');
    for(var i=0;i<pairs.length;i++){
        var pair = pairs[i].split('=');
        GET[(pair[0])] = pair[1];
    }
    
    //if mon1 is present, add mon1, day1 and year1 to query string
    if('undefined' != typeof(GET['mon1'])){
            newUrl += 'mon1' +'='+GET['mon1']+'&';
            newUrl += 'year1'+'='+GET['year1']+'&';
            newUrl += 'day1' +'='+GET['day1']+'&';
    }
    //if passthrough is present, add it
    if('undefined' != typeof(GET['passthrough'])){
            newUrl += 'passthrough' +'='+GET['passthrough']+'&';
    }    
    //if pageState is present, add it
    if('undefined' != typeof(GET['pageState'])){
            newUrl += 'pageState' +'='+GET['pageState']+'&';
    }    
    
    //add scopeDay
    newUrl += "scopeDay="+y+m+d;
    
    
    //if the querystring has mon1, that means we're on numberology 
    //and a non logged in user is passing in a birthday so we'll
    //append the entire querystring, otherwise,handle single cases
    if(query.indexOf){
    }
    else{
        newUrl += "?scopeDay="+y+m+d;
        if(query.indexOf('passthrough=true') != -1){
            newUrl += '&passthrough=true';
        }
        if(query.indexOf('pageState=general') != -1){
            newUrl += '&pageState=general';
        }
    }
    //add domain and protcal to URL, to ensure it's exactly
    //the same (used to fix "//oracle/daily" problem
    newUrl = document.location.protocol+'//'+document.location.host+newUrl;
    document.location = newUrl;
}    
