////////////////////////////////////
// Application Configuration file //
// Created By Jithin              //
// 16-09-2014			  //
// Aahocc Software Technologies   //
////////////////////////////////////

if(typeof Object.create !== 'function') {
    Object.create = function (o) {
        function F() {
        }

        F.prototype = o;
        return new F();
    };
}


var application = {
	name : "add-HRM",
    description:"Aadhocc Human Resource Management Software",
    path:"http://aadhocc.com/demo/AdminLTE-master",
    hompage:"http://addhrm.com/",
	version : "",
	author: {
                "name": "Aadhocc Software Technologies",
                "shortName":"Aadhocc",
                "email": "info@aadhocc.com",
                "url": "http://aadhocc.com/"
        },
        
	init: function(){ // Initial function.
		setTimeout(function(){ application.checkupdate(); },5000);
	},
	checkupdate : function(){
		$.getJSON("update/index.php",function(data){
	 	application.version 	= data.currentversion;
		
		latestVersion 	= data.latestversion;
		isNew			= data.message;
		console.log("checking for updates");
		$('.currentversion').html(data.currentversion);
		if(isNew == "latest"){
			var message = "You are using latest version";	
		}else{
			var message = 'New version '+latestVersion+' available. <span class="updateApp" data-version="'+latestVersion+'" style="cursor:pointer;">Click here to update</span>';
			application.update(latestVersion);
		}
		//$('.top-contact').html('<H2>'+application.name+' V.'+data.currentversion+'</H2><span class="statusMsg">'+message+'</span>');
		
		});
		
		console.log(message);
		
		
	},
	update : function(latestVersion){
		console.log("New version "+latestVersion +" available.");
		console.log("Downloading......");
			$.get('update/updater.php?nv='+latestVersion,function(data){
													   
				if(data=='Done'){	
				console.log("Finish Downloading.");
					application.extractingApp(latestVersion);
					
				}else{
					$('.statusMsg').html('Downloading faild. Please try later.');
				}
			});
	},
	extractingApp: function(nv){
	$('.statusMsg').html('Extracting New Version......');
		$.get('update/extracting.php?nv='+nv,function(data){
                    application.version = nv;
			if(data == 'ok'){
				location.reload(true);
				application.checkUpdates();
			}else{
				application.checkUpdates();	
			}
										  
		});
}
}

var app = Object.create (application); 
app.init(); 



