////////////////////////////////////////////////////
// Script to hide and show images - Used for close ups on images
////////////////////////////////////////////////////
function showImage(img) {
  img.style.display = "block";
}
function hideImage(img) {
  img.style.display = "none";
}

////////////////////////////////////////////////////
//
// This is the Popup
//
////////////////////////////////////////////////////
function popUp(URL, width, height) {
	var width = (width == null) ? 600: width;
	var height = (height == null) ? 500: height;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + "');");
}

////////////////////////////////////////////////////
//
// This is the Cookie.js
//
////////////////////////////////////////////////////

////////////////////////////////////////////////////
// Parce Standard Marketing Variables from URL
////////////////////////////////////////////////////
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
	var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
	for (var i=0; i<pairs.length; i++) {
		nameVal = pairs[i].split('=');
		params[nameVal[0]] = nameVal[1];
   		}
	}
return params;
}
function saveReferrerInfo() {
	if (document.referrer == "")
		return;
	var referrer = document.referrer;
	var engine = '';
	var keywords = '';
	var param;
	setCookie("referrer_url_cookie", referrer, "", "/", "insidesales.com");

	if (referrer.indexOf('http://www.google.com') == 0) {
		engine = 'Google'; param = 'q';	}
	else if (referrer.indexOf('http://www.bing.com') == 0) {
		engine = 'Bing'; param = 'q';	}
	else if (referrer.indexOf('http://search.yahoo.com') == 0) {
		engine = 'Yahoo'; param = 'p';	}
	var idx = referrer.indexOf('?');
	if (engine && idx != -1) {
		var pairs = referrer.substring(idx+1, referrer.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			if (nameVal[0] == param) {
				setCookie("search_keywords_cookie", nameVal[1], "", "/", "insidesales.com");
				setCookie("search_engine_name_cookie", engine, "", "/", "insidesales.com");
			}
   		}
	}
}

params = getParams();
saveReferrerInfo();

search_engine_id		= unescape(params["seid"]);
ad_campaign_id			= unescape(params["acid"]);
ad_group_id				= unescape(params["agid"]);
ad_id					= unescape(params["aid"]);
keyword_id				= unescape(params["kid"]);

category = unescape(params["category"]);
value = unescape(params["key"]);
affiliate = unescape(params["a"]);
engine = unescape(params["engine"]);
lead_source_id = unescape(params["lead_source_id"]);


if (params["seid"]!=null) 				setCookie("search_engine_id_cookie", search_engine_id, "", "/", "insidesales.com");
if (params["acid"]!=null) 				setCookie("ad_campaign_id_cookie", ad_campaign_id, "", "/", "insidesales.com");
if (params["agid"]!=null) 				setCookie("ad_group_id_cookie", ad_group_id, "", "/", "insidesales.com");
if (params["aid"]!=null) 				setCookie("ad_id_cookie", ad_id, "", "/", "insidesales.com");
if (params["kid"]!=null) 				setCookie("keyword_id_cookie", keyword_id, "", "/", "insidesales.com");

if (params["a"]!=null) 					setCookie("a_cookie", affiliate, "", "/", "insidesales.com");
if (params["key"]!=null) 				setCookie("key_cookie", value, "", "/", "insidesales.com");
if (params["engine"]!=null) 			setCookie("engine_cookie", engine, "", "/", "insidesales.com");
if (params["category"]!=null) 			setCookie("category_cookie", category, "", "/", "insidesales.com");
if (params["lead_source_id"]!=null)  	setCookie("lead_source_id_cookie", lead_source_id, "", "/", "insidesales.com");



////////////////////////////////////////////////////
// General Cookie Functionality
////////////////////////////////////////////////////
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +		
		((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}