/* Used on the home page */
var imgStart = new Image();
imgStart.src = 'images/start.gif';

function addbookmark(){
    var bookmarkurl='http://www.wschurch.org/';
    var bookmarktitle="West Side Christian Church - Online!";
    if (document.all)
        window.external.AddFavorite(bookmarkurl,bookmarktitle);
}

/* Used for date validation */
function validateUSDate(oSrc, args) {

    args.IsValid=false;

    var strValue = args.Value;
    var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

    //check to see if in correct format
    if(!objRegExp.test(strValue))
        return; //doesn't match pattern, bad date
    else{
        var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
	       var intDay = parseInt(arrayDate[1],10);
	       var intYear = parseInt(arrayDate[2],10);
        var intMonth = parseInt(arrayDate[0],10);

	   //check for valid month
	   if(intMonth > 12 || intMonth < 1) {
            return;
	   }

        //create a lookup for months not equal to Feb.
        var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}

        //check if month value and day value agree
        if(arrayLookup[arrayDate[0]] != null) {
            args.IsValid = (intDay <= arrayLookup[arrayDate[0]] && intDay != 0);
            return; //found in lookup table, good date
        }

        //check for February
	       var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
        args.IsValid=(((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
        return; //Feb. had valid number of days
    }
    alert(args.IsValid);
    return; //any other values, bad date
}

/* Used for virtual tours */
function OpenTourWindow(tourName, tourTitle) {

    // window coordinates for virtual tours
    winwidth = 340; // width of the new window
    winheight = 300; // height of the new window
    winleft   = 0; // just dummie values
    wintop    = 0; // just dummie values
    if(parseInt(navigator.appVersion)>=4) {
        winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
        wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom
    }
    var winFileName = 'tours/tourwindow.aspx?title=' + tourTitle + '&tour=' + tourName;
    window.open(winFileName, '', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width='+winwidth+',height='+winheight+',top=' + wintop + ',left=' + winleft)
}

/* Used for map windows */
function OpenPopUp(wid, hgt, x, y , title, resource) {

    // window coordinates for virtual tours
    var winwidth = wid;     // width of the new window
    var winheight = hgt;    // height of the new window
    var winleft   = x;      // just dummie values
    var wintop    = y;      // just dummie values
    if(parseInt(navigator.appVersion) >= 4) {
        winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
        wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom
    }
    var winFileName = 'popup.aspx?title=' + title + '&resource=' + resource;
    window.open(winFileName, '', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width='+winwidth+',height='+winheight+',top=' + wintop + ',left=' + winleft)
}

