// prepare the form when the DOM is ready 
$(document).ready(function() { 
    var options = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=google'// override for form's 'action' attribute 
    }; 
    var options1 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=gbacklink'// override for form's 'action' attribute 
    }; 
    var options2 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=technorati'// override for form's 'action' attribute 
    }; 
    var options3 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=live'// override for form's 'action' attribute 
    }; 
    var options4 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=backyahoo'// override for form's 'action' attribute 
    }; 
    var options5 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=compete'// override for form's 'action' attribute 
    }; 
    var options6 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=alexa'// override for form's 'action' attribute 
    }; 

    var options7 = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        url: 'ajax/process.php?c=bloglines'// override for form's 'action' attribute 
    }; 
    
	$('#btnGo').click(function() { 
		$('#form1').ajaxSubmit(options); 
    	$('#form1').ajaxSubmit(options1); 
    	$('#form1').ajaxSubmit(options2);
    	$('#form1').ajaxSubmit(options3);
    	$('#form1').ajaxSubmit(options4);
    	$('#form1').ajaxSubmit(options5);
    	$('#form1').ajaxSubmit(options6);
    	$('#form1').ajaxSubmit(options7);
	});

	$("#txtUrl").keydown(checkForEnter);
 function checkForEnter (event) {
  if (event.keyCode == 13) {
 		$('#form1').ajaxSubmit(options); 
    	$('#form1').ajaxSubmit(options1); 
    	$('#form1').ajaxSubmit(options2);
    	$('#form1').ajaxSubmit(options3);
    	$('#form1').ajaxSubmit(options4);
    	$('#form1').ajaxSubmit(options5);
    	$('#form1').ajaxSubmit(options6);
    	$('#form1').ajaxSubmit(options7);
    	$('#form1').submit(function() { return false; });

  } 
};	
}); 

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    $("#btnGo").attr("disabled", "true"); 
	var queryString = $.param(formData); 

	 $("#resultGooglePageRank").html('<img src="images/loading.gif">');
	 $("#resultAlexaRank").html('<img src="images/loading.gif">');
	 $("#resultCompeteRank").html('<img src="images/loading.gif">');
	 $("#resultQuantcastRank").html('<img src="images/loading.gif">');
	 $("#resultGoogleBackLinks").html('<img src="images/loading.gif">');
	 $("#resultYahooBackLinks").html('<img src="images/loading.gif">');
	 $("#resultLiveSearchBackLinks").html('<img src="images/loading.gif">');
	 $("#resultTechnoratiLinks").html('<img src="images/loading.gif">');
	 $("#resultdeliciousBookmarks").html('<img src="images/loading.gif">');
	 $("#resultBloglinessubscribers").html('<img src="images/loading.gif">');
	 $("#resultWHOIS").html('<img src="images/loading.gif">');
	 $("#resultDNSReport").html('<img src="images/loading.gif">');

      $("#moreinfoGooglePageRank").html('');
      $("#moreinfoAlexaRank").html('');
      $("#moreinfoCompeteRank").html('');
      $("#moreinfoQuantcastRank").html('');
      $("#moreinfoGoogleBackLinks").html('');
      $("#moreinfoYahooBackLinks").html('');
      $("#moreinfoLiveSearchBackLinks").html('');
      $("#moreinfoTechnoratiLinks").html('');
      $("#moreinfodeliciousBookmarks").html('');
      $("#moreinfoBloglinessubscribers").html('');
      $("#moreinfoWHOIS").html('');
      $("#moreinfoDNSReport").html('');
      
    return true; 
} 
 
// post-submit callback 
function showResponse(responseXML, statusText)  { 
	 var ID = Array("resultGooglePageRank", "resultAlexaRank", "resultCompeteRank", "resultQuantcastRank","resultGoogleBackLinks","resultYahooBackLinks","resultLiveSearchBackLinks","resultTechnoratiLinks","resultdeliciousBookmarks","resultBloglinessubscribers","resultWHOIS","resultDNSReport");
 
	 url=escape($("#txtUrl").val());
	 
	 domain=$("#txtUrl").val();
	 domain=domain.replace("http://","");
	 domain=domain.replace("www.","");
	 domain=escape(domain); 	
	 array = (responseXML.match(/(.*?)#(.*?)$/));
	 $idd=array[1];
	 $value=array[2];
	 if($idd=='resultGooglePageRank'){
		 $("#resultGooglePageRank").html($value);
		 $("#moreinfoGooglePageRank").html('<a href="http://www.google.com/technology/" target="_blank">Detail</a>'); 
	 }else if($idd=='resultAlexaRank'){
	 	 $("#resultAlexaRank").html($value);
	 	$("#moreinfoAlexaRank").html('<a href="http://www.alexa.com/siteinfo/'+domain+'" target="_blank">Detail</a>');
	 }else if($idd=='resultCompeteRank'){
	 	$("#resultCompeteRank").html($value);
	 	$("#moreinfoCompeteRank").html('<a href="http://snapshot.compete.com/'+domain+'" target="_blank">Detail</a>');
	 }else if($idd=='resultQuantcastRank'){
		 $("#resultQuantcastRank").html('N/A');
		 $("#moreinfoQuantcastRank").html('');	 	
	 }else if($idd=='resultGoogleBackLinks'){
		 $("#resultGoogleBackLinks").html($value);
		 $("#moreinfoGoogleBackLinks").html('<a href="http://www.google.com/search?hl=en&q=link%3A'+url+'" target=_blank">Detail</a>');	 	
	 }else if($idd=='resultYahooBackLinks'){
		 $("#resultYahooBackLinks").html($value);
		 $("#moreinfoYahooBackLinks").html('<a href="https://siteexplorer.search.yahoo.com/search?ei=UTF-8&p='+url+'&bwm=i&bwmf=s'+'" target="_blank">Detail</a>');		 	
	 }else if($idd=='resultLiveSearchBackLinks'){
		 $("#resultLiveSearchBackLinks").html($value);
		 $("#moreinfoLiveSearchBackLinks").html('<a href="http://search.live.com/results.aspx?q=link%3A'+url+'" target="_blank">Detail</a>');	 	
	 }else if($idd=='resultTechnoratiLinks'){
		 $("#resultTechnoratiLinks").html($value);
		 $("#moreinfoTechnoratiLinks").html('<a href="http://technorati.com/search/'+url+'" target="_blank">Detail</a>');
	 }	else if($idd=='resultdeliciousBookmarks'){
		 $("#resultdeliciousBookmarks").html($value);
		 $("#moreinfodeliciousBookmarks").html('');			 	
	 }else if($idd=='resultBloglinessubscribers'){
		 $("#resultBloglinessubscribers").html($value);
		 $("#moreinfoBloglinessubscribers").html('<a href="http://www.bloglines.com/search?q='+url+'&t=f'+'" target="_blank">Detail</a>');	 	
	 }
	 
		 $("#resultWHOIS").html('--->');
		 $("#moreinfoWHOIS").html('<a href="http://www.whoistheowner.com/" target="_blank">Detail</a>');
		 $("#resultDNSReport").html('--->');
		 $("#moreinfoDNSReport").html('<a href="http://www.dnsreport.com/tools/dnsreport.ch?domain='+url+'" target="_blank">Detail</a>'); 	 	

	 $("#btnGo").removeAttr("disabled");  
} 
