﻿
//birthdate

window.onload = function() {
	try {
		populatedropdown('<%= monthdropdown.ClientID.ToString() %>', '<%= yeardropdown.ClientID.ToString() %>', '<%= daydropdown.ClientID.ToString() %>');
		document.getElementById('<%= monthdropdown.ClientID.ToString() %>').onchange = function() {
			populatedays(document.getElementById('<%= monthdropdown.ClientID.ToString() %>').selectedIndex, document.getElementById('<%= yeardropdown.ClientID.ToString() %>').value, '<%= daydropdown.ClientID.ToString() %>');
			ValidatorEnable(document.getElementById('<%= rqValMonth.ClientID.ToString() %>'), true);
		}
		document.getElementById('<%= yeardropdown.ClientID.ToString() %>').onchange = function() {
			populatedays(document.getElementById('<%= monthdropdown.ClientID.ToString() %>').selectedIndex, document.getElementById('<%= yeardropdown.ClientID.ToString() %>').value, '<%= daydropdown.ClientID.ToString() %>');
			ValidatorEnable(document.getElementById('<%= rqValYear.ClientID.ToString() %>'), true);
		}
	} catch (x) { }
	CheckMailSent();
	//d_sweepPop();
}

var monthtext = ['Month','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 
                    'September', 'October', 'November', 'December'];

function populatedropdown(monthid, yearid, dayid) {
   
    var today = new Date()

    var monthfield = document.getElementById(monthid);
    var monthfieldSelectedIndex = monthfield.selectedIndex;

    var yearfield = document.getElementById(yearid);
    var yearfieldSelectedIndex = yearfield.selectedIndex;

    var dayfield = document.getElementById(dayid);
    var dayfieldSelectedIndex = dayfield.selectedIndex;
   
    for (var m = 0; m <= 12; m++)
        monthfield.options[m] = new Option(monthtext[m], m)
    var thisyear = today.getFullYear();
    for (var y = 0; y <= 100; y++) {
        if (y == 0)
            yearfield.options[0] = new Option('Yr.', 0);
        else {
            yearfield.options[y] = new Option(thisyear, thisyear);
            thisyear--;
        }
    }
    populatedays(monthfield.selectedIndex, yearfield.value, dayid);

    yearfield.selectedIndex = yearfieldSelectedIndex != 0 ? yearfieldSelectedIndex + 1 : 0;
    monthfield.selectedIndex = monthfieldSelectedIndex!= 0 ?monthfieldSelectedIndex+ 1 : 0;
    dayfield.selectedIndex = dayfieldSelectedIndex != 0 ? dayfieldSelectedIndex + 1 : 0;
}
function populatedays(month, year, dayid) {
    var dayfield = document.getElementById(dayid);
    var selectedDay = dayfield.selectedIndex;
    var days = getdays(month, year);
    dayfield.length = 0;
    for (var i = 0; i <= days; i++)
        if (i == 0)
        dayfield.options[i] = new Option('Day', i);
    else
        dayfield.options[i] = new Option(i, i);
    if (dayfield.length > selectedDay)
        dayfield.selectedIndex = selectedDay != -1 ? selectedDay : 0;
    else
        dayfield.selectedIndex = dayfield.length - 1; 
}
function getdays(month, year) {
    var days;
    var m = [31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    if (month != 2) return m[month];
    if (year % 4 != 0) return  m[2];
    if (year % 100 == 0 && year % 400 != 0) return m[2];
   return m[2] + 1;

}

//fileupload
if (!window.SI) { var SI = {}; };
SI.Files =
{
    htmlClass: 'SI-FILES-STYLIZED',
    fileClass: 'file',
    wrapClass: 'cabinet',

    fini: false,
    able: false,
    init: function() {
        this.fini = true;
        var ie = 0//@cc_on + @_jscript_version
        if (window.opera || (ie && ie < 5.5) || !document.getElementsByTagName) { return; } // no support for opacity or the DOM
        this.able = true;

        var html = document.getElementsByTagName('html')[0];
        html.className += (html.className != '' ? ' ' : '') + this.htmlClass;
    },
    stylize: function(elem) {
        if (!this.fini) { this.init(); };
        if (!this.able) { return; };

        elem.parentNode.file = elem;
        elem.parentNode.onmousemove = function(e) {
            if (typeof e == 'undefined') e = window.event;
            if (typeof e.pageY == 'undefined' && typeof e.clientX == 'number' && document.documentElement) {
                e.pageX = e.clientX + document.documentElement.scrollLeft;
                e.pageY = e.clientY + document.documentElement.scrollTop;
            };
            var ox = oy = 0;
            var elem = this;
            if (elem.offsetParent) {
                ox = elem.offsetLeft;
                oy = elem.offsetTop;
                while (elem = elem.offsetParent) {
                    ox += elem.offsetLeft;
                    oy += elem.offsetTop;
                };
            };
            var x = e.pageX - ox;
            var y = e.pageY - oy;
            var w = this.file.offsetWidth;
            var h = this.file.offsetHeight;

            this.file.style.top = y - (h / 2) + 'px';
            this.file.style.left = x - (w - 30) + 'px';
        };
    },
    stylizeById: function(id) {
        this.stylize(document.getElementById(id));
    },
    stylizeAll: function() {
        if (!this.fini) { this.init(); };
        if (!this.able) { return; };

        var inputs = document.getElementsByTagName('input');
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i];
            if (input.type == 'file' && input.className.indexOf(this.fileClass) != -1 && input.parentNode.className.indexOf(this.wrapClass) != -1) {
                this.stylize(input);
            };
        };
    }
};

//ctear textbox
function clearText() {
    var inputs = document.getElementsByTagName('input');
    var count = document.getElementsByTagName('input').length;
    for (var i = 0; i < count; i++) {
        var theInput = inputs[i];

        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {
            if (theInput.addEventListener) {
                theInput.addEventListener("focus", clearDefaultText, true);
                theInput.addEventListener("blur", replaceDefaultText, true);
            }
            else
            {
               theInput.attachEvent("onfocus", clearDefaultText, true);
               theInput.attachEvent("onblur", replaceDefaultText, true);
            }
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}
function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}
function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
   }
   function ShareURL(file) {
   	//alert("share");
   	//inshare
   	var sh_url = location.protocol + '//' + location.host + '/';
   	try {
   		var vid = file.replace(/.*(\d+)\_(\d+).flv$/ig, "$2");
   		if (vid && vid.length<6) {
   			sh_url = sh_url + "?vid=" + vid;
   		}
   		sh_url = escape(sh_url);
   		//mail share url
   		var mshurl = 'mailto:?subject=Join the Surge&body=Check out this awesome video from Join the Surge, a massive movement of teens doing something good for their communities. There is a lot of cool stuff, like coupons and contests, Join the Surge so click here [url] to visit!';
   		//fb shareurl
   		var fbshurl = 'http://www.facebook.com/sharer.php?u=[url]&t=Check+out+this+awesome+video+from+Join+the+Surge%2C+a+massive+movement+of+teens+doing+something+good+for+their+communities.+There+is+a+lot+of+cool+stuff%2C+like+coupons+and+contests%2C+Join+the+Surge+so+click+here+[url]+to+visit!';
   		document.getElementById('ash1').href = mshurl.replace('[url]', sh_url);
   		document.getElementById('ash2').href = fbshurl.replace('[url]', sh_url);
   		document.getElementById('ash2').href = fbshurl.replace('[url]', sh_url);
   	} catch (x) { }
   	//document.getElementById('shreinp').setAttribute("enabled", false);
   	$("#shredv").overlay();
   $("#shredv").overlay().load();
   }
   var cwdt = 0;
   function hideCarousel() {
   	//alert('hideCarousel');
   	//$("#dnn_ctr404_ModuleContent").hide();
   	crsl = document.getElementById('3Drotate');
   	//alert('get ' + crsl.clientHeight);
   	if (crsl.clientHeight>0) {
   		//alert('set ' + crsl.style.height);
   		cwdt = crsl.clientHeight;
   	}
   	crsl.style.height = '0px';
   	//$("#dnn_ctr404_ModuleContent")
   }
   function showCarousel() {
   	//alert('showCarousel');
   	//$("#dnn_ctr404_ModuleContent").show();
   	crsl = document.getElementById('3Drotate');
   	if(cwdt!=0)
   		crsl.style.height = cwdt;

   }
   function CheckMailSent() {
   	if (document.location.search == "?sent") {
   		$("#dvMailSent").overlay();
   		$("#dvMailSent").overlay().load();
   	}
   	//dvMailSent
   }
   function d_sweepPop() {
   	if (document.location.search == "?sent")
   		return;
   	var pp = {
   	mask: {
   		color: '#000',
   		loadSpeed: 200,
   		opacity: 0.9
   	},
   	closeOnClick: false
   };
   //$("#widgetbox_widget_flash_0").hide();
   	$("#sweepPop").overlay(pp);
   	$("#sweepPop").overlay(pp).load();
   	setTimeout('$("#sweepPop").overlay().close();', 13000);
   }
   

