var site_url = "http://www.whichesp.com/widget/";



var vsite_url = "http://www.whichesp.com/";



var scripts = document.getElementsByTagName('script');







var myScript = scripts[ scripts.length - 1 ];







var queryString = myScript.src.replace(/^[^\?]+\??/,'');







var exstr = "";







var s = queryString.split("=")[1]















/*function CreateWidget()







{*/















	$(document).ready(function($){







		







		//alert(site_url+"features.php?jsoncallback=?&s="+s)







		$.getJSON(site_url+"features.php?jsoncallback=?&s="+s,function(data){







			var html = "";







			html+='<table border="0" cellpadding="2" cellspacing="2" width="100%">';







			html+='<tr>';







				html+='	<td colspan="2" class="heading">Looking for an Email Service Provider?</td>';







			html+='</tr>';







			html+='<tr>';







				html+='<td valign="middle" colspan="2" align="left"  class="mmatter" >Our database contains a huge selection of ESPs all over the World. Let us find an Email Marketing Service Provider matching your requirements and budget.</td>';







			html+='</tr>';







			html+='<tr>';







				html+='<td valign="middle" colspan="2" align="left"  class="wmatter" >Please select the features you require:</td>';







			html+='</tr>';







			for (var x = 0; x < data.length; x++)







			{  







				if (data[x].iFeatureId == 7)







				{







					html+='<tr>';







						html+='<td width="10%"><input type="Checkbox" name="chkfea[]" id="chkfea[]" value="'+data[x].vFeature+'"></td>';				







						html+='<td width="80%"  class="bmatter">Support Language: &nbsp;&nbsp;';				







							html+='<select id="support_language" name="support_language">';		







							html+='<option value="English">English</option>';								







							html+='<option value="Spanish">Spanish</option>';								







							html+='<option value="German">German</option>';								







							html+='<option value="French">French</option>';								







							html+='<option value="Italian">Italian</option>';								







							html+='<option value="Russian">Russian</option>';								







							html+='<option value="Chinese">Chinese</option>';								







							html+='<option value="Other">Other</option>';								







						html+='</select>';				 







						html+='</td>';				







					html+='</tr>';







					







					







				}







				else if (data[x].iFeatureId == 42)







				{







					html+='<tr>';







						html+='<td width="10%"><input type="Checkbox" name="chkfea[]" id="chkfea[]" value="'+data[x].vFeature+'"></td>';				







						html+='<td width="80%"  class="bmatter">Integration with: &nbsp;&nbsp;';				







						







						html+='<select id="integration_with" name="integration_with">';		







							html+='<option value="Google Analytics">Google Analytics</option> ';								







							html+='<option value="Joomla">Joomla</option>';								







							html+='<option value="Joomla">Drupal</option> ';								







							html+='<option value="Oscommerce">Oscommerce</option>';								







							html+='<option value="Cubecart">Cubecart</option>';								







							html+='<option value="Magento">Magento</option>';								







							html+='<option value="WordPress">WordPress</option> ';								







							html+='<option value="SalesForce">SalesForce</option> ';								







						        html+='<option value="ZenCart">ZenCart</option> ';								







							html+='<option value="Other">Other</option>  ';







						html+='</select>';				 







						html+='</td>';				







					html+='</tr>';







					







					







				}







				else if (data[x].iFeatureId == 5)







				{







					html+='<tr>';







						html+='<td width="10%"><input type="Checkbox" name="chkfea[]" id="chkfea[]" value="'+data[x].vFeature+'"></td>';				







						html+='<td width="80%"  class="bmatter">'+data[x].vFeature+'&nbsp;&nbsp;';				







							html+='<select id="credibility_with" name="credibility_with">';		







							html+='<option value="Clients">Clients</option> ';								







							html+='<option value="Feedback loops">Feedback loops</option> ';								







							html+='<option value="Other">Other</option> ';								







							html+='<option value="DMA UK">DMA UK</option> ';								







							html+='<option value="DMA US">DMA US</option> ';								







							html+='<option value="EEC">EEC</option> ';								







							html+='<option value="MAAWG">MAAWG</option>' ;								







							html+='<option value="ESPC">ESPC</option> ';		







							html+='<option value="Return Path">Return Path</option>  ';								







							html+='<option value="TRUSTe">TRUSTe</option>' ;								







							html+='<option value="OTA">OTA</option> ';							







						html+='</select>';				 







						html+='</td>';				







					html+='</tr>';







					







					







				}







				else if (data[x].iFeatureId == 55)







				{







					html+='<tr>';







						html+='<td width="10%"><input type="Checkbox" name="chkfea[]" id="chkfea[]" value="'+data[x].vFeature+'"></td>';				







						html+='<td width="80%"  class="bmatter">Server location: &nbsp;&nbsp;';				







							html+='<select id="server_locations" name="server_locations">';		







							html+='<OPTION value="Anywhere">Anywhere</OPTION> ';								







							html+='<OPTION value="United States">United States</OPTION> ';								







							html+='<OPTION value="UK">UK</OPTION> ';								







							html+='<OPTION value="France">France</OPTION> ';								







							html+='<OPTION value="Germany">Germany</OPTION> ';								







							html+='<OPTION value="Russia">Russia</OPTION> ';								







							html+='<OPTION value="India">India</OPTION> ';								







							html+='<OPTION value="Spain">Spain</OPTION>';								







							html+='<OPTION value="China">China</OPTION> ';								







							html+='<OPTION value="Japan">Japan</OPTION>';								







						html+='</select>';				 







						html+='</td>';				







					html+='</tr>';







					







					







				}







				else







				{







					html+='<tr>';







						html+='<td width="10%"><input type="Checkbox" name="chkfea[]" id="chkfea[]" value="'+data[x].vFeature+'"></td>';				







						html+='<td width="80%"  class="bmatter">'+data[x].vFeature+'&nbsp;&nbsp;<span class="info" title="'+data[x].vDescription+'"></span></td>';				







					html+='<tr>';







				}	







			}







			







			html+='<tr><td colspan="2" align="center"><input type="Button" value="Find ESP" name="btnSub" id="btnSub" onclick="SearchESP();" ></td></tr>';







			html+='<tr>';







				html+='<td align="center" colspan="2"  class="wfooter">Powered by <a href="http://www.whichesp.com" target="_blank">WhichESP.com</a></td>';







			html+='</tr>';







			html+='<tr>';







					html+='<td align="center" class="wfooter" colspan="2"><a href="http://whichesp.com/signup" target="_blank">Are you an ESP?</a></td>';







				html+='</tr>';







			html+='</table>';







			$('#divwidget').html(html);







		    });







	});







//}















function SearchESP()







{







	







	$(document).ready(function($){







		var values = new Array();







		$.each($("input[@name='chkfea[]']:checked"), function() {







		







			if ($(this).val() == "Support (LANGUAGE)")







				exstr ="&support_language="+$("#support_language").val();







			else if ($(this).val() == "Integration with")			







				exstr+="&integration_with="+$("#integration_with").val();			







			else if ($(this).val() == "Credibility")			







				exstr+="&credibility_with="+$("#credibility_with").val();			







			else if ($(this).val() == "Server Locations")									







				exstr+="&server_locations="+$("#server_locations").val();			















			values.push($(this).val());







		});







		







	//	alert(site_url+"searchesps.php?&values="+values+"&jsoncallback=?&s="+s+exstr)







		







		//return false







		$.getJSON(site_url+"searchesps.php?&values="+values+"&jsoncallback=?&s="+s+exstr,function(data){







			//alert(data)







			var html = "";







			html+='<table border="0" cellpadding="2" cellspacing="2" width="100%">';







			html+='<tr>';







				html+='	<td colspan="2" class="heading"  >'+data.tot_esps+'  ESPs have been found matching your criteria</td>';







			html+='</tr>';







			







			html+='<tr><td valign="middle"  align="left" class="wmatter" >Contact all ESPs at once by filling in your details. After you submit the form you will be able to view all matching ESPs.</td></tr>';







			html+='<tr id="validation-msg" style="display:none"><td class="werror">Ooops! Please complete the form.</td></tr>';







			html+='<tr>';







				html+='<td valign="middle"> ';	







				







					html+='<table border="0"  class="bmatter" cellpadding="2" cellspacing="2" width="100%">';







					html+='<tr>';







						html+='<td>Name</td>';







						html+='<td>:</td>';







						html+='<td><input type="Text" name="vName" id="vName"></td>';







					html+='</tr>';







					html+='<tr>';







						html+='<td >Email</td>';







						html+='<td>:</td>';







						html+='<td><input type="Text" name="vEmail" id="vEmail"></td>';







					html+='</tr>';







					html+='<tr>';







						html+='<td >Company</td>';







						html+='<td>:</td>';







						html+='<td><input type="Text" name="vCompany" id="vCompany"></td>';







					html+='</tr>';







					html+='<tr>';







						html+='<td >Telephone</td>';







						html+='<td>:</td>';







						html+='<td><input type="Text" name="vPhone" id="vPhone"></td>';







					html+='</tr>';					







					html+='<tr>';







						html+='<td colspan="3" >Requirements:</td>';







					html+='</tr>';					







										







					html+='<tr>';







						html+='<td colspan="3" ><textarea name="vMessage" id="vMessage" rows="10" cols="25"></textarea></td>';







					html+='</tr>';					







					







					html+='<tr>';







						html+='<td colspan="3" align="center">&nbsp;&nbsp;<span class="info" title="All Providers matching your criteria will receive your contact details and your requirements. Also they will be notified of what features you have selected."></span>&nbsp;&nbsp;<input type="Button" value="Contact ESPs" name="btnSub" id="btnSub" onclick="contactESP(\''+values+'\',\''+exstr+'\');" ></td>';







					html+='</tr>';







					html+='</table> ';















				html+='</td>';				







			html+='</tr>';







			







			







			







			







			html+='<tr>';







				html+='<td align="center" colspan="2"  class="wfooter">Powered by &nbsp; <a href="http://www.whichesp.com" target="_blank">WhichESP.com</a></td>';







			html+='</tr>';







			html+='</table>';







			$('#divwidget').html(html);







		});







	});







	







}		















function contactESP(vals,exstr)







{















	$(document).ready(function($){







		







		if($('#vName').val() == ""  || $('#vEmail').val() == "" || $('#vCompany').val() == "" || $('#vPhone').val() == "" || $('#vMessage').val() == "")







		{







			$('#validation-msg').css('display','')







			return false







		}







		else







		{







			name = $('#vName').val();







			email = $('#vEmail').val();







			company = $('#vCompany').val();







			phone = $('#vPhone').val();







			message = $('#vMessage').val();		







			dataStr = "&vals="+vals+"&name="+name+"&email="+email+"&jsoncallback=?&s="+s+"&company="+company+"&phone="+phone+"&message="+message+exstr;







			$.getJSON(site_url+"sendmail.php?"+dataStr,function(data){







				var html = "";







				html+='<table border="0" cellpadding="2" cellspacing="2" width="100%">';







				html+='<tr>';







					html+='	<td colspan="2" class="heading">Thank You!</td>';







				html+='</tr>';







				







				html+='<tr><td valign="middle"  style="height:100px;"  align="center" class="bmatter"> The enquiry has been submitted to '+data.tot_esps+' ESPs on your behalf.<br/>You should hear from them shortly.</td></tr>';







				html+='<tr><td valign="middle"  style="height:100px;"  align="center" class="bmatter"> To view all  '+data.tot_esps+' ESPs please <a href=" '+vsite_url+'index.php?file=c-esplist&aff=1&as='+vals+'" target="_blank" >click here</a></td></tr>';

				





				







				







				html+='<tr>';







					html+='<td align="center" colspan="2"  class="wfooter">Powered by &nbsp; <a href="http://www.whichesp.com" target="_blank">WhichESP.com</a></td>';







				html+='</tr>';







				html+='</table>';







				$('#divwidget').html(html);







			});







			







		}







		







		







	});







	







}







