$(document).ready(function() { 
	$("#simple").tablesorter({
		sortColumn: 'Posting Date',						// Integer or String of the name of the column to sort by.
		sortDir:1,										// Ensures sort is newest-to-oldest, top-to-bottom
		sortClassAsc: 'headerSortUp', 					// class name for ascending sorting action to header
		sortClassDesc: 'headerSortDown', 				// class name for descending sorting action to header
		headerClass: 'header', 							// class name for headers (th's)
		stripingRowClass: ['table_even','table_odd'],	// class names for striping supplyed as a array.
		stripeRowsOnStartUp: true
	});
	
	$('#ccePartners').cycle({
		fx:     'fade', 
		speed:  'slow', 
		timeout: 2500, 
		pause: 1				 
	});
	
	$('#cceEvents').cycle({
		fx:     'fade', 
		speed:  'slow', 
		timeout: 2500, 
		pause: 1				 
	});
	
});

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=635,height=590,left=100,top=100');");
}

	function ValidateForm(myForm) {
	    if ((myForm.from.value=="")||(myForm.sendersemail.value=="")||(myForm.recipient.value=="")) {
	        alert("Error: Required information missing.\nPlease check that you have provided your name, your e-mail address and the e-mail address of the recipient.");
        return false;
    	} else {
	        if (!ValidateEmail(myForm.sendersemail.value)) {
	        alert("Error: Invalid E-mail Address\nPlease check the e-mail addresses you have supplied for any errors or invalid characters.");
    	    return false;
        }

        if (myForm.comments.value.length>500) {
	        alert("Error: Comments exceed maximum number of characters.\nPlease check that your comments do not exceed 500 characters.");
    	    return false;
        }

        var recipients = myForm.recipient.value;
        var tempemail;
        var i;
        var recipientslength;
        if (recipients.indexOf(",")==-1) {
            if (!ValidateEmail(recipients)) {
                alert("Error: Invalid E-mail Address\nPlease check the e-mail addresses you have supplied for any errors or invalid characters.");
                return false;
            }

            if (!RestrictAccess(recipients)) {
                alert("Error: Invalid recipient(s) exist in list.");
                return false;
            }
        }

        while (recipients.indexOf(",")!=-1) {
            i=recipients.indexOf(",");
            tempemail=recipients.substring(0,i);
            if (!ValidateEmail(tempemail)) {
                alert("Error: Invalid Email Address\nPlease check the email addresses you have supplied for any errors or invalid characters.");
                return false;
            }
			
            if (!RestrictAccess(tempemail)) {
                alert("Error: Invalid recipient(s) exist in list.");
                return false;
            }

            recipients=recipients.substring(i+1,recipients.length);
            if (recipients.indexOf(",")==-1) {
                if (!ValidateEmail(recipients)) {
                    alert("Error: Invalid Email Address\nPlease check the email addresses you have supplied for any errors or invalid characters.");
                    return false;
                }
				
                if (!RestrictAccess(recipients)) {
                    alert("Error: Invalid recipient(s) exist in list.");
                    return false;
                }
            }
        }
    }
}

function RestrictAccess (EmailString) {
    var Restricted = "";
    if(Restricted=="")
        return true;

    Restricted = Restricted.toLowerCase();
    EmailString = trim(EmailString);
    EmailString = EmailString.toLowerCase();
    var index = EmailString.indexOf("@");
    var domain = EmailString.substr(index+1);

    if(Restricted.search(domain)!= -1) {
        return true;
    } else {
        return false;
    }
}

