// $Id: core.js 8583 2010-01-12 16:03:35Z lexa $

function fn_set_type (vr, type) 
{
	// http://kevin.vanzonneveld.net
	// +   original by: Waldo Malqui Silva
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +    revised by: Brett Zamir (http://brett-zamir.me)    // %        note 1: Credits to Crockford also
	// %        note 2: only works on global variables, and "vr" must be passed in as a string
	// *     example 1: foo = '5bar';
	// *     example 1: settype(foo, 'integer');
	// *     results 1: foo == 5    // *     returns 1: true
	// *     example 2: foo = true;
	// *     example 2: settype(foo, 'string');
	// *     results 2: foo == '1'
	// *     returns 2: true    
	var is_array = function (arr) {
		return typeof arr === 'object' && typeof arr.length === 'number' &&
			!(arr.propertyIsEnumerable('length')) &&
			typeof arr.splice === 'function';
	};    var v, mtch, i, obj;
	v = this[vr] ? this[vr] : vr;
	
	try {
		switch (type) {            case 'boolean':
			if (is_array(v) && v.length === 0) {return false;}
			else if (v === '0') {return false;}
			else if (typeof v === 'object' && !is_array(v)) {
			var lgth = false;                    for (i in v) {
				lgth = true;
			}
			return lgth;
			}                else {return !!v;}
			break;
		case 'integer':
			if (typeof v === 'number') {return parseInt(v, 10);}
			else if (typeof v === 'string') {                    mtch = v.match(/^([+\-]?)(\d+)/);
			if (!mtch) {return 0;}
			else {return parseInt(v, 10);}
			}
			else if (v === true) {return 1;}                else if (v === false || v === null) {return 0;}
			else if (is_array(v) && v.length === 0) {return 0;}
			else if (typeof v === 'object') {return 1;}
	
			break;            
		case 'float':
			if (typeof v === 'string') {
			mtch = v.match(/^([+\-]?)(\d+(\.\d+)?|\.\d+)([eE][+\-]?\d+)?/);
			if (!mtch) {return 0;}
			else {return parseFloat(v, 10);}                }
			else if (v === true) {return 1;}
			else if (v === false || v === null) {return 0;}
			else if (is_array(v) && v.length === 0) {return 0;}
			else if (typeof v === 'object') {return 1;}                break;
		case 'string':
			if (v === null || v === false) {return '';}
			else if (is_array(v)) {return 'Array';}
			else if (typeof v === 'object') {return 'Object';}                else if (v === true) {return '1';}
			else { return '';} // numbers (and functions?)
			break;
		case 'array':
			if (v === null) {return [];}                else if (typeof v !== 'object') {return [v];}
			break;
		case 'object':
			if (v === null) {return {};}
			else if (is_array(v)) {                    for (i = 0, obj={}; i < v.length; i++) {
				obj[i] = v;
			}
			return obj;
			}                else if (typeof v !== 'object') {return {scalar:v};}
			break;
		case 'null':
			return false;
			break;        }
	} catch (e) {
		return false;
	}
}

$(document).ready(function() {
	$('#opener_av_form').click();

	$("#age #age_d").keyup(function () {
		if ($(this).val().length >=2) {
			$("#age #age_m").focus();
		}
	});
	$("#age #age_m").keyup(function () {
		if ($(this).val().length >=2) {
			$("#age #age_y").focus();
		}
	});

	$("#av_form .popupbox-closer").click(function () {
		self.location = 'http://www.malts.com';
	});

	$('body').attr('style','overflow: hidden');

	$('#av_form_submit').click(function () {

		var date_DD = fn_set_type($("#age #age_d").val(), 'integer');
		var date_MM = fn_set_type($("#age #age_m").val(), 'integer');
		var date_YY = fn_set_type($("#age #age_y").val(), 'integer');

		if (date_DD > 31 || date_MM > 12 || date_YY < 1900 || date_YY > 2008) {
			$("#gateway_error_message").show()
			return false;
		}
		return true;
	});

});

$(function(){
	$(".up-count").click(function(){
		c = $(this).prev().val();
		c++;
		$(this).prev().val(c);
	});
	$(".down-count").click(function(){
		c = $(this).prev().prev().val();
		if(c >1){
			c--;
			$(this).prev().prev().val(c);
		}
	});
	
});
