
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function set_currency() {
}

$(function() {

	//$(".png").pngfix();
	//if ($.browser.version <= 6 && $.browser.msie) {

//	} else {
		if ($('#offers').length > 0) {
			$('#offers').cycle({
				timeout: 8000,
				random: 1
			});
		}
//	}
	
	//$('.highlight1').css({backgroundPosition: '-240 0'});
	$('.highlight1').mouseover(function() {
		$(this).stop().animate(
			//{paddingLeft:"7px"},
			{backgroundColor:'#c4161c', color:'#ffffff !important'},
			{duration:300})
		})
	.mouseout(function() {
		$(this).stop().animate(
			//{paddingLeft:"0"},
			{backgroundColor:'#bac7ce'},
			{duration:300})
		});

	$('.highlight2').mouseover(function() {
		$(this).stop().animate(
			//{paddingLeft:"7px"},
			{backgroundColor:'#c4161c'},
			{duration:300})
		})
	.mouseout(function() {
		$(this).stop().animate(
			//{paddingLeft:"0"},
			{backgroundColor:'#b1c2d9'},
			{duration:300})
		});

	if ($("#tabs").length > 0) {
		$("#tabs").tabs({
			fx: {
				height: 'toggle',
				opacity: 'toggle'
			}
		})//.tabs('rotate', 8000);
	}

	$('#menuMain > li > ul').hide();
	$('#menuMain > li').mouseover(function() {
		$(this).children('ul').show();
	});
	$('#menuMain > li').mouseout(function() {
		$(this).children('ul').hide();
	});

	if ($.browser.msie) {
		} else {
		if ($(".offer").length > 0) {
			$(".offer img").css('opacity', 0.0).animate({opacity: 0.0}, 1000).animate({opacity: 1.0}, 500);
		}
	}

	//set_currency();

	$("#currency p").click(function() {
		createCookie('currency2', $(this).attr('id'), 365);
		$("#currency").html('<h2>Loading&hellip;</h2>');
		document.location = document.URL;
	});

	$("#currency p").mouseover(function() {
		$(this).stop().animate({paddingLeft: '5px', opacity: 1.0}, 100);
	});

	$("#currency p").mouseout(function() {
		$(this).stop().animate({paddingLeft: 0, opacity: 0.7}, 100);
	});
	

	

	// CLASSES
	// add another class dropdown - eu only, max 3
	$('.addAnotherClass').click(function(event) {
		classesSelectCount++;
		classesSelectCountID++;
		$.ajax({
			url: 'includes/register-classselect.php',
			dataType: 'html',
			data: {
				id: classesSelectCountID
			},
			success: function(data) {
				$('.addAnotherClass').before(data).prev().hide().show('normal');
				//showHideAddClass();
				// remove click class then add it back to stop duplication
				$('.removeTMClass').unbind('click').bind('click', function() {
					$(this).parent().hide('normal', function() {
							$(this).remove();
							set_trademark_classes();
					});
					classesSelectCount--;
					//showHideAddClass();
					return false;
				});
			},
			error: function(xhr,err,e) {
				$('.addAnotherClass').before('<div>ERROR').prev().hide().show('normal');
			}
		});
		return false;
	});

	$('.application_class_search').live('click', function() {
		$('#formHelp').load('includes/register-class-search.php');
		return false;
	});

	// show extra class select boxes
	$('#searchTMClasses').live('submit', function() {
		var inputs = [];
		$(':input', this).each(function() {
			inputs.push(this.name + '=' + escape(this.value));
		});
		$.ajax({
			url: 'includes/register-class-search.php',
			data: inputs.join('&'),
			dataType: 'html',
			success: function(data) {
				$('#formHelp').html(data).fadeIn('fast');
				$('.tmClassDetails').hide();
				var showDetails = 0;
				$('.tmClassTitle').live('click', function(event) {
					if (showDetails == 0) {
						$('.tmClassTitle').not(this).hide('normal');
						$('.tmClassDetails').hide('normal');
						$(this).next('.tmClassDetails').show('fast').after('<a href="#" class="tmClassBack">BACK</a>').hide().fadeIn('normal');
						$('.tmClassBack').live('click', function(event) {
							$('.tmClassTitle').show('normal');
							$('.tmClassDetails').hide('normal');
							$('.tmClassBack').remove();
							showDetails = 0
							return false;
						});

						showDetails = 1;
						return false;
					} else {
						return false;
					}
				});
				return false;
			},
			error: function(xhr,err,e) {
				$('#formHelp').html('Error loading data: ' + err).fadeIn('fast');
			}
		});
		return false;
	});

});


function sort_number(a,b) {
	return a - b;
}

function get_step_help(stage) {
	$('.help').hide();
	$('.help:eq('+stage+')').show();
}

function isDecimal(sNum)
{
  return !isNaN(sNum!="" && sNum);
}

function validate_email(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(address) == false) {
		return false;
	} else {
		return true;
	}
}
