﻿// JScript File

function addToFavorites(sErrorMessage) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(document.title, location.href, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', location.href);
        elem.setAttribute('title', document.title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(location.href, document.title);

    else {
        alert(sErrorMessage);
    }    
}

//function showEmailWindow(link) {
//    var slink = link + '/SendEmail.aspx?link=' + location.href;
//    var win = window.open(slink, 'SendEmail', 'left=200px,top=200px,width=520px,height=500px,scrollbars=0,location=0,menubar=0,statusbar=0,toolbar=0,resizable=0,modal=no');

//}

//function showShareYourStory(link) {
//    var slink = link + '/Share_Your_Story.aspx?link=' + location.href;
//    //var slink = '../ShareYourStory.aspx?link=' + location.href;
//    var win = window.open(slink, 'ShareYourStory', 'left=10px,top=10px,width=1000px,height=800px,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=0,modal=no');

//} 

function showVideoWindow(link)
  {
       //var slink = link + 'VideoPopup.aspx?link=' + location.href;
       var browser=navigator.appName;
       var win = window.open(link,'Popup',"left=200px,top=140px,width=640px,height=390px");

      }

function checkFileUpload(control) {
	var ccontrol = document.getElementsByName(control)[0];
	if (ccontrol.value.length >= 1) {
		var ccontrol1 = ccontrol.cloneNode(true);
		ccontrol1.onchange = ccontrol.onchange;
		ccontrol.parentNode.replaceChild(ccontrol1, ccontrol);
	}
}

function calculateSubTotal(qty,lprice,disc,stotal)
{
    var cqty = document.getElementById(qty);
    var clprice = document.getElementById(lprice);
   var cdisc = document.getElementById(disc);
    var csubt =  document.getElementById(stotal);
     var lp = 0;
     var di = 0;
     var qt = 0;
     var ssubt = 0;
     qt = cqty.value;
     lp = clprice.value;
     di = cdisc.value;
     //if (IsDecimal(lp) == true && IsDecimal(di) == true && IsInt(qt) == true)
     if (!(isNaN(qt) || isNaN(di) || isNaN(lp)))
     {
     ssubt = (qt * lp) - di;
     csubt.value = ssubt.toFixed(2); 
     }
      
}

function CheckUncheckAll(cbid,gvid)
{    
    var gv = document.getElementById(gvid);
    var cell;
    if (gv.rows.length > 0)
    {
      for (i=0;i<gv.rows.length;i++)
        {
            cell = gv.rows[i].cells[0];
            for (j=0;j<cell.childNodes.length;j++)
              {
                if (cell.childNodes[j].type == "checkbox")
                    {
                        cell.childNodes[j].checked = document.getElementById(cbid).checked;
                    }
              }
        }
     }               
}

function IsDecimal(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
   function IsInt(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

  /* code for switching background images in master pages */
   var imgArr = new Array("http://www.cytoritx.com/App_Images/navigation/madrid_nav01.jpg", "http://www.cytoritx.com/App_Images/navigation/madrid_nav02.jpg", "http://www.cytoritx.com/App_Images/navigation/madrid_nav03.jpg");
   var imgArr2 = new Array("http://www.cytoritx.com/App_Images/navigation/nav11.jpg", "http://www.cytoritx.com/App_Images/navigation/nav12.jpg", "http://www.cytoritx.com/App_Images/navigation/nav13.jpg");
   var imgArr4 = new Array("http://www.cytoritx.com/App_Images/navigation/nav51.jpg", "http://www.cytoritx.com/App_Images/navigation/nav52.jpg", "http://www.cytoritx.com/App_Images/navigation/nav53.jpg");
   var imgArr5 = new Array("http://www.cytoritx.com/App_Themes/cytori/spacer.gif");  
   
   function doMenu(divName) {
       $(document).ready(function() {

           divName.length > 6 ? arr = eval("imgArr" + divName.substr(divName.length - 1, 1)) : arr = imgArr;
           divName = "#" + divName;
           if ($(divName).length) { $(divName).css("display", "none"); }
           var dDiv = $(divName + "Menu");
           if (dDiv.length) {    /* if exists */
               dDiv.css("display", "block");
               var dMenuTop = $(dDiv).css('height');
               dMenuTop = dMenuTop.substr(0, dMenuTop.length - 2) - 28;
               $(".rmRootGroup").css("margin-top", dMenuTop);   /* for primary, secondary, and generalpurpose master only */
               if (arr.length > 1) { chgImage(dDiv, 0, arr); }  /* ignore image rotation if flash-only master */
           }
       })
    }

   function chgImage(dDiv, start, arr) {
       if (start >= arr.length) { start = 0; }
       $(dDiv).css("background-image", "url(" + arr[start] + ")");
       window.setTimeout(function() {
           chgImage(dDiv, (start + 1), arr);
       }, 15000);
   }

   function checkLength(control, maxLength) {
       var ccontrol = document.getElementById(control);

       if (ccontrol.value.length > maxLength) {
           ccontrol.value = ccontrol.value.substring(0, maxLength);
       }
   }
