﻿$(document).ready(function() {
	$('#Logo').click(function() {
		document.location = 'Default.aspx';
	});
});
function ClientProxy(methodName, paramArray, successFunction, errorFunction) {
	var pagePath = window.location.pathname;
	var paramList = '';

	if (paramArray.length > 1) {
		for (var i = 0; i < paramArray.length; i += 2) {
			if (paramList.length > 0) paramList += ',';
			paramList += '"' + paramArray[i] + '"' + ':' + '"' + convertQuotes(paramArray[i + 1].toString()) + '"';
		}
	}
	paramList = '{' + paramList + '}';
	var length = pagePath.length;
	if (pagePath.substring(length - 1, length) == "/") {
		pagePath += "Default.aspx";
	}
	else if (pagePath.substring(length - 5, length) != ".aspx") {
		pagePath += "/Default.aspx";
	}

	$.ajax({
		type: "POST",
		url: pagePath + "/" + methodName,
		contentType: "application/json; charset=utf-8",
		data: paramList,
		dataType: "json",
		success: function(msg) {
			successFunction(msg);
		},
		error: function(xhr, status, error) {
			errorFunction(xhr, status, error);
		}

	});
	return false;
}

function mycarousel_initCallback(carousel) {
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

function checkEmail(email) {
	var arr = email.split(",");
	$.each(arr, function(idx, val) {
		var str = trim(val);
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (!filter.test(str)) {
			return false;
		}
	});

}
function isValidEmail(email) {
	var expr = /^[A-Za-z0-9]([A-Za-z0-9_-]|(\.[A-Za-z0-9]))+@[A-Za-z0-9](([A-Za-z0-9]|(-[A-Za-z0-9]))+)\.([A-Za-z]{2,6})(\.([A-Za-z]{2}))?$/;
	if (email.match(expr)) { return true; }
	else { return false; }
}
function trim(str) {
	var str = str.replace(/^\s\s*/, ''),
			ws = /\s/,
			i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}
function isValidURL(url) {
	if (url.indexOf("localhost") >= 0) {
		return true;
	}
	var urlRegxp = new RegExp();
	urlRegxp.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
	if (!urlRegxp.test(url)) {
		return false;
	}
	return true;
} 
(function($) {
	$.fn.showModalDialog = function(type, options) {
		settings = jQuery.extend({
			title: "",
			message: "",
			timeout: 0,
			callback: null,
			cssClass: "dialogIcons process",
			width: 340,
			height: 300,
			cssClass: ""
		}, options);

		var $this = $(this);
		$this.dialog({ bgiframe: true, modal: true, resizable: false, autoOpen: false, width: settings.width, height: settings.height, title: settings.title });
		$this.dialog('open');

		//Set HTML template of dialog      
		type = type.toLowerCase();
		var template = $("#htmDialog_" + type).html();
		$this.html(template);
		var dialogIcon = $this.find(".dialogIcons");
		dialogIcon.attr("class", dialogIcon.attr("class") + " " + settings.cssClass);
		$this.find("#msg").html(settings.message);

		if (settings.timeout > 0) {
			setTimeout("CloseDialog('" + $this.attr("id") + "')", settings.timeout);
		}
		else {
			$this.find(".smallButtons").click(function(evt) {
				if (settings.callback != null) {
					if (!settings.callback($(this), evt)) {
						CloseDialog($this.attr("id"));
					}
				}
				else {
					CloseDialog($this.attr("id"));
				}
				return;
			});
		}



	};
})(jQuery);

(function($) {
	$.fn.closeModalDialog = function() {
		var $this = this;
		$this.dialog("close");
		$this.dialog("destroy");
	};
})(jQuery);

(function($) {
	$.fn.switchCss = function(oldCss, newCss) {
		$(this).removeClass(oldCss).addClass(newCss);
	};
})(jQuery);

function convertQuotes(doubleQuoteString) {
	return doubleQuoteString.replace(/"/g, "'");
}
function CloseDialog(id) {
	$("#" + id).dialog('close');
	$("#" + id).dialog('destroy');
}
function OpenPopupWin(url) {
	popupWindow = window.open(
				url, '_blank', 'location=0,status=1,scrollbars=1,resizable=1, width=1000, height=600')
}
function imgpreload(a, b) { if (b instanceof Function) { b = { all: b} } if (typeof a == "string") { a = [a] } var c = []; var t = a.length; var i = 0; for (i; i < t; i++) { var d = new Image(); d.onload = function() { c.push(this); if (b.each instanceof Function) { b.each.call(this) } if (c.length >= t && b.all instanceof Function) { b.all.call(c) } }; d.src = a[i] } } if (typeof jQuery != "undefined") { (function($) { $.imgpreload = imgpreload; $.fn.imgpreload = function(b) { b = $.extend({}, $.fn.imgpreload.defaults, (b instanceof Function) ? { all: b} : b); this.each(function() { var a = this; imgpreload($(this).attr('src'), function() { if (b.each instanceof Function) { b.each.call(a) } }) }); var c = []; this.each(function() { c.push($(this).attr('src')) }); var d = this; imgpreload(c, function() { if (b.all instanceof Function) { b.all.call(d) } }); return this }; $.fn.imgpreload.defaults = { each: null, all: null} })(jQuery) }
