﻿// JScript File
function getPageSize(){
    var x,y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    {
	    x = document.body.scrollWidth;
	    y = document.body.scrollHeight;
    }
    else // Explorer Mac;
         //would also work in Explorer 6 Strict, Mozilla and Safari
    {
	    x = document.body.offsetWidth;
	    y = document.body.offsetHeight;
    }
    return { width: x, height: y }
}


function getScrollSize()
{
    var x,y;
    if (self.pageYOffset) // all except Explorer
    {
	    x = self.pageXOffset;
	    y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
	    // Explorer 6 Strict
    {
	    x = document.documentElement.scrollLeft;
	    y = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
	    x = document.body.scrollLeft;
	    y = document.body.scrollTop;
    }
    return { width: x, height: y }
}

function getViewSize()
{
    var x,y;
    if (self.innerHeight) // all except Explorer
    {
	    x = self.innerWidth;
	    y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
	    // Explorer 6 Strict Mode
    {
	    x = document.documentElement.clientWidth;
	    y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
	    x = document.body.clientWidth;
	    y = document.body.clientHeight;
    }
    return { width: x, height: y }
}

function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      }
} 

function justClickButton(buttonid){ 
    var bt = document.getElementById(buttonid); 
    bt.click(); 
    return false; 
}

function GetUserInput(panelid, id, company, fname, email)
{

    var hidden_surveyorid = document.getElementById('hidSurveyorID');
    var hidden_surveyor_name = document.getElementById('hidSurveyorName');
    var hidden_surveyor_firstname = document.getElementById('hidSurveyorFirstname');
    var hidden_surveyor_email = document.getElementById('hidSurveyorEmail');

    hidden_surveyorid.value = id;
    hidden_surveyor_name.value = company;
    hidden_surveyor_firstname.value = fname;
    hidden_surveyor_email.value = email;
    
    DarkenPage();
    ShowInputPanel(panelid);
}


function ShowInputPanel(panelid)
{
    var newsletter_panel = document.getElementById(panelid);
    
    // w is a width of the newsletter panel
    w = 400;
    // h is a height of the newsletter panel
    if (panelid.indexOf("contactme") >= 0)
        h=175;
    else
        h=300;
    
    scrollSize = getScrollSize();
    viewSize = getViewSize();
    
    // get the x and y coordinates to center the newsletter panel
    xc = Math.round((viewSize.width/2)-(w/2))
    yc = Math.round((viewSize.height/2)-(h/2)+scrollSize.height)
    
    // show the newsletter panel
    newsletter_panel.style.left = xc + "px";
    newsletter_panel.style.top  = yc + "px";
    newsletter_panel.style.display = 'block';
}

function HideInputPanel(panelid)
{
    // hide the newsletter panel
    var newsletter_panel = document.getElementById(panelid);
    newsletter_panel.style.display = 'none';
}

function SignUp(buttonid, panelid)
{

    var validate = new Boolean(false);

    if (panelid == "contactme-panel") // contactme
    {
        // validate require
        
        // validate like email
    }
    else // panel = sendemail-panel
    {
        // validate required
        
        // validate like email
    }

    if (validate) 
    {
        // get rid of the form
        HideInputPanel(panelid);

        // lighten the page again
        LightenPage();
        
        // submit the form
        justClickButton(buttonid);
    }       
}

// this function puts the dark screen over the entire page
function DarkenPage()
{
    var myWidth = 0, myHeight = 0;  
    var cwSize = getPageSize();

    myWidth = cwSize.width;
    myHeight = cwSize.height + 25;

    var page_screen = document.getElementById('page-screen');

    page_screen.style.height = myHeight + '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';
}
