<!--
//Code by Lonnie Lee Best copyright 2000
var insideWidth;
var insideHeight;
function handler()
{
	insideWidth = document.body.offsetWidth;
	insideHeight = document.body.offsetHeight;
	if (insideWidth > 200)
	{
		document.getElementById('Preview').style.width = (insideWidth/2 - 20) + "px";
		document.getElementById('Code').style.width = (insideWidth/2 - 20) + "px";
		if (insideHeight > 200)
		{
			document.getElementById('Preview').style.height = (insideHeight - 100) + "px";
			document.getElementById('Code').style.height = (insideHeight - 100) + "px";
		}
	}
	document.getElementById('Code').focus();
}
	
onload = handler;
onresize = handler;

//_____________________________________________
// RPC
//_____________________________________________

//Global Variables
var startTime;
var httpRequest;
var url = "";
var countReadyStateChanges = 0;
var readyStateChangeLog = "";
function setStartTime()
{
    var startDate = new Date();
    startTime = startDate.getTime();
}
setStartTime();

function handleReadyStateChange() 
{
	countReadyStateChanges++;
	readyStateChangeLog = readyStateChangeLog + "\n" + countReadyStateChanges + " httpRequest.readyState:" + httpRequest.readyState;

	// only if the httpRequest's readyState is "complete"
	if (httpRequest.readyState == 4)
	{
        // only if "OK"
        if (httpRequest.status == 200)
		{
			// ...processing statements go here...
			document.getElementById('Preview').innerHTML = httpRequest.responseText;
			//alert("Success:\n" + httpRequest.statusText + "\nThe httpRequest's status is: " + httpRequest.status + "\nThe httpRequest's readyState is: " + httpRequest.readyState + "\nreadyState changed " + countReadyStateChanges + " times." + "\n" + readyStateChangeLog);
			httpRequest = "";
        }
		else 
		{
			document.getElementById('Preview').innerHTML = httpRequest.responseText;
			alert("The httpRequest's Status was not 200:\n" + httpRequest.statusText + "\nThe httpRequest's status is: " + httpRequest.status + "\nThe httpRequest's readyState is: " + httpRequest.readyState + "\nreadyState changed " + countReadyStateChanges + " times." + "\n" + readyStateChangeLog);
        }
	}
}
function NormalizeNewLines(str)
{
    if (!(str == null))
    {
        var unlikelyString = startTime + "MooMooCow";
        var regEx = /\r\n/gi;
        str = str.replace(regEx,unlikelyString);
        regEx = /\n/gi;
        str = str.replace(regEx,unlikelyString);
        regEx = /\r/gi;
        str = str.replace(regEx,unlikelyString);
        regEx = eval("/" + unlikelyString + "/gi");
        str = str.replace(regEx,"\r\n");
    }
    return str;
}
function Prep(str)
{
    str = NormalizeNewLines(str);
    str = escape(str);
    return str;
}

function PreviewClick()
{
    document.getElementById('Preview').innerHTML = "<table style=\"background-color:#F4F4F4;border:solid 1px #333333;padding:7px;\"><tr style=\"color:#333333;font-size:10px;\"><td>Loading...&nbsp;</td><td><img src=\"spin.gif\" /></td></tr></table></div>";
    GetPreview();
}

function GetPreview()
{
    
        
//    var currentDate = new Date();
//    var currentTime = currentDate.getTime();

    var strValues = "Subject=" + Prep(document.getElementById("Subject").value) + "&Name=" + Prep(document.getElementById("Name").value) + "&Email=" + Prep(document.getElementById("Email").value) + "&Title=" + Prep(document.getElementById("Title").value) + "&SubTitle=" + Prep(document.getElementById("SubTitle").value) + "&ArticleBody=" + Prep(document.getElementById("ArticleBody").value) + "&AboutTheAuthor=" + Prep(document.getElementById("AboutTheAuthor").value) + "&Description=" + Prep(document.getElementById("Description").value) + "&KeyPhrases=" + Prep(document.getElementById("KeyPhrases").value) + "&Path=" + Prep(document.getElementById("Path").value);
    var currentTime = new Date().getTime();
    var duration = currentTime - startTime;

        httpRequest = "";
        countReadyStateChanges = 0;
        readyStateChangeLog = "";
        url = "Previewer.aspx"
        
    	if (window.XMLHttpRequest) 
    	{
		    httpRequest = new XMLHttpRequest();
    		httpRequest.onreadystatechange = handleReadyStateChange;
	    	try
	    	{
			httpRequest.open("POST", url, true);
			httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

    		}
    		catch (e)
    		{
		        alert(e);
    		}
	    	httpRequest.send(strValues);
    	}
    	// branch for IE/Windows ActiveX version
    	else if (window.ActiveXObject)
    	{
    		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            if (httpRequest)
            {
                httpRequest.onreadystatechange = handleReadyStateChange;
                httpRequest.open("POST", url, true);
		        httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                httpRequest.send(strValues);
            }
	    }

}



// -->