var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
$(document).ready(function(){
	popupBtn();
	validate();

});


function popupBtn(){
	$('a.popup-btn').each(function(){
		var _p1;
		this.onclick = function(){
			var _t, _l;
			if (Nav4){
				_l = window.screenX + ((window.outerWidth - this.href.split(",")[2]) / 2);
				_t = window.screenY + ((window.outerHeight - this.href.split(",")[3]) / 2);
			}
			else{
				_l = (screen.width - this.href.split(",")[2]) / 2;
				_t = (screen.height - this.href.split(",")[3]) / 2;
			}
			_p1 = window.open(this.href.split(',')[0], this.href.split(',')[1], 'width='+this.href.split(",")[2]+', height='+this.href.split(',')[3]+'left='+_l+', top='+_t+', toolbar=0, location=0, directories=0, menubar=0, scrollbars=0, resizable=0, status=0, fullscreen=0');
			_p1.focus();
			return false;
		}
	});
}

function popUpIE(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=1,width=926,height=670,left = 177,top = 177');");
}

//validate form
function validate(){
	if ($("form").length){
		$("form").each(function(){
			var _this = $(this);
			_this.find("input[type='submit']").click(function(){
				if (checkValues(_this)) {return false;}
			});
		})
	}
}

function checkValues(_this){
	var _emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var _f = false;
	var _t = 'Please complete the following fields:';
	$('tr.required', _this).each(function(){
		var _field = $(this).find('select');
		if(_field.length != 0){
			if(_field.attr('value') == '' || _field.attr('value') == 'default'){
				_field = $(this).find('input');
				if(_field.attr('value') == ''){
					_f = true;
					if($(this).hasClass('interest')) _t += '\n-'+'Interest';
					else _t += '\n-'+$(this).find('.info-field').text();
				}
			}
		}
		else{
			_field = $(this).find('input');
			if(_field.attr('value') == ''){
				_f = true;
				_t += '\n-'+$(this).find('.info-field').text();
			} else if(_field.attr('class') == 'email-validate') {
				if (!_emailReg.test(_field.val())) {
					console.log(_field.val())
					_f= true;
					_t += '\n- Email field incorect';
				};
			}
		}
	});
	if(_f){
		alert(_t);
	}
	return _f;
}