/*
	myrss.js is a javascript library that helps doing javascript remote scripting calls using the methods described in
	Apple.com and various other sites.
	
/* CVS Info: **************************************
	$RCSfile: myrss.js,v $\
	$Date: 2008/11/30 21:16:50 $\
	$Revision: 1.1 $\
	$Name:  $\
	$Author: cvsuser $\
	$State: Exp $\
**************************************************/
function myRss() {
	this.IFrameObj = null;
}

myRss.prototype.init = function(target) {
	this.target = target;
}

myRss.prototype.callToServer = function (formName,fieldName,fieldValue) {
	this.submit(formName,fieldName,fieldValue);
}



myRss.prototype.submit = function (formName,fieldName,fieldValue) {
	if (!document.createElement) {return true};
	var IFrameDoc;
	if (typeof(fieldName)=="undefined") var URL = this.target+'?doit=yes&form_name='+escape(formName)+'&'+this.buildQueryString(formName);
	else var URL = this.target+'?doit=yes&form_name='+escape(formName)+'&field_name='+escape(fieldName)+'&field_value='+escape(fieldValue);
	if (!this.IFrameObj && document.createElement) {
		// create the IFrame and assign a reference to the
		// object to our global variable IFrameObj.
		// this will only happen the first time 
		// callToServer() is called
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			this.IFrameObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				// this is for IE5 Mac, because it will only
				// allow access to the document object
				// of the IFrame if we access it through
				// the document.frames array
				this.IFrameObj = document.frames['RSIFrame'];
			}
		} catch(exception) {
			// This is for IE5 PC, which does not allow dynamic creation
			// and manipulation of an iframe object. Instead, we'll fake
			// it up by creating our own objects.
			iframeHTML='<iframe id=\"RSIFrame\" style=\"';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='\"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			this.IFrameObj = new Object();
			this.IFrameObj.document = new Object();
			this.IFrameObj.document.location = new Object();
			this.IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
			this.IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !this.IFrameObj.contentDocument) {
		// we have to give NS6 a fraction of a second
		// to recognize the new IFrame
		setTimeout(this.submit(formName,fieldName,fieldValue),10);
		return false;
	}
	
	if (this.IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = this.IFrameObj.contentDocument; 
	} else if (this.IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = this.IFrameObj.contentWindow.document;
	} else if (this.IFrameObj.document) {
		// For IE5
		IFrameDoc = this.IFrameObj.document;
	} else {
		return true;
	}	
	IFrameDoc.location.replace(URL);
	return false;
}

myRss.prototype.buildQueryString = function(theFormName) {
	theForm = document.forms[theFormName];
	var qs = '';
	var done = new Array();
	if (typeof(theForm)!="undefined") {
		for (e=0;e<theForm.elements.length;e++) {
			if (theForm.elements[e].name!='') {
				if (!done[theForm.elements[e].name]) {
					qs+=(qs=='')?'':'&';
					qs+=theForm.elements[e].name+'='
					+escape(getValue(theForm[theForm.elements[e].name]));
					done[theForm.elements[e].name] = true;
				}
			}
		}
	}
	return qs
}
