﻿// ajax for add-on

var xmlhttp;
var divInfo2;
function add_addon(adonID,qty,IsSubscription,divInfo)
{
if (qty == '')
{
document.getElementById(divInfo).style.color = "red";
document.getElementById(divInfo).innerHTML="Enter Add-on Count";
return false;
}
//var isSelection = channelName;
document.getElementById(divInfo).style.color = "#000";
//document.getElementById(divInfo).innerHTML = "Prosessing";
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return false;
  }
  var url="/addon-tosb.ashx";
url=url+"?AccessoriesID=" + adonID +"&Qty="+qty +"&IsSubscription=" + IsSubscription;
divInfo2 = divInfo;
//url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
return false;
} 

function stateChanged()
{
if (xmlhttp.readyState==4)
{

var response = xmlhttp.responseText;
if (response.indexOf("done") == 0)
{
        document.getElementById(divInfo2).style.color = "#000";
    window.location = location.href;
}
else
{
alert(response);
//window.location = location.href;
}
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function showHidePanel(caller,target)
{

elemTd=document.getElementById(target);
  enableDisabeValidators(caller);

if(caller.checked)
 elemTd.style.display="none";
else
 elemTd.style.display="block";

}

function calculateTotal(unitPriceSourceId,targetTotalId,targetAmountId,caller)
{
   amount=caller.options[caller.selectedIndex].value;
   
   if(targetTotalId=="txtHrTotal"   && amount=="")
   {
    document.getElementById("tblHrPrice").style.display='none';
    document.getElementById("tdAmountHRLabel").innerHTML="";
   }
   else if(targetTotalId=="txtHrTotal"   && amount!="")
   {
    document.getElementById("tblHrPrice").style.display='block';
    document.getElementById("tdAmountHRLabel").innerHTML="Amount payable for Hours";
   }
   else if(targetTotalId=="txtSMSTotal"   && amount=="")
   {
    document.getElementById("tblSMSPrice").style.display='none';
    document.getElementById("tdAmountSMSLabel").innerHTML="";
   }
   else if(targetTotalId=="txtSMSTotal"   && amount!="")
   {
    document.getElementById("tblSMSPrice").style.display='block';
    document.getElementById("tdAmountSMSLabel").innerHTML="Amount payable for SMS";
   }
   
   unitPrice=document.getElementById(unitPriceSourceId).value;
   targetTot=document.getElementById(targetTotalId);
   targetAmount=document.getElementById(targetAmountId);
   total=unitPrice*amount;
   targetTot.innerHTML = formatCurrency(total); //+targetTot.innerHTML;
   targetAmount.innerHTML = formatCurrency(amount);
  // setSubTotal();
}
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + num + '.' + cents);
}

function setSubTotal()
{
  totalAmountSms=document.getElementById('txtSMSTotal').innerHTML;
  totalAmountHrs=document.getElementById('txtHrTotal').innerHTML;
  document.getElementById('txtSubTotal').innerHTML=totalAmountSms*1+totalAmountHrs*1;
}

function checkCountry(ddlCountryDel,ddlCountryBill,delSame,chkTnS)
{
  
  ddlDel=document.getElementById(ddlCountryDel);
  ddlBill=document.getElementById(ddlCountryBill);
  chkDlSame=document.getElementById(delSame);
  if(chkTnS!=null)
  { 
      chkTandS=document.getElementById(chkTnS);
      
      if(!chkTandS.checked)
      {
        alert("Please read and accept the terms and conditions.");
        return false;
      }
  }

  
  selectionDelCountry=ddlDel.options[ddlDel.selectedIndex].value;
  selectionBillCountry=ddlBill.options[ddlBill.selectedIndex].value;
  
  checkValue=(!chkDlSame.checked)?true && selectionDelCountry!="GB":false ;
 
  if(checkValue || selectionBillCountry!="GB")
   {   
    alert("Currently our services are within UK only \n Please select UK as country")
    return false;
   }
  else
   return true;
  
}

function isSMSorHoursSelected(msglbl,ddlSMSList)
{

  msg=document.getElementById(msglbl);
  smsList=document.getElementById(ddlSMSList);
 
  
  sms=smsList.options[smsList.selectedIndex].value;
 
  
  if(sms=="")
  {
  msg.innerHTML="Please select at lease one out of SMSs and Hours to continue.";
  return false;
  }
  else
  {
  return true;
  }

}

function isServiceSelected(msglbl,ddlService)
{
  ddlServ=document.getElementById(ddlService);
  msg=document.getElementById(msglbl);
  
  service=ddlServ.options[ddlServ.selectedIndex].value;
   if(service=="")
   {
    msg.innerHTML="Please select an option to continue.";
    return false;
   }
   else
   {
     return true;
   }
}


function PopUp() {

  path = "/ShoppingCart/TermsAndCondition.aspx";
  width = 625;
  heigth = 325;
  javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
  return false;
            
}

function buttonPopUp(SystemID) {
  path = "/cameraSeletionPopup.aspx?SystemId="+SystemID;
  width = 625;
  heigth = 350;
  javascript: Telligent_Modal.Open(path, width, heigth);
  return false;

}

function packageButtonPopUp(SystemID) {
  path = "/PackageSelectionPopup.aspx?SystemId="+SystemID;
  width = 625;
  heigth = 250;
  javascript: Telligent_Modal.Open(path, width, heigth);
  return false;

}

function accessoriesButtonPopUp(AccessoriesID,SystemID) {
var lbl = document.getElementById(SystemID);
//alert(lbl.value );
  path = "/accessoriesSeletionPopup.aspx?AccessoriesID=" + AccessoriesID + "&Qty=" + lbl.value;
  width = 625;
  heigth = 450;
  javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
  return false;

}
function buttonPopUpHW() {

    path = "/cameraSeletionPopup.aspx";
    width = 625;
    heigth = 450;
    javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
    return true;

}
function feedBackPopUp() {

    path = "/feedBackPopUp.aspx?";
    width = 550;
    heigth =450;
    javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
    return false;

} 
  

function closePopup()
{
window.parent.Telligent_Modal.CloseNoBaseRefresh(true);
return true;
}       


function verifyTnC(chkTandS)
{
  chkTnS=document.getElementById(chkTandS);
  
  if(!chkTnS.checked)
  {
    alert("Please read and accept the terms and conditions.");
    return false;
  }
  else
  return true;
}

function selectCameraOrAccessories() {
    alert("The shopping cart has been updated. Click on the shopping cart at the top right corner");
    return true;
}
function noCopyMouse(e) {
    var isRight = (e.button) ? (e.button == 2) : (e.which == 3);

    if (isRight) {
//        alert('You are prompted to type this twice for a reason!');
        return false;
    }
    return true;
}

function noCopyKey(e) {
    var forbiddenKeys = new Array('c', 'x', 'v');
    var keyCode = (e.keyCode) ? e.keyCode : e.which;
    var isCtrl;

    if (window.event)
        isCtrl = e.ctrlKey
    else
        isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;

    if (isCtrl) {
        for (i = 0; i < forbiddenKeys.length; i++) {
            if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
//                alert('You are prompted to type this twice for a reason!');
                return false;
            }
        }
    }
    return true;
}

function userAccessoryDetails(AID) {
    path = "/userAccessoryDetailsPopUp.aspx?AID=" + AID;
    width = 625;
    heigth = 205;
    javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
    return false;

}

function cameraDetails(CID) {
    path = "/cameraDetails.aspx?CID=" + CID;
    width = 625;
    heigth = 405;
    javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
    return false;

}

function SMSPrice(ddSMS) {
var selectedVal = ddSMS.options[ddSMS.selectedIndex].value
if (selectedVal != '<-- Select -->')
{
document.getElementById("divSMSPrice").innerHTML = "£ " + selectedVal;
document.getElementById("divSMSPrice").style.color = "green";
}
else
{
document.getElementById("divSMSPrice").innerHTML = "";
}
    return false;
}

function StoragePrice(ddStorage) {
var selectedVal = ddStorage.options[ddStorage.selectedIndex].value;
if (selectedVal != '<-- Select -->')
{
document.getElementById("divRecording").innerHTML = "£ " + selectedVal;
document.getElementById("divRecording").style.color = "green";
}
else
{
document.getElementById("divRecording").innerHTML = "";
}
    return false;
}

function logintoSystem (to,p) {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    if (p[k] == "")
    {
        return;
    }
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}
function feedback(){
    path = "/ShoppingCart/feedBackPopUp.aspx";
    width = 625;
    heigth = 405;
    javascript: Telligent_Modal.OpenNoBaseRefresh(path, width, heigth);
    return false;
}