/*Beginning of form validation for Contests*/

function val_required(field,alerttext) {
	with (field) {
		if (value == null || value == "") {
			window.alert(alerttext);
			return false;
		}
		else {
			return true;
		}
	}
}

function val_email(field,alerttext) {
	with (field) {
		apos = value.indexOf("@");
		dotpos = value.lastIndexOf(".");
		if (apos < 1 || dotpos-apos < 2) {
			alert(alerttext);
			return false;
		}
		else {
			return true;
		}
	}
}

function val_form(thisform) {
	with (thisform) {
		if (val_required(realName, "Please be sure to enter your name.") == false) {
			realName.focus();
			return false;
		}
		else if (val_email(email, "Please be sure to enter a valid email address.") == false) {
			email.focus();
			return false;
		}
	}
}



/*end of form validation*/

//checing for cookies and hiding the form

if (navigator.cookieEnabled == 0) {
  alert("You must enable cookies in order to vote.  Without cookies enabled your vote will not be recorded!");

}

jQuery.noConflict();

jQuery(document).ready(function() {
	if (navigator.cookieEnabled == 0) {
	jQuery("form#Vote").css({visibility : "hidden"});
	}
});

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

jQuery(document).ready(function() {
	 jQuery.cookie('surveys[579]', null);
	 return false;
 });
 
/*jQuery(document).ready(function() { 
	jQuery("form#Vote submit[name='submit']").click(function() {
	var date = new Date();
	date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
	jQuery.cookie('surveys[579]', 'Survey', { path: '/', expires: date });
	return false;
}); 
});*/

/*end of cookie val*/