/**
 * JavaScript format string function
 * 
 */
String.prototype.format = function()
{
  var args = arguments;

  return this.replace(/{(\d+)}/g, function(match, number)
  {
    return typeof args[number] != 'undefined' ? args[number] :
                                                '{' + number + '}';
  });
};


// JavaScript Document

$(document).ready(function() {
	

	
	

setInterval(function() {
              $.post('login_exec.php',{type:'ping'},function (html) {
				html = $.trim(html);
			if(html=='expired')
			{
				jSuccess('Session Time Out. Please login again');
				window.location = 'index.html';
			}
		

	});
            }, 600000
 ); //set an interval timer up to repeat the function

	




});//document ends

  $(window).load(function() {
	changeLinkSize();
	$.post("../../data.php",function(data){
	var str=data.split('@@@');
	var fny=str[0].split('#fny#');
	var sel_fny =$("#fny_text_confirm").text();
	var temp="";
	for(i=0;i<fny.length-1;i++)
	{
		temp = "";
		if(fny[i]==sel_fny)
		temp = "selected='selected'";
	$("#fny_text").append("<option "+"value='"+fny[i]+"' "+temp+">"+fny[i]+"</option>");
	}
  });
  
    $('#transperent').hide();
  });

 $(window).resize(function() {
	changeLinkSize();
});
  
  
  function checkFinYear(inputID)
{
	var inputDate= $(inputID).val();
	if($.trim(inputDate)=='')
	return;
	inputDate=inputDate.split("/");
    var d2 = new Date(Number(inputDate[2]),Number(inputDate[1])-1,Number(inputDate[0]));
	d2 = d2.getTime();
	//var finYear = inputFinYear.toString().split("-");
	var finYear=sessionStorage.fny.split("-");
	var startFinYear=finYear[0];
	var endFinYear=finYear[1];
	var startDate = "01/04/20"+startFinYear;
	var endDate	=	"31/03/20"+endFinYear;
	
	startDate=startDate.split("/");
    var d1 = new Date(Number(startDate[2]),Number(startDate[1])-1,Number(startDate[0]));
	d1 = d1.getTime();
	
	endDate=endDate.split("/");
    var d3 = new Date(Number(endDate[2]),Number(endDate[1])-1,Number(endDate[0]));
	d3 = d3.getTime();
	
	if(d2<d1||d2>d3)
	{
	jError("Date Entered is outside the current Financial year "+$('#fny_text').text(),
	{
		autoHide : false,
		onClosed:function(){
		$(inputID).focus();	
	}								
	});
		
	return false;	
	}
	else
	return true;
	
}
  function changeLinkSize()
  {
	  	var url = window.location.pathname;
		var str = url.split('/');
		var buttonfont=($('.left-panel').width()/11);
		var buttonwidth=($('.left-panel').width()/1.8);
		var buttonheight=($('.left-panel').width()/5);
	  $('.button').css({'font-size':buttonfont,"width":buttonwidth,"height":buttonheight});
	  $('.left-content ul  a,.left-content ul  h3').css({'font-size':$('.left-panel').width()/11});
	  $('.left-content ul li span').css({'font-size':$('.left-panel').width()/9});
	  $('.left-content ul li a').css({'font-size':$('.left-panel').width()/11});
	 $('.left-content ul li a.cname_val').css({'font-size':$('.left-panel').width()/15});
	 // jSuccess(str[2]);
	 
	
	  if(str[2]=='sales'||str[2]=='purchase'||str[2]=='jobreg'||str[2]=='inventory'){
		   var statusColor = {sorder:"ORDER", spackinglist :"PACKINGLIST ",sinvoice :"INVOICE ",porder:"ORDER", preceivinglist :"RECEIVINGLIST ",pinvoice :"INVOICE ",jobissued:"JOB ISSUED", jobrecived:"JOB RECIVED", jobprocess:"JOB PROCESS", creditnote:"CERDIT NOTE", debitnote:"DEBIT NOTE", stockin:"STOCK IN", stockout:"STOCK OUT"}; 
		  var salesVal = "."+str[2];
		  var other = str[2];
		  $(salesVal).trigger('click');
		  $(".left-content ul li ul ol a."+other+"").css({'color':'#000','font-weight':'bolder' ,'font-size':$('.left-panel').width()/10});
		  $(".currenttab").text(" | "+statusColor[other]+" | ");
		  }
		  else{
			  var trgVal = "."+str[1];
			  var othersp = str[5];
			  var productr = "productreg";
			  var sorder   = "sales order";
			  var spackinglist   = "sales packing list";
			  var sinvoice   = "sales invoice";
			  
			  var pordre   = "purchase order";
			  var pinvoice   = "purchase invoice";
			   var preceivinglist   = "purchase receiving list";
			   $(trgVal).trigger('click');
			   $(".left-content ul li a."+othersp+"").css({'color':'#000','font-weight':'bolder' ,'font-size':$('.left-panel').width()/10});
			   		if(othersp=="productreg.php"){
						$(".currenttab").text(" | "+productr+" | "); 
					}
					else if(othersp=="sorder"){
						$(".currenttab").text(" | "+sorder+" | "); 
					}
					else if(othersp=="spackinglist"){
						$(".currenttab").text(" | "+spackinglist+" | "); 
					}
					else if(othersp=="sinvoice"){
						$(".currenttab").text(" | "+sinvoice+" | "); 
					}
					
					
					else if(othersp=="porder"){
						$(".currenttab").text(" | "+pordre+" | "); 
					}
					else if(othersp=="preceivinglist"){
						$(".currenttab").text(" | "+preceivinglist+" | "); 
					}
					else if(othersp=="pinvoice"){
						$(".currenttab").text(" | "+pinvoice+" | "); 
					}
					else{
			   			$(".currenttab").text(" | "+othersp+" | ");
					}
			  } 
	}

