

function nav(url)
{
    document.location = url;
}

// Home page functions
var g_HomeImages = new Array();
var g_HomeImageNames = new Array("images/home/home1.jpg", "images/home/home2.jpg");
var g_HomeImageIndex = 0;
function ScrollImagePanel()
{
    var homeImagePanel = document.images.imagePanel;
    document.images.imagePanel.style.filter = "blendTrans(duration=2)";
    document.images.imagePanel.style.filter = "blendTrans(duration=3)";
    document.images.imagePanel.style.filters.blendTrans.Apply(); 
    
    // Preload the rest of the images
    if(g_HomeImages.length == 0)
    {
       // Load the first image for now
       homeImagePanel.src = g_HomeImageNames[0];
 
       // Now preload everything else
       for (var i = 0; i < g_HomeImageNames.length; i++)
       {
           g_HomeImages[i] = new Image();
           g_HomeImages[i].src = g_HomeImageNames[i];
       } 
    }
    else
    {
        homeImagePanel.src = g_HomeImages[g_HomeImageIndex++].src;
        homeImagePanel.filters.blendTrans.Play()

        // Set back to 0 if necessary        
        if (g_HomeImageIndex >= g_HomeImages.length)
        {
            g_HomeImageIndex = 0;
        }
    }
    
    setTimeout("ScrollImagePanel()", 4000); 
}

var g_XmlHttp;
var __WebAppRoot = "http://versatechdevelopment.com/";
var __LocalRoot = "http://localhost/versatech/";

function IsLocalDebugging()
{   
    return false;
    // var url = document.location + "";
    // return url.indexOf("localhost") == -1 ? __WebAppRoot : __LocalRoot;
}

function AjaxPost(url, message, callback)
{
    g_XmlHttp = CreateAjaxRequestObject();
    
    g_XmlHttp.onreadystatechange = callback;
    
    if (IsLocalDebugging())
    {
        url = __LocalRoot + url;
    }
    else
    {
        url = __WebAppRoot + url;
    }

    //Synchrounous or not (true or false)
    //g_XmlHttp.Async = true;
    
    //open the connection to the server at this url
    g_XmlHttp.open("POST", url, false);
   
    //Send the xml
    g_XmlHttp.send(message);
}

function AjaxProxyGet(url, message, callback, isAsynch)
{
    g_XmlHttp = CreateAjaxRequestObject();
    
    g_XmlHttp.onreadystatechange = callback;

    // Default to asynchronous GETs
    if (isAsynch == undefined)
    {
        isAsynch = true;
    }
    
    // Asynchrounous or not (true or false)
    if (window.XMLHttpRequest)
    {
        // Only a valid property on an actual XMLHttpRequest object
        g_XmlHttp.Async = isAsynch;
    }
    
    g_XmlHttp.open("GET", url, isAsynch);
   
    //Send the xml
    g_XmlHttp.send(message);
}

function AjaxProxyPost(url, message, callback, isAsynch)
{
    g_XmlHttp = CreateAjaxRequestObject();
    
    g_XmlHttp.onreadystatechange = callback;
    
    // Default to synchronous POSTs
    if (isAsynch == undefined)
    {
        isAsynch = false;
    }
    
    // Synchrounous or not (true or false)
    // g_XmlHttp.Async = isAsynch;
    
    // open the connection to the server at this url
    g_XmlHttp.open("POST", url, isAsynch);
   
    //Send the xml
    g_XmlHttp.send(message);
}

function AjaxProxyCall(url, message, callback, postorget, isAsynch)
{
    var path = url + "?message=" + message;
    var actualUrl;
    
    if (IsLocalDebugging())
    {
        actualUrl = __LocalRoot + path;
    }
    else
    {
        actualUrl = 'ajax_proxy.php?ws_path=' + encodeURIComponent(path);    
    }

    if (postorget == "POST")
    {
        AjaxProxyPost(actualUrl, null, callback, isAsynch);
    }
    else if (postorget == "GET")
    {
        AjaxProxyGet(actualUrl, null, callback, isAsynch);
    }
    else
    {
        alert("Invalid postorget parameter; must be POST or GET");
    }
}

function Sanitize(str)
{
	var regExp;
	
	regExp = /</g;
	str = str.replace(regExp,"&lt;");

	regExp = />/g;
	str = str.replace(regExp,"&gt;");

	regExp = /'/g; 
	str = str.replace(regExp,"&#39;");
	
	regExp = /"/g; 
	str = str.replace(regExp,"&#34;");
	
	regExp = /\n/g;
	str = str.replace(regExp, "<br/>");

//	regExp = / /g; 
//	str = str.replace(regExp,"&nbsp;");

	return str;
}

function Desanitize(str)
{
	var regExp;
	
	regExp = /<br\/>/g;
	str = str.replace(regExp, "\n");

    return str;
}

function CreateAjaxRequestObject() 
{
    return window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
}

function User(userName, password, isAuthenticated)
{
    this.userName = userName;
    this.password = password;
    this.isAuthenticated = isAuthenticated;
}

/////////////////////
// UNUSED
////////


function loadcontent(URL)
{
  document.location=URL;  //Load the new content into the main content window
}

function swap(item)
{
	item.style.backgroundColor='white';
	item.style.border = 'black solid 1px';
}

function swapback(item)  
{
	item.style.backgroundColor='black';
	item.style.border = 'black solid 1px';
}

function sendEmail(contact, url)
{
	document.location="mailto:" + contact + "@" + url;
	return false;
}

////////////
//Menu Stuff
////////////
function MenuHandler()
{
	this.HideMenu = HideMenu;
	this.ShowMenu = ShowMenu;
	this.SetWaitTime = SetWaitTime;
	this.WaitCallback = 0;
	this.EndWait = EndWait;
	
	this.LastMenu = null;
}

function ShowMenu(menu)
{
    if (this.LastMenu != null)
    {
        HideMenu(this.LastMenu);
    }

	var item = document.getElementById(menu);
	if (item != null)
	{
	    item.style.visibility='visible';
	}
	
	this.LastMenu = menu;
}

function HideMenu(menu)
{
	var item = document.getElementById(menu);
	if (item != null)
	{
	    item.style.visibility='hidden';
	}
}

function SetWaitTime(menu)
{
	var wait = 60;
	this.WaitCallback = setTimeout('HideMenu("' + menu + '")', wait);
}

function EndWait(menu)
{
	clearTimeout(this.WaitCallback);
}

g_MenuHandler = new MenuHandler();


function HoverMenu(menu)
{
    menu.className = "sidenavOffHover";
}

function UnHoverMenu(menu)
{
    menu.className = "sidenavOff";
}
