var defines 	= new Array();
var defines1 	= new Array();
var defines2 	= new Array();
var visible	= 0;
var request = 0;

$(document).ready(function() {
	$('#dock').Fisheye({
		maxWidth: 35,
		items: 'a',
		itemsText: 'span',
		container: '.dock-container',
		itemWidth: 55,
		proximity: 90,
		halign : 'center'
	});
});
function only_numbers() {
	$("#license_number").keypress(function (e) {
		if( e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
			return false;
		}
	});
};
function sendSMS(){
	var license_code = $("#license_code").val();
	var sms_sender 	= $('#sms_sender').is(':checked');
	if ( (license_code == "") || (license_code == undefined) ) return false;
	var text 	= $.ajax({
		type    : "GET",
		url 	: "licence.php?action=sms_sender&license_sms="+license_code+"&sms_sender="+sms_sender,
		cache 	: false,
		async	: false
	}).responseText;
	$("div#sms_context").css({"display":"none"})
	$("div#sms_context2").css({"display" : "block"});
	$("div#sms_context2").html( text );
	clearDisplay();
}
function clearDisplay() {
	$("div#add_smssender").animate({
		opacity: 0
	}, 2500, function() {
		add_form(0);
    });
}
function insertBD() {
	var license_number 	= $("#license_number").val();
	var product_name	= $("#product_name").val();
	var client_name	= $("#client_name").val();
	var expiration	= $("#expiration").val();
	if (
		((license_number == "") || (license_number == undefined))
		||
		((product_name == "") || (product_name == undefined))
		||
		((client_name == "") || (client_name == undefined))
	) return false;
	var text 	= $.ajax({
		type    : "GET",
		url 	: "licence.php?action=into&license_number="+ license_number +"&product_name="+ product_name +"&client_name="+client_name+"&expiration="+expiration,
		cache 	: false,
		async	: false
	}).responseText;
	$("div#mess_context").html( text );
	setTimeout("OpenDatePicker('apps_licenses')", 1200);
	setTimeout("add_text(\""+text+"\")", 1200);
}
function add_text( text ) {
	add_form(1);
	$("div#mess_context").html(""+text+"");
}
function reset_date(current_date) {
	$("input#datepicker_from").val(current_date);
	$("input#datepicker_to").val(current_date);
	$("input#reg_code").val("");
}
function reset_name() {
	$("input#datepicker_name").val("");
}
function OpenDatePicker(tables, date_from, date_to) {
	var client = "";
	if (date_from == undefined) { date_from = $("input#datepicker_from").val(); }
	if (date_to == undefined) { date_to = $("input#datepicker_to").val(); }

	if (tables == 'download') {
		var country	= $("input#country_from").val();
		var product_name= $("input#pr_name").val();
	}
	if (tables == 'apps_licenses') {
		client = $("input#datepicker_name").val();
		if (client == undefined) client = "";
	}
	if (tables == 'sms_table') {
		var client	= $("input#reg_code").val();
		if (client == undefined) {
			client = "";
		}
	}
	if ((country == undefined) && (product_name == undefined)) {
		product_name 	= "";
		country 	= "";
	}
	var only_errors = $("#only_errors").is(":checked");
	var display_all = $("#display_all").is(":checked");
	var html	= $.ajax({
		url 	: "select_db.php?tables="+tables+"&date_from="+date_from+"&date_to="+date_to+"&country="+country+"&pr_name="+product_name+"&client="+client+"&reg_code="+client+"&only_errors="+only_errors+"&display_all="+display_all,
		cache 	: false,
		async	: false
	}).responseText;
	$('div#content').html(html);
	$("#myTable").tablesorter();
	$("#myTable1").tablesorter();
	$("#myTable2").tablesorter();
	defines = new Array();
	defines1 = new Array();
	datepicker();
}
function check_box(id, tables) {
	var check = document.getElementById(id);
	var checked_status = check.checked;
	$("input.select").each(function() {
		this.checked = checked_status;
		if (tables == 1) {
			defines[defines.length]		= this.id;
		} else if (tables == 2) {
			defines1[defines1.length]	= this.id;
		}
	});
	if (checked_status == false) {
		defines 	= new Array();
		defines1 	= new Array();
	}
}
function delete_bd(id) {
	if (id == "") return;
	var confirm_val = confirm("You sure you want to delete the message with ID: "+ id +"?");
	if (confirm_val == true) {
		for (var i = 0; i < id.length; i++) {
			$.ajax({
				type	: "POST",
				url	: "delete_applications.php",
				data	: "id="+ id[i]
			});
		}
	OpenDatePicker('messages');
	} else return;
}
function delete_bd1(id) {
	if (id == "") return;
	var confirm_val = confirm("You sure you want to delete the message with ID: "+ id +"?");
	if (confirm_val == true) {
		for (var i = 0; i < id.length; i++) {
			$.ajax({
				type	: "POST",
				url	: "delete_websites.php",
				data	: "id="+ id[i]
			});
		}
	OpenDatePicker('data');
	} else return;
}
function delete_bd2(id) {
	if (id == "") return;
	var confirm_val = confirm("You sure you want to delete the message with ID: "+ id +"?");
	if (confirm_val == true) {
		for (var i = 0; i < id.length; i++) {
			$.ajax({
				type	: "POST",
				url		: "delete_licences.php",
				data	: "id="+ id[i]
			});
		}
	OpenDatePicker('apps_licenses');
	} else return;
}
function add_search_form() {
	$('#content_table').animate( {
		height: 'toggle'
	}, "normal");
}
function select_id(id, tables) {
	if (tables == 1) {
		var check		= document.getElementById(id).checked;
		if (check == true) {
			defines[defines.length]	= id;
		} else {
			for (var i = 0; i < defines.length; i++) {
				if (defines[i] == id) {
					defines.splice(defines.indexOf(id), 1);
				}
			}
		}
	} else if (tables == 2) {
		var check		= document.getElementById(id).checked;
		if (check == true) {
			defines1[defines1.length]	= id;
		} else {
			for (var i = 0; i < defines1.length; i++) {
				if (defines1[i] == id) {
					defines1.splice(defines1.indexOf(id), 1);
				}
			}
		}
	} else if (tables == 3) {
		var check		= document.getElementById(id).checked;
		if (check == true) {
			defines2[defines2.length]	= id;
		} else {
			for (var i = 0; i < defines2.length; i++) {
				if (defines2[i] == id) {
					defines2.splice(defines2.indexOf(id), 1);
				}
			}
		}
	}
}
function delete_all(tables) {
	if (tables == 1) {
		delete_bd1(defines);
	} else if (tables == 2) {
		delete_bd(defines1);
	} else if (tables == 3) {
		delete_bd2(defines2);
	}
}
function add_form(val) {
	if (val == 1) {
		$("div#add_licences").css({"display" : "block"});
		$("input#product_name").focus().select();
		only_numbers();
	} else if (val == 2) {
		$("div#sms_context").css({"display":"block"})
		$("div#add_smssender").css({"display" : "block"});
		$("input#sms_context").focus().select();
	} else if (val == 0) {
		$("input#product_name").val("");
		$("input#license_number").val("");
		$("input#license_code").val("");
		$("input#exp_date").val("")
		$("div#add_licences").css({"display" : "none"});
		$("div#expiration").css({"display" : "none"});
		$("div#add_smssender").css({"opacity": "1"});
		$("div#add_smssender").css({"display" : "none"});
		$("div#sms_context2").css({"display" : "none"});
		$("input#exp_name").val("");
		$("div#client").css({"display" : "none"});
		$("div#mac").css({"display" : "none"});

	}else if (val == 3){
		$("div#expiration").css({"display" : "block"});
		//$("input#product_name").focus().select();
	}
	else if (val == 4){
		$("div#client").css({"display" : "block"});
		//$("input#product_name").focus().select();
	}
	else if (val == 6){
		$("div#mac").css({"display" : "block"});
			//$("input#product_name").focus().select();
			}
}
function RemoveImage(id, date_from, date_to) {
     $.ajax({
        type: "GET",
        url: "remove_image.php",
        data: "id="+id,
        success: function(){          
        }
     });
     OpenDatePicker('problem_reports', date_from, date_to);
}

function statusChange(id,elem){
	var cheked = $(elem).attr("checked");
	var value;
	if(cheked)
		value=1;
	else
		value=0;
	$.ajax({
        type: "GET",
        url: "licensetest.php",
        data: "id="+id+"&value="+value,
        cache:false,
        success: function(data){
        	if(data=="success"){
        		if(value==1)
        			$("#test_"+id).html("Yes");
        		else
        			$("#test_"+id).html("No");
        	}else if(cheked){
        		$(elem).attr("checked");
        	}else $(elem).removeAttr("checked");
        }
     });
	
}
function addid(id){
	$("#iduri").val(id);
	$("#exp_date").val($("#expid_"+id).text());
}
function editExpiration(){
	var id = $("#iduri").val();
	if ($("#exp_date").val() == "") 
		alert("No date inputed!");
	else {
		$("#expid_"+id).text($("#exp_date").val());
			$.ajax({
				type: "GET",
		        url: "expiration_edit.php",
		        data: "id="+id+"&date="+$("#exp_date").val(),
		        cache:false,
		        success: function(data){
					if(data=="success"){
						alert("Success Edited!");
						$("#expid_"+id).val($("#exp_date").val());
					}else alert("Edit Filed!");
				}
			})
		$("#iduri").val("");	
		$("#exp_date").val("")
		$("div#expiration").css({"display" : "none"});
	}
}
function editname(){
	var id = $("#iduri").val();
	if ($("#exp_name").val() == "") 
		alert("No date inputed!");
	else {
		$("#expide_"+id).text($("#exp_name").val());
			$.ajax({
				type: "GET",
		        url: "name_edit.php",
		        data: "id="+id+"&date="+$("#exp_name").val(),
		        cache:false,
		        success: function(data){
					if(data=="success"){
						alert("Success Edited!");
						$("#expide_"+id).val($("#exp_name").val());
					}else alert("Edit Filed!");
				}
			})
		$("#iduri").val("");	
		$("#exp_name").val("")
		$("div#client").css({"display" : "none"});
	}
}

function editmac(){
	var id = $("#iduri").val();
	if ($("#exp_mac").val() == "") 
		alert("No date inputed!");
	else {
		$("#expids_"+id).text($("#exp_mac").val());
			$.ajax({
				type: "GET",
		        url: "mac_edit.php",
		        data: "id="+id+"&date="+$("#exp_mac").val(),
		        cache:false,
		        success: function(data){
					if(data=="success"){
						alert("Success Edited!");
						$("#expids_"+id).val($("#exp_mac").val());
					}else alert("Edit Filed!");
				}
			})
		$("#iduri").val("");	
		$("#exp_mac").val("")
		$("div#mac").css({"display" : "none"});
	}
}

function delete_mac(id) {
	if (id == "") return;
	//var confirm_val = confirm("You sure you want to delete the mac with ID: "+ id +"?");
	//if (confirm_val == true) {
		
			$.ajax({
				type	: "GET",
				url	: "delete_mac.php",
				data	: "id="+ id
			});
		
	//OpenDatePicker('apps_licenses');
	//} else return;
}


// change language

$(document).ready(function(){
	
	var curent_lang = getCookie('lang');
        
    $('#lang').change(function() {   
        changeLang($(this).val());
		location.reload(true);	       	
	});	
       
   // $('#lang_flag').css({'background':'transparent url(./img/header/'+curent_lang+'.gif) no-repeat'});    
    $("#lang option[value='"+curent_lang+"']").attr('selected', 'selected');
    change_id();
	 
 }); 
  
  function getCookie(c_name)
  {
  if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
      {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
      }
    }
  return "";
  }
  
 
  
  function changeLang(lang){
	  setCookie("lang", lang, 30, '/' ); 
  }
  
  
  
  function change_id(val_id){
	
	val_id = (val_id != "" && val_id != null) ? val_id : "overview";
	switch(val_id)
	{
		case "overview" : 
		{
			$("#overview").attr("class", "flex_btn_over");
			$("#features").attr("class", "flex_btn");
			$("#spec_feat").attr("class", "flex_btn");
			$("#whats_new").attr("class", "flex_btn");
			$("#tech_car").attr("class", "flex_btn");
			
			$("#overview").mouseover(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#overview").mouseout(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#tech_car").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#tech_car").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#features").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#features").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#spec_feat").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#spec_feat").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#whats_new").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#whats_new").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			break;
		} 
		case "tech_car" : 
		{
			$("#tech_car").attr("class", "flex_btn_over");
			$("#overview").attr("class", "flex_btn");
			$("#features").attr("class", "flex_btn");
			$("#spec_feat").attr("class", "flex_btn");
			$("#whats_new").attr("class", "flex_btn");
			
			$("#tech_car").mouseover(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#tech_car").mouseout(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#overview").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#overview").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#features").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#features").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#spec_feat").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#spec_feat").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#whats_new").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#whats_new").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			break;
		} 
		case "features" : 
		{
			$("#overview").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#overview").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#tech_car").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#tech_car").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
									
			$("#spec_feat").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#spec_feat").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#whats_new").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#whats_new").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			$("#features").mouseover(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#features").mouseout(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#features").attr("class", "flex_btn_over");
			$("#overview").attr("class", "flex_btn");
			$("#spec_feat").attr("class", "flex_btn");
			$("#whats_new").attr("class", "flex_btn");
			$("#tech_car").attr("class", "flex_btn");
			break;
		} 
		case "spec_feat" : 
		{
			$("#overview").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#overview").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#tech_car").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#tech_car").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#features").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#features").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
								
			$("#whats_new").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#whats_new").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			$("#spec_feat").mouseover(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#spec_feat").mouseout(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#spec_feat").attr("class", "flex_btn_over");
			$("#overview").attr("class", "flex_btn");
			$("#features").attr("class", "flex_btn");
			$("#whats_new").attr("class", "flex_btn");
			$("#tech_car").attr("class", "flex_btn");
			break;
		} 
		case "whats_new" : 
		{
			$("#overview").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#overview").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#tech_car").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#tech_car").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			
			$("#features").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#features").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
								
			$("#spec_feat").mouseover(function(){
				$(this).removeClass("flex_btn").addClass("flex_btn_over");
			});
			$("#spec_feat").mouseout(function(){
				$(this).removeClass("flex_btn_over").addClass("flex_btn");
			});
			$("#whats_new").mouseover(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#whats_new").mouseout(function(){
				$(this).attr("class", "flex_btn_over");
			});
			$("#whats_new").attr("class", "flex_btn_over");
			$("#overview").attr("class", "flex_btn");
			$("#features").attr("class", "flex_btn");
			$("#spec_feat").attr("class", "flex_btn");
			$("#tech_car").attr("class", "flex_btn");
			break;
		} 
	}	
}

function changeCover ( ids ) {
	$("#photos_ids").html("<img src='/img/brochures/"+ids+".jpg'>");
}



