//set script vars from request string var subject = '-3'; var showLoc = 'true'; //load jQuery programmatically WZ_loadScript('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); //wait for jQuery to load and then call jQuery_Loaded function function WZ_jQWait() { //alert('waitStarted'); if (typeof jQuery == 'undefined') { window.setTimeout(WZ_jQWait, 100); } else { $ = jQuery; jQuery_Loaded(); } } WZ_jQWait(); //exectued after jQuery has loaded function jQuery_Loaded() { //alert($); var qs = new Querystring(); if (qs.contains('subject')) { //override the default subject that was passed in with the script request subject = qs.get('subject'); } var scriptLoc = 'http://www.wyzant.com/AffiliatesWidget/WidgetServer.aspx?subject=' + subject; if (qs.contains('zip')) { scriptLoc = scriptLoc + '&zip=' + qs.get('zip'); } scriptLoc = scriptLoc + '&showLoc=' + showLoc; WZ_loadScript(scriptLoc); } function WyzAntSearchBTN_Clicked() { var docLoc = document.location.href; var zipVal = $('#ZipTB').val(); //var subjectVal = $('.WyzSubjectsDDL').val(); subjectVal = $('#SubjectTB').val(); if (docLoc.indexOf('?') > -1) { //qs already exists so see if zip is already in it var zipRegex = /zip=\d*/i; if (docLoc.match(zipRegex)) { //zip is already in qs so replace it var newZipStr = 'zip=' + zipVal; docLoc = docLoc.replace(zipRegex, newZipStr); } else { //no zip in qs so add it docLoc = docLoc + '&zip=' + zipVal; } } else { //no qs so add it docLoc = docLoc + '?zip=' + zipVal; } var subjectRegex = /&subject=.*/i; if (subjectVal.length > 0) { if (docLoc.match(subjectRegex)) { docLoc = docLoc.replace(subjectRegex, '&subject=' + subjectVal); } else { docLoc = docLoc + '&subject=' + subjectVal; } } else if (docLoc.match(subjectRegex)) { docLoc = docLoc.replace(subjectRegex, ''); } document.location = docLoc; return false; } function WZ_loadScript(src) { var script = document.createElement('script'); script.src = src; script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); } /* Client-side access to querystring name=value pairs Version 1.3 28 May 2008 License (Simplified BSD): http://adamv.com/dev/javascript/qslicense.txt */ function Querystring(qs) { // optionally pass a querystring to parse this.params = {}; if (qs == null) qs = location.search.substring(1, location.search.length); if (qs.length == 0) return; // Turn back to // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1 qs = qs.replace(/\+/g, ' '); var args = qs.split('&'); // parse out name/value pairs separated via & // split out each name=value pair for (var i = 0; i < args.length; i++) { var pair = args[i].split('='); var name = decodeURIComponent(pair[0]); var value = (pair.length==2) ? decodeURIComponent(pair[1]) : name; this.params[name] = value; } } Querystring.prototype.get = function(key, default_) { var value = this.params[key]; return (value != null) ? value : default_; } Querystring.prototype.contains = function(key) { var value = this.params[key]; return (value != null); }