$(document).ready(function() {

	// Set up qTip
	$(".lists_features li").qtip({
		content: $(this).attr("alt"),
		style: { 
			width: 322,
			padding: 0,
			background: 'transparent',
			color: '#494A56',
			textAlign: 'left',
			border: { width: 0 }
		},
		position: {
			corner: {
				target: 'topRight',
				tooltip: 'topLeft'
			},
			adjust: { x: -5, y: -8}
		}
	});
	
	//Module opt-in / opt-out
	$("#emailOptinout").focus(function(){
		$(this).val("");
	});
	
	$("#emailOptinout").blur(function(){
		var str = $(this).val();
		if ( jQuery.trim( str ) == "" ){
			$(this).val($(this).attr("ovalue"));
		}
	});
	
});


/*error messages*/
var ERROR_EMAIL_INVALID = "Invalid eMail!";

/*color for input filed to indicate wrong/correct values*/
var ERROR_INPUT_BG_COLOR = "#FF9D7F";
var ERROR_INPUT_BR_COLOR = "#FF0505";
var OK_INPUT_BG_COLOR = "#FFFFFF";
var OK_INPUT_BR_COLOR = "#dfdfdf";

/*change input filed border and background color*/
function input_changecolor(field, brd, bck) {
	field.style.backgroundColor=bck;
	field.style.borderColor=brd;
}

/*email validation*/
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

/*
download plugin validation
*/
function plgn_checkform() {
	var strErr='';
	with (document.plugin_download_form) {
		if (email.value!='') {
			if (!isValidEmailAddress(email.value)) {
				strErr+=ERROR_EMAIL_INVALID+'\n';
				input_changecolor(document.getElementById('email'), ERROR_INPUT_BR_COLOR, ERROR_INPUT_BG_COLOR);
			} else input_changecolor(document.getElementById('email'), OK_INPUT_BR_COLOR, OK_INPUT_BG_COLOR);
		}
		
		if (strErr!='') alert(strErr);
		else submit();
	}
}



/*
OPTIN
*/
function optin_now() {
	var emailAdd=document.frmOptInOut.emailOptinout.value;
	var errorMonitor=document.getElementById('error_box');
	errorMonitor.style.display='none';
	if (isValidEmailAddress(emailAdd)) {
		$.ajax({
			url: OPTINDOM+'pages/optin.php',
			data: "ordermail_buyer="+emailAdd+'&lang='+OPTINLANG,
			type: "POST",
			cache: false,
			async: true, 
			success: function(myCode){
				$("#opt_box_context").html(myCode);
			}
		});
	} else {
		if (errorMonitor) {
			errorMonitor.innerHTML=ERROR_EMAIL_INVALID;
			errorMonitor.style.display='block';
		}
	}
	
}


function lang_view() {
	document.getElementById('lang_menu_box').style.height='auto';
	document.getElementById('lang_menu_box').style.overflow='visible';
	document.getElementById('lang_flag_active').style.height='14px';	
}
function lang_off() {
	//document.getElementById('languages_list').style.display='none';
	document.getElementById('lang_menu_box').style.height='11px';
	document.getElementById('lang_menu_box').style.overflow='hidden';
	document.getElementById('lang_flag_active').style.height='16px';
}
function lang_change(myurl) {
	document.location.href=myurl;
}
