var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);
 
function getDocumentHeight() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}

function RotateExp(id){
if (strpos($(id).src,'images/expand1.gif',0)!=false)
	$(id).src='images/collapse1.gif';
	else
	$(id).src='images/expand1.gif'
}
function strpos( haystack, needle, offset){

    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}

function ChangeTab(t){
	//if ($('status').value=='0')
	{
	
	
	$j("div#container-1 ul li a").attr("class","tabs-disabled").attr("className", "tabs-disabled");
	$j("#" + t).attr("class", "tabs-selected").attr("className", "tabs-selected");
	
//	setTimeout("$j('#footer').css('top',(getDocumentHeight()-parseInt($j('#footer').css('height')))+'px')",200);
	}
	
}
function simple_tooltip(target_items, name,t,z){
	$j(target_items).each(function(i){
		$j("body").append("<div class='"+name+"' id='"+name+z+i+"'><p>"+t+"</p></div>");
		var my_tooltip = $j("#"+name+z+i);
		$j(this).removeAttr("title").mouseover(function(){
			my_tooltip.css({opacity:0.9, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
		my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
			my_tooltip.fadeOut(400);
		});
	});
}
$j(document).ready(function(){
//create tooltips
	simple_tooltip("#tool_tip1","tooltip","This is the setting by default. It means that you agree to wait for the results after your text is uploaded.<br>Depending on the amount of text and your internet connection the waiting time can vary",1);
	simple_tooltip("#tool_tip2","tooltip","If you do not wish to spend time waiting for the plagiarism results of the uploaded text - <br> simply check this option, upload the text, and click the analyze button. <br>The results will be sent to your email, for you to review later, when you have time.",2);
	simple_tooltip("#tool_tip3","tooltip","Use the accurate account engine to find more plagiarism. <br>The accurate account engine is much more effective in comparison with the free account engine.<br> This setting is set by default.",3);
	simple_tooltip("#tool_tip4","tooltip","Use the Free account engine to compare results with the accurate account engine. <br>The free account engine is the same as the engine used in the free account.  ",4);
	simple_tooltip("#tool_tip5","tooltip","You can either copy/paste your text to the search box on your right,<br> or use the upload feature, to search text in the file.<br> Files supported are: <b>.txt, .doc, .docx</b>",5);
	
//build tabs	
 $j('#container-1').tabs();
//generate animated functions
  $j(".btn-slide").toggle(
		function(){
			$j(".panel").animate({"width": "-=340px",opacity: "hide"}, "fast",'',function(){$j(".panel").css("display", "none");});
			
			$j(this).toggleClass("active"); return false;

		},
		function(){
		try{
			$j(".panel").css("width", "340px").css("display", "table-cell");
			}catch(e){}
			$j(".panel").animate({"width": "+=0px"}, "fast");
			$j(this).toggleClass("active"); return false;
		}
	);

	
 $j("#hide_pref2").toggle(function(){$j("#pref2").slideToggle("fast");},function(){$j("#pref2").slideToggle("fast");});
 $j("#hide_pref1").toggle(function(){$j("#pref1").slideToggle("fast");},function(){$j("#pref1").slideToggle("fast");});
 $j("#saved_hide").toggle(function(){$j("#saved_h").slideToggle("fast");},function(){$j("#saved_h").slideToggle("fast");});
 $j("#recent_hide").toggle(function(){$j("#recent_s").slideToggle("fast");},function(){$j("#recent_s").slideToggle("fast");});	
 $j("#hide_upload1").toggle(function(){$j("#upload_f").slideToggle("fast");},function(){$j("#upload_f").slideToggle("fast");});		
 $j("#hide_results").toggle(function(){$j("#show_results").slideToggle("fast");},function(){$j("#show_results").slideToggle("fast");});		
 if (typeof(FileUploaded)=='function') FileUploaded();
	RZ();
 GetAllHistory();
 
});
function RZ(){
try{
if (getDocumentHeight()<document.documentElement.clientHeight)
	h=document.documentElement.clientHeight;
	else
	h=getDocumentHeight();

$j("#bd").css("min-height",h-parseInt($j('#footer').css('height'))+'px');
 }catch(e){}

}
//------------ get recents history or saved reports
function GetAllSavedRep(t){
$('main_text').style.display='none';
$('text_on_main').style.display='block';
$('text_on_main').innerHTML='<img style="padding:20px 0 20px 28px;" src="images/small_loader_green.gif">';

new Ajax.Request('newp.php',{method:'POST',parameters:{act:'all_saved_rep',type:t},onSuccess:
		function(request){
			$('text_on_main').innerHTML=request.responseText;
		}
	})

}


function GetAllHistory(){
try{
$('text_on_main').style.display='none';
$('main_text').style.display='block';
GetHistory('scan_history','recent_s');
GetHistory('saved_reports','saved_h');
}catch(e){}
}
function GetHistory(action,div){
try{
$(div).innerHTML='<img style="padding:20px 0 20px 28px;" src="images/small_loader_green.gif">';
new Ajax.Request('newp.php',{method:'POST',parameters:{act:action},onSuccess:
		function(request){
			$(div).innerHTML=request.responseText;
		}
	})
}catch(e){}
}


function abcdef(mode){
if (mode=='print'){
	pr = $('output').innerHTML;
	newWin=window.open('','printWindow','Toolbar=0,Location=0,Directories=0,Status=0,Menubar=0,Scrollbars=0,Resizable=0'); 
	newWin.document.open(); 
	newWin.document.write(pr); 
	newWin.print();
	newWin.document.close();
}
if (mode=='mail'){
	var tt=$('output').innerHTML;
	var mails = $('mail_user_send').value; 
	new Ajax.Request ('pdfc.php', {method:'POST',parameters:{text:tt,moder:mode,mail:mails}, onSuccess:function(request){
	//$('output').innerHTML=  request.responseText;
	}});
}
if (mode=='pdf'){
	var tt=$('output').innerHTML;
	new Ajax.Request ('pdfc.php', {method:'POST',parameters:{text:tt,moder:mode}, onSuccess:function(request){
	myTempWindow = window.open(request.responseText,'SaveMe','Toolbar=0,Location=0,Directories=0,Status=0,Menubar=0,Scrollbars=0,Resizable=0'); 
	}});
	new Ajax.Request ("newp.php", {method: "post", parameters: {act:'save_history',simil:$('plagiate').innerHTML,rep:$('output').innerHTML,pages:PD.total_sentences,type:'save'}});
}
}

function testSRC(){

	var v=$('src').value;
	if (v=='') {alert('Select file'); return false;}
	else{
	
		var ext=v.substr(v.length-4,4);
		var ext=ext.toUpperCase();
		//alert(ext);
		if ((ext=='.DOC')||(ext=='.TXT')||(ext=='DOCX'))
			document.uploaded_file.submit();
		else {
			alert('Wrong file format.Please upload .doc or .docx or .txt or .html file');
		}
	}
}

function enabled(){
//alert($('srctext').value.ismorethan (10, 3));
 //(PD.text.ismorethan (10, 3))
//alert($('srctext').value);
//alert($('srctext').value.ismorethan (10, 3));
try{
if ($('srctext').value!='')
{
if ($('srctext').value.ismorethan (5, 2))
	{
		$('analyzebtn').disabled=false;
		$('btn_analyze').src="images/analyze.jpg";
		return true;
	}
else {
		$('analyzebtn').disabled=true;
		//$('btn_analyze').src="images/analyze_disabled.jpg";
		return false;
	}
}
else
	{
		$('analyzebtn').disabled=true;
		//$('btn_analyze').src="images/analyze_disabled.jpg";
		return false;
	}
}catch(e){}
}
function RunAnalyze(){
if (enabled()==true) PD.startAnalyze();
}
function checkLogin(){
/*if	(($('uid').value!='')&&($('pwd').value!=''))
	$('login_button').style.background='url(/images/login_btn.jpg)';
	else
	$('login_button').style.background='url(/images/login_btn_disabled.jpg)';
*/
}

function CheckFormLogin(){
if	(($('uid').value!='')&&($('pwd').value!='')) return true;
	else return false;
}

function GetSavedReport(dt,tp){
$('main_text').style.display='none';
$('text_on_main').style.display='block';
$('text_on_main').innerHTML='<img src="images/big_loader_black.gif">';
new Ajax.Request('newp.php',{method:'POST',parameters:{act:'get_save_rep',d:dt,t:tp},onSuccess:
		function(request){
			delim=request.responseText.split('####@@@####');
			//$('text_on_main').innerHTML=request.responseText;
			$('domains').innerHTML=delim[0];
			$('working2').innerHTML=delim[1];
			PD.sndmn=delim[2].split('@#@@@#@');
			sntt3=delim[3].split('@#@@@#@');
			PD.totalwords=delim[4];
			PD.foundedwords=delim[5];
			$('sentences_count').innerHTML=delim[6];
			for (pok=0;pok<PD.sndmn.length;pok++) if (PD.sndmn[pok]=='') PD.sndmn[pok]=String.noSuchProperty;
			for (pok=0;pok<PD.sndmn.length;pok++) if (sntt3[pok]=='') sntt3[pok]=String.noSuchProperty;
			$('domains').style.display='block';
			$('working2').style.display='block';
			$('leftbar2').style.display='block';	
			$('output_not_run').style.display='none';	
			$j('#hr_4').click();
		}
	})
}

function SBS(){
if ($('tbl_snt').style.display!='none'){
	$('tbl_snt').style.display='none';
	$('output').style.display='block';
	$('sbs_p').src='images/opfview.jpg';	
	
}else{
	$('tbl_snt').style.display='block';
	$('output').style.display='none';
	
	$('sbs_p').src='images/sbs.jpg';
}

}

function GetBalance(){
new Ajax.Request('newp.php',{asynchronous:false,method:'POST',parameters:{act:'get_balance'},onSuccess:
		function(request){
			$('days_left').innerHTML=request.responseText;
		}
	})

}