﻿var _glossaryOpen = false;
var _registrationFormOpen = false;

function showGlossaryDefinition(id, evt)
{
    var x = mouseX(evt);
    var y = mouseY(evt);
    
    if((x+260) > getPageSizeWithScroll()[0])
    {
        x = x-260;
    }
    
    if($(id).style.display == "none" && _glossaryOpen == false)
    {
        $(id).style.left = x + 'px';
        $(id).style.top = y + 'px';
            
        if(Prototype.Browser.IE)
        {
            $(id).style.display = "";
        }
        else
        {
            $(id).appear({ duration: 0.5 });
        }
        
        window.setTimeout("hideGlossaryDefinition('"+id+"');", 3000);
        
        _glossaryOpen = true;
    }
}

function hideGlossaryDefinition(id)
{
    if(Prototype.Browser.IE)
    {
        $(id).style.display = "none";
        _glossaryOpen = false;
    }
    else
    {
        $(id).fade({ duration: 0.5 });
        _glossaryOpen = false;
    }
}

function showOverlay(id)
{
    $(id).appear({ duration: 0.5, to: .95 });
}

function hideOverlay(id)
{
    $(id).fade({ duration: 0.5 });
}

function showVeraTagAnimation()
{
    var pageSize = getPageSizeWithScroll();
    var pageHeight = getPageHeight();
    var scrollTop = getScrollTopPosition();
    var centeredTop = 0;
    var flashvars = {};
    var params = {quality: "high", play: "true", loop: "true", wmode: "opaque", devicefont: "false", name: "Monogram_eTag", menu: "true", allowFullScreen: "false", allowScriptAccess: "sameDomain", movie: "Monogram_eTag"};
    var attributes = {id: "Monogram_eTag", name: "Monogram_eTag", align: "center"};
    var flashCode = "";
    
    centeredTop = ((pageHeight - 480)/2)+scrollTop;
    
    $("overlay").style.width = pageSize[0] + 'px';
    $("overlay").style.height = pageSize[1]-170 + 'px';
    showOverlay("overlay");
    
    if((centeredTop-100)< 175)
    {
        $("flashcontainer").style.top = '50px';
    }
    else
    {
        $("flashcontainer").style.top = centeredTop-175 + 'px';
    }
    
    $("flashcontainer").innerHTML = "<div id='closeflash'><a href='javascript: closeVeraTagAnimation();'>Close</a></div>";
    $("flashcontainer").innerHTML += "<div id='flashvideo'></div>";
    
    flashCode += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="480" id="Monogram_eTag" align="middle"> ';
	flashCode += '<param name="allowScriptAccess" value="sameDomain" /> ';
	flashCode += '<param name="allowFullScreen" value="false" /> ';
	flashCode += '<param name="movie" value="/assets/flash/module1_section3.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="/assets/flash/module1_section3.swf" quality="high" bgcolor="#ffffff" width="600" height="480" name="Monogram_eTag" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> ';
	flashCode += '</object> ';
	
	$("flashvideo").innerHTML += flashCode;
    
    //swfobject.embedSWF("http://sciencemedia.com/Monogram_ASCO_209/draftAnimation/Monogram_eTag.swf", "flashvideo", "600", "480", "9.0.0","/assets/flash/expressInstall.swf", flashvars, params, attributes);
}

function closeVeraTagAnimation()
{
    $("flashcontainer").innerHTML = "";
    hideOverlay("overlay");
}

function search_onfocus(searchbox)
{
    if(searchbox.value == "Search")
    {
        searchbox.value = "";
    }
}

function search_onblur(searchbox)
{
    if(searchbox.value == "")
    {
        searchbox.value = "Search";
    }
}

function mouseX(evt) 
{
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
       return evt.clientX + (document.documentElement.scrollLeft ?
       document.documentElement.scrollLeft :
       document.body.scrollLeft);
    else return null;
}
function mouseY(evt) 
{
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
       return evt.clientY + (document.documentElement.scrollTop ?
       document.documentElement.scrollTop :
       document.body.scrollTop);
    else return null;
}

function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);

	return arrayPageSizeWithScroll;
}

function getPageHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getScrollTopPosition()
{
    var scrollTop = document.body.scrollTop;

    if (scrollTop == 0)
    {
        if (window.pageYOffset)
        {
            scrollTop = window.pageYOffset;
        }
        else
        {
            scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
    }
    
    return scrollTop;
}

function showRegistrationForm(evt)
{
    var x = mouseX(evt);
    var y = mouseY(evt);
    var id = "registrationForm";
    
    if((x+500) > getPageSizeWithScroll()[0])
    {
        x = x-500;
    }
    
    if($(id).style.display == "none" && _glossaryOpen == false)
    {
        $(id).style.left = x + 'px';
        $(id).style.top = y + 'px';
            
        if(Prototype.Browser.IE)
        {
            $(id).style.display = "";
        }
        else
        {
            $(id).appear({ duration: 0.5 });
        }
        
        _registrationFormOpen = true;
    }
}

function hideRegistrationForm()
{
    var id = "registrationForm";
    
    if(Prototype.Browser.IE)
    {
        $(id).style.display = "none";
        _registrationFormOpen = false;
    }
    else
    {
        $(id).fade({ duration: 0.5 });
        _registrationFormOpen = false;
    }
}

function submitRegistrationForm()
{
	var firstName = $("txtFirstName").value;
	var lastName = $("txtLastName").value;
	var title = $("txtTitle").value;
	var specialty = $("txtSpecialty").value;
	var institution = $("txtInstitution").value;
	var emailAddress = $("txtEmailAddress").value;
	var zipCode = $("txtZipCode").value;
	var phoneNumber = $("txtPhoneNumber").value;
	var message = "The following field contain missing/invalid information:\n"
	var isValid = true;
	
	if(firstName.length == 0)
	{
	    isValid = false;
		message += "\n   -First Name";
	}
	
	if(lastName.length == 0)
	{
	    isValid = false;
		message += "\n   -Last Name";
	}
	
	if(title.length == 0)
	{
	    isValid = false;
		message += "\n   -Title";
	}
	
	if(specialty.length == 0)
	{
	    isValid = false;
		message += "\n   -Specialty";
	}
	
	if(institution.length == 0)
	{
	    isValid = false;
		message += "\n   -Institution";
	}
	
	if(emailAddress.length > 0)
	{
		if(!_validateEmailAddress(emailAddress))
		{
			isValid = false;
			message += "\n   -Email Address";
		}
	}
	else
	{
		isValid = false;
		message += "\n   -Email Address";
	}
	
	if(zipCode.length == 0)
	{
	    isValid = false;
		message += "\n   -Zip Code";
	}
	
	if(phoneNumber.length == 0)
	{
	    isValid = false;
		message += "\n   -Phone Number";
	}
	
	if(isValid)
	{
		new Ajax.Request('/registration/processRegistration.aspx', 
			{
				method: 'post', 
				postBody: 'firstName='+firstName+'&lastName='+lastName+'&title='+title+'&specialty='+specialty+'&institution='+institution+'&emailAddress='+emailAddress+'&zipCode='+zipCode+'&phoneNumber='+phoneNumber,
				onComplete: function(response)
				{
					$("tblRegister").style.display = "none";
					$("tblRegisterComplete").style.display = "";
				}
			}
		);
		
		//$("tblRegister").style.display = "none";
	    //$("tblRegisterComplete").style.display = "";
	}
	else
	{
		alert(message);
	}
	
}

function _validateEmailAddress(EmailAddress)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(EmailAddress))
	{
		return true;
	}
	else
	{
		return false;
	}
}

String.prototype.trim=function()
{
	return this.replace(/^\s*|\s*$/g,'');
}
