﻿var xmlHttp;
var sAjURL;


function createAjaxRequest() {
	
	if ( window.ActiveXObject ) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	} else if ( window.XMLHttpRequest ) {
		xmlHttp = new XMLHttpRequest();
		
	}
}

function startRequest() {
	if ( sAjURL.length > 0 ) {
		createAjaxRequest();	
		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.open( "GET" , sAjURL , true );
		xmlHttp.send( null );
	}
}

function handleStateChange() {
	// alert( "ready state: " + xmlHttp.readyState );
	if ( xmlHttp.readyState == 4 ) {
		if ( xmlHttp.status == 200 ) {
			// alert('data changed');
			
			alert( xmlHttp.responseText );
		}
	}
}



function theChangeAjax() {
	var sArg = arguments[0];
	
	// alert (sArg);
	
	var theElement;
	
	if ( sArg == undefined ) {
		theElement = event.srcElement;
		
	} else {
		theElement = document.getElementById(sArg);
		
	}
	
	// alert ( "element's name: " + theElement.name );
	// alert ( "element's ID: " + theElement.id );
	
	
	var theValue;
	
	if ( theElement.type == "checkbox" ) {
		theValue = ( theElement.checked ) ?  -1  :  0  ;
	} else {
		theValue = escape(theElement.value);
	}
	
	// alert ( "the value: " + theValue );
	
	
	var sDomain = escape(theElement.getAttribute("dom"));
	// alert ( "the domain: " + sDomain );
	
	
	var sFldName ;
	var sCrit ;
	
	if (sDomain != null) {
		sFldName = escape(theElement.getAttribute("fldName"));
		sCrit = escape(theElement.getAttribute("crit"));
		
		// alert ( "the criteria: " + sCrit );
	
		if ( sFldName != null  &&  sCrit != null ) {
			sAjURL = 
			    'selector.aspx?fld=' + sDomain 
			    + '&pid=' + sFldName 
			    + '&mov=' + theValue 
			    + '&crit=' + sCrit 
			    + '&cmd=update';
			startRequest();
			
			return;
			
		} else {
			
			// don't do anything
			return; 
		}
		
	} else {

		return; 
	}
	
	return; 
}

function getWindowHeight() 
{
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') 
    {
        windowHeight=window.innerHeight;
    }
    else 
    {
    if (document.documentElement && document.documentElement.clientHeight) 
        {
            windowHeight = document.documentElement.clientHeight;
        }
        else 
        {
            if (document.body&&document.body.clientHeight) 
            {
                windowHeight=document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}






function resizeDivs(){

	// --------  Window Height  -------------
	var windowHeight = getWindowHeight();
	
	// --------  Window Width  -------------
	//var windowWidth = window.innerWidth;
	
	//if (windowWidth == undefined ) { windowWidth = document.body.offsetWidth; }
	
	var divTop = document.getElementById('navDiv').offsetTop;

	var divHeight = windowHeight - divTop - 20;
	
	var heightInput = document.getElementById('divHeight');
	
	heightInput.value = divHeight;
	

	setStyle( 'navDiv' , 'height' , divHeight + 'px' );
	//setStyle( 'google_scraper' , 'height' , divHeight + 'px' );
	setStyle( 'bodyDiv' , 'height' , divHeight + 'px' );
}


function setStyle( objId , style , value) {
    document.getElementById(objId).style[style] = value;
}


function goThere(one,two,three,four,five)
{
    var earl = 'http' + one + two + three + four + five;
    // alert (earl);
    window.top.location.href = earl;
}


function selection(id)
{
	var divTop = document.getElementById('navDiv').offsetTop;
	var divHeight = windowHeight - divTop - 20;
    var earl = '?f=' + id + '&h=' + divHeight;
    // alert (earl);
    window.top.location.href = earl;
}



