jQuery(document).ready(function($) {
	$('input').each(function() {
		if ($(this).attr('title') != '' && $(this).val() == '') $(this).val($(this).attr('title'));
	}).focus(function() {
		if ($(this).val() == $(this).attr('title')) $(this).val('');
	}).blur(function() {
		if ($(this).attr('title') != '' && $(this).val() == '') $(this).val($(this).attr('title'));
	});
	$('body').pngFix();
	$('#menu li:has(div.submen)').hover(function() {
		$('.submen', this).stop(true, true).fadeIn(200);
		$('a:first', this).css('backgroundPosition', '0 -30px');
	}, function() {
		$('.submen', this).stop(true, true).fadeOut(200);
		$('a:first', this).css('backgroundPosition', '0 0');
	})
	$("a[href*='/client/order/?new']").click(function() {
		loc = $(this).attr('href');
		if (orderInProgress) {
			jConfirm('You are currently editing an order, do you wish to start a new one?<br />You will lose any data you haven\'t saved.', 'Start New Order?', function(t) {
				if (t) {
					saved = true;
					window.location = loc;
				}
			});
		} else {
			saved = true;
			window.location = loc;
		}
		return false;
	});
});
function checknum(e) {
	var filter = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/
	return filter.test(e);
}
function checkemail(e){
	var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	return emailfilter.test(e);
}
function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function cookie(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
		}
		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]);
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
function getCookie(name) {
    var theCookies = document.cookie.split(/[; ]+/);
    for (var i = 0 ; i < theCookies.length; i++) {
        var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
        if (aName == name) {
            return theCookies[i];
        }
    }
}



