// validate.js
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

var validateX  = (isInternetExplorer?"0px":"0px");

// Handle all the FSCommand messages in a Flash movie.
function r_DoFSCommand(command, args) {
	var rObj = isInternetExplorer ? document.all.r : document.r;

	eval( command ).apply( null , args.split(",") );
	//
	// Place your code here.
	//
}

function closeValidate ()
{
/*	YAHOO.util.Dom.setStyle('validate','position','relative');
	YAHOO.util.Dom.setStyle('validate','left','2000px');*/
	YAHOO.util.Dom.setStyle('validate','display','none');
	YAHOO.util.Dom.setStyle('validate','visibility','hidden');

	//remove <iframe>
	var container = document.getElementById('validate');
	if (container)
		container.removeChild(container.childNodes[0]);
}

function openValidate ( bURL )
{
/*	YAHOO.util.Dom.setStyle('validate','position','absolute');*/
/*	YAHOO.util.Dom.setStyle('validate','left',validateX);*/
	YAHOO.util.Dom.setStyle('validate','display','block');
	YAHOO.util.Dom.setStyle('validate','visibility','visible');

	if (!document.getElementById('validate').hasChildNodes()) {
		var iframe = document.createElement('iframe');
		if (iframe) {
			iframe.setAttribute('id','secureValidate');
			iframe.setAttribute('src',bURL);
			iframe.setAttribute('width',490);
			iframe.setAttribute('height',60);
			iframe.setAttribute('scrolling','no');
			iframe.setAttribute('frameBorder','0');
			iframe.setAttribute('allowtransparency','true');
			iframe.setAttribute('style','z-index: 10000; display: block; border: 0 !important;');

			document.getElementById('validate').appendChild(iframe);
		}
	}
}
function openValidateTeaser ( bURL )
{
	validateX = "250px";
	openValidate(bURL);
}






/******** optin.js *********************/
YAHOO.util.Event.addListener("optin_form","submit",function(e) {																																																															
	document.getElementById('error').style.visibility = "hidden";
	var form = document.getElementById('optin_form');
	
	form.FNAME.style.border="solid 1px #FFF";
	form.LNAME.style.border="solid 1px #FFF";
	form.email.style.border="solid 1px #FFF";
	form.emailConfirm.style.border="solid 1px #FFF";						
			
	var error = 0;
	
	if (form.FNAME.value == ""){		
		form.FNAME.style.border="solid 1px red";
		error = 1;
	}
	if (form.LNAME.value == ""){		
		form.LNAME.style.border="solid 1px red";
		error = 1;
	}
	if (!(emailValidate(form.email.value))){
		form.email.style.border="solid 1px red";
		error = 1;	
	}
	if ((form.email.value != form.emailConfirm.value) || (form.emailConfirm.value == "")){
		form.emailConfirm.style.border="solid 1px red";
		error = 1;
	}
	
	if (error){
		document.getElementById('error').style.visibility = "visible";
		YAHOO.util.Event.preventDefault(e);
	}
	else{
		document.getElementById('thanks').style.display = "block";
		document.getElementById('frm_info').style.display = "none";
		omniture.SendBeacon("optin_teaser_form")
		
		// Double click send
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		document.getElementById('dbclick_iframe').src = 'http://fls.doubleclick.net/activityi;src=189445;type=2008h855;cat=2008h491;ord=1;num='+ a + '?';
	}
});

function emailValidate(email){
    var emailRE = /^[a-zA-Z0-9_\+-]+(\.[a-zA-Z0-9_\+-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.([a-zA-Z]{2,4})$/;
    if (email.match(emailRE)){
        return true;
    }
    else {
        return false;
    }
}