﻿// 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;
   }
