﻿function valPostalCode(obj)
{
    var evt = window.event;
    var charCode = evt.keyCode;
    var newChar =  String.fromCharCode(charCode).toUpperCase();
    var currentCodeValue = obj.value;
    var codeLength = currentCodeValue.length;
    var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var num = "0123456789";
    if (codeLength == 6)
        if (charCode == 13)
            submitInfo();
        else
            return false;
        
    if (codeLength % 2 == 0)
    {
        if (alpha.indexOf(newChar) == -1)
            return false;
    }
    else
    {
        if (num.indexOf(newChar) == -1)
            return false;
    }
}


var qsParm = new Array();

function init()
{
    checkReferrer();
}

//---------------------------------------------
// read a cookie using the supplied name
//---------------------------------------------
function readCookie(name) 
{
    name = name.replace(/_/g, "%5F");
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(name + "=")
		if (c_start!=-1)
		{ 
			c_start=c_start + name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return null;
}

function setCookie(name, value) 
{
    var expires = new Date();
    expires.setTime( expires.getTime() );
    expires.setHours(expires.getHours() + (24 * 365));
    
    var curCookie = name + "=" + value +
        ((expires) ? "; expires=" + expires.toGMTString() : "") + ";path=/";

    document.cookie = curCookie;
    
    return;
}	

function getReferrer()
{
    parse_QueryString();
    
    var url = '';
    var sessionID = get_QueryStringParm("sessionID");
    if (sessionID == undefined)
        sessionID = "";
        
    // check if user supports cookies
    setCookie('test', 'none'); 

    // if readCookie succeeds, cookies are enabled, since the cookie was successfully created.
    if (readCookie('test'))
    {
        // check if last page is the publication director - if not go back to the beginning of page without sessionID
        if (readCookie(BANNER_ID + "SESSIONID") != sessionID)
        {
            if (window.location.href.indexOf('cached_pages') < 0)
                url = 'default.aspx?'
            else
                url = '../default.aspx?'
            var query = window.location.search.substring(1);
            var parms = query.split('&');
            for (var i=0; i<parms.length; i++)
            {
                var pos = parms[i].indexOf('=');
                if (pos > 0)
                {
                    if ( parms[i].substring(0,pos).toLowerCase() != 'sessionid')
                    {
                        url += parms[i].substring(0,pos) + '=' + parms[i].substring(pos+1) + '&';
                    }
                }
            }
        }
    }
    
    return url;
}

function checkReferrer()
{
     // check if last page is the publication director - if not go back to the beginning of page without sessionID
    var url = getReferrer();
    if (url != '')
        window.location.href = url;
}

function redirect(url)
{
    window.location.href = url;
}

// return a query string parameter
// using the supplied name
//
function get_QueryStringParm(name)
{
    return qsParm[name];
}


// return a query string parameter
// using the supplied name
//
function parse_QueryString()
{
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++)
    {
        var pos = parms[i].indexOf('=');
        if (pos > 0)
        {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
}