

function loadIFrame(urlToLoad) {
      document.write("<tr><td align=center><B>Market Indices</B><br><iframe src="+urlToLoad+" width='350' height='120' scrolling='no' frameborder='1'></iframe></td></tr>");
};
function loadIndices(requestParam) {
       var requestString = "http://hosting.standardandpoors.com/cgi-bin/WebObjects/SNP?action=gotoExtMarketIndices&"+requestParam;
       loadIFrame(requestString);
};

function removeCommas(fieldValue){
// this function is called during the call to the individualhelphints function to strip out any commas in the page numbers.  It works 
// with certain pages that have multiple pages together like the NMS home page.
	var myString=fieldValue;

  while (myString.indexOf(",")!=-1) {
   	var pattern = ",";
 	  myString = myString.replace(pattern,"");
  }
	return myString;
}

// openWin starts
function checkInt(myString) {
  var isInteger=new Boolean();
  isInteger=true;
  var myChar="";
  var myInt=0;
  if (myString!="" && typeof(myString)=="string") {
    for (i=0;i<myString.length;i++) {
      myChar=myString.charAt(i);
      myInt=parseInt(myChar);
      if (isNaN(myInt)) {
        isInteger=false;
      }
    }
  } else {
    isInteger=false;
  }
  return isInteger;
}
function winResize(winObj,winprops) {
  if(winObj&&winprops){
    var winheight="";
    var winwidth="";
    if(winprops.match(/height=[0-9]+/i)){
      winheight=winprops.match(/height=[0-9]+/i).toString().replace(/height=/i,"");
    }
    if(winprops.match(/width=[0-9]+/i)){
      winwidth=winprops.match(/width=[0-9]+/i).toString().replace(/width=/i,"");
    }
    if(checkInt(winheight)&&checkInt(winwidth)){
      winObj.resizeTo(winwidth,winheight);
    }
  }
}
function grabDomain(urlObj) {
  var a=urlObj.toString().split('/');
  var u='';
  if (a[0]=='http:')u=a[0]+'//'+a[2]+'/';
  return u;
}

function checkSameDomain(urlObj) {
  var domMatch=new Boolean();
  domMatch=true;
  var curDom=document.location.href;
  if(urlObj && grabDomain(curDom)!=grabDomain(urlObj)) {
    domMatch=false;
  }
  return domMatch;
}

var keyid=0;

function spawn(url,nme){
  keyid++;
  this.name=nme;
  this.winkey=keyid;
  this.extdom=(checkSameDomain(url))?0:1;
  return this;
}

var childrenInfo=new Array();
var children=new Array();

function openWin(urlObj,name,props) {
  var newkey="";
  var winhref=(!urlObj)?"":urlObj.toString();
  var winname=(!name)?"newwin":name;   
  var winprops="";
  var winchild="";
  switch (winname){
    //Insert all special cases here:
    case "IER_demo": 
      winprops="toolbar=no,width=579,height=558,directories=no,status=no,scrollbars=no,resize=no,menubar=no,location=no,copyhistory=no";
    break;
    case "reportPDF":
    winprops="width=500,height=700,locationbar=no,menubar=no,toolbar=no,resizable=yes";
    winname="reportwin";
    break;
    case "alertHtml":
    winprops="width=523,height=720,locationbar=no,menubar=no,toolbar=no,resizable=yes";
    winname="reportwin";
    break;
    case "alertText":
    winprops="width=523,height=720,locationbar=no,menubar=no,toolbar=no,resizable=yes";
    winname="reportwin";
    break;
    case "alertWireless":
    winprops="width=656,height=41,locationbar=no,menubar=no,toolbar=no,resizable=yes";
		winname="reportwin";
    break;
    case "privacy":
    winprops="location=no,menubar=no,addressbar=no,resizable=yes,scrollbars=yes,height=600,width=600";
		winname="footer";
    break;
    case "terms":
    winprops="location=no,menubar=no,addressbar=no,resizable=yes,scrollbars=yes,height=800,width=600";
		winname="footer";
    break;
    case "disclosure":
    winprops="location=no,menubar=no,addressbar=no,resizable=yes,scrollbars=yes,height=800,width=600";
		winname="footer";
    break;
    case "sandp":
    if(winhref.indexOf("AboutUsMainPg") >0 ) winhref="http://www2.standardandpoors.com/portal/site/sp/en/us/page.category/aboutsp/4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.html";
    winprops="location=yes,menubar=yes,addressbar=yes,resizable=yes,scrollbars=yes,height=800,width=600";
		winname="sandp";
    break;
    case "salestool":
    winprops="toolbar=no,menubar=no,addressbar=yes,resizable=yes,scrollbars=yes,titlebar=no,status=no,height=600,width=800";
		winname="sales";
    break;
    case "promo":
    winprops="toolbar=no,menubar=no,addressbar=no,resizable=yes,scrollbars=yes,titlebar=yes,status=yes,height=600,width=850";
    break;
    case "deny":
    winprops="toolbar=no,menubar=no,addressbar=no,resizable=no,scrollbars=no,titlebar=no,status=no,height=400,width=650";
    break;
    case "quote":
    winprops="toolbar=no,menubar=no,addressbar=no,resizable=yes,scrollbars=yes,titlebar=yes,status=yes,height=500,width=650";
    break;    
    case "profile":
    winprops="toolbar=no,menubar=no,addressbar=no,resizable=yes,scrollbars=yes,titlebar=yes,status=yes,height=600,width=850";
    break;    
  }
  winprops=(!props)?winprops:props; 
  var i=0;
  //clean up arrays:
  if(childrenInfo.length>0){
    for(i=0;i<childrenInfo.length;i++){
      if(!children[childrenInfo[i].winkey]){
        childrenInfo.splice(i,1);
      } else if (!children[childrenInfo[i].winkey].closed){
        //no action
      } else {
        if(children[childrenInfo[i].winkey]){
          children.splice(childrenInfo[i].winkey,1);
        }
        childrenInfo.splice(i,1);
      }
    }
  }
  //check childrenInfo for match with requested window
  matchloop:
  if(childrenInfo.length>0){
    for(i=0;i<childrenInfo.length;i++){
      if(childrenInfo[i].name==winname && children[childrenInfo[i].winkey]){
        if(childrenInfo[i].extdom==1) {
          childrenInfo[i].extdom=(!checkSameDomain(urlObj))?1:0;
          children[childrenInfo[i].winkey].close();
        } else if(!checkSameDomain(urlObj)) {
          childrenInfo[i].extdom=1;
          children[childrenInfo[i].winkey].close();
        } else if(childrenInfo[i].extdom==0&&winprops){
          winResize(children[childrenInfo[i].winkey],winprops);
        }
        newkey=childrenInfo[i].winkey;
        break matchloop;
      }
    }
    childrenInfo.push(new spawn(winhref,winname));
    newkey=childrenInfo[i].winkey;
  } else {
    childrenInfo.push(new spawn(winhref,winname));
    newkey=childrenInfo[0].winkey;
  }
  children[newkey]=window.open(winhref,winname,winprops);
  children[newkey].focus();
}

