﻿// script.js
var req;
var gBW = new detectBrowser();

function detectBrowser()
{
	var d = document;
	var nav=navigator;
	this.agt=nav.userAgent.toLowerCase();
	this.major = parseInt(nav.appVersion);
	this.ns=(d.layers);
	this.dom=(d.getElementById)?1:0;
	this.ns4up=(this.ns && this.major >=4);
	this.ns6=(this.agt.indexOf("Netscape6")!=-1);
	this.op=(window.opera? 1:0);
	if(d.all)
		this.ie=1;
	else 
		this.ie=0;
	this.ie4up=(this.ie && this.major >= 4);
	this.ie5=(d.all&&this.dom);
	this.gk=(typeof(nav.product)!="undefine"&&nav.product)?1:0;
	this.fb=(this.agt.indexOf("firebird")!=-1);
	this.fx=(this.agt.indexOf("firefox")!=-1);
	this.sf=(this.agt.indexOf("safari")!=-1);
	this.win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
	this.mac=(this.agt.indexOf("mac")!=-1);
}

function getReqXMLHTTPObj()
{
	var a = null;
	try{a = new ActiveXObject("Msxml2.XMLHTTP")}
	catch(b)
	{
		try{a = new ActiveXObject("Microsoft.XMLHTTP")}
		catch(c){a=null;}
	}
	if(!a && typeof XMLHttpRequest!="undefined")
	{
		a = new XMLHttpRequest();
	} 
	return a;
}

function AjaxCall(url, onCallback) 
{
	req = getReqXMLHTTPObj();
    req.onreadystatechange = onCallback;
    var rnd = Math.floor(Math.random()*100000)
    url = url + "&rnd=" + rnd;
    req.open("GET", url, true);
    req.send(null);
}

function AjaxCallNoCallBack(url) 
{
	req = getReqXMLHTTPObj();
    req.open("GET", url, false);
    req.send(null);
}
function AjaxPostCall(url, qs, onCallback) 
{
	req = getReqXMLHTTPObj();
    if (onCallback)
        req.onreadystatechange = onCallback;
    var rnd = Math.floor(Math.random()*100000);
    qs = qs + "&rnd=" + rnd + "&method=post";
    req.open("POST", url, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Accept","text/xml");
    req.send(qs);
}
function GenericAjaxLink(loadingDiv, replaceDiv, url, qs, errorMsg, confirmMsg, hideReplaceDiv)
{  
    var doAjax = 1;
    
    if (confirmMsg.length > 0)
    {
        if (!confirm(confirmMsg))
            doAjax = 0;    
    }        
    
    if (doAjax == 1)
    {  
        currProfileSectionStr = errorMsg;
        ajaxCheckLoadingDiv = loadingDiv;
        if (ajaxCheckLoadingDiv.length > 0)
            ShowDivById(loadingDiv);   
        ajaxCheckDivToShow = replaceDiv;
        if (hideReplaceDiv == '1')
            HideDivById(ajaxCheckDivToShow);
        AjaxPostCall(url, qs, GenericAjaxLinkPostback);
    }         
}
function GenericAjaxLinkPostback()
{
    if (req.readyState == 4) 
    {
        var success = false;
        var replaceDiv = document.getElementById(ajaxCheckDivToShow);
        if (req.status == 200)
        {
            if (ajaxCheckLoadingDiv.length > 0)
                HideDivById(ajaxCheckLoadingDiv); 
        
            var rtext = req.responseText;
            if (rtext.length > 0)
            {                     
                success = true;
                replaceDiv.innerHTML = rtext;
                replaceDiv.style.display = "inline";
            }           
        }
        if (!success)
        {
            if (currProfileSectionStr.length > 0)
                replaceDiv.innerHTML = rtext;
            else
                replaceDiv.innerHTML = 'Error:  Please try again later';
        }
    }
}
function ShowDivById(DivId)
{
    var rDiv = document.getElementById(DivId);
    if (rDiv)
    {
        rDiv.style.display = 'block';  
    }
}  
function HideDivById(DivId)
{
    var rDiv = document.getElementById(DivId);
    if (rDiv)
    {
        rDiv.style.display = 'none';  
    }
}


