/***** BEGIN CUFON ***************/

// Home : Featured Area
Cufon.replace('.audience_feature .feature_blurb h2, .audience_feature .feature_blurb .deck', {
	textShadow: 'rgb(0,0,0) 0 1px;'		  
});
Cufon.replace('.audience_feature nav', {
	textShadow: 'rgba(0,0,0,0.2) 0 1px;'		  
});
Cufon.replace('.audience_feature .in_this_section h5');
Cufon.replace('.audience_feature .in_this_section a.button');
Cufon.replace('.audience_feature .in_this_section a.button span', {
	textShadow: 'rgba(0,0,0,0.4) 0 1px;'		  
});

// Header 
Cufon.replace('.header_actions .search .calls_to_action  li a');

// Video Playlist
Cufon.replace('.body_liner article .video_area nav li a', { hover:true });

// News
Cufon.replace('.tabbed nav');
Cufon.replace('.news .button', {
	textShadow: 'rgba(0,0,0,0.4) 0 2px'		  
});

// Modules
Cufon.replace('.module h2 span, div.module.navy div p');
Cufon.replace('aside .getstarted li', {
	textShadow: 'rgba(255,255,255,0.5) 0 1px'
});

// Page Content
Cufon.replace('.landingpage article h1, .main_content .image_area h1, .main_content .image_area h2');
Cufon.replace('.more');

// Secondary Content
Cufon.replace('.secondary_content .mega h1, .secondary_content .mega h2, .secondary_content .steps h1');
Cufon.replace(' .secondary_content .steps h2', {
	textShadow: 'rgb(17,19,23) 0 1px'
});

/*_____END CUFON________________*/

var WSC = new Object;
WSC.featured_section;
WSC.index;
WSC.sections = [];
WSC.search_page;
WSC.activeNewsTab = "all";
WSC.newsPage = 0;

jQuery(document).ready(function() {
	if ($("body").hasClass("tour")) {
		tour();
	}
	if ($("body").hasClass("frontpage")) {
		WSC.slideshow.init();
		initNewsArea();
		initAjaxSearch();
	}
	if ($("body").hasClass("serp")) {
		initViewMoreSearch();
	}
	if (exists($("video"))) {
		initFlashVideo(EE_base_URI + "_videos/WSC-Academics.mp4", false);
		videoPlaylist();
	}
	if ($("body").hasClass("hub")) {
		news();
//		initNewsAjax();
	}
	truncateBreadcrumbs();
	printPage();
});

function truncateBreadcrumbs() {
	if (exists($(".breadcrumbs"))) {
		var w = 0;
		$(".breadcrumbs ul li").each(function() {
			w += $(this).outerWidth();
		});
		var tot = $(".breadcrumbs a").size();
		if (w > 750) {
			var keepers = [0, 1, tot - 1];
			if ($(".breadcrumbs li:eq(" + (tot - 2) + ")").outerWidth() < 200) {
				keepers.push(tot - 2);
			}
			// truncate every breadcrumb to an ellipsis except for the first and last
			$(".breadcrumbs li a").each(function(n) {
				if ($.inArray(n, keepers) == -1) {
					$(this).html("&hellip;");
				}
			});
		}
	}
}

/**** BEGIN NEWS PAGE *****************/

WSC.news = new Object;

WSC.news.currentTags = [];
WSC.news.currentDate = "";
WSC.news.currentCategory = [];
WSC.news.currentPage;

WSC.news.newTags = [];
WSC.news.newDate = "";
WSC.news.newCategory = [];
WSC.news.newPage;

WSC.news.categoryMap = ["all", "news", "events", "announcements"];

function news() {
	prepNewsParameters();
	handleNewsCategories();
	handleNewsDatesAndTags();
	viewMoreNews();
}

function prepNewsParameters() {
	// get category
	var category = $(".tabbed .active").attr("id");
	if (category == "all") {
		WSC.news.currentCategory = [1,2,3];
	}
	else {
		var cat_index = $.inArray(category, WSC.news.categoryMap);
		WSC.news.currentCategory.push(cat_index);
	}
		
	// get date
	if (exists($("aside .dates .selected"))) {
		WSC.news.currentDate = $("aside .dates .selected span").html();
	}
	else {
		WSC.news.currentDate = "";
	}

	// get tags
	$("aside .module .tags .selected").each(function() {
		WSC.news.currentTags.push($(this).find("a span").html());
	});

	// set page
	WSC.news.currentPage = 0;
	
	// copy all values to new
	WSC.news.newCategory = WSC.news.currentCategory;
	WSC.news.newDate = WSC.news.currentDate;
	WSC.news.newTags = WSC.news.currentTags;
	WSC.news.newPage = WSC.news.currentPage;
}

function handleNewsCategories() {
	$(".tabbed a").click(function(event) {

		// set new category
		var newCategory = $(this).parent().attr("id");
		if (newCategory == "all") {
			WSC.news.newCategory = [1,2,3];
		}
		else {
			WSC.news.newCategory = [];
			WSC.news.newCategory.push($.inArray(newCategory, WSC.news.categoryMap));
		}
		
		// switch active class
		$(".tabbed li").removeClass("active");
		$(this).parent().addClass("active");
		Cufon.refresh(".tabbed nav");		
		
		// update content
		getNews(false);
		
		event.preventDefault();
	});
}

function handleNewsDatesAndTags() {
	$("aside .module a").click(function(event) {
										
		if ($(this).parent().parent().hasClass("dates")) {
			var type = "dates";
		}
		else {
			var type = "tags";
		}
		
		if (type == "dates") {
			// update nav
			if ($(this).parent().hasClass("selected")) {
				$(this).parent().removeClass("selected");
			}
			else {
				$("aside .module .dates li").removeClass("selected");
				$(this).parent().addClass("selected");
			}		
			
			// update date
			WSC.news.newDate = $(this).find("span").html();
		}
		else if (type == "tags") {			
			// update nav
			if ($(this).parent().hasClass("selected")) {
				$(this).parent().removeClass("selected");
			}
			else {
				$(this).parent().addClass("selected");
			}		
			
			// add or subtract this tag from the list of current tags
			var tag = $(this).find("span").html();
			var index = $.inArray(tag, WSC.news.currentTags);
			if (index == -1) {
				WSC.news.newTags.push(tag);
			}
			else {
				WSC.news.newTags.splice(index, 1);
			}
		}
		
		getNews(false);
		
		event.preventDefault();
	});
}

function viewMoreNews() {
	$.post(EE_base_URI + 'news/ajax', {
			date : WSC.news.newDate,
			tags : WSC.news.newTags,
			categories : WSC.news.newCategory,
			limit : 10,
			page : WSC.news.newPage,
			canviewmore : ""
		}, function(data) {
			if (data == 1) {
				if (exists($(".more")) === false) {
					// create button
					var a = document.createElement("a");
					$(a).attr("href", "");
					$(a).addClass("more");
					$(a).html("View More");
				}
				
				$(a).click(function(event) {
					WSC.news.newPage++;
					getNews(true);
					event.preventDefault();
				});
			
				// append to end of .elements
				$(".elements").append(a);
				Cufon.refresh(".more");
			}
			else {
				$(".more").remove();
			}
		}
	);	
}

function getNews(append) {
	// String in the format of "Month Year", array of strings, array of numbers, int, int		
	if (append == false) {
		WSC.news.newPage = 0;
	}

	$.post(EE_base_URI + 'news/ajax', {
			date : WSC.news.newDate,
			tags : WSC.news.newTags,
			categories : WSC.news.newCategory,
			limit : 10,
			page : WSC.news.newPage
		}, function(data) {
			
			WSC.news.currentDate = WSC.news.newDate;
			WSC.news.currentTags = WSC.news.newTags;
			WSC.news.currentCategory = WSC.news.newCategory;
			WSC.news.currentPage = WSC.news.newPage;

			printNews(append, data);
			viewMoreNews();
		}
	);
}

function printNews(append, data) {
	var target = $(".results");
	if (data.length <= 5) {
		$(target).html("<li>No results found.</li>");
	}
	else {
		if (append) {
			$(target).append(innerShiv(data));
		}
		else {
			$(target).fadeOut("slow", function() {
				$(this).html(innerShiv(data));
				$(this).fadeIn("slow");
			});
		}
	}
}
/*_______END NEWS PAGE________*/

function printPage() {
	$(".sharing .print a").click(function(event) {
		window.print();
		event.preventDefault();
	});
}

function initViewMoreSearch() {
	
	WSC.search_page = 0;
	// EE_search_results_total_pages
	// index.php/search/view-more-ajax/{entries_search_id}{page_number_you_want}/
	
	if (EE_search_results_total_pages > 1) {
		var view_more = document.createElement("a");
		$(view_more).attr("href", "");
		$(view_more).html("View More");
		$(view_more).addClass("more");
		$(".body_liner .results").after(view_more);
		Cufon.replace('.body_liner .more');
		
		$(view_more).click(function(event) {
			WSC.search_page++;

			requestSearchPages();
			if (WSC.search_page >= EE_search_results_total_pages - 1) {
				$(".body_liner .more").remove();
			}
			event.preventDefault();
		});
	}
}

function requestSearchPages() {
	$.get(EE_base_URI + 'search/view-more-ajax/P' + WSC.search_page + '/' + EE_search_results_search_id, function(data) {
		$('.body_liner .results').append(data);
	});		
}

function initNewsArea() {
	$(".news nav a").click(function(event) {
									
		// update nav state
		$(".news nav li").removeClass("active");
		$(this).parent().addClass("active");
		Cufon.refresh(".tabbed nav");
		
		// update entries displayed
		var index = $(this).parent().index();
		$(".news .elements>ol>li").each(function() {
			if ($(this).css("display") == "block" || $(this).css("display") == "list-item") {
				$(this).fadeOut("slow", function() {
					$(".news .elements>ol>li:eq(" + index + ")").fadeIn("slow");
				});
			}
		});
		
		event.preventDefault();
	});
}

function videoPlaylist() {	
	$(".video_area nav a").click(function(event) {
		$(".video_area nav a").removeClass("selected");
		$(this).addClass("selected");
		Cufon.refresh(".body_liner article .video_area nav li a");
		var src = $(this).attr("href");		
/*		
		var poster = src.replace(/mp4/, "jpg");
		poster = EE_base_URI + "_videos/img/" + poster;
		
		// update poster image
		$("video").attr("poster", poster);
*/		
		var video = document.getElementsByTagName("video")[0];
		var sources = video.getElementsByTagName('source');
		
		if (Modernizr.video) {		
			if (Modernizr.video.h264) {
				// replace source (mp4)
				sources[0].src = src;
				video.src = src;
			}
			else if (Modernizr.video.ogg) {
				// replace source (ogv)
				src = src.replace(/mp4/, "ogv");
				sources[1].src = src;		
				video.src = src;
			}		
			
			video.load();
			video.play();
		}
		else {
			initFlashVideo(src, true);
		}
		
		event.preventDefault();
	});
}

function initFlashVideo(src, autoplay) {
	var s1 = new SWFObject(EE_base_URI + 'jw/player.swf','player','592','353','9');
	s1.addParam('allowfullscreen','true');
	s1.addParam('allowscriptaccess','always');
	s1.addParam('flashvars','file=' + src);
	s1.addVariable('autostart',autoplay);
	s1.write('flash');
}


WSC.slideshow = {	
	config: {
		duration: '15s',
		resume_after: '20s'
	},
	meta: {
		current: 0,
		total: 0
	},
	init: function() {
		this.nav();
		this.timer();
	},
	nav: function() {
		var self = this;
		
		var $slides = $(".audience_feature nav li a");
		self.meta.total = $slides.size();
						
		$slides.each(function(index) {						
			$(this).click(function(event) {
				$(".audience_feature").stopTime();
				
				if (self.meta.current != $(this).data("slide")) {
					$(".audience_feature").oneTime(self.config.resume_after, "temp", function() {
						self.timer();
					 });
					self.update(index);
				}
				
				event.preventDefault();
		   	});			
		})		
	},
	timer: function() {
		var self = this;
		$(".audience_feature").everyTime(self.config.duration, "slideshow", function() {			
			self.update("next");
		});
	},
	update: function(new_slide) {
		var self = this;
		
		if (new_slide == "next") {
			if (self.meta.current < (self.meta.total - 1)) {
				new_slide = self.meta.current + 1;
			}
			else {
				new_slide = 0;
			}
		}
		
		if (self.meta.current != new_slide) {		
			// Update nav 
			$(".audience_feature nav .active").removeClass("active");
			$(".audience_feature nav li:eq(" + new_slide + ")").addClass("active");
			Cufon.refresh(".audience_feature nav");		
			
			// Update slide		
			var $current_el = $(".audience_feature .feature>ol>li:eq(" + (self.meta.current) + ")");
			var $new_el = $(".audience_feature .feature>ol>li:eq(" + new_slide + ")");		
			
			$new_el.css("display", "block");		
					
			self.meta.current = new_slide;
			
			// fade in placeholder image
			$current_el.fadeOut("slow", function() {
				$current_el.removeClass("active");
				$new_el.addClass("active");
			});
		}
	}
};

function initAjaxSearch() {
		
	// gather links to index + directory, switch boxes on click
	$(".directory_and_index nav a").click(function(event) {
		$(".directory_and_index nav li").removeClass("active");
		$(this).parent().addClass("active");
		Cufon.refresh(".tabbed nav");
		var type = $(this).attr("href");
		type = type.replace(/#/, "");
		var anti_type = (type == "index") ? "directory" : "index";
		$(".directory_and_index ." + anti_type).fadeOut("slow", function() {
			$(".directory_and_index ." + type).fadeIn("slow");
		});
		event.preventDefault();
	});
	
	// do search to show initial results
	doAjaxSearch("", "index", "alphabetical");	
	doAjaxSearch("", "directory", "alphabetical");	
	
	// handle index box
	captureSearchInput("index");
	blurBox("index");
	

	// handle directory box	
	captureSearchInput("directory");
	blurBox("directory");

}

function addSearchLink(type) {
	var search_link = document.createElement("a");
	$(search_link).attr({
		"id" : type + "_search_link",
		"href" : ""
	});
	$(search_link).addClass("search_link");
	$(search_link).html("Search for <b>Board</b>");
	$(".results_box ." + type).append(search_link);
	$(search_link).click(function(event) {
		$("#" + type + "_form").submit();
		event.preventDefault();
	});
}

function toggleSearchLink(type) {
	$(".results_box ." + type + " .search_link").toggleClass("hide");
}

function blurBox(type) {
	$("#" + type + "_input").click(function() {
		if ($(this).val() == "Search") {
			$(this).val("");
		}													
	});
}

// search query [string], search type [string: "index" | "directory"]
function doAjaxSearch(q, type, special) {
	var total = (type == "index") ? 5 : 3;

	if (special == "alphabetical") {
		var url = EE_base_URI + 'search/ajax/' + type + '_list_alphabetical/' + total + '/';
		$.get(url, function(data) {
		  $('.news_and_directory .' + type + ' .results_list').html(data);
		});		
	}
	else if (q == "" && special === undefined) {
		$.get(EE_base_URI + 'search/ajax/' + type + '_list_alphabetical/' + total + '/', function(data) {
		  $('.news_and_directory .' + type + ' .results_list').html(data);
		});
		if ($(".results_box ." + type + " .search_link").hasClass("hide") == false) {
			toggleSearchLink(type);
		}
	}
	else {
		if (exists($(".results_box ." + type + " .search_link")) == false) {
			addSearchLink(type);
		}
		if ($(".results_box ." + type + " .search_link").hasClass("hide")) {
			toggleSearchLink(type);
		}
		updateSearchLinkTerm(q, type);
		q = sanitize(q);
		var url = EE_base_URI + 'search/ajax/' + type + '_search/' + q + '/' + total + '/'
		$.get(url, function(data) {
		  $('.news_and_directory .' + type + ' .results_list').html(data);
		});		
	}
}

function updateSearchLinkTerm(q, type) {
	$(".results_box ." + type + " .search_link b").html(q);
}

function captureSearchInput(type) {
	$("#" + type + "_form #" + type + "_input").keyup(function() {
		var q = $("#" + type + "_form #" + type + "_input").val();
		doAjaxSearch(q, type);
	});
}

function sanitize(q) {
	/* 
		TO DO
		
		- Avoid sending requests on EVERY key press
		- Avoid additional requests for unacceptable characters 
		
	*/
	
	// strip everything but A-Z, 0-9, and quotes
	q = q.replace(/([^a-z0-9\'\"]*)/i, '');
	// encode quotes
	q = escape(q);
	return q;
}

/* ---------------------------------------- */


/****** BEGIN TOUR MODULE ******************/

function tour() {
	enableMonthNav();
	handleTourDateSelections();
	updateCalendarByAttendees();
	submitTour();
}


function enableMonthNav() {
	var months = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];

	$("table .month a").click(function(event) {
		// get next / previous
		var direction = $(this).attr("data-direction");

		// update month name and year
		// get the current month, compare it to the month array, find index, move one spot in desired direction
		var current_month = $("table .month time").html();
		month = stripAlphaChars(current_month);
		month = month.toLowerCase();
		month = $.trim(month);
		var array_pos = $.inArray(month, months);
		
		// get the year
		year = stripNumChars(current_month);
		year = $.trim(year);
		
		if (direction == "prev") {
			if (array_pos == 0) {
				year--;
				array_pos = 11;
			}
			else {
				array_pos--;
			}
		}
		else if (direction == "next") {
			if (array_pos == 11) {
				year++;
				array_pos = 0;
			}
			else {
				array_pos++;
			}
		}
		
		// get next or previous month
		var date = year + '-' + (array_pos + 1) + '-01';
		
		$("table .month time").html(months[array_pos] + " " + year);	
		$("table .month time").attr("datetime", date);	
		
		// update calendar to display new month
		// call the new calendar URL with attendees and date inserted 
		var num_attendees = $("form .attending option:selected").val();
		updateCalendar(num_attendees, date);

		event.preventDefault();
	});
}

function handleTourDateSelections() {
	// remove the selected date (if it exists) any time the calendar is loaded
	$("table tbody .selected").removeClass("selected");
	
	// if the date in the hidden input form is visible, add the selected class
	var selected_date = $("input[name=date]").attr("value");
	var date_parent = $("table tbody time[datetime=" + selected_date + "]").parent();
	if ($(date_parent).filter("a").length > 0) {
		date_parent.parent().addClass("selected");
	}

	// handle date selections
	$("table tbody a").click(function(event) {
		/* Add behavior for unselecting a date */
									  
		// copy datetime to hidden input
		var time = $(this).find("time")
		var datetime = $(time).attr("datetime");
		$("input[name=date]").attr("value", datetime);		
		
		// make selected
		$("table tbody .selected").removeClass("selected");
		$(this).parents("td").addClass("selected");
		
		// update status
		// get human date
		var human_date = $(time).attr("data-human-date");
		$("#schedule_tour .date").removeClass("error");
		$("table tfoot td").html("You selected <time datetime=\"" + datetime + "\">" + human_date + "</time>.");

		// get available times, insert them
		var num_attendees = $("form .attending option:selected").val();
		insertAvailableTimes(num_attendees, datetime);							  
									  
		// block default link behavior
		event.preventDefault();
	});
}

function insertAvailableTimes(num_attendees, date) {
	// do Ajax request for new times
	var url = EE_base_URI + 'tour/ajax/generate_times/' + num_attendees + '/' + date + '/';
	
	$.get(url, function(data) {
		// insert results of Ajax request
		$(".tour .wizard .time .available_times").html(data);
	});		
}

function updateCalendarByAttendees() {
	// update calendar when number of attendees changes
	$("form .attending select").change(function(event) {
		// update calendar
		var num_attendees = $(this).find("option:selected").val();
		var date = $("#schedule_tour .date .month time").attr("datetime");
		
		// remove selected date
		$("#schedule_tour tbody .selected").removeClass("selected");
		$("input[name=date]").attr("value", "");
		$("table tfoot td").html("You have not selected a date yet.");
		
		updateCalendar(num_attendees, date);
		if (exists($("#schedule_tour tbody .selected"))) {
			date = $("#schedule_tour tbody .selected time").attr("datetime");
			insertAvailableTimes(num_attendees, date);
		}
	});
}


function submitTour() {
	// validate form
	$("#schedule_tour").submit(function(event) {
		var form_ready = true;								
										
		$("#schedule_tour .date input[data-req=true]").each(function() {
			if ($(this).val() == "") {
				$("#schedule_tour .date").addClass("error");
				form_ready = false;
			}
			else {
				$("#schedule_tour .date").removeClass("error");
			}
		});
		
		var selected_time = "";
		$("#schedule_tour .time input").each(function() {
			if ($(this).attr("checked")) {
				selected_time = $(this).val();
			}
		});
		
		if (
			selected_time == "" 
			&& exists($("#schedule_tour .time input"))
			&& exists($("#schedule_tour .time .error")) == false
			) 
		{
			$("#schedule_tour .time .header").after("<p class='error'>Please select a time for your tour.</p>");
			form_ready = false;
		}
		else if (selected_time != "") {
			$("#schedule_tour .time .error").remove();
		}
		
										
		// find any empty fields that are required
		$("#schedule_tour .about input[data-req=true], #schedule_tour .about select[data-req=true]").each(function() {
			
			var errors = [];
			var is_empty = false;
			
			if ($(this).is("input")) {
				var is_invalid_email = false;
				
				// check to see if current element is empty
				var is_empty = checkForEmpty($(this));
				
				if (is_empty) {
					errors = ["empty"];
				}
	
				// check to see if current element is of type email, if so, check to see if it is an invalid email
				if ($(this).hasClass("form_email")) {
					is_invalid_email = checkEmailValidity($(this));
				}
				
				if (is_invalid_email) {
					errors = ["invalid email"];
				}	
			}
			else if ($(this).is("select")) {
				if ($(this).find("option:selected").val() == "-----------------") {
					is_empty = true;
					errors = ["empty"];
				}
			}
			
			// if the field is empty or there is an invalid email, add a class of error. else, remove any existing errors
			if (errors.length > 0) {
				$(this).parent().addClass("error");
				if (exists($(this).prev().find("span")) == false) {
					$(this).prev().prepend("<span class=\"preamble\">Please provide your </span>");
				}
				form_ready = false;
			}
			else {
				$(this).parent().removeClass("error");
				var label = $(this).prev().find("span").remove();
			}
		});
		
		// scroll to highest error
		if (exists($("#schedule_tour .error"))) {
			var scroll_to = $("#schedule_tour .error:first").offset();
			$("body,html").animate({
				scrollTop: scroll_to.top
			}, "slow");
		}
		
		// if errrors, stop form from submitting
		if (form_ready == false) {
			event.preventDefault();
		}
	});
}

function updateCalendar(num_attendees, date) {
	$.getJSON(EE_base_URI + 'tour/ajax/generate_calendar/' + num_attendees + '/' + date + '/', on_json_dates_response);	
}
function on_json_dates_response(data) {
	updateTableRows(data.weeks_in_month);
	emptyCells(data);
}

function updateTableRows(weeks_in_month) {	
	var rows = $("#schedule_tour table tbody tr").size();
	var diff =  weeks_in_month - rows;
	
	if (diff < 0) {
		for (var i=0; i<Math.abs(diff); i++) {
			$("#schedule_tour tbody tr:last-child").remove();
		}	
	}
	else if (diff > 0) {
		for (var i=0; i<diff; i++) {
			var tr = document.createElement("tr");
			$("#schedule_tour tbody").append(tr);
			for (var j=0; j<7; j++) {
				$(tr).append("<td><div><span>&nbsp;</span></div></td>");
			}
		}
	}
}

function emptyCells(data) {
	var td = $("#schedule_tour tbody td");
	var h = $(td).find(":first-child").height();
	var w = $(td).find(":first-child").width();
	var div = $("#schedule_tour tbody div");
	
	$(div).css({
		height : h,
		width : w
	});

	$(div).empty();
	fillCells(data);
}

function fillCells(data) {
	var day = 0;
	$("#schedule_tour tbody div").each(function(i) {
		if (data.dates[day] && i >= data.start_day) {
				// create <time>
				var time = document.createElement("time");
				// insert attributes on <time>
				$(time).attr("datetime", data.dates[day][0]);
				$(time).attr("data-human-date", data.dates[day][1]);
				$(time).html(day + 1);
	
				if (data.dates[day][2]) {	
					var a = document.createElement("a");
					$(a).attr("href", "");
					$(a).append(time);
					$(a).css("display", "none");
					$(this).html(a);
				}
				else {
					$(time).css("display", "none");
					$(this).html(time);
				}
				
				day++;
		}
		else {
			$(this).html("<span>&nbsp;</span>");
		}
	});
	
	$("#schedule_tour tbody div").find(":first-child").fadeIn("slow");
	
	handleTourDateSelections();
}

/*_____END TOUR MODULE________________*/



function checkForEmpty(el) {
	if ($(el).val() == "") {
		return true;
	}	
}
function checkEmailValidity(el) {
	var myregex = /@.*\./;
	var mymatch = myregex.exec($(el).val());

	if (mymatch == null) {
		return true;
	} 
}


function stripAlphaChars(pstrSource) { 
	var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[0-9]/g, ''); 

    return m_strOut; 
}

function stripNumChars(pstrSource) { 
	var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[a-z]/gi, ''); 

    return m_strOut; 
}

function exists(el) {
	if (el.length > 0) {
		return true;
	}
	else {
		return false;
	}
}
