//32 urls
var solutionUrls = []
var serviceUrls = []

var totalSol = 2000;
var totalSer = 500;
var totalPack = 0; 

var dtmf = 0;
var transfer = 0;
var video = 0;
var g729 = 0;
var chat = 0;
var lines = 0;

var dtmfCost = 250;
var transferCost = 500;
var videoCost = 500;
var g729Cost = 500;
var chatCost = 250;

/* ------------------------ */

function buy(type){
	scanCheckboxes(type);
	var index = ((chat<<4)|(g729<<3)|(transfer<<2)|(video<<1)|dtmf);
	var url="";
	
  if (type == 'sol'){
     url = 'https://usd.swreg.org/cgi-bin/s.cgi?s=119097&p=119097-6&q=1&v='+index+'&d=0'; 	
	} else if (type == 'ser'){
	   url = 'https://usd.swreg.org/cgi-bin/s.cgi?s=119097&p=119097-7&q=1&v='+index+'&d=0';
	}
  	
  window.location = url;
}

function binary(value){
   if (value==true){
     return 1;
   }else{
     return 0;
   }	
}
     
function scanCheckboxes(type){
  dtmf = binary($('.'+type+' .dtmf').prop("checked"));
  video = binary($('.'+type+' .video').prop("checked"));
  transfer = binary($('.'+type+' .transfer').prop("checked"));
  g729 = binary($('.'+type+' .g729').prop("checked"));
  chat = binary($('.'+type+' .chat').prop("checked"));
  lines = binary($('.'+type+' .lines').prop("checked"));
}     
     
function recountTotal(licenseType, featureType, action) {

  scanCheckboxes(licenseType);
  
  if (licenseType == "ser") {
    totalSer = 500 + dtmfCost*dtmf + transferCost*transfer + videoCost*video + g729Cost*g729 + chatCost*chat;
    $('.last_tr .'+licenseType).html('$'+totalSer); 
  } else if (licenseType == "sol"){
    totalSol = 2000 + dtmfCost*dtmf + transferCost*transfer + videoCost*video + g729Cost*g729 + chatCost*chat;
    $('.last_tr .'+licenseType).html('$'+totalSol);
  }
}
     
$(function() {  
    
    $("#getLicense").click(function() {
      window.location = 'http://flashphoner.com/license';
    });

    $("#download").click(function() {
      window.location = 'http://docs.flashphoner.com/display/FPN/Downloads';
    });

    $(".buy").click(function() {
      buy($(this).attr('id'));
    });
    
    $(".get").click(function() {
      window.location = 'http://flashphoner.com/license';
    });

    $("#developer").click(function() {
      $(".dev").css('opacity','1');
      $(".sol").css('opacity','0.15');
      $(".ser").css('opacity','0.15');
    });
    
    $("#service").click(function() {    
      $(".dev").css('opacity','0.15');
      $(".sol").css('opacity','0.15');
      $(".ser").css('opacity','1');
    });    

    $("#solution").click(function() {    
      $(".dev").css('opacity','0.15');
      $(".sol").css('opacity','1');
      $(".ser").css('opacity','0.15');
    });
    
    $(".priceButton").mousedown(function() {    
      $(this).css('border-style', 'inset');
    }).mouseup(function() {    
      $(this).css('border-style', 'outset');
    });
    
    $("input:checkbox").click(function() {    
      var licenseType = $(this).parent().attr('class'); 
      recountTotal(licenseType);
    });
    
    $("#20lines").click(function() {    
      window.location = '';
    });

    $("#6monthsUpdates").click(function() {    
      window.location = '';
    });
    
    $("#3monthsSupport").click(function() {    
      window.location = '';
    });
    
    $("#lmonthSupport").click(function() {    
      window.location = '';
    });
    
    $("#callme").click(function() {    
      window.open('http://flashphoner.com/flashphoner_client/click2call.html','_blank','width=320,height=240,resizable=no,toolbar=no,menubar=no,location=no,status=no,scrollbar=no')
    });

});

