// jsr_class.js
//
// JSONscriptRequest -- a simple class for making HTTP requests
// using dynamically generated script tags and JSON
//
// Author: Jason Levitt
// Date: December 7th, 2005

// Constructor -- pass a REST request URL to the constructor
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head")[0];
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
JSONscriptRequest.prototype.buildScriptTag = function () {
    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

function setHeight() {
	var req  = 'https://www.crm-gx.com/frame_height.php?bid=' + aws_id + '&frame_id=' + aws_frame_id; 
	bObj = new JSONscriptRequest(req); 
	bObj.buildScriptTag(); 
	bObj.addScriptTag();
//	if (navigator.userAgent.indexOf('KHTML') > 0)
//		setTimeout('onLoadSetHeight()',1000);
}

function frameHeight(jsonData) {
	if (jsonData.height > 0) {
		document.getElementById('aws_frm').style.height = jsonData.height + 'px';
		if (navigator.userAgent.indexOf('KHTML') > 0)
			setTimeout('setHeight()',500);
	} else {
		if (navigator.userAgent.indexOf('KHTML') > 0)
			setTimeout('setHeight()',500);
		else
			setTimeout('setHeight()',500);
	}

	bObj.removeScriptTag();
}

function onLoadSetHeight() {
	var aws_new_url = frames['aws_frm'].location.href;
	if (aws_new_url > '' && aws_new_url != aws_curr_url) {
		aws_curr_url = aws_new_url;
		setHeight();
	} else
		setTimeout('onLoadSetHeight()',500);
}

document.cookie="testcookie";
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;

var aws_id = Math.floor(Math.random() * 2147483647);

document.write('<iframe id=aws_frm name=aws_frm onLoad="setTimeout(&#39;setHeight()&#39;,50)" src="' + aws_url + '&bid=' + aws_id + ((cookieEnabled)?'&nocookie=1':'') + '" style="height:' + aws_initial_height + 'px;width:' + aws_width + 'px" scrolling=no frameborder=0></iframe>');

if (navigator.userAgent.indexOf('KHTML') > 0) {
	var aws_curr_url = aws_url + '&bid=' + aws_id;
	window.addEventListener('load',setTimeout('setHeight()',500),false);
}

