function submitForm()
{
        var frm = document.getElementById('frmAdvantage');
        var frmEntryAd = frm.entryAd;
        var frmID = frm.id;
        var id = getAdId();
        var adcookie = readEntryAdCookie();
        
        if(typeof(frmID) == 'object')
	        frmID.value = id;
        
        if(typeof(frmEntryAd) == 'object')
	        frmEntryAd.value = readEntryAdCookie();

        return true;
}

function readEntryAdCookie()
{
        var nameValueList = document.cookie.split(';');
        for (var item = 0; item < nameValueList.length; item++)
        {
                var nameValue = nameValueList[item].split('=');
                nameValue[0] = nameValue[0].replace(/^\s*/, "").replace(/\s*$/, "");

                if(nameValue[0] == "TMENTRYAD")
                {
                        return nameValue[1];
                }
        }

        return "";
}

function readAdCookie()
{
        var nameValueList = document.cookie.split(';');
        for (var item = 0; item < nameValueList.length; item++)
        {
                var nameValue = nameValueList[item].split('=');
                nameValue[0] = nameValue[0].replace(/^\s*/, "").replace(/\s*$/, "");

                if(nameValue[0] == "TMENTRYADID")
                {
                        return nameValue[1];
                }
        }

        return "";
}

function writeEntryAdCookie()
{
        var id = getEntryAd();

        if(id != "")
                document.cookie = "TMENTRYAD=" + id + "; path=/;";
}

function writeAdCookie()
{
        var id = getAd();

        if(id != "")
                document.cookie = "TMENTRYADID=" + id + "; path=/;";
}

function getAdId()
{
        var hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        var id = "";
        var frmID = document.getElementById('frmAdvantage').id;

        for(var i = 0; i < hashes.length; i++)
        {
                hash = hashes[i].split('=');
                if(hash[0].toLowerCase() == "id")
                {
                        id = hash[1];
                        break;
                }
        }
        
        if(typeof(frmID) == 'object' && id == "")
		id = frmID.value;

        return id;
}

function getEntryAd()
{
        var hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

        for(var i = 0; i < hashes.length; i++)
        {
                hash = hashes[i].split('=');
                if(hash[0] == "entryAd")
                        return hash[1];
        }

        return "";
}

function getAd()
{
        var hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

        for(var i = 0; i < hashes.length; i++)
        {
                hash = hashes[i].split('=');
                if(hash[0] == "id")
                        return hash[1];
        }

        return "";
}

window.onload = function()
{
	var entryAd = readEntryAdCookie();
	var ad = readAdCookie();
	var frm = document.getElementById('frmAdvantage');
	
        if ( entryAd == "")
                writeEntryAdCookie();
                
        if (ad == "")
        	writeAdCookie();
        	
        if (frm != null && typeof(frm) == 'object')
        {
        	if (typeof(frm.entryAd) == 'object' && entryAd != '')
        		frm.entryAd.value = entryAd;
        		
        	if (typeof(frm.id) == 'object' && ad != '')
        		frm.id.value = ad;
        }
}


