// JavaScript Document
var DHTML = (document.getElementById || document.all || document.layers);

function GetReport(theForm)
{
	var IFrameDoc;
	var URL = './templates/scan_report.php' + buildQueryString(theForm);
	var theFrame = document.getElementById('scan_report');
	if (theFrame.contentDocument) {
    	// For NS6
    	IFrameDoc = theFrame.contentDocument; 
  	} else if (theFrame.contentWindow) {
    	// For IE5.5 and IE6
    	IFrameDoc = theFrame.contentWindow.document;
  	} else if (theFrame.document) {
    	// For IE5
    	IFrameDoc = theFrame.document;
  	}
	IFrameDoc.location.replace(URL);
}

function ShowReport()
{
	showPage('scanreport');
	window.scroll(0,0);
}

function SetQuotes(theFormName,StkLast,Opt1Last,Opt2Last)
{
	var theForm = document.forms[theFormName];
	for (e=0;e<theForm.elements.length;e++) {
		if (theForm.elements[e].name == 'Stk_Close') theForm.elements[e].value=StkLast;
		if (theForm.elements[e].name == 'Opt1_Close') theForm.elements[e].value=Opt1Last;
		if (theForm.elements[e].name == 'Opt2_Close') theForm.elements[e].value=Opt2Last;
	}
}

function buildQueryString(theFormName) {
  	var theForm = document.forms[theFormName];
 	var qs = '';
 	for (e=0;e<theForm.elements.length;e++) {
    	if ((theForm.elements[e].name!='') && (theForm.elements[e].name!='getquote') && (theForm.elements[e].name!='getreport')) {
      		qs+=(qs=='')?'?':'&';
      		qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value);
      	}
    }
  	return qs;
}

var IFrameObj; // our IFrame object
function callToServer(theForm) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  var URL = './templates/yahoo_quote.php' + buildQueryString(theForm) + '&form=' + theForm;
  //var URL = 'server.html' + buildQueryString(theFormName);
  if (!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';
      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
        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;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

function handleResponse() {
	var theFormDiv = document.getElementById('theFormDiv');
	theFormDiv.style.display = 'none';
	var responseMessage = document.getElementById('responseMessage');
	var message = '<p>Your message has been sent! Thank you.<\/p>'
	message += '<p><a href="#" onclick="showForm(); return false;">Send another message<\/a><\/p>'
	responseMessage.innerHTML = message;
	responseMessage.style.display = 'block';
}

function getDiv(name)
{
	if (document.getElementById)
	{
		return document.getElementById(name).style;
	}
	else if (document.all)
	{
		return document.all[name].style;
	}
	else if (document.layers)
	{
		return document.layers[name];
	}
	else return false;
}

function showPage(name)
{
	if (!DHTML) return;
	var elm1 = getDiv('scanreport');
	var elm2 = getDiv('screenpage');
	if (name)
	{
		var elmx = getDiv(name);
		if ( elmx == elm1 ) {
			elmx.visibility = 'visible';
		}
		else {
			elm1.visibility = 'hidden';
		}
		if ( elmx == elm2 ) {
			elmx.visibility = 'visible';
		}
		else {
			elm2.visibility = 'hidden';
		}
	}
}

function setForm(theform,toform)
{
	if (( theform == 'testtrades1' ) && ( toform == 'testtrades2' )) {
		for (i=0;i<document.testtrades1.tradetype.length;i++){
			document.testtrades2.tradetype[i].checked = document.testtrades1.tradetype[i].checked;
		}
	}
	if (( theform == 'testtrades1' ) && ( toform == 'testtrades3' )) {
		for (i=0;i<document.testtrades1.tradetype.length;i++){
			document.testtrades3.tradetype[i].checked = document.testtrades1.tradetype[i].checked;
		}
	}
	if (( theform == 'testtrades2' ) && ( toform == 'testtrades1' )) {
		for (i=0;i<document.testtrades2.tradetype.length;i++){
			document.testtrades1.tradetype[i].checked = document.testtrades2.tradetype[i].checked;
		}
	}
	if (( theform == 'testtrades2' ) && ( toform == 'testtrades3' )) {
		for (i=0;i<document.testtrades2.tradetype.length;i++){
			document.testtrades3.tradetype[i].checked = document.testtrades2.tradetype[i].checked;
		}
	}
	if (( theform == 'testtrades3' ) && ( toform == 'testtrades1' )) {
		for (i=0;i<document.testtrades3.tradetype.length;i++){
			document.testtrades1.tradetype[i].checked = document.testtrades3.tradetype[i].checked;
		}
	}
	if (( theform == 'testtrades3' ) && ( toform == 'testtrades2' )) {
		for (i=0;i<document.testtrades3.tradetype.length;i++){
			document.testtrades2.tradetype[i].checked = document.testtrades3.tradetype[i].checked;
		}
	}
}

function showform(name)
{
	if (!DHTML) return;
	var elm1 = getDiv('tradestype1');
	var elm2 = getDiv('tradestype2');
	var elm3 = getDiv('tradestype3');
	if (name)
	{
		var elmx = getDiv(name);
		if ( elmx == elm1 ) {
			elmx.visibility = 'visible';
		}
		else {
			elm1.visibility = 'hidden';
		}
		if ( elmx == elm2 ) {
			elmx.visibility = 'visible';
		}
		else {
			elm2.visibility = 'hidden';
		}
		if ( elmx == elm3 ) {
			elmx.visibility = 'visible';
		}
		else {
			elm3.visibility = 'hidden';
		}
	}
}