
var frameWidth;
var frameHeight;
var popWin; var FormElement;
var url;
var Params;
var xmlHttp;
var TextStream='';
var xmlAction='';
var fldfocus;
var tmpHTML;


function popWinder(page, pagename, w, h, scroll) {
popWin = open(page, pagename, "width="+w+",height="+h+",toolbar=no,menubar=no,location=no,statusbar=no,scrollbars="+scroll+",resizable=yes");popWin.focus();return false;
}

function GetDocSize()
{
    if (self.innerWidth)
    {
	    frameWidth = self.innerWidth;
	    frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
	    frameWidth = document.documentElement.clientWidth;
	    frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
	    frameWidth = document.body.clientWidth;
	    frameHeight = document.body.clientHeight;
    }
    else
    {
	    frameWidth = 800;
	    frameHeight = 600;
    }
}

function RetrieveAndEncode(sFormElementName)
{
	var oValue;
	var oElement;
	
	if(document.getElementById(sFormElementName))
	{
	    //alert(sFormElementName);
	    oElement = document.getElementById(sFormElementName);
	    //alert(oElement.value);
	    //oValue = oElement.value;
	    //alert(oValue);
	}
	else
	{
	    oElement = document.getElementsByName(sFormElementName)
	}
	if (oElement.type == "checkbox" || oElement.type == "radio")
	{
	    if (oElement.checked) 
        {
            oValue = 1;
        }
        else
        {
            oValue = '0';
        }
	}
	else
	{
		oValue = oElement.value;
		
	}		
	if (!oValue)
	{
		oValue="";
	}
	return escape(encodeURI(oValue));
}

function GetXmlHttpObject()
{
xmlHttp=null;
try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
catch (e)
    {
    // Internet Explorer
    try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
            {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
    }
return xmlHttp;
}

function FireXML()
{
    xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange=XMLReady;
    xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", Params.length);
    xmlHttp.setRequestHeader("Cache-Control", "no-cache");
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(Params);
}

function XMLReady()
{
    if(xmlHttp.readyState==4)
    {
        TextStream = xmlHttp.responseText;
        xmlHttp.close;
        delete xmlHttp;
        AJAXDone();
    }
    else
    { }
} 

function TrimIt(str)
{
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function valuevalidation(entered, min, max, alertbox, datatype)
{
    with (entered)
    {
        checkvalue=parseFloat(value);
        if (datatype)
        {
            smalldatatype=datatype.toLowerCase();
            if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
        }
        if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
        {
            return false;
        }
        else {return true;}
    }
}

function emptyvalidation(entered, alertbox)
{
    entered = document.getElementById(entered).value;
    if (entered==null || entered==""){return false;}
    else {return true;}
}

// Check to make sure the field meets minimum length
function minlengthvalidation(entered, alertbox,len)
{
    entered = document.getElementById(entered).value;
    entered = TrimIt(entered);
    if (entered.length<len){return false;}
    else {return true;}
}

function valuevalidation(entered, min, max, datatype)
{
    entered = document.getElementById(entered).value;
    checkvalue=parseFloat(entered);
    if (datatype)
    {
        smalldatatype=datatype.toLowerCase();
        if (smalldatatype.charAt(0)=="i"){checkvalue=parseInt(entered)};
    }
    if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || entered!=checkvalue)
    {
        return false;
    }
    else {return true;}
}

function checkBoxer(tmpElement)
{
   tmpElement = document.getElementById(tmpElement);
   if(tmpElement.checked==1){return true;}
   else {return false;}
}

function validateRadio(radiogrp)
{ 
    var thisOne = -1;
    var thisRadioGroup;
    if(document.getElementById(radiogrp)){thisRadioGroup = document.getElementById(radiogrp)}
    if(document.getElementsByName(radiogrp)){thisRadioGroup = document.getElementsByName(radiogrp)}
    //alert(thisRadioGroup);
    for (i=0; i < thisRadioGroup.length; i++)
    { 
        if (thisRadioGroup[i].checked)
        { 
            thisOne = i;
            whichOne = (thisOne+1);
            //idIt=document.getElementsByTagName("INPUT")[i].id 
        } 
    } 
    if (thisOne == -1)
    { 
        //alert("You must select a radio button!"); 
        return false; 
    } 
    else
    { 
        //alert("You selected: " +thisRadioGroup[thisOne].value+ "\n Radio Button: " +whichOne); 
        return true; 
    }

}

function getRadioVal(sfrmElement)
{
    var iVal;
    var iElement;
    iElement = document.getElementsByName(sfrmElement)
    for(j = 0; j < iElement.length; j++)
    {
        if(iElement[j].checked){iVal =iElement[j].value;}
    }
    if(iVal==undefined){iVal=0;}
return iVal;
}
