// JavaScript Document

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function selectMenu(menuId) {
    var date = new Date();
	date.setTime(date.getTime()+(30*24*60*60*1000));
    document.cookie =
        "menu=" + menuId + ";expires=" + date.toGMTString() + ";path=/"
}


function OpenPagePanel()
{
    DarkenPage();
    ShowPanel();
}


function ShowPanel()
{
   var page_panel = document.getElementById('page_panel');
    
    // w is a width of the page panel
   w = 500;
    // h is a height of the page panel
   h = 300;
    
   //get the x and y coordinates to center the page panel
   xc = Math.round((document.body.clientWidth/2)-(w/2))
   yc = Math.round(150)
    
    //show the page panel
   page_panel.style.left = xc + "px";
   page_panel.style.top  = yc + "px";
   page_panel.style.display = 'block'; 
}


function HidePanel()
{
    // hide the page panel
    var page_panel = document.getElementById('page_panel');
    page_panel.style.display = 'none';
    
    // clear errors
    ClearErrorMessages();    
    
    // lighten the page again
    LightenPage();
}


// this function puts the dark screen over the entire page
function DarkenPage()
{
    var page_screen = document.getElementById('page_screen');
    page_screen.style.height = document.body.parentNode.scrollHeight + 'px';
    page_screen.style.display = 'block';
}


// this function removes the dark screen and the page is light again
function LightenPage()
{
    var page_screen = document.getElementById('page_screen');
    page_screen.style.display = 'none';
}


// Email form validation functions
function IsEmailFormValid()
{
    // clear previous errors
    ClearErrorMessages();

    var yourName = document.getElementById('ctl00_EmailFriendForm1_txtYourName').value;
    var yourEmail = document.getElementById('ctl00_EmailFriendForm1_txtYourEmail').value;
    var friendName = document.getElementById('ctl00_EmailFriendForm1_txtFriendsName').value;
    var friendEmail = document.getElementById('ctl00_EmailFriendForm1_txtFriendsEmail').value;
    
    var formIsValid = true;
    
    if (yourName.length <= 0)
    {
        document.getElementById('txtYourNameMsg').style.display = 'block';
        formIsValid = false;
    }
    
    if (yourEmail.length <= 0)
    {
        document.getElementById('txtYourEmailMsg').style.display = 'block';
        formIsValid = false;
    } 
    else if (IsEmailValid(yourEmail) == false)
    {
        document.getElementById('txtYourEmailMsgInvalid').style.display = 'block';
        formIsValid = false;
    }
    
    if (friendName.length <= 0)
    {
        document.getElementById('txtFriendsNameMsg').style.display = 'block';
        formIsValid = false;
    }            
    
    if (friendEmail.length <= 0)
    {
        document.getElementById('txtFriendsEmailMsg').style.display = 'block';
        formIsValid = false;
    }
    else if (IsEmailValid(friendEmail) == false)
    {
        document.getElementById('txtFriendsEmailMsgInvalid').style.display = 'block';
        formIsValid = false;        
    }             

    return formIsValid;
}

function ClearErrorMessages()
{
    document.getElementById('txtYourNameMsg').style.display = 'none';
    document.getElementById('txtYourEmailMsg').style.display = 'none';
    document.getElementById('txtYourEmailMsgInvalid').style.display = 'none';
    document.getElementById('txtFriendsNameMsg').style.display = 'none';
    document.getElementById('txtFriendsEmailMsg').style.display = 'none';
    document.getElementById('txtFriendsEmailMsgInvalid').style.display = 'none';
}

function IsEmailValid(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
    if (str.indexOf(at,(lat+1))!=-1){
        return false
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false
    }
    if (str.indexOf(dot,(lat+2))==-1){
        return false
    }
    if (str.indexOf(" ")!=-1){
        return false
    }

	return true					
}
