var absPath = "http://www.controlbyweb.com/";
var absPathS = "https://www.controlbyweb.com/";

function set_cookie(cookie_name, cookie_value, cookie_expire, cookie_path, cookie_domain, cookie_secure) {

    // replace '=' with '`'
    var newString = cookie_value.replace("=", "`");
    cookie_value = newString;

    // Begin the cookie parameter string
    var cookie_string = cookie_name + "=" + cookie_value;
    
    // Add the expiration date, if it was specified
    if (cookie_expire) {
        var expire_date = new Date();
        var ms_from_now = cookie_expire * 24 * 60 * 60 * 1000;
        expire_date.setTime(expire_date.getTime() + ms_from_now);
        var expire_string = expire_date.toGMTString();
        cookie_string += "; expires=" + expire_string;
    }
    
    // Add the path, if it was specified
    // if (cookie_path) {
    //    cookie_string += "; path=" + cookie_path;
    //}
    cookie_string += "; path=/";

    // Add the domain, if it was specified
    if (cookie_domain) {
        cookie_string += "; domain=" + cookie_domain;
    }
    
    // Add the secure boolean, if it's true
    if (cookie_secure) {
        cookie_string += "; true";
    }
    
    // Set the cookie
    document.cookie = cookie_string;

}

function get_cookie(name_to_get) {

    var cookie_pair;
    var cookie_name;
    var cookie_value;
    
    // Split all the cookies into an array
    var cookie_array = document.cookie.split("; ");
    
    // Run through the cookies
    for (var counter = 0; counter < cookie_array.length; counter++) {
    
        // Split the cookie into a name/value pair
        cookie_pair = cookie_array[counter].split("=");
        cookie_name = cookie_pair[0];
        cookie_value = cookie_pair[1];
        
        // Compare the name with the name we want
        if (cookie_name == name_to_get) {
        
            // If this is the one, return the value
            var newString = unescape(cookie_value);
            cookie_value = newString.replace("`", "=");
            return cookie_value;
        }
    }
    
    // If the cookie doesn't exist, return null
    return null;
}

function delete_cookie(cookie_name) {
    set_cookie(cookie_name, "", -1000*60*60*24*5);
}

function checkCookiesEnabled()
{
    /* Set a cookie to be sure that one exists. Note that this is outside the function*/
    document.cookie = 'killme' + escape('nothing');
     
    /* check for a cookie */
    if (document.cookie == "") 
    {
        /* if a cookie is not found - alert user - change cookieexists field value to false */
        alert("The shopping cart requires COOKIES to be enabled!");
    }
}

// this function returns 'ff3_win' if the browser is ff3 on windows
// or 'ie' on windows.
// all other browsers return 'all'
function browserType()
{
var uagent=navigator.userAgent.toLowerCase();
if (uagent.indexOf("firefox") != -1) 
{
	return 'ff';	
}
else if (uagent.indexOf("msie") != -1) 
	return 'ie';
else
	return 'all';
}

// this function returns the firefox version number (and os)
function ffVersion()
{
	var uagent=navigator.userAgent.toLowerCase();
	var os;
	var version;
	
	if(uagent.indexOf("windows") != -1)
		os = 'win';
	else
		os = 'other';
	
	if (uagent.indexOf("firefox/3.0") != -1) 
		return 'ff3_' + os;
	else if (uagent.indexOf("firefox/2.0") != -1) 
		return 'ff2_' + os;	
	else
		return 'too_old';
}

// this function returns the ie version number
function ieVersion()
{
	var uagent=navigator.userAgent.toLowerCase();
	if (uagent.indexOf("msie 7.0") != -1) 
		return 'ie7';
	else if (uagent.indexOf("msie 6.0") != -1) 
		return 'ie6';	
	else
		return 'too_old';
}

function fixOrderNowImage()
{
	var bType = browserType();
	
	// we shift the order now image left one pixel for all browsers accept
	// internet exploreer and firefox 3 on windows
	if(bType == 'ff')
	{
		// get the ie version number
		version = ffVersion();
		
		if(version == 'ff3_win')
			document.getElementById('order_now').style.left = "36px";
		else
			document.getElementById('order_now').style.left = "35px";
	}
	else if(bType == 'all')
	{
		document.getElementById('order_now').style.left = "35px";
	}
	
	
	document.getElementById('order_now').style.visibility = "visible";
		
}
