/* This is the file that was passed to me, just added the click to open in the first place - Delmarc */
/* Browser detection */
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function formFinished() {
}

function showThanksHomepage() {
	$('#pledge_box').hide();
	$('#pledge_box_thanks').show();
    document.cookie='subscribeSplash=Filled;path=/;expires=Thu, 01-Jan-2030 00:00:01 GMT; host=www.specialolympics.org;';
    setTimeout("javascript:__doPostBack('submitSubscription','')", 10000);
}

function showThanks() {
	$('#pledge_box').hide();
	$('#pledge_box_thanks').show();
	document.cookie='subscribeSplash=Filled;path=/;expires=Thu, 01-Jan-2030 00:00:01 GMT; host=www.specialolympics.org;';
    setTimeout("javascript:__doPostBack('ctl00$uiSectionHeader$submitSubscription','')", 10000);
}

function showSplash() {
    $('#splash').show();
    $('#splashinner').show();
    $('#videoBox').hide();
}

function showXmasSplash() {
    $('#splash').show();
    $('#holidayModal').show();
	$('#pledge_box').hide();
 //   $('#videoBox').hide();
}

function showRegionModal () {
    $('#splash').show();
    $('#modal_backdrop').show();
}

function hideSplash() {
    $('#splash').hide();
    $('#splashinner').hide();
}
function hideHolidaySplash() {
    $('#splash').hide();
    $('#holidayModal').hide();
	document.cookie='subscribeSplash=Filled;path=/;expires=Thu, 01-Jan-2030 00:00:01 GMT; host=www.specialolympics.org;';
}



	function TrimString(sInString) {
		sInString = sInString.replace( /^\s+/g, "" );// strip leading
		return sInString.replace( /\s+$/g, "" );// strip trailing
    }


    $(document).ready(function () {
        var splashValue = readCookie('subscribeSplash');
      /*  if (splashValue != 'Filled') {
            showSplash();
            showXmasSplash();
        } else {
            // alert('no masty');
        }*/

        var regionValue = readCookie('chooseRegion');
        if (regionValue != 'Chosen') {
            showRegionModal() 
        }

        // For Language Modal
        $('#close_button, div.modal_regions ul li a, div.modal_languages ul li a').click(function () {
            $('#splash').hide();
            $('#modal_backdrop').hide();
            document.cookie = 'chooseRegion=Chosen;path=/;expires=Thu, 01-Jan-2030 00:00:01 GMT; host=www.specialolympics.org;';
        });

        $(document).unload(function () {
            $.cookie("subscribeSplash", null);
        });
    });

function validate_form() {
    errors = false;
//    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
//    if (!pattern.test($('#Email').val())) { 
//        alert('Please put a valid E-Mail Address');
//        errors = false;
//    }
   // else {
        showThanksHomepage();
    //}
    return errors;
}

function validate_formOther() {
    errors = false;
    //var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    //if (!pattern.test($('#ctl00_uiSectionHeader_Email').val())) { 
        //alert('Please put a valid E-Mail Address');
        //errors = false;
    //}
    //else {
        showThanks();
    //}
    return errors;
}

function validate_formEmbeded() {
    errors = false;
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if (!pattern.test($('#ctl00_ContentPlaceHolder1_Email').val())) { 
        alert('Please put a valid E-Mail Address');
        errors = false;
    }
    else {
    javascript:__doPostBack('ctl00$ContentPlaceHolder1$submitSubscription','');
    }
    return errors;
}
