function saveTest()
{
	/* $(".saveTestPopup").fadeIn(1000,function(){
		$(".saveTestPopup").fadeOut();
	}); */
	showLoader();
	var totalArr = getShuffledQuestionArr(false);
	
	var totalStr = '[';

	for(var i=0; i<totalArr.length; i++)
	{
		var qImage = LZString.compressToBase64(totalArr[i].questImg);
		var aImage = LZString.compressToBase64(totalArr[i].questAnsImg);
		
		var queTxt = String(totalArr[i].questTxt).replace(/\"/g,'\\"');
		var ansTxt = String(totalArr[i].questAns).replace(/\"/g,'\\"');
		var titleTxt = String(totalArr[i].title).replace(/\"/g,'\\"');
		var queAddTxt = String(totalArr[i].addedQuest).replace(/\"/g,'\\"');
		
		totalStr += '{"num":"'+totalArr[i].num+'", "id":"'+totalArr[i].id+'", "questTxt":"'+queTxt+'", "questImg":"'+qImage+'","questAns":"'+ansTxt+'","questAnsImg":"'+aImage+'","questMark":"'+totalArr[i].questMark+'","title":"'+titleTxt+'","addedQuest":"'+queAddTxt+'"}';
		
		if(i<totalArr.length-1)
		totalStr += ', ';
	}		
	totalStr += ']';
	
	if(totalArr.length == 0)
		totalArr = '';
	
	
	
	//console.log(totalStr);
	uploadFile(totalStr);
	
	
}

function loadFile()
{
	showLoader();
	setTimeout(function(){
	var str = LZString.decompress(localStorage.getItem('tgSaveFile'));
	
	if(str != null && str.length>2)
	{
		var obj = JSON.parse(str);
		
		addedQuestions.length = 0;
		addedNewQuestions.length = 0;
		totalShuffleArr.length = 0;
		
		for(var i=0; i<obj.length; i++)
		{
			var qImage = LZString.decompressFromBase64(obj[i].questImg);
			var aImage = LZString.decompressFromBase64(obj[i].questAnsImg);
			
			if(qImage == null)
			qImage = '';
			if(aImage == null)
			aImage = ''
		
			
			if(obj[i].addedQuest == 'false'){
				console.log('loadFile01==', obj[i].addedQuest)
				addedQuestions.push({num:obj[i].num, id:obj[i].id, questTxt:obj[i].questTxt, questImg:qImage, questAns:obj[i].questAns, questAnsImg:aImage, questMark:obj[i].questMark, title:obj[i].title});
			}
			else
				addedNewQuestions.push({num:obj[i].num, id:obj[i].id, questTxt:obj[i].questTxt, questImg:qImage, questAns:obj[i].questAns,   questAnsImg:aImage, questMark:obj[i].questMark, title:obj[i].title});
			
			totalShuffleArr.push({num:obj[i].num, id:obj[i].id, questTxt:obj[i].questTxt, questImg:qImage, questAns:obj[i].questAns, questAnsImg:aImage, questMark:obj[i].questMark, title:obj[i].title, addedQuest:obj[i].addedQuest});
		}
		setAddToDetail("", true);//this function is addToTestDetail.js file
	}
	console.log('loadFile1==', addedQuestions.length, addedNewQuestions.length, totalShuffleArr.length)
	}, 500);
}
function checkLastPage()
{
	var str = localStorage.getItem('tgSaveFile');
	var strName = localStorage.getItem('tgSaveFileName');
	
	if(str != null && str.length > 2 && strName == tgTitle)
		return true;
	else
		return false;
}

function uploadFile(fullStr)
{
	console.log('uploadFile')
	//var jsonobj = {'sample': 'This is supposed to be ling string', 'score': 'another long string which is going to be compressed'}
	var jsonobj = fullStr;
    
   var string = fullStr;//JSON.stringify(jsonobj);
    
    //alert("Size of sample is: " + string); 
    
    var compressed = LZString.compress(string);
    
    /*localStorage.setItem('tgSaveFile', compressed);
    
     alert("Size of compressed sample is: " + localStorage.getItem('tgSaveFile').length); 
    
    alert("Compressed localstorage item is: " + localStorage.getItem('tgSaveFile')); 
    
    string = LZString.decompress(localStorage.getItem('tgSaveFile'));  */
    
   // alert("Decompressed sample is: " + compressed); 
	
	localStorage.setItem('tgSaveFile', compressed);
	localStorage.setItem('tgSaveFileName', tgTitle);
	//$(".saveTestPopup").hide();
	hideLoader();
}
function showLoader(){
	$(".saveTestPopup").show();
}
function hideLoader(){	
		$(".saveTestPopup").fadeOut();	
}