﻿var MC_Tmr;
var MC_ToolTipTmr=null;
var MC_DID;
var MC_Incr;
var MC_Level;
var MC_Req;
var MC_Stage;
var MC_ToolTipOpac;
var MC_Warning=true;
var MC_Mode;
window.onresize=function MC_WindowResize(){if(document.getElementById("BackDrop")!=null&&document.getElementById("BackDrop").style.display=="block"){MC_PositionBackDrop();}}
window.onscroll=function MC_WindowScroll(){if(document.getElementById("BackDrop")!=null&&document.getElementById("BackDrop").style.display=="block"){MC_PositionBackDrop();}}

/**************************************************************/
/*                  DATA VALIDATION FUNCTIONS                 */
/**************************************************************/
function MC_ValidateForm()
{
  var isValid=false;
  if(MC_ValidateEntry("AmountBorrowedTextBox",false)){
    if(MC_ValidateEntry("InterestRateTextBox",false)){
      if(MC_ValidateEntry("RepaymentPeriodTextBox",false)){
        if(MC_ValidateEntry("FirstRepaymentTextBox",true)){
          isValid=true;
        }
      }
    }
  }
  return(isValid);
}
function MC_ValidateNewRate()
{
  var isValid=false;
  if(MC_ValidateEntry("NewInterestRateTextBox",false)){
    if(MC_ValidateEntry("EffectiveAfterTextBox",false)){
      isValid=true;
    }    
  }
  return(isValid);
}
function MC_IsNumeric(e,obj,allowDecimals){
  var code=e.charCode? e.charCode : e.keyCode;
  if(code==8||(code>=48&&code<=57)||(code==46&&allowDecimals&&obj.value.indexOf(".")==-1)){
    return true;
  }
  else {
    return false;
  }
}
function MC_IsValidDateChar(e){
  var code=e.charCode? e.charCode : e.keyCode;
  if(code!=8&&(code<47||code>57)){
    return false;
  }
}
function MC_IsValidEmailChar(e){
  var code=e.charCode? e.charCode : e.keyCode;
  if(code==" ")
  {
    return false;
  }
}
function MC_ValidateEntry(id,isDate){
  var obj=document.getElementById(MC_ID+id);
  var value=obj.value;
  if(value==""){
    MC_ShowToolTip("Please complete this field before proceeding",obj,3000);
    return(false);
  }
  else{
    if(isDate){
      var isValid=value.length==10&&value.substr(2,1)=="/"&&value.substr(5,1)=="/";
      if(isValid){
        isValid=MC_isValidDate(value,"DMY");      
      }
      if(!isValid){
        MC_ShowToolTip("Please enter a valid date in the format dd/mm/yyyy",obj,3000);
        return(false);
      }
    }
    else{
      if(value*1==0){
        MC_ShowToolTip("Please ensure that this value is greater than 0",obj,3000);
        return(false);
      }
    }
  }
  return(true);
}
function MC_ValidateEmailAddress()
{
  var email1=document.getElementById(MC_ID+"EmailAddressTextBox").value;
  var email2=document.getElementById(MC_ID+"ConfirmEmailAddressTextBox").value;
  var isValid=true;
  if(email1==""){
    MC_ShowToolTip("Please enter your e-mail address",document.getElementById(MC_ID+"EmailAddressTextBox"),3000);
    isValid=false;
  }
  else{
    if(email2==""){
      MC_ShowToolTip("Please confirm your e-mail address",document.getElementById(MC_ID+"ConfirmEmailAddressTextBox"),3000);
      isValid=false;
    }
    else{
      var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
      var regex = new RegExp(emailReg);
      if(!regex.test(email1)){
        MC_ShowToolTip("The e-mail address that you have entered is invalid",document.getElementById(MC_ID+"EmailAddressTextBox"),3000);
        isValid=false;
      }
      else{
        if(email1!=email2){
          MC_ShowToolTip("The e-mail addresses that you entered don't match",document.getElementById(MC_ID+"ConfirmEmailAddressTextBox"),3000);
          isValid=false;
        }
      }      
    }
  }
  return isValid;
}
function MC_isValidDate(dateStr, format) {
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
   }
   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else 
      if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else 
      if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else 
      if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}

/**************************************************************/
/*                      E-MAIL FUNCTIONS                      */
/**************************************************************/
function MC_EmailCheckChange()
{
  document.getElementById("EmailFields").style.display=(document.getElementById("EmailProjectionsCheckbox").checked?"block":"none");
}
function MC_EmailProjections()
{
  MC_Mode=2;
  MC_RemoveOutOfRangeRates();
  document.getElementById("UserInput").disabled=true;
  document.getElementById("CommandRow").style.display="none";
  document.getElementById("WaitRow").style.display="block";
  document.getElementById("Projections").style.display="none";
  MC_RequestCalculations();
  MC_Warning=false;
}

/**************************************************************/
/*                    RATE CHANGE FUNCTIONS                   */
/**************************************************************/
function MC_ShowRateChangeDlg()
{
  document.getElementById(MC_ID+"NewInterestRateTextBox").value="";
  document.getElementById(MC_ID+"EffectiveAfterTextBox").value="";
  document.getElementById(MC_ID+"NewRateFixedRadio").checked=document.getElementById(MC_ID+"FixedRateRadio").checked;
  document.getElementById(MC_ID+"NewRateVariableRadio").checked=document.getElementById(MC_ID+"VariableRateRadio").checked;
  document.getElementById(MC_ID+"NewRateYearsRadio").checked=document.getElementById(MC_ID+"RepayYearsRadio").checked;
  document.getElementById(MC_ID+"NewRateMonthsRadio").checked=document.getElementById(MC_ID+"RepayMonthsRadio").checked;
  document.getElementById(MC_ID+"MortgageCalculator").style.zIndex=498;
  document.getElementById(MC_ID+"RateChangeDialog").style.left=(((f_clientWidth()-757)/2)+25)+"px";
  document.getElementById(MC_ID+"RateChangeDialog").style.top=(document.getElementById(MC_ID+"MortgageCalculator").offsetTop+40)+"px";
  MC_ShowDialog(MC_ID+"RateChangeDialog");
}
function MC_HideRateChangeDlg()
{
  MC_HideDialog(MC_ID+'RateChangeDialog');
  document.getElementById(MC_ID+"MortgageCalculator").style.zIndex=500;
}
function MC_AddNewRate()
{
  MC_HideRateChangeDlg();
  var newRate=document.getElementById(MC_ID+"NewInterestRateTextBox").value;
  var newRateType=(document.getElementById(MC_ID+"NewRateFixedRadio").checked?"1":"2");
  var effectiveAfter=document.getElementById(MC_ID+"EffectiveAfterTextBox").value;
  var effectiveType=(document.getElementById(MC_ID+"NewRateYearsRadio").checked?"1":"2");
  var totalMonths=effectiveAfter*(effectiveType=="1"?12:1);
  var loanTermInMonths=document.getElementById(MC_ID+"RepaymentPeriodTextBox").value*(document.getElementById(MC_ID+"RepayYearsRadio").checked?"12":"1");
  if(loanTermInMonths>=totalMonths){
    document.getElementById("AdditionalRates").style.display="block";
    var newRateEntry=document.createElement("span");
    newRateEntry.i_value=newRate+"|"+newRateType+"|"+effectiveAfter+"|"+effectiveType;
    newRateEntry.className="NewRateEntry";
    var newRateDetails=document.createElement("span");
    newRateDetails.innerHTML=newRate+"% after "+effectiveAfter+" "+(effectiveType==1?"year":"month")+(effectiveAfter==1?"":"s");
    newRateDetails.className="Normal";
    newRateEntry.appendChild(newRateDetails);
    var remLink=document.createElement("a");
    remLink.href="#";
    remLink.onclick=function MC_RemoveAdditionalRate(){MC_RemoveRateEntry(newRateEntry.i_value);return(false);};
    remLink.className="CommandButton";
    remLink.innerHTML="(remove)";
    newRateEntry.appendChild(remLink);
    var rateTable=document.getElementById("RateChangesSpan");
    var currRates=rateTable.childNodes;
    var pos=-1;
    var i=0;
    while(i<currRates.length&&pos==-1){
      var rateDtls=currRates[i].i_value.split("|");
      var months=rateDtls[2]*(rateDtls[3]=="1"?12:1);
      if(months==totalMonths){
        pos=-2;
      }
      else{
        if(months>totalMonths){
          pos=i;
        }
        else{
          i++;
        }
      }
    }
    switch(pos){
      case -2:
        rateTable.replaceChild(newRateEntry,currRates[i]);
        break;
      case -1:
        rateTable.appendChild(newRateEntry);
        break;
      default:
        rateTable.insertBefore(newRateEntry,currRates[i]);
        break;
    }
    if(!MC_Warning){
      MC_Warning=true;
      MC_ShowToolTip("Remeber to click here to view updated projections",document.getElementById("CalculateButton"),4500);
    }
  }  
}
function MC_RemoveRateEntry(id)
{
  var rateTable=document.getElementById("RateChangesSpan");
  var currRates=rateTable.childNodes;
  var i=0;
  while(i<currRates.length){
    if(currRates[i].i_value==id){
      rateTable.removeChild(currRates[i]);
      i=currRates.length;
    }
    else{
      i++;
    }
  }
  if(rateTable.childNodes.length==0){
    document.getElementById("AdditionalRates").style.display="none";
  }
  if(!MC_Warning){
    MC_Warning=true;
    MC_ShowToolTip("Remeber to click here to view updated projections",document.getElementById("CalculateButton"),4500);
  }
}
function MC_RemoveOutOfRangeRates()
{
  var totalMonths=document.getElementById(MC_ID+"RepaymentPeriodTextBox").value*(document.getElementById(MC_ID+"RepayYearsRadio").checked?12:1);
  var rateTable=document.getElementById("RateChangesSpan");
  var currRates=rateTable.childNodes;
  var i=currRates.length-1;
  while(i>=0){
    var rateDtls=currRates[i].i_value.split("|");
    var months=rateDtls[2]*(rateDtls[3]=="1"?12:1);
    if(totalMonths<=months){
      rateTable.removeChild(currRates[i]);
    }
    i--;
  }
  if(rateTable.childNodes.length==0){
    document.getElementById("AdditionalRates").style.display="none";
  }
}


/**************************************************************/
/*                       TOOLTIP FUNCTIONS                    */
/**************************************************************/
function MC_BackDropClick()
{
  if(document.getElementById(MC_ID+"RateChangeDialog").style.display=="block"){
    MC_ShowToolTip("Click here to cancel this option and return to the Mortgage Calculator",document.getElementById("CancelRateChangeButton"),3000);
  }
  else{
    MC_ShowToolTip(MC_BackDropMsg,document.getElementById(MC_ID+"CloseCalculatorButton"),3000);
  }  
}
function MC_CheckForWarning(obj)
{
  if(obj.i_value&&obj.i_value!=obj.value){
    if(!MC_Warning){
      MC_Warning=true;
      MC_ShowToolTip("Remeber to click here to view updated projections",document.getElementById("CalculateButton"),4500);
    }
  }  
  obj.i_value=obj.value;
}
function MC_ShowToolTip(text,obj,timer)
{
  var pos=findPos(obj);
  var posx=pos[0]+obj.offsetWidth-5;
  var posy=pos[1]-2;
  document.getElementById("ToolTipText").innerHTML=text;
  var toolTipDlg=document.getElementById("ToolTip");
  toolTipDlg.style.left=posx+"px";
  toolTipDlg.style.top=posy+"px";
  toolTipDlg.style.opacity=".99";
  toolTipDlg.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=99)";
  toolTipDlg.style.display="block";  
  MC_ToolTipOpac=99;
  if(MC_ToolTipTmr!=null){
    window.clearInterval(MC_ToolTipTmr);
  }
  MC_ToolTipTmr=window.setInterval(MC_ToolTipCountDown,timer);
}
function MC_ToolTipCountDown()
{
  window.clearInterval(MC_ToolTipTmr);
  MC_ToolTipTmr=window.setInterval(MC_FadeToolTip,25);
}
function MC_FadeToolTip()
{
  var toolTipDlg=document.getElementById("ToolTip");
  toolTipDlg.style.opacity="."+MC_ToolTipOpac;
  toolTipDlg.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity="+MC_ToolTipOpac+")";
  MC_ToolTipOpac=MC_ToolTipOpac-10;
  if(MC_ToolTipOpac<0){
    window.clearInterval(MC_ToolTipTmr);
    MC_ToolTipTmr=null;
    toolTipDlg.style.display="none";
  }
}

/**************************************************************/
/*                       DIALOG FUNCTIONS                     */
/**************************************************************/
function MC_ShowCalculator()
{
  document.getElementById(MC_ID+"MortgageCalculator").style.left=((f_clientWidth()-757)/2)+"px";
  MC_ShowDialog(MC_ID+"MortgageCalculator");
}
function MC_HideCalculator()
{
  if(MC_ToolTipTmr!=null){
    window.clearInterval(MC_ToolTipTmr);
    MC_ToolTipTmr=window.setInterval(MC_FadeToolTip,25);
  }
  MC_HideDialog(MC_ID+"MortgageCalculator");
}
function MC_ShowDialog(id)
{
  MC_DID=id;
  MC_Level=0;
  MC_Incr=25;
  MC_PositionBackDrop();
  var ids=MC_DID.split("|");
  for(i=0;i<ids.length;i++){
    document.getElementById(ids[i]).style.display="block";
  }
  if(MC_DID.indexOf("RateChangeDialog")==-1){
    document.getElementById("BackDrop").style.display="block";
  }
  MC_Tmr=window.setInterval(MC_FadeDialog,25);
}
function MC_HideDialog(id)
{
  MC_DID=id;
  MC_Level=99;
  MC_Incr=-25;
  MC_Tmr=window.setInterval(MC_FadeDialog,25);
}
function MC_PositionBackDrop()
{
  document.getElementById("BackDrop").style.width=(f_scrollWidth())+"px";
  document.getElementById("BackDrop").style.height=(f_scrollHeight())+"px";
}
function MC_FadeDialog()
{
  if((MC_Level<99&&MC_Incr==25)||(MC_Level>0&&MC_Incr==-25)){  
    MC_Level=MC_Level+MC_Incr;
    if(MC_Level>99){
      MC_Level=99;
    }
    else{
      if(MC_Level<0){
        MC_Level=0;
      }
    }
    var ids=MC_DID.split("|");
    for(i=0;i<ids.length;i++){
      document.getElementById(ids[i]).style.opacity="."+MC_Level;
      document.getElementById(ids[i]).style.filter="progid:DXImageTransform.Microsoft.alpha(opacity="+MC_Level+")";
    }    
    if(MC_DID.indexOf("RateChangeDialog")==-1){
      document.getElementById("BackDrop").style.opacity="."+(Math.round(MC_Level/1.3));
      document.getElementById("BackDrop").style.filter="progid:DXImageTransform.Microsoft.alpha(opacity="+(Math.round(MC_Level/1.3))+")";
    }
  }
  else{
    window.clearInterval(MC_Tmr);
    MC_Tmr=null;
    if(MC_Incr==-25){
      var ids=MC_DID.split("|");
      for(i=0;i<ids.length;i++){
        document.getElementById(ids[i]).style.display="none";        
      }      
      if(MC_DID.indexOf("RateChangeDialog")==-1){
        document.getElementById("BackDrop").style.display="none";
      }
    }
  }
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_scrollHeight() {	
  if(document.body){
    return f_filterResults (
      0,
	    0,
	    document.body ? document.body.scrollHeight : 0
	  );
  }
  else{
    return f_filterResults (
      0,
	    document.documentElement ? document.documentElement.scrollHeight : 0,
	    document.body ? document.body.scrollHeight : 0
	  );
  }		
}
function f_scrollWidth() {	
  if(document.body){
    return f_filterResults (
      0,
	    0,
	    document.body ? document.body.scrollWidth : 0
	  );
  }
  else{
    return f_filterResults (
      0,
	    document.documentElement ? document.documentElement.scrollWidth : 0,
	    document.body ? document.body.scrollWidth : 0
	  );
  }		
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function findPos(obj) {
	var curleft=0;
	var curtop=0;
  if(obj.offsetParent){
    do{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
    }while(obj=obj.offsetParent);
  }
  return [curleft,curtop];
}


/**************************************************************/
/*                    CALCULATION FUNCTIONS                   */
/**************************************************************/
function MC_Calculate()
{
  MC_RemoveOutOfRangeRates();
  document.getElementById("UserInput").disabled=true;
  document.getElementById("CommandRow").style.display="none";
  document.getElementById("WaitRow").style.display="block";
  document.getElementById("Projections").style.display="none";
  MC_ChangeView(document.getElementById(MC_ID+"SummaryTab"),1);
  MC_RequestCalculations();
  MC_Warning=false;
}
function MC_RequestCalculations()
{
  MC_Req=null;
  if(window.XMLHttpRequest){
    MC_Req = new XMLHttpRequest();
  }
  else {
    if(window.ActiveXObject){
      MC_Req = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else{
      if(window.ActiveXObject){
        //For IE 6+
        MC_Req = new ActiveXObject("Msxml2.XMLHTTP");
      }
      else{
        MC_HideProgress();
        MC_ShowToolTip("Sorry, your browser does not support the mortgage calculator",document.getElementById("CalculateButton"),3000);
      }
    }
  }
  if(MC_Req){
    var emailAddr=MC_Email;
    var inputEmailAddr=document.getElementById(MC_ID+"EmailAddressTextBox").value;
    if(MC_Mode==2){
      emailAddr=inputEmailAddr;
    }
    else{
      if(inputEmailAddr!=""){
        var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
        var regex = new RegExp(emailReg);
        if(regex.test(inputEmailAddr)){
          emailAddr=inputEmailAddr;
        }
      }
    }
    var reqData="<mortgages stage='"+MC_Stage+"' mode='"+MC_Mode+"'><guid>"+MC_GUID+"</guid><siteName>"+MC_Portal+"</siteName><emailType>1</emailType><emailAddress>"+emailAddr+"</emailAddress><mortgage>";
    reqData=reqData+"<amount>"+document.getElementById(MC_ID+"AmountBorrowedTextBox").value+"</amount>";
    reqData=reqData+"<rates>";
    reqData=reqData+"<entry>";
    reqData=reqData+"<rate>"+document.getElementById(MC_ID+"InterestRateTextBox").value+"</rate>";
    reqData=reqData+"<type>"+(document.getElementById(MC_ID+"FixedRateRadio").checked?"1":"2")+"</type>";
    reqData=reqData+"<effective>0</effective>";
    reqData=reqData+"<period>1</period>";
    reqData=reqData+"</entry>";
    if(document.getElementById("AdditionalRates").style.display=="block"){
      var rates=document.getElementById("RateChangesSpan").childNodes;
      var i=0;
      while(i<rates.length){        
        var rateDtls=rates[i].i_value.split("|");
        reqData=reqData+"<entry>";
        reqData=reqData+"<rate>"+rateDtls[0]+"</rate>";
        reqData=reqData+"<type>"+rateDtls[1]+"</type>";
        reqData=reqData+"<effective>"+rateDtls[2]+"</effective>";
        reqData=reqData+"<period>"+rateDtls[3]+"</period>";
        reqData=reqData+"</entry>";
        i++;
      }
    }
    reqData=reqData+"</rates>";
    reqData=reqData+"<term>"+document.getElementById(MC_ID+"RepaymentPeriodTextBox").value+"</term>";
    reqData=reqData+"<termType>"+(document.getElementById(MC_ID+"RepayYearsRadio").checked?"1":"2")+"</termType>";
    reqData=reqData+"<firstPayment>"+document.getElementById(MC_ID+"FirstRepaymentTextBox").value+"</firstPayment>";
    reqData=reqData+"</mortgage></mortgages>";
    MC_Req.open("POST",window.location,true);
    MC_Req.setRequestHeader('Content-Type', "text/xml");   
    MC_Req.onreadystatechange = MC_GetResponse; 
    MC_Req.send(reqData);
  }
}
function MC_GetResponse()
{
  if(MC_Req.readyState==4)
  {
    MC_HideProgress();
    if(MC_Mode==1){
      if(MC_Req.status==200&&MC_Req.responseText!=""){
        document.getElementById("Results").innerHTML=MC_Req.responseText;
        document.getElementById("Projections").style.display="block";
      }
      else{
        MC_ShowToolTip("Sorry, a problem occurred calculating your morgage projections",document.getElementById("CalculateButton"),3000);
      }    
    }
    else{
      document.getElementById("Projections").style.display="block";
      if(MC_Req.status==200&&MC_Req.responseText=="success"){
        MC_ShowToolTip("Your mortgage projections have been successfully e-mailed to you",document.getElementById("EmailProjectionsButton"),3000);
      }
      else{
        MC_ShowToolTip("Sorry, a problem occurred sending your mortgage projections",document.getElementById("EmailProjectionsButton"),3000);
      }      
    }
  }
}
function MC_HideProgress()
{
  document.getElementById("UserInput").disabled=false;
  document.getElementById("CommandRow").style.display="block";
  document.getElementById("WaitRow").style.display="none";
}
function MC_ChangeView(obj,stage)
{
  var tabChange=false;
  if(obj.className.indexOf("Active")==-1){
    var spans=obj.parentNode.getElementsByTagName("span");
    var i=0;
    while(i<spans.length){
      if(spans[i]!=obj&&spans[i].className.indexOf("Active")>-1){
        spans[i].className="Tab";
        spans[i].childNodes[0].src=spans[i].childNodes[0].src.substr(0,spans[i].childNodes[0].src.indexOf("-selected"))+".gif";
        i=spans.length;
      }
      else{
        i++;
      }
    }
    obj.className="Tab Active";
    obj.childNodes[0].src=obj.childNodes[0].src.substr(0,obj.childNodes[0].src.indexOf(".gif"))+"-selected.gif";
    tabChange=true;
  }
  MC_Stage=stage;
  MC_Mode=1;
  return(tabChange);
}