	google.load("search", "1.0");
	//---------------  UTILS FUNCTIONS ---------
	function Stopped(){
		$('cool_tips_a').style.display='none';
		$('status').value=0;
		$('anal_not_run').style.display='block';
		$('anal_run_email').style.display='none';
		$('anal_run').style.display='none';
		$('progress').style.display='none';
		$('output_not_run').style.display='block';
		$('leftbar2').style.display='none';
		$('working2').style.display='none';
		//$('working2').style.display='none';	
		setTimeout("$j('#hr_2').click();",1000);
	}
	function KillProc(){
	$('status').value=0;
	api_type=$j('input[name="prefer2"]:checked').val();
	if (api_type=='api_goog')
		PD.stopAnalyze();
	if (api_type=='api_plag'){
	}

	}
	
	function SubmitAnother(){
			//$('leftbar2').style.display='none';
			//$('working2').style.display='none';	
			$('leftbar').style.display='inline';
			$('working').style.display='inline';
			//$('srctext').value='';
			$('srctext').disabled=false;
			//$('btn_analyze').src="images/analyze_disabled.jpg";
			$('pdf_img').src="images/savereport_disabled.jpg";
			$('btn_stop_analyze').src='images/stopanalyze.jpg';
			

	
	}
	function getElementByClass(theClass) {
		allHTMLTags = new Array();
		result=new Array();
		j=0;
		allHTMLTags=document.getElementsByTagName('*');
		//Loop through all tags using a for loop
		for (i=0; i<allHTMLTags.length; i++) {
		//Get all tags with the specified class name.
			if (allHTMLTags[i].className==theClass) {
			//allHTMLTags[i].checked=false;
				result[j]=allHTMLTags[i];
				j++;
			}
		}
		return result;
	}
	function strpos( haystack, needle, offset){
    // Finds position of first occurrence of a string within another  
    // 
    // version: 810.1317
    // discuss at: http://phpjs.org/functions/strpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}
	function HideSourceces(){
	//alert(strpos($('btn_hidesrc').src,'_disabled',0));
	if(strpos($('btn_hidesrc').src,'_disabled',0)==false)
		{
			$('btn_showsrc').src="images/show_all_sim.jpg";
			$('btn_showsrc').style.cursor="pointer";
			$('btn_hidesrc').src="images/hidesource_disabled.jpg";
			$('btn_hidesrc').style.cursor="default";
			PD.checkDomain();
		}
	}
	function CheckAllC(){
	
		AllTag=new Array();
		 state=false;
		AllTag=document.getElementsByName('dmn_checkbox');
		for (i=0; i<AllTag.length; i++) {
			if (AllTag[i].checked==true) state=true;
		}
		if (state==true){
			//$('btn_showsrc').src="images/show_all_sim.jpg";
			$('btn_hidesrc').src="images/hidesource.jpg";
			$('btn_hidesrc').style.cursor="pointer";
			
			}
		 else{		 
			//$('btn_showsrc').src="images/show_all_sim_disabled.jpg";
			$('btn_showsrc').src="images/show_all_sim.jpg";
			$('btn_showsrc').style.cursor="pointer";
			$('btn_hidesrc').src="images/hidesource_disabled.jpg";
			$('btn_hidesrc').style.cursor="default";
			//$('plagiate').innerHTML = Math.round (PD.foundedwords * 1000 / PD.totalwords) / 10;
			}
			
	}
	
	function ShowAllSimilary(){
	if ($('btn_showsrc').style.cursor=="pointer"){
		AllTag2=new Array();
		AllTag2=document.getElementsByName('dmn_checkbox');
		
		for (z=0; z<AllTag2.length; z++) {
			if (AllTag2[z].checked==true) AllTag2[z].checked=false;//uncechk all checked
		
		}
		
		$j('input[name="dmn_checkbox"]').each(
			function(){
			$j('div.'+this.className).css('display','block');
		});
		
		$('plagiate').innerHTML = Math.round (PD.foundedwords * 1000 / PD.totalwords) / 10;

		//$('plagiate').innerHTML = Math.round (PD.found  * 1000 / PD.numAll) / 10;
		$('btn_showsrc').src="images/show_all_sim_disabled.jpg";
		$('btn_showsrc').style.cursor="default";
		$('btn_hidesrc').src="images/hidesource_disabled.jpg";
		$('btn_hidesrc').style.cursor="default";
	}
	}
	function trim (str, charlist) {
    var whitespace, l = 0, i = 0;
    str += '';
    
    if (!charlist) {
        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}	
	var $ = function (s) { return document.getElementById (s); };
	function extract (a, b) {
		var r = {};
		for (var k in a)
			r [k] = a [k];
			
		for (var k in b)
		if (typeof r [k] != 'undefined')
			delete r [k];
		
		return r;
	}
	function isempty (a) {
		for (var k in a)
			return false;
		
		return true;
	}
	//Kills the end of the string, leaving <=precent% of words in it
	String.prototype.shrink = function (percent) {
		var s = this.split (/\s+/);
		var i = s.length;
		
		while ( i * 100 > s.length * percent) i--;
		
		if (i == 0) i = 1;
		
		var res = [];
		for (var j = 0; j < i; j++)
			res [res.length] = s [j];
		
		return res.join (' ');
	}
	//Word count
	String.prototype.wordcount = function () {
		var s = this.split (/\s+/);
		return s.length;
	}
	//Checks for string more than words*charsperword
	String.prototype.ismorethan = function (words, charsperword) {
		var s = this.split (/\s/);
		
		var num = 0;
		
		for (var i = 0; i < s.length; i++)
			if (s [i].length >= charsperword)
				num++;
		
		return num >= words;
	}
	String.prototype.ismorethan2 = function (words, charsperword) {
	
		var s = this.split (/\s/);
		var l=s.length;
		
		//alert(l);
		var num = 0;
		var cc =false;
		
		for (var i = 0; i < s.length; i++)
			if (s [i].length >= charsperword) cc=true;
			
			
		//
		
		if ((l>=words)&&(cc) )  return true; else return false;
	}
	var sntt3 = new Array();
	var PD = {
		total_sentences: null,
		text : null,
		sentences : null,
		current : null,
		numAll : null,
		found : 0,
		foundWeb : 0,
		foundPDF : 0,
		foundBlog : 0,
		foundBook : 0,
		searchersLeft : 0,
		output4Sentence : null,
		domains : {},
		ignorelist : {},
		results : {},
		sntclength:0,
		totalwords:0,
		foundedwords:0,
		currentFoundN:0,
		sndmn: new Array(),
		
		onSearchComplete : function () {
		
			if (PD.sentences)
			{//we are analyzing something
			
				if (--PD.searchersLeft > 0)
					return;

				var res = [];
				
				var fnd = {web:false, pdf:false, blog:false, book:false};
				//alert(searcherWeb.results.length);
				if ($('sweb').checked)//for (var i = 0; i < 1; i++)
				for (var i = 0; i < searcherWeb.results.length; i++){
					
					//alert(searcherWeb.results[0]['url']);
					
					if (!searcherWeb.results[i]['url'].match(/\.pdf$/i)){
				
						res[res.length] = searcherWeb.results[i];
						fnd.web = true;					
					}
				}
				
				
				if ($('spdf').checked)
				for (var i = 0; i < searcherWeb.results.length; i++)if (searcherWeb.results[i]['url'].match(/\.pdf$/i)){
					res[res.length] = searcherWeb.results[i];
					fnd.pdf = true;					
				}
				
				if ($('sblog').checked)	for (var i = 0; i < searcherBlog.results.length; i++){
					res[res.length] = searcherBlog.results[i];
					fnd.blog = true;					
				}
				
				if ($('sbook').checked)	for (var i = 0; i < searcherBook.results.length; i++){
					res[res.length] = searcherBook.results[i];
					fnd.book = true;					
				}
				
				PD.output4Sentence.nodeValue = res.length;
				PD.output4Sentence = null;

				if (fnd.web  == true) {PD.foundWeb++;
				
				PD.foundedwords=PD.foundedwords+PD.sentences[PD.currentFoundN-1].wordcount();
				//if ((PD.currentFoundN-1)==6)
					//alert(PD.currentFoundN-1+'#'+PD.sentences[PD.currentFoundN-1].wordcount());
					//alert(PD.sentences[PD.currentFoundN-1]);
				}
				if (fnd.pdf  == true) PD.foundPDF++;
				if (fnd.blog == true) PD.foundBlog++;
				if (fnd.book == true) PD.foundBook++;
					
				if (res.length > 0){ //found something
					PD.found++;	
					
					PD.sndmn[PD.current]=new Array();
					for (var i = 0; i < res.length; i++)
					{
						if (typeof PD.domains [res [0]['url']] == 'undefined')
							PD.domains [res [0]['url']] = {};
						PD.domains [res [0]['url']] [i] = true;
						//alert(PD.domains [res [0]['url']] [i])	;
						if (typeof PD.results [PD.current-1] == 'undefined')
							PD.results [PD.current-1] = {};
						PD.results [PD.current-1] [res [i]['url']] = true;
						
						res [i]['html']['style']['cursor'] = 'pointer';
						res [i]['html'].onmouseover = function () {this.style.backgroundColor = "#fff";};
						res [i]['html'].onmouseout = function () {this.style.backgroundColor = "";};
						var dmn = res [i]['url'];
						
						
						PD.sndmn[PD.current]+=dmn+'#####';
						
						
						
						
						eval ('res ['+i+']["html"].onclick = function () {'+
						'	var a = $("domains").getElementsByTagName ("INPUT");'+
						'	'+
						'	for (var j = 0; j < a.length; j++)'+
						'	if (a [j] ["name"] == "'+dmn+'")'+
						'	{'+
						'		if (!a [j] ["checked"])'+
						'			a [j].click ();'+
						'		if (typeof window.scrolledToTopOnce == "undefined")'+
						'		{'+
						'			window.scroll (0,0);'+
						'			window.scrolledToTopOnce = true;'+
						'		};'+
						'		return;'+
						'	}'+
						'}');
						$('output').appendChild (res [i]['html']);
						
						
					}
				};

				
				if (PD.current >= PD.sentences.length){ //analyze complete					
					var a = PD.numAll;
					var b = PD.found;
					var c = PD.domains;
					var d = PD.results;
					var e = PD.foundWeb;
					var f = PD.foundPDF;
					var g = PD.foundBlog;
					var j = PD.foundBook;
					PD.stopAnalyze();
					PD.numAll = a;
					PD.found = b;
					PD.domains = c;
					PD.results = d;
					PD.outputDomains();
					//alert(PD.foundedwords);
					//NEW ALGORITHM
					a=PD.totalwords;
					b=PD.foundedwords;
					$('plagiate').innerHTML = Math.round (b * 1000 / a) / 10;
					$('cool_tips_a').style.display='none';
					$('anal_not_run').style.display='block';
					$('anal_run_email').style.display='none';
					$('anal_run').style.display='none';
					$('progress').style.display='none';
					
					//send result to email
					if ($j('input[name="prefer1"]:checked').val()=='sendemail')
						abcdef('mail');
					
					
					function loadPD(request){$('output').innerHTML = request.responseText;}

					try{
					new Ajax.Request ("newp.php", {method: "post", parameters: {
					act:'save_history',
					simil:$('plagiate').innerHTML,
					rep:$('working2').innerHTML,
					dom:$('domains').innerHTML,
					pages:PD.total_sentences,
					p_sndmn:PD.sndmn.join('@#@@@#@'),
					p_sntt3:sntt3.join('@#@@@#@'),
					p_t:PD.totalwords,
					f_t:PD.foundedwords,
					sc:$('sentences_count').innerHTML,
					type:'search'
					}});
					
					}catch(e){}

					try{new Ajax.Request ("plug2.php", {method: "post", parameters: {htmler:$('htmlview').value,domine:$('domains').innerHTML,pp:$('plagiate').innerHTML,id:$('output').innerHTML,uid:$('userid22').value}, onSuccess: loadPD});
					}catch (e){}
					try{new Ajax.Request ("getga.php", {method: "post", parameters: {htmler:$('htmlview').value,id:$('output').innerHTML}});
					}catch (e){}

					try{//change buttons
					//$('print_img').src="images/print.jpg";
					$('pdf_img').src="images/savereport.jpg";
					//$('email_img').src="images/email.jpg";
					}catch(e){}
					
					var s= "plagiarism=" + Math.round (b * 100 / a);
					if ($('sweb').checked)
						s += "&plagiarismWeb="+Math.round (b * 100 / a);
					if ($('spdf').checked)
						s += "&plagiarismPDF="+Math.round (f * 100 / a);
					if ($('sblog').checked)
						s += "&plagiarismBlog="+Math.round (g * 100 / a);
					if ($('sbook').checked)
						s += "&plagiarismBook="+Math.round (j * 100 / a);
					new Ajax.Request ('log.php?'+s, {method:"get"});
					
					$('status').value=0;
					$j('#hr_4').click();
    				return;	
					
				}
								
				PD.callSearch();
			}
		},

		callSearch : function () {
		
			if (PD.current == null)
				PD.current = 0;
			$('progress').innerHTML=(PD.current+1)+'/'+PD.sentences.length;
			var q = PD.sentences [PD.current];
			sntt3[PD.current] = PD.sentences [PD.current];
			//var q2 = q.shrink (70);
			var q2=q;
			var q3 = "<span class='marked'>" + q2 + "</span>" + q.substring (q2.length);
			PD.current++;
			
			
			var o = document.createElement ('DIV');
			o.className = "sentenceresult";
			PD.output4Sentence = document.createTextNode ("wait...");
			o.appendChild (PD.output4Sentence);
			o2 = o;
			
			var o = document.createElement ('DIV');
			o.className = "sentence";
			o.appendChild (o2);
			
			var o4 = document.createElement ('SPAN');
			o4.innerHTML = q3 + ".";
			
			o.appendChild (o4);
			$('output').appendChild (o);
			try{
			searcherWeb.clearResults();
			searcherBlog.clearResults();
			searcherBook.clearResults();
			}catch (e) {}
			PD.searchersLeft = 0;
			if ($('sweb').checked || $('spdf').checked)
			{
				PD.searchersLeft++;
				PD.currentFoundN++;
				searcherWeb.execute ('"' + q2.replace ('"', '') + '"');
				
			}
			if ($('sblog').checked)
			{
				PD.searchersLeft++;
				searcherBlog.execute ('"' + q2.replace ('"', '') + '"');
			}
			if ($('sbook').checked)
			{
				PD.searchersLeft++;
				searcherBook.execute ('"' + q2.replace ('"', '') + '"');
			}
		},
		
		checkDomain : function (dom, val) {
			 allelem=document.getElementsByName('dmn_checkbox');
			 for (dd=0;dd<allelem.length;dd++)
				if (allelem[dd].checked==true) PD.ignorelist [allelem[dd].id] = true;
					else
					delete PD.ignorelist [allelem[dd].id];
			var a=PD.totalwords;
			var b=PD.foundedwords;
			for (i=0;i<sntt3.length;i++){
				if (typeof PD.sndmn[i+1] != 'undefined'){
					where_found=PD.sndmn[i+1].split('#####');
					sovpad=0;
							for (dd=0;dd<allelem.length;dd++) if (allelem[dd].checked==true) {
								if (allelem[dd].id==where_found[0]) sovpad++;
								if (sovpad>0) break;
							}
						if (sovpad>0) b=b-sntt3[i].wordcount();
				}
			}
			//---------------------------------------- ALL ------------------------------
			$('plagiate').innerHTML = Math.round (b * 1000 / a) / 10;
			//build new table plagiate only
			$j('input[name="dmn_checkbox"]:checked').each(
			function(){
				$j('div.'+this.className).css('display','none');
			});
			$j('input[name="dmn_checkbox"]:not(:checked)').each(
			function(){
				$j('div.'+this.className).css('display','block');
			});
		},
		
		outputDomains : function () {
		color= ['DC143C','8A2BE2','0000FF','A52A2A','DEB887','5F9EA0',
				'7FFF00','D2691E','FF7F50','6495ED','00FFFF','008B8B','B8860B','A9A9A9','006400','BDB76B','8B008b','556B2F','FF8C00',
				'9932CC','8B0000','E9967A','8FBC8F','483D8B','00CED1','9400D3','FF1493','00BFFF','696969','1E90FF','B22222','DAA520',
				'808080','008000','ADFF2F','90EE90','D3D3D3','FFB6C1','FFA07A','20B2AA','87CEFA','778899','B0C4DE','FFFFE0','00FF00','32CD32',
				'00FF7F','4682B4','D2B48C','008080','FF6347','40E0D0','EE82EE','F5DEB3'];
		set_color = new Array();
		dmcnt=0;ci=0;
		lsnt = $('srctext').value.replace(/(\s|\n|\t|\r)+/g,' ').split(/\.\s|\!\s|\?\s/);
		new_snt = new Array;
		new_snt_found = new Array;
		table='<table border="0" width="200">';
			for (var k in PD.domains){
				//calculate % per domain
				a2=PD.totalwords;
				b2=0;
				for (pi=0;pi<sntt3.length;pi++){
				if (typeof PD.sndmn[pi+1] != 'undefined'){
						where_found=PD.sndmn[pi+1].split('#####');
						sovpad=0;
							if (k==where_found[0]) sovpad++;
							if (sovpad>0) {b2=b2+sntt3[pi].wordcount();
							new_snt[pi]=sntt3[pi];
							new_snt_found[pi]=k;
							set_color[pi]=color[dmcnt];
							}
				}
				}
				table+='<tr><td valign="center"><input class="'+color[dmcnt]+'" type="checkbox" onClick="CheckAllC();" onChange="CheckAllC();" id="'+k+'" name="dmn_checkbox"/></td>';
				table+='<td width="180" style="" valign="center"><a id="vitek'+dmcnt+'" href="'+k+'" style="color:#'+color[dmcnt]+'" target="_blank">'+k.substr(0,20)+'...'+'</a></td>';
				table+='<td valign="center">'+(Math.round(b2 * 1000 / a2) / 10)+'%</td>';
				table+='</tr>';
				dmcnt++;
			}
			table+='</table>';$('domains').innerHTML=table;$('domain_count').innerHTML=dmcnt;
			//resortable
			sovpad=0;
			var npod=1;
				new_ar='<table id="tbl_snt" style="padding-left:28px">';
			for (lls=0;lls<lsnt.length;lls++){
				sovpad=0;
				for (pi=0;pi<new_snt.length;pi++)
				 if (typeof new_snt[pi] != 'undefined'){
				//add or not add last point 
				if (new_snt[pi].substr(new_snt[pi].length-1,new_snt[pi].length)=='.')
					new_snt[pi]=new_snt[pi].substr(0,new_snt[pi].length-1);
					if (typeof (strpos(lsnt[lls],new_snt[pi],0))!='boolean'){
						new_ar+='<tr  class="'+set_color[pi]+'"><td valign="top"><div style="color:#'+set_color[pi]+'" class="'+set_color[pi]+'">'+npod+'.</div></td><td style="padding-left:10px"><div class="'+set_color[pi]+'" style="color:#'+set_color[pi]+'">'+lsnt[lls]+'.<br><br><br></div></td></tr>';
						sovpad=1;npod++;break;}
				}
				//if ((sovpad==0)&&(trim(lsnt[lls])!='')) new_ar+='<tr><td valign="top">'+(lls+1)+'.</td><td style="padding:0 0 20px 10px">'+lsnt[lls]+'.</td></tr>';
			}
			new_ar+='</table>';
			$('snt_tbl_div').innerHTML=new_ar;
		},
		
		startAnalyze : function () {
		GetBalance();
		if ($('days_left').innerHTML=='0') alert ('You must paid\n');
		else
		{
			$('progress').innerHTML='Connecting...';
			$('output_not_run').style.display='none';
			$('anal_not_run').style.display='none';
			$('cool_tips_a').style.display='block';
			$('anal_run_email').style.display='block';
			$('anal_run').style.display='block';
			$('progress').style.display='block';
			$j('#hr_3').click();
			$('status').value=1;
			PD.sndmn=[];
			$('leftbar').style.display='none';
			$('working').style.display='none';
			$('leftbar2').style.display='inline';
			$('working2').style.display='inline';	
			$('words_count').innerHTML='0';
			$('domain_count').innerHTML='0';
			$('sentences_count').innerHTML='0';
			sntt3.length=0;
			PD.text =trim($('srctext').value);
			var sntcs = PD.text.replace(/(\s|\n|\t|\r)+/g,' ').split(/\.\s|\!\s|\?\s/);
			PD.sentences = [];
			PD.total_sentences=sntcs.length;
			PD.sntclength=sntcs.length;
			//----------------------------
			tmptxt=trim($('srctext').value);
			var sntcs2 = tmptxt.replace(/(\s|\n|\t|\r)+/g,' ').split(/\.\s|\!\s|\?\s/);
			sentences2 = [];
			$('words_count').innerHTML=trim($('srctext').value).wordcount();
			for (var i = 0; i < sntcs2.length; i++)
			{
			if (! sntcs2 [i].match (/^(\s|\d)*$/g))					
				if (sntcs2 [i].ismorethan2 (5, 2))
				//if predlogenie has a more than 30 words, cut it to 30 words
				if (sntcs2 [i].wordcount()>32)
				 {var bb2=[];
				  var zz2 = sntcs2 [i].split (/\s+/);
				  
				   for (var jj=0;jj<32;jj++) {  bb2[jj]=zz2 [jj];}
					 bb2=bb2.join(' ');
 					 sentences2 [sentences2.length] = bb2+'.';//add sentence with cut 30 words
				 }else 	 sentences2 [sentences2.length] = sntcs2 [i]+'.';//add sentence wit <30 words
			}
			pp=sentences2.join(' ');
			PD.totalwords=pp.wordcount();//obrezaem predlojeniya do 30slov
			//----------------------------
			PD.foundedwords=0;
			for (var i = 0; i < sntcs.length; i++)
			{
			if (! sntcs [i].match (/^(\s|\d)*$/g))					
				if (sntcs [i].ismorethan2 (5, 2))
				//alert();
				//if predlogenie has a more than 30 words, cut it to 30 words
				if (sntcs [i].wordcount()>32)
				 {var bb=[];
				  var zz = sntcs [i].split (/\s+/);
				  
				   for (var jj=0;jj<32;jj++) {  bb[jj]=zz [jj];}
					 bb=bb.join(' ');
 					 PD.sentences [PD.sentences.length] = bb;//add sentence with cut 30 words
				 }else 	 PD.sentences [PD.sentences.length] = sntcs [i];//add sentence wit <30 words
					
			}
			if (PD.sentences.length>0)
			 	PD.__startAnalyzeCommon();
		}},
		RecurDH: function (zp,sentences2){
		if ($('status').value==0) {zp=sentences2.length;Stopped();}

			if (zp!=sentences2.length) {
			new Ajax.Request ("doho.php", {asynchronous:true,method: "post", parameters: {snt:sentences2[zp],rnd:Math.random()},onSuccess: 
					function (request){
					if  (strpos(request.responseText,'NOT FOUND')!=false) {
					if (typeof (sentences2[zp])!='undefined'){
					$('output').innerHTML+='<div class="sentence"><div class="sentenceresult">0</div><span><span class="marked">'+sentences2[zp]+'</span></span></div>';
					}
					}else{
					

					$('output').innerHTML += request.responseText;
						doma=request.responseText.split('gs-title');
						doma2=doma[2].split('href="');
						doma3=doma2[1].split('target');
						doma3[0]=trim(doma3[0]);
						//PD.domains[i]=doma3[0].substr(0,doma3[0].length-1);
						PD.domains[doma3[0].substr(0,doma3[0].length-1)]=doma3[0].substr(0,doma3[0].length-1);
						PD.foundedwords=PD.foundedwords+sentences2[zp].wordcount();
					//alert(t+'###'+PD.foundedwords+'#'+PD.totalwords+'#'+sentences2.length);
						sntt3[PD.found]=sentences2[zp];
						PD.found++;
						PD.sndmn[PD.found]=new Array();
						PD.sndmn[PD.found]=doma3[0].substr(0,doma3[0].length-1);
						$('progress').innerHTML=zp+'/'+PD.sentences.length;	
					}
					PD.RecurDH(zp+1,sentences2);
					}});
			}
			else {
			if ($('status').value==0) {Stopped();}else{
			//build all completed request
			PD.outputDomains();
			$('plagiate').innerHTML=Math.round (PD.foundedwords * 1000 / PD.totalwords) / 10;
			$('cool_tips_a').style.display='none';
			try{new Ajax.Request ("newp.php", {method: "post", parameters: {
			act:'save_history',
			simil:$('plagiate').innerHTML,
			rep:$('working2').innerHTML,
			dom:$('domains').innerHTML,
			pages:PD.total_sentences,
			p_sndmn:PD.sndmn.join('@#@@@#@'),
			p_sntt3:sntt3.join('@#@@@#@'),
			p_t:PD.totalwords,
			f_t:PD.foundedwords,
			sc:$('sentences_count').innerHTML,
			type:'search'}});}catch(e){}
			setTimeout("$('status').value=0;$('anal_not_run').style.display='block';$('anal_run').style.display='none';$('progress').style.display='none';$j('#hr_4').click();",2000);
			if ($j('input[name="prefer1"]:checked').val()=='sendemail')	abcdef('mail');
			try{$('pdf_img').src="images/savereport.jpg";}catch(e){}
			try{
			var s= "plagiarism=" + Math.round (PD.foundedwords * 1000 / PD.totalwords) / 10;
			s += "&plagiarismWeb="+Math.round (PD.foundedwords * 1000 / PD.totalwords) / 10;
			new Ajax.Request ('log.php?'+s, {method:"get"});
			}catch(e){}
			}
			}

		},

		__startDhooNdhoo: function(sentences2){
			totalsnt=sentences2.length;
			PD.foundedwords=0;
			//send and get request
			var t=0;
			var f = false;
			PD.RecurDH(0,sentences2);
		},
		
		
		
		__startAnalyzeCommon  : function () {
			api_type=$j('input[name="prefer2"]:checked').val();
			$('output').innerHTML = '';
			$('domains').innerHTML = '';
			$('output').style.display='none';
			//alert(
			PD.current = null;
			PD.found = 0;
			PD.foundWeb = 0;
			PD.foundPDF = 0;
			PD.foundBlog = 0;
			PD.foundBook = 0;
			PD.domains = {};
			PD.ignorelist = {};
			PD.results = {};
			PD.currentFoundN=0;
			

			PD.numAll = PD.sentences.length;
			
			$('srctext').disabled = true;
			
			//alert($('srctext').disabled);
			
			
			
			$('analyzebtn').value = ' Stop Analysis ';
			$('analyzebtn').onclick = PD.stopAnalyze;
			$('lightanalyzebtn').value = ' Stop Analysis ';
			$('lightanalyzebtn').onclick = PD.stopAnalyze;
			$('spdf').disabled = true;
			$('sblog').disabled = true;
			$('sbook').disabled = true;
			if (PD.text.ismorethan2 (5, 2)){
			$('sentences_count').innerHTML=PD.sentences.length;
			if (api_type=='api_goog')
			PD.callSearch();
			if (api_type=='api_plag'){
				$j('#hr_3').click();
				setTimeout("PD.__startDhooNdhoo(PD.sentences);",2000)
				
				}
			
			
			}else PD.stopAnalyze();
		},

		
		
		
		stopAnalyze : function () {
			
			PD.text = null;
			PD.sentences = null;
			PD.numAll = null;
			PD.current = null;
			PD.domains = {};
			PD.ignorelist = {};
			PD.results = {};
			PD.found = 0;
			PD.foundWeb = 0;
			PD.foundPDF = 0;
			PD.foundBlog = 0;
			PD.foundBook = 0;
			$('srctext').disabled = false;
			
			
			$('analyzebtn').value = ' Analyze ';
			$('analyzebtn').onclick = PD.startAnalyze;
			//$('lightanalyzebtn').value = ' Light analysis ';
			//$('lightanalyzebtn').onclick = PD.startLightAnalyze;
			$('btn_stop_analyze').src='images/stopanalyze_disabled.jpg';
			$('spdf').disabled = false;
			$('sblog').disabled = false;
			$('sbook').disabled = false;
			if ($('status').value==0) Stopped();
		}
	};
	
	
	var searcherWeb = null;
	var searcherBook = null;
	var searcherBlog = null;	
    function OnLoad() {
	  
	  //var searchControl = new google.search.SearchControl();
	  //searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	
	  searcherWeb = new google.search.WebSearch();
	  
	  searcherWeb.setSearchCompleteCallback (PD, PD.onSearchComplete);
	  
	  searcherBook = new google.search.BookSearch();
	  searcherBook.setSearchCompleteCallback (PD, PD.onSearchComplete);

	  
	  searcherBlog = new google.search.BlogSearch();
	  searcherBlog.setSearchCompleteCallback (PD, PD.onSearchComplete);
    }
    google.setOnLoadCallback(OnLoad);

