var insertNodeId = 'content'; // ID of the element where new content will be inserted
var removeNodeId = ''; // ID of the element you want to remove
var newContent = '<div style="background:#F0E5C3; border:3px solid #D7CAA2; height:220px; margin-bottom:25px;">'+
'<img src="images/search.png" alt="search" width="140" height="140" style="float:left; padding:15px;" />'+
'<img src="images/welcome.gif" alt="welcome searcher" width="296" height="26" style="margin:20px 0 12px 0;" />'+
'<p style="padding:0 10px 12px 0;">New-Gutters.com can help you with <span style="background:#D5C89E; font-size:1.2em; padding:4px;"><strong>JS_CONTENT</strong></span> in the <span style="background:#D5C89E; font-size:1.2em; padding:4px;"><strong><?php echo $city; ?>, <?php echo $state; ?></strong></span> area. To talk with a professional, enter your zip code below.</p>'+
'<div style="margin-left:171px;">'+
'<form method="post" action="" name="contact-form" id="contact-form">'+
'<fieldset>'+
'<input class="input" id="zip" name="zip" type="text" value="Enter Your Zip Code..." onFocus="clearText(this)" style="background:#fff; width:200px; color:#808097; height:24px; padding-left:10px; font:normal 16px Trebuchet MS, Arial, Helvetica, sans-serif;" />'+
'<input id="submit" type="submit" name="Submit" value="Continue &gt;&gt;" style="margin-top:7px; font-size:.8em; height:41px; text-transform:uppercase; padding:6px 12px;" />'+
'</fieldset>'+
'<img src="http://www.click-trak.com/tracking/pixel.php?aid=5026&cid=123&sid=0">'+
'<input name="validate" type="hidden" id="validate" value="yes">'+
'<input name="holdpen" type="hidden" id="holdpen" value="<?=$holdpen?>">'+
'<input type="hidden" name="ownproperty" value="yes" />'+
'<input type="hidden" name="whypurchase[]" value="So I will not have to clean my gutters every year" />'+
'</form>'+
'</div>'+
'</div>';

$(function () { welcomeReferred(); });

function welcomeReferred() {
	refDomain = document.referrer.replace('http://','').split('/');
	if (document.referrer != '' && refDomain != document.domain) {
		q = getQSVar('q',document.referrer);
		if(!q) q = getQSVar('p',document.referrer);
		if(q) {
			q = q.replace( /\+/g ," ");
			newContent = newContent.replace('JS_CONTENT',q);
			$('#'+insertNodeId).prepend(newContent);
			$('#'+removeNodeId).empty();
		}
	}
}

function getQSVar(qsVar,url) {
	url = url.split('?');
	var vars = url[1].split('&');
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == qsVar) {
			return pair[1];
		}
	}
	return false;
}