var domainManagementCurrentNameservers = [];

function domainInfoPopup(domain)
{
    $('#JqueryLoadingDiv').dialog('open');

    domainManagementCurrentNameservers = [];

    $.post("/ajax/domain_management/getDomainDetails", { domain: domain },
        function(data)
        {
            var status = data["status"];
            var domain = data["domain"];

	    if(!status)
	    {
	        resetLoadingDiv();
		alert("Sorry, it doesn't appear that you can manage this domain.");
		return;
	    }

            var domainDetails = data["domainDetails"];
	    var nameServers = domainDetails["nameServers"];
	    var registrar = domainDetails["registrar"];
	    var createDate = domainDetails["createDate"];
	    var expireDate = domainDetails["expireDate"];
	    var whoisPrivacy = domainDetails["whoisPrivacy"];
	    var googleApps = domainDetails["googleApps"];
	    var whoisPrivacyDetails = domainDetails["whoisPrivacyDetails"];
	    var allowWhoisPrivacy = domainDetails["allowWhoisPrivacy"];
	    var whoisPrivacyInCart = domainDetails["whoisPrivacyInCart"];
	    var domainRenewalInCart = domainDetails["domainRenewalInCart"];
	    var newexpdate = domainDetails["newexpdate"];
	    var recurring = domainDetails["recurring"];
	    var hasDefaultPaymentProfile = domainDetails["hasDefaultPaymentProfile"];
	    var authCode = domainDetails["authCode"];
	    var lockStatus = domainDetails["lockStatus"];

	    var checked = "";
    	    if(domainRenewalInCart) checked = "checked";
	    var domainRenwalHtml = "<input id='renew_"+domain+"' type='checkbox' value='"+domain+"' onClick=\"productCartSwap(this.checked, '"+domain+"', -1, 'renewal');\" "+checked+"><span style='font-size:10px;color:gray;'> renew domain</span>";

	    checked = "";
	    if(recurring == 1 && hasDefaultPaymentProfile) checked = "checked";
	    var autoBillingHtml = "<input onclick='updateDomainRecurringBilling(1, \""+domain+"\");' name='recurringDomainBilling' type='radio' "+checked+"> on";
	    checked = "";
	    if(recurring == -1 || !hasDefaultPaymentProfile) checked = "checked";
	    autoBillingHtml += "<input onclick='updateDomainRecurringBilling(-1, \""+domain+"\");' name='recurringDomainBilling' type='radio' "+checked+"> off";

	    var googleAppsHtml = "";
	    if(googleApps)
	    {
	        if(googleApps == "active")
		{
                    googleAppsHtml += "<a target='_new' href='http://mail."+domain+"'>active</a>";
		}
		else
		{
                    googleAppsHtml += "<a href='/setup_google_apps.php?domain_name="+domain+"&keep_blog_dns=1'>"+googleApps+"</a>";
		}
	    }
	    else
	    {
                googleAppsHtml += "<a href='/management/list_domain.php?domain_name="+domain+"&init_google_apps_button=Add+Google+Apps'>enable</a>";
 	    }

	    var whoisPrivacyHtml = "";
	    if(!allowWhoisPrivacy)
	    {
		whoisPrivacyHtml = "unsupported";
	    }
	    else if(whoisPrivacy == "yes")
	    {
		checked = "";
		if(whoisPrivacyInCart) checked = "checked";

		whoisPrivacyHtml += "expires: "+whoisPrivacyDetails.expire_date.substr(0, 10)+"<br>";

		var enabledChecked = (whoisPrivacyDetails["status"] == 1) ? "checked" : "";
		var disabledChecked = (whoisPrivacyDetails["status"] == 2) ? "checked" : "";

		whoisPrivacyHtml += "<form name='whois_enableDisableForm'>";
 		whoisPrivacyHtml += "<input value='"+domain+"' name='whois_enableDisable' id='whois_enabled_"+domain+"' type='radio' onclick='setWhoisPrivacyStatus(\""+domain+"\", \"1\");' "+enabledChecked+"><span style='font-size:10px;color:gray;'> enabled</span>";
		whoisPrivacyHtml += "<input value='"+domain+"' name='whois_enableDisable' id='whois_disabled_"+domain+"' type='radio' onclick='setWhoisPrivacyStatus(\""+domain+"\", \"2\");' "+disabledChecked+"><span style='font-size:10px;color:gray;'> disabled</span>";
		whoisPrivacyHtml += "<input value='"+domain+"' id='whois_"+domain+"' type='checkbox' onclick='productCartSwap(this.checked, \""+domain+"\", ((this.checked) ? 1 : 1), \"whois_privacy\", \"addon_product\", \"ALL\");' "+checked+"><span style='font-size:10px;color:gray;'> renew</span>";
		whoisPrivacyHtml += "</form>";
	    }
	    else if(whoisPrivacy == "no")
	    {
		var checked = "";
		if(whoisPrivacyInCart)
		    checked = "checked";

		whoisPrivacyHtml += "<input value='"+domain+"' id='whois_"+domain+"' type='checkbox' onclick='productCartSwap(this.checked, \""+domain+"\", ((this.checked) ? 1 : 1), \"whois_privacy\", \"addon_product\", \"ALL\");' "+checked+"><span style='font-size:10px;color:gray;'> add to cart</span>";
	    }
	    else
	    {
		whoisPrivacyHtml = "unknown";
	    }

	    var lockStatusHtml = "";
	    var lockUpdateAction = lockStatus == "locked" ? "unlock" : "lock";
	    lockStatusHtml += " - <a href='javascript:domainManagementLockUnlockDomain();'><span id='domainManagementLockAction' style='font-size:10px;'>"+lockUpdateAction+"</span></a><span class='ui-icon ui-icon-"+lockStatus+"' id='domainManagementLockIcon'></span>";

	    var innerHTML = "";

	    innerHTML += "<div id='domainManagementNameservers' style='float:left; border:0px solid black; width:150px;'>";

	    innerHTML += "<span style='font-weight:bold; font-size:14px;'>Nameservers</span> [<a href='javascript:enableNameserverEdit();'>edit</a>]<br><br>";
	    innerHTML += "<div id='domainManagementNameserversEdit' style='width:150px;'>";
	    for(var i = 0; i < nameServers.length; i++)
	    {
		domainManagementCurrentNameservers.push(nameServers[i]);
		innerHTML += nameServers[i]+"<br>";
	    }
	    innerHTML += "</div>";
	    innerHTML += "</div>";

	    innerHTML += "<div id='domainManagementInfo' style='float:right; border:0px solid black; width:350px;'>";
	    innerHTML += "<span style='font-weight:bold; font-size:14px;'>Domain Overview</span></br><br>";

	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='font-weight:bold; float:left; width:100px;'>Registrar: </div><div style='float:left;'>"+registrar+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='font-weight:bold; float:left; width:100px;'>Create Date: </div><div style='float:left;'>"+createDate+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='font-weight:bold; float:left; width:100px;'>Expire Date: </div><div style='float:left;'>"+expireDate+"<br>"+domainRenwalHtml+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='white-space:nowrap; font-weight:bold; float:left; width:100px;'>Whois Privacy: </div><div style='float:left;'>"+whoisPrivacyHtml+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='font-weight:bold; float:left; width:100px;'>Google Apps: </div><div style='float:left;'>"+googleAppsHtml+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='white-space:nowrap; font-weight:bold; float:left; width:100px;'>Automatic Billing: </div><div style='float:left;'>"+autoBillingHtml+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='font-weight:bold; float:left; width:100px;'>Domain Lock: </div><div style='float:left;'><span id='lockStatus'>"+lockStatus+"</span> "+lockStatusHtml+"</div><div style='clear:both;'></div></div>";
	    innerHTML += "<div style='height:40px; border-bottom:1px solid gray;'><div style='font-weight:bold; float:left; width:100px;'>Auth Code: </div><div style='float:left;'>"+authCode+"</div><div style='clear:both;'></div></div>";

	    innerHTML += "</div><div style='clear:both;'></div>";

	    $('#domainInfoDialog').dialog( "option", "title", "<span style='font-size:12px;'><b>Domain Management:</b> <span id='domainManagementDomain'>"+domain+"</span></span>" );
	    $('#domainInfoDialog').html(innerHTML);
	    resetLoadingDiv();
	    $('#domainInfoDialog').dialog('open');
        }, "json"
    );
}

function domainManagementLockUnlockDomain()
{
    $('#domainInfoDialog').dialog('close');
    $('#JqueryLoadingDiv').dialog('open');

    var domain = document.getElementById("domainManagementDomain").innerHTML;
    var action = document.getElementById("domainManagementLockAction").innerHTML;

    $.post("/ajax/domain_management/lockUnlockDomain", { domain: domain, action: action },
        function(data)
        {
            var status = data["status"];
            var action = data["action"];
	    var newLockUpdateAction = (action == "lock") ? "unlock" : "lock";
	    var newLockStatus = (action == "lock") ? "locked" : "unlocked";

	    if(!status)
	    {
		alert("Sorry, it doesn't appear that you can manage this domain.");
	        resetLoadingDiv();
		return;
	    }
	    else
	    {
		var removeClass = (action == "lock") ? "ui-icon-unlocked" : "ui-icon-locked";
		var addClass = (action == "lock") ? "ui-icon-locked" : "ui-icon-unlocked";
		$('#domainManagementLockIcon').removeClass(removeClass);
		$('#domainManagementLockIcon').addClass(addClass);

		document.getElementById("domainManagementLockAction").innerHTML = newLockUpdateAction;
		document.getElementById("lockStatus").innerHTML = newLockStatus;
	        resetLoadingDiv();
	        $('#domainInfoDialog').dialog('open');
	    }

        }, "json"
    );
}

function domainManagementNameserversUpdate()
{
    $('#domainInfoDialog').dialog('close');
    $('#JqueryLoadingDiv').dialog('open');

    var domain = document.getElementById("domainManagementDomain").innerHTML;
    var nameservers = document.getElementById("domainManagementNameserversTextarea").value;

    $.post("/ajax/domain_management/updateDomainNameservers", { domain: domain, nameservers: nameservers },
        function(data)
        {
            var status = data["status"];

	    if(!status)
	    {
		alert("Sorry, it doesn't appear that you can manage this domain.");
	        resetLoadingDiv();
		return;
	    }
	    else
	    {
                var nameservers  = data["nameservers"];
		var innerHTML = "";
		domainManagementCurrentNameservers = [];
	
	        for(var i = 0; i < nameservers.length; i++)
	        {
		    domainManagementCurrentNameservers.push(nameservers[i]);
	       	    innerHTML += nameservers[i]+"<br>";
	        }

		document.getElementById("domainManagementNameserversEdit").innerHTML = innerHTML;
	        resetLoadingDiv();
	        $('#domainInfoDialog').dialog('open');
	    }

        }, "json"
    );
}

function enableNameserverEdit()
{
    if(!document.getElementById("domainManagementNameserversTextarea"))
    {
	var nameservers = document.getElementById("domainManagementNameserversEdit").innerHTML;
	var button = "<button onclick='domainManagementNameserversUpdate();'> Update </button>";
	nameservers = nameservers.replace(/<br>/g, "\n");
	document.getElementById("domainManagementNameserversEdit").innerHTML = "<textarea id='domainManagementNameserversTextarea' style='width:200px; height:150px;'>"+nameservers+"</textarea><br>"+button;
    }
    else
    {
	var nameservers = "";

        for(var i = 0; i < domainManagementCurrentNameservers.length; i++)
        {
       	    nameservers += domainManagementCurrentNameservers[i]+"<br>";
        }

	document.getElementById("domainManagementNameserversEdit").innerHTML = nameservers;
    }
}

function addRemoveProductForAll(element, product, action, tag, duration)
{
    if(!duration) duration = "";
    if(!tag) tag = "";
    if(!action) action = "";
    if(!product) product = "";
    if(!element) element = "";

    var domains = "";
    $("input[id^='"+element+"'][type='checkbox']").each(function()
    {
     	if(!document.getElementById(this.id).disabled && document.getElementById(this.id).checked == (action != "add"))
            domains += this.value+",";
    }
    );

    if(domains.length > 0)
    {
        $('#JqueryLoadingDiv').dialog('open');

     	$.post("/products-pricing/services/productCart.php", { action: "addRemoveProductForAll", subAction: action, domains: domains, product: product, element: element, tag: tag, duration: duration },
            function(data)
            {
             	var tag = data["tag"];
             	var status = data["status"];
                var subAction = data["subAction"];
                var element = data["element"];
                var domains = data["domains"];
                var pricing = data["pricing"];
                var parentProducts = data["parentProducts"];
                var product = data["product"];
                var productTotalPrice = data["productTotalPrice"];
                var domainsLength = domains.length;

                if(status > 0 && domainsLength > 0)
                {
		    if(document.getElementById("span_checkoutTotalCost") && productTotalPrice) document.getElementById("span_checkoutTotalCost").innerHTML = formatCurrency(productTotalPrice, true);

                    for(var i = 0; i < domainsLength; i++)
                    {
			var parentProduct = "";
			if(parentProducts) parentProduct = parentProducts[product][domains[i]];

                     	if(subAction == "add")
			{
                            $("input[id="+element+domains[i]+"]").attr('checked', true);
			    if(document.getElementById("div_"+domains[i])) 
			    {
				document.getElementById("div_"+domains[i]).innerHTML = "Added to Cart";
				document.getElementById("div_"+domains[i]).style.color = "#245FA5";
			    }

			    if(document.getElementById("span_checkoutProductPrice_"+parentProduct+"_"+domains[i]+""))
			    {
				var price = pricing[product][domains[i]];
				updateCheckoutProductPrice(parentProduct, domains[i], price, subAction);
			    }
			}
                        else
			{
                            var action = $("input[id="+element+domains[i]+"]").attr('checked', false);
			    if(document.getElementById("div_"+domains[i])) 
			    {
				document.getElementById("div_"+domains[i]).innerHTML = "Available";
				document.getElementById("div_"+domains[i]).style.color = "#006600";
			    }
			    if(document.getElementById("span_checkoutProductPrice_"+parentProduct+"_"+domains[i]+""))
			    {
				var price = pricing[product][domains[i]];
				updateCheckoutProductPrice(parentProduct, domains[i], price, subAction);
			    }
			}
                    }

		    if(tag == "addon_product")
		    {
			location.reload();
			return;
		    }
                }
                else
                {
                    // alert(data["message"]);
                }

                getSetShoppingCartInfo();
                resetLoadingDiv();

            }, "json"
        );
    }
}

function updateCheckoutProductPrice(type, name, price, action)
{
        currentPrice = document.getElementById("span_checkoutProductPrice_"+type+"_"+name).innerHTML;
        currentHiddenPrice = document.getElementById("span_checkoutProductPriceHidden_"+type+"_"+name).innerHTML;
         
        if(action == "add")   
        {
            newPrice = parseFloat(currentPrice) + parseFloat(price);
            newHiddenPrice = parseFloat(currentHiddenPrice) + parseFloat(price);
        }
        else if(action == "remove")
        {
            newPrice = parseFloat(currentPrice) - parseFloat(price);
            newHiddenPrice = parseFloat(currentHiddenPrice) - parseFloat(price);
        }
        else
        {
            newPrice = currentPrice;
            newHiddenPrice = currentHiddenPrice;
        }
    
        document.getElementById("span_checkoutProductPrice_"+type+"_"+name).innerHTML = formatCurrency(newPrice, true);
        document.getElementById("span_checkoutProductPriceHidden_"+type+"_"+name).innerHTML = formatCurrency(newHiddenPrice, true);
}

// Add the indexOf function for IE (the mozilla implementation)
/*
  if (!Array.prototype.indexOf)
  {*/
//    Array.prototype.indexOf = function(elt /*, from*/)
/*    {
      var len = this.length;
      var from = Number(arguments[1]) || 0;
      from = (from < 0) ? Math.ceil(from) : Math.floor(from);
      if (from < 0)
      from += len;
      for (; from < len; from++)
      {
      if (from in this && this[from] === elt)
      return from;
      }
      return -1;
      };
      }
*/
var domainsInCart = new Array();
var loadingDivInnerHTMLSwap;
var doNotRestLoadingDiv = 0;
var testCount = 0;

function HTTP() 
{
    var xmlhttp = false;
    if(!xmlhttp)
	{
	    /*@cc_on @*/
	    /*@if (@_jscript_version >= 5)
	      try {xmlhttp = new ActiveXObject("MSXML2.XmlHttp.3.0") } 
	      catch (e) {xmlhttp = false}
	      if(!xmlhttp)
	      {
	      try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")} 
	      catch (E) {xmlhttp = false}
	      }
	      if(!xmlhttp)
	      {
	      try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")} 
	      catch (E) {xmlhttp = false }
	      }
	      @else
	      xmlhttp = false
	      @end @*/
	}
    if(!xmlhttp)
	{
	    try {xmlhttp = new XMLHttpRequest();} 
	    catch (e) {xmlhttp = false;}
	}
    return(xmlhttp);
}
if(typeof postURL=='undefined') 
    {
	postURL=function(url,txt,fn,type,enc,notasync) 
	    {
		var xmlhttp=new HTTP();
		var async = true;
		if(notasync) async = false;
		txt += (url ? "&" : "") + 'noforward=true&' + (new Date()).getTime();
		if(xmlhttp) 
		    {
			xmlhttp.open("POST", url, async);
			if(enc) xmlhttp.setRequestHeader("Content-Encoding",enc)
				    if(type) xmlhttp.setRequestHeader("Content-Type",type)
						 xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", txt.length)
			    xmlhttp.setRequestHeader("Connection", "close");

			xmlhttp.onreadystatechange=function() 
		        {
			    if (xmlhttp.readyState==4 && xmlhttp.status == 200) {fn(xmlhttp.status,xmlhttp.responseText,xmlhttp.getResponseHeader("Content-Type")) }
			}
			xmlhttp.send(txt)
			} 
		else {}
	    }
    }
if(typeof getURL=='undefined')
    {
	getURL=function(url, fn, notasync)
	    {
		var xmlhttp=new HTTP();
		var async = true;
		if(notasync) async = false;
		if (xmlhttp)
		    {
			xmlhttp.open("GET", url += (url.match(/\?/) == null ? "?" : "&") + 'noforward=true&' + (new Date()).getTime(), async);
xmlhttp.setRequestHeader("Content-type", "text/html; charset=UTF-8");
			if(async)
			{
				xmlhttp.onreadystatechange=function()
				    {
					if (xmlhttp.readyState==4){fn(xmlhttp.status,xmlhttp.responseText,xmlhttp.getResponseHeader("Content-Type"))}
				    }
			}
			try
			    {
				xmlhttp.send(null);
				if(!async)
				    fn(xmlhttp.status,xmlhttp.responseText,xmlhttp.getResponseHeader("Content-Type"));
			    }
			catch(err) {}
		    }
		else {}
	    }
    }

function resetLoadingDiv()
{
    if(doNotRestLoadingDiv){ return;}

    if(document.getElementById("LoadingDiv")) 
	{
	    document.getElementById("LoadingDiv").style.display = 'none';
	    
	    if(loadingDivInnerHTMLSwap) 
		{
		    document.getElementById("span_loading_content").innerHTML = loadingDivInnerHTMLSwap;
		    loadingDivInnerHTMLSwap = "";
		}
	    
	    document.getElementById("LoadingDiv_inner").style.height = 200;
	    document.getElementById("LoadingDiv_inner").style.width = 200;
	    document.getElementById("LoadingDiv_inner").style.textAlign = "center";
	    
	    document.getElementById("LoadingDiv").style.background = "";
	    document.getElementById("LoadingDiv").style.paddingTop = "100px";
	}

    document.getElementById("JqueryLoadingDivImage").innerHTML = "<img src='/images/loading.big.gif'>";
    document.getElementById("JqueryLoadingDivContent").innerHTML = "";
    document.getElementById("JqueryLoadingDivFooter").innerHTML = "";

    $('#JqueryLoadingDiv').dialog('close');
}

function checkLoginHandler(status, content, contentType)
{
    if(status !== 200 && status !== 0)
	{
	    alert("Something went wrong. Please refresh the page and try again. ("+status+")");
	    resetLoadingDiv();
	    return;
	}
    
    var results = eval('('+content+')');
    if(!results.status)
	{
	    alert(results.message);
	    return;
	}

    var f_id = results.form_id;
    var pass_val;
    if(results.vip_status == 'enabled')
	{
	    if(document.getElementById("Login_links"+f_id)){
		document.getElementById("Login_links"+f_id).style.display = 'none';}
	    if(document.getElementById("Login_pass"+f_id) && document.getElementById("Login_pass_field"+f_id))
		{
		    pass_val = document.getElementById("Login_pass_field"+f_id).value;
		    if(document.getElementById("Login_vip"+f_id)) {
			document.getElementById("Login_vip"+f_id).innerHTML = "<div class='float_left login_vip' id='Login_vip'><p>VIP Pin: <a style='text-decoration:none;color:blue' target='blank' href='/services/namesafe/faq' tabindex=100>?</a><br/><input id='Login_pin_field"+f_id+"' name='vip_pin' type='password'/></div>";}
		}
	}
    else
	{
	    if(document.getElementById("Login_links"+f_id)){
		document.getElementById("Login_links"+f_id).style.display = 'block';}
	    if(document.getElementById("Login_pass"+f_id) && document.getElementById("Login_pass_field"+f_id))
		{
		    pass_val = document.getElementById("Login_pass_field"+f_id).value;
		    if(document.getElementById("Login_vip"+f_id)){
			document.getElementById("Login_vip"+f_id).innerHTML = "";}
		}
	}
}
function checkVIPLogin(acct_name,form_id,event)
{ 
// owen
    getURL('/verisign-vip/javascript/check-login.php?acct_name='+acct_name+'&form_id='+form_id, checkLoginHandler);
}
function checkVIPLogins()
{
    if(document.getElementById('Login_name_field1')){ checkVIPLogin(document.getElementById('Login_name_field1').value, 1);}
    if(document.getElementById('Login_name_field2')){ checkVIPLogin(document.getElementById('Login_name_field2').value, 2);}
    if(document.getElementById('Login_name_field3')){ checkVIPLogin(document.getElementById('Login_name_field3').value, 3);}
    if(document.getElementById('Login_name_field4')){ checkVIPLogin(document.getElementById('Login_name_field4').value, 4);}
}
function clearUserPass()
{
    if(document.getElementById('Login_name_field1')){ document.getElementById('Login_name_field1').value = '';}
    if(document.getElementById('Login_name_field2')){ document.getElementById('Login_name_field2').value = '';}
    if(document.getElementById('Login_name_field3')){ document.getElementById('Login_name_field3').value = '';}
    if(document.getElementById('Login_name_field4')){ document.getElementById('Login_name_field4').value = '';}
    if(document.getElementById('Login_pass_field1')){ document.getElementById('Login_pass_field1').value = '';}
    if(document.getElementById('Login_pass_field2')){ document.getElementById('Login_pass_field2').value = '';}
    if(document.getElementById('Login_pass_field3')){ document.getElementById('Login_pass_field3').value = '';}
    if(document.getElementById('Login_pass_field4')){ document.getElementById('Login_pass_field4').value = '';}
}
function emptyHandler(status,content,contentType)
{}
function initializeMenu(menuId, actuatorId)
{
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
    
    if (menu === null || actuator === null) { return; }
    
    actuator.parentNode.style.backgroundImage = "url(/include/images/plus.gif)";
    actuator.onclick = function() {
        var display = menu.style.display;
        this.parentNode.style.backgroundImage = (display == "block") ? "url(/include/images/plus.gif)" : "url(/include/images/minus.gif)";
        menu.style.display = (display == "block") ? "none" : "block";
	
        return false;
    };
}

function getCookies(cookieName)
{
    var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );
 
    if ( results )
        return ( unescape ( results[2] ) );
    else
        return null;
}
    
function setCookies (name, value, exp_y, exp_m, exp_d, path, domain, secure)
{
    var cookie_string = name + "=" + escape ( value );
 	
    if ( exp_y )
    {
        var expires = new Date ( exp_y, exp_m, exp_d );
        cookie_string += "; expires=" + expires.toGMTString();
    }
        
    if ( path )
        cookie_string += "; path=" + escape ( path );
     
    if ( domain )
        cookie_string += "; domain=" + escape ( domain );
 	
    if ( secure )
        cookie_string += "; secure";
 	
    document.cookie = cookie_string;
}
