
function hidePass(fakeID, passID){
    document.getElementById(fakeID).style.display = 'none';
    document.getElementById(passID).value = '';
    document.getElementById(passID).style.display = 'block';
    document.getElementById(passID).focus();
 }
 
function showPass(fakeID, passID){
    if('' == document.getElementById(passID).value)
    {
        document.getElementById(passID).style.display = 'none';
        document.getElementById(fakeID).style.display = 'block';
    }
}

function toggleHomepageFeatures(featureId)
{
    // all are of format 'droparrow' + <id> + [on/off]
    ResetHomepageFeatures();
    
    // if they click an "on" block, turn everything off
    var prefix = 'droparrow';
    var arg = featureId.toString().substring(9);
    
    document.getElementById(featureId).style.display = 'none';
    if(arg.substring(1) == 'on')
    {
        arg = prefix + arg.substring(0,1) + 'off';
        document.getElementById(arg).style.display = 'block';
    }
    else
    {
        // you just turned this guy on, turn everything else off
        arg = prefix + arg.substring(0,1) + 'on';
        document.getElementById(arg).style.display = 'block';
    }
}
function ResetHomepageFeatures()
{
	document.getElementById('droparrow1on').style.display = 'none';
	document.getElementById('droparrow2on').style.display = 'none';
	document.getElementById('droparrow3on').style.display = 'none';
	document.getElementById('droparrow1off').style.display = 'block';
	document.getElementById('droparrow2off').style.display = 'block';
	document.getElementById('droparrow3off').style.display = 'block';
}
function trim(val)
{
    var cleanVal = val;
    cleanVal = trimStart(cleanVal);
    cleanVal = trimEnd(cleanVal);
    //cleanVal = cleanVal.replace(/^\s*|\s*$/g,"");
    
    return cleanVal;
}
function trimStart(val)
{
    return val.replace(/^\s*/,"");
}
function trimEnd(val)
{
    return val.replace(/\s*$/, "");
}
function checkFrames()
{
    if (top.frames.length > 0)
    {
        top.location.href = location.href;
    }
}
function doHourglass()
{
	document.body.style.cursor = 'wait';
	var content = document.getElementById('menuActionData');
	if(null != content)
	    content.style.display = 'none';
	var pleaseWait = document.getElementById('pleaseWait');
	pleaseWait.style.display = 'block';
}
function infowindow(page)
{
	// TODO update with relative path
	newWindow = window.open(page,'Info','menubar=no,location=no,toolbar=no,status=no,titlebar=no,scrollbars=yes,resizable=no,left=300,top=300,width=450,height=310');
	newWindow.focus();
}
function infowindowSize(page,width,height)
{
    var params = 'menubar=no,location=no,toolbar=no,status=no,titlebar=no,scrollbars=yes,resizable=no,left=300,top=300,width=' + width + ',height=' + height;
	newWindow = window.open(page,'Info',params);
	newWindow.focus();
}
function printWindow(page)
{
    newWindow = window.open(page,'Print', 'menubar=no,location=no,toolbar=no,status=no,titlebar=no,scrollbars=yes,resizable=yes,left=200,top=100,width=700,height=600');
    newWindow.focus();
}
function popLabelsTest( labels, delim, server, page )
{
	alert('welcome');
}
function popLabels( labels, delim, server, page )
{
	var idArray = labels.split( delim );
	var address = 'http://' + server + '/' + page + '?weblabelid=';
	var currentAddress;
	
	var parms = 'dialogHeight:600px;dialogWidth:800px;scroll:yes';

	// check to see if showModalDialog is supported (Mozilla)
	if (!window.showModalDialog) 
	{
		// do not cause a postback, as we cannot enforce a true modal
		//postback = false;
		window.showModalDialog = function(url, vArguments, sFeatures) {
        var sf = 'height=600, width=800, scrollbars, resizable, location=no, menubar=no, toolbar=yes, status=no, titlebar=no, left=0, top=0, screenX=0, screenY=0, dependent=1, modal=1';
        var mw = window.open(url, '', sf);
        mw.dialogArguments = vArguments;
        return mw.returnValue;
     }
	}

	if ( idArray.length )
	{
		for (i = 0; i < idArray.length ; i++)
		{
			// note, it is possible to retrieve a value from the modal dialog
			//     var result;
			//     result = window.showModalDialog(target, '', parms);
			// however, this would require setting a return value within the target
			//     window.returnValue = myString;

			currentAddress = address + idArray[i];
			window.showModalDialog(currentAddress, window, parms);
		}
	}
	else
	{
		currentAddress = address + idArray;
		
		window.showModalDialog(currentAddress, window, parms);
	}	
}
function popLabelsNonModal( labels, delim, server, page )
{
	var idArray = labels.split( delim );
	var address = 'http://' + server + '/' + page + '?weblabelid=';
	var currentAddress;
	
	var parms = 'dialogHeight:600px;dialogWidth:800px;scroll:yes';

	// do not cause a postback, as we cannot enforce a true modal
	//postback = false;
	window.showMyNonModalDialog = function(url, vArguments, sFeatures) {
    var sf = 'height=600, width=800, scrollbars, resizable, location=no, menubar=no, toolbar=yes, status=no, titlebar=no, left=0, top=0, screenX=0, screenY=0, dependent=1, modal=1';
    var mw = window.open(url, '', sf);
    mw.dialogArguments = vArguments;
    return mw.returnValue;}

	if ( idArray.length )
	{
		for (i = 0; i < idArray.length ; i++)
		{
			// note, it is possible to retrieve a value from the modal dialog
			//     var result;
			//     result = window.showModalDialog(target, '', parms);
			// however, this would require setting a return value within the target
			//     window.returnValue = myString;

			currentAddress = address + idArray[i];
			window.showMyNonModalDialog(currentAddress, window, parms);
		}
	}
	else
	{
		currentAddress = address + idArray;
		
		window.showMyNonModalDialog(currentAddress, window, parms);
	}	
}
function popConsumerShipmentNonModal( csId, server, page )
{
	var address = 'http://' + server + '/' + page + '?weblabelid=';
	var currentAddress;
	
	var parms = 'dialogHeight:600px;dialogWidth:800px;scroll:yes';

	// do not cause a postback, as we cannot enforce a true modal
	//postback = false;
	window.showMyNonModalDialog = function(url, vArguments, sFeatures) {
    var sf = 'height=600, width=800, scrollbars, resizable, location=no, menubar=no, toolbar=yes, status=no, titlebar=no, left=0, top=0, screenX=0, screenY=0, dependent=1, modal=1';
    var mw = window.open(url, '', sf);
    mw.dialogArguments = vArguments;
    return mw.returnValue;}

	currentAddress = address + csId;
		
	window.showMyNonModalDialog(currentAddress, window, parms);	
}
function popReportNonModal(server, page)
{
	var address = 'http://' + server + page;
	var parms = 'dialogHeight:600px;dialogWidth:800px;scroll:yes';
	// do not cause a postback, as we cannot enforce a true modal
	//postback = false;
	window.showMyNonModalDialog = function(url, vArguments, sFeatures) {
    var sf = 'height=768, width=1024, scrollbars, resizable, location=no, menubar=no, toolbar=yes, status=no, titlebar=no, left=0, top=0, screenX=0, screenY=0, dependent=1, modal=1';
    var mw = window.open(url, '', sf);
    mw.dialogArguments = vArguments;
    return mw.returnValue;}
		
	window.showMyNonModalDialog(address, window, parms);	
}
function setEmailValidators()
{
	// if email option is selected, enable validators (otherwise disable them)
	if ( document.Form1.deliveryMethodOptions[1].checked )
	{
		ValidatorEnable( document.getElementById('RegExEmail'), true );
		ValidatorEnable( document.getElementById('RequiredFieldEmail'), true );
	}
	else
	{
		ValidatorEnable( document.getElementById('RegExEmail'), false );
		ValidatorEnable( document.getElementById('RequiredFieldEmail'), false );
	}
}

function validateLabelDeliveryMethod( summaryId, optionId, emailId, buttonId, emailVisible )
{
	var isValid = true;

    // disable the button while we figure things out
    disableAndWait(buttonId);

	if( 'true' == emailVisible)
	{
	    var summaryCtl		= document.getElementById(summaryId);
	    var optionCtl		= document.getElementById(optionId);
	    var emailCtl		= document.getElementById(emailId);

	    var errorMessages	= '';
	    var errorMessageDelimiter = '|';
	    var errorCount		= 0;

        emailCtl.value = CleanString(emailCtl.value, '>');
        emailCtl.value = CleanString(emailCtl.value, '<');
        emailCtl.value = trim(emailCtl.value);
        
	    if ( true == optionCtl.checked )
	    {
		    // validate email required
		    if ( emailCtl.value < 1 )
		    {
			    errorMessages = AddMessage( '- please provide an email address for label delivery', errorMessages, errorMessageDelimiter );		
			    errorCount++;
		    }
    		
		    // validate email regex
		    if ( false == IsEmail( emailCtl.value ) )
		    {
			    errorMessages = AddMessage( '- email must be of format name@address.suffix', errorMessages, errorMessageDelimiter );				
			    errorCount++;
		    }
	    }	
	    // check error count
	    if ( errorCount > 0 )
	    {
		    var errors = errorMessages.split('|');
		    var text = '<ul>';
		    for ( index=0;index < errors.length;index++ )
		    {
			    text = text + '<li>' + errors[index] + '</li>';
		    }
		    text = text + '</ul>';
		    // populate the summary message control
		    summaryCtl.innerHTML = text;
		    // fail validation
		    isValid = false;
	        // reset mouse pointer and submit
		    enable(buttonId);
	    }
	}
	return isValid;
}
function validateCustomerEmail( summaryId, optionId, emailId, buttonId )
{
	var isValid = true;
	
	var summaryCtl		= document.getElementById(summaryId);

	// this is hokey, but because the option turns into a table of radio buttons, we have to 
	//	grab the email option directly
	var emailOptionId	= optionId + '_1';
	var optionCtl		= document.getElementById(emailOptionId);
	var emailCtl		= document.getElementById(emailId);

	var flag = emailId + 'Flag';
	var emailFlag		= document.getElementById(flag);	

	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

    // disable the button while we figure things out
    disableAndWait(buttonId);
    
	// clear flags
	emailFlag.style.display = 'none';

    emailCtl.value = CleanString(emailCtl.value, '>');
    emailCtl.value = CleanString(emailCtl.value, '<');
    emailCtl.value = trim(emailCtl.value);

	//Email
	// if email option selected, validate email address
	// (we rely on email being the second option)
	if ( true == optionCtl.checked )
	{
		// validate email required
		if ( emailCtl.value < 1 )
		{
			emailFlag.style.display = 'block';
			errorMessages = AddMessage( '- please provide an email address for label delivery', errorMessages, errorMessageDelimiter );		
			errorCount++;
		}
		
		// validate email regex
		if ( false == IsEmail( emailCtl.value ) )
		{
			emailFlag.style.display = 'block';
			errorMessages = AddMessage( '- email must be of format name@address.suffix', errorMessages, errorMessageDelimiter );				
			errorCount++;
		}
	}
	
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
		// reset mouse pointer and submit
		enable(buttonId);
	}
	
	return isValid;
}
function validateOutboundTrackingData( buttonId, summaryId, trackingOptionsId, trackingInputId, optionCount, validationData )
{
    var isValid = true;
    var summaryCtl      = document.getElementById(summaryId);
    var blockInfo       = validationData.split('::');
    var wordInfo;
    var currentCtl;
    var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;
	
    var validateBID = false;
    var validateIID = false;
    var validateOID = false;

    if('' != summaryCtl.innerHTML)
        summaryCtl.innerHTML = '';

    var optionCtl;
    var optionCtlKey = '';

    disableAndWait(buttonId);

  	currentCtl		= document.getElementById(trackingInputId);
  	currentCtl.value = CleanString(currentCtl.value, '>');
  	currentCtl.value = CleanString(currentCtl.value, '<');
    currentCtl.value = trim(currentCtl.value);

    if('1' == optionCount)
    {
        // just validate against blockinfo[0]
        wordInfo = blockInfo[0].split(':');
    }
    else
    {
        for (var optionIndex = 0;optionIndex < optionCount; optionIndex++)
        {
            optionCtlKey = trackingOptionsId + '_' + optionIndex;
            optionCtl = document.getElementById(optionCtlKey);
            //alert(optionCtl.value + ' ' + optionCtl.checked);
            if(true == optionCtl.checked)
            {
                // which option is checked?
                break;
            }
        }
        wordInfo = blockInfo[optionIndex].split(':');
    }
    
	if( currentCtl.value.length < 1 )
	{
		if( wordInfo[1].charAt( wordInfo[1].length - 1 ) == ':' )
		    wordInfo[1] = wordInfo[1].substring( 0, ( wordInfo[1].length - 1 ) );
		
		tempMessage = '- ' + wordInfo[1] + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	} 
	else
	{
		// trim off the leading '/' and append the '$'
		var re = new RegExp( wordInfo[0], "g" );
		var val = currentCtl.value;
		var result = '';
		
		val = re.exec( val );

		var num = Number( val );
		if( num == 0 )
		{			    
		    errorMessages = AddMessage( wordInfo[2], errorMessages, errorMessageDelimiter );		
		    errorCount++;
		}
		else
		{
			//for( var i=1; i<val.length; i++ )
			//{
			//    result += val[i];
			//}
			result = val[0];
			currentCtl.value = result;
		}
	}
	
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
		
		enable(buttonId);
	}
	return isValid;	
}
function validateTrackingDatav3( summaryId, trackingOptionsId, trackingInputId, optionCount, validationData )
{
    var isValid = true;
    var summaryCtl      = document.getElementById(summaryId);
    var blockInfo       = validationData.split('$$');
    var wordInfo;
    var currentCtl;
    var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;
    var validateRID = false;
    var validateBID = false;
    var validateIID = false;
    var validateOID = false;
    
    if('' != summaryCtl.innerHTML)
        summaryCtl.innerHTML = '';
    // 0 - regex
    // 1 - field name
    // 2 - error message
    // alert(wordInfo[0] + ' ' + wordInfo[1] + ' ' + wordInfo[2]);
    
    var optionCtl;
    var optionCtlKey = '';
    for (var optionIndex = 0;optionIndex < optionCount; optionIndex++)
    {
        optionCtlKey = trackingOptionsId + '_' + optionIndex;
        optionCtl = document.getElementById(optionCtlKey);
        //alert(optionCtl.value + ' ' + optionCtl.checked);
        if(('RID' == optionCtl.value) && (true == optionCtl.checked))
        {
            // only validate against return identifier text
            validateRID = true;
        }
        else if(('BID' == optionCtl.value) && (true == optionCtl.checked))
        {
            validateBID = true;
        }
        else if(('IID' == optionCtl.value) && (true == optionCtl.checked))
        {
            validateIID = true;
        }
        else if(('OID' == optionCtl.value) && (true == optionCtl.checked))
        {
            validateOID = true;
        }
    }

  	currentCtl		= document.getElementById(trackingInputId);
  	currentCtl.value = CleanString(currentCtl.value, '>');
  	currentCtl.value = CleanString(currentCtl.value, '<');
    currentCtl.value = trim(currentCtl.value);
    
    // validation
    if (true == validateRID)
    {
        wordInfo		= blockInfo[0].split('$');

		if( currentCtl.value.length < 1 )
		{
			if( wordInfo[1].charAt( wordInfo[1].length - 1 ) == ':' )
			    wordInfo[1] = wordInfo[1].substring( 0, ( wordInfo[1].length - 1 ) );
			
    		tempMessage = '- ' + wordInfo[1] + ' is a required field.';
			errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			errorCount++;
		}
		else
		{
			// trim off the leading '/' and append the '$'
			var re = new RegExp( wordInfo[0].substring(1) + '$', "g" );
			var val = currentCtl.value;
			var result = '';
			
			val = re.exec( val );

			var num = Number( val );
			if( num == 0 )
			{			    
			    errorMessages = AddMessage( wordInfo[2], errorMessages, errorMessageDelimiter );		
			    errorCount++;
			}
			else
			{
                // we used to concatenate the subgroups (after sub-zero, the full match) in an attempt to generate the 
                // returnidentifierkey
                // now we pass the returnidentifier down to the tracking component, and allow the component to generate the key
				//for( var i=1; i<val.length; i++ )
				//{
				//    result += val[i];
				//}
				result = val[0];
				currentCtl.value = result;
			}
		}
    }
    else if (true == validateBID)
    {
        wordInfo		= blockInfo[1].split('$');

		if( currentCtl.value.length < 1 )
		{
			if( wordInfo[1].charAt( wordInfo[1].length - 1 ) == ':' )
			    wordInfo[1] = wordInfo[1].substring( 0, ( wordInfo[1].length - 1 ) );
			
    		tempMessage = '- ' + wordInfo[1] + ' is a required field.';
			errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			errorCount++;
		}    
    }
    else if (true == validateIID)
    {
        wordInfo		= blockInfo[2].split('$');
    
		if( currentCtl.value.length < 1 )
		{
			if( wordInfo[1].charAt( wordInfo[1].length - 1 ) == ':' )
			    wordInfo[1] = wordInfo[1].substring( 0, ( wordInfo[1].length - 1 ) );
			
    		tempMessage = '- ' + wordInfo[1] + ' is a required field.';
			errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			errorCount++;
		}    
    }
    else if (true == validateOID)
    {
        wordInfo		= blockInfo[3].split('$');

		if( currentCtl.value.length < 1 )
		{
			if( wordInfo[1].charAt( wordInfo[1].length - 1 ) == ':' )
			    wordInfo[1] = wordInfo[1].substring( 0, ( wordInfo[1].length - 1 ) );
			
    		tempMessage = '- ' + wordInfo[1] + ' is a required field.';
			errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			errorCount++;
		}        
    }
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;	
}
function validateTrackingData( summaryId, validationData, orderErrorMessage, trackErrorMessage, orderNumLabel, trackingNumLabel )
{
	var isValid = true;
	
	var summaryCtl		= document.getElementById(summaryId);
	var blockInfo		= validationData.split('$$');
    var wordInfo;
    var currentCtl;
    var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

    // order number
   	var validateOrderNumber = false;
    
    wordInfo		= blockInfo[0].split('$');
	if( 'true' == wordInfo[1] )
		validateOrderNumber = true;
	else if( 'false' == wordInfo[1] )
		validateOrderNumber = false;
	else
	{
		validateOrderNumber = document.getElementById(wordInfo[1]).checked;
	}
	
	if( true == validateOrderNumber )
	{
		currentCtl		= document.getElementById(wordInfo[0]);
  	    currentCtl.value = CleanString(currentCtl.value, '>');
  	    currentCtl.value = CleanString(currentCtl.value, '<');
  	    currentCtl.value = trim(currentCtl.value);

		if( currentCtl.value.length < 1 )
		{
			if( orderNumLabel.charAt( orderNumLabel.length - 1 ) == ':' )
			    orderNumLabel = orderNumLabel.substring( 0, ( orderNumLabel.length - 1 ) );
			
    		tempMessage = '- ' + orderNumLabel + ' is a required field.';
			errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			errorCount++;
		}
		else
		{
			// trim off the leading '/' and append the '$'
			var re = new RegExp( wordInfo[2].substring(1) + '$', "g" );
			var val = currentCtl.value;
			var result = '';
			
			val = re.exec( val );

			var num = Number( val );
			if( num == 0 )
			{			    
			    errorMessages = AddMessage( orderErrorMessage, errorMessages, errorMessageDelimiter );		
			    errorCount++;
			}
			else
			{
				for( var i=1; i<val.length; i++ )
				{
					result += val[i];
				}
				currentCtl.value = result;
			}
		}
	}
	// tracking number
	var validateTrackingNumber = false;

    wordInfo		= blockInfo[1].split('$');	
	if( 'true' == wordInfo[1] )
		validateTrackingNumber = true;
	else if( 'false' == wordInfo[1] )
		validateTrackingNumber = false;
	else
	{
		validateTrackingNumber = document.getElementById(wordInfo[1]).checked;
	}

	if( true == validateTrackingNumber )
	{
		currentCtl		= document.getElementById(wordInfo[0]);
  	    currentCtl.value = CleanString(currentCtl.value, '>');
  	    currentCtl.value = CleanString(currentCtl.value, '<');
  	    currentCtl.value = trim(currentCtl.value);

		if( currentCtl.value.length < 1 )
		{
			if( trackingNumLabel.charAt( trackingNumLabel.length - 1 ) == ':' )
			    trackingNumLabel = trackingNumLabel.substring( 0, ( trackingNumLabel.length - 1 ) );
			
    		tempMessage = '- ' + trackingNumLabel + ' is a required field.';
			errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			errorCount++;
		}
		else
		{
			// trim off the leading '/' and append the '$'
			var re = new RegExp( wordInfo[2].substring(1) + '$', "g" );
			var val = currentCtl.value;
			var result = '';
			
			val = re.exec( val );

			var num = Number( val );
			if( num == 0 )
			{			    
			    errorMessages = AddMessage( trackErrorMessage, errorMessages, errorMessageDelimiter );		
			    errorCount++;
			}
			else
			{
				for( var i=1; i<val.length; i++ )
				{
					result += val[i];
				}
				currentCtl.value = result;
			}
		}	
    }
	
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;	
}

function validatePickupData( summaryId, validationData, errorMessage )
{
    var isValid = true;
    
    var summaryCtl		= document.getElementById(summaryId);
	var blockInfo		= validationData.split('$$');
	var wordInfo;
	var currentCtl;

	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

	for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
	{
		wordInfo		= blockInfo[blockIndex].split('$');
		currentCtl		= document.getElementById(wordInfo[0]);
		
        // is this field required?
  	    currentCtl.value = CleanString(currentCtl.value, '>');
  	    currentCtl.value = CleanString(currentCtl.value, '<');
  	    currentCtl.value = trim(currentCtl.value);

		if( 'true' == wordInfo[1] )
		{
			if ((currentCtl.value.length < 1) || (currentCtl.value < 0))
			{
			    tempMessage = 'Please fill in all required fields.';
    		    errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			    errorCount++;
				break;
			}
		}
		// does this field match its regex?
		if ( false == MatchRegEx( currentCtl.value, wordInfo[2] + '$' ) )
		{	
		    errorMessages = AddMessage( errorMessage, errorMessages, errorMessageDelimiter );		
		    errorCount++;
			break;
		}
	}
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;	
}
function validateStaticOrderLookupData()
{ 
    // if the item is not required, we should still check to see if it is currently selected (if selected -> required)
    var isValid = true;
    
    var summaryCtl      = document.getElementById('orderLookupError');
  
    var primaryCtlPhone1 = document.getElementById('ucStaticOrderLookup_primaryRequiredField1');
    var primaryCtlPhone2 = document.getElementById('ucStaticOrderLookup_primaryRequiredField2');
    var primaryCtlPhone3 = document.getElementById('ucStaticOrderLookup_primaryRequiredField3');
    var phoneErrorMessage = 'The information provided does not match the correct format for the Wireless Phone Number.  Please re-enter your 10 digit Wireless Phone Number.';
    
    var orderNumberRegEx = '^\\d{1,10}$';
    
    var secondaryCtlSelect = document.getElementById('ucStaticOrderLookup_secondaryRequiredFieldSelect');
    var tertiaryCtlSelect = document.getElementById('ucStaticOrderLookup_tertiaryRequiredFieldSelect');
    
    var secondaryCtl = document.getElementById('ucStaticOrderLookup_secondaryRequiredField1');
    var orderNumberErrorMessage = 'The information provided does not match the correct format for the  Phone Replacement Order Number.  Please verify the number and try again. Your Order Number was provided in the emailed shipment confirmation and instructions in your replacement kit.';

    var tertiaryCtl1 = document.getElementById('ucStaticOrderLookup_tertiaryRequiredField1');
    var emailErrorMessage = 'The information provided does not match our records.  Please verify the email address and shipping zip code entered at the time of your Phone Replacement Order.';
  
    var tertiaryCtl2 = document.getElementById('ucStaticOrderLookup_tertiaryRequiredField2');
    var zipErrorMessage = 'The information provided does not match our records.  Please verify the email address and shipping zip code entered at the time of your Phone Replacement Order.';
    	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;
    
    // ****************************************
    // ** Validate Phone Number
    // ****************************************
    
    // is phone present?
    primaryCtlPhone1.value = CleanString(primaryCtlPhone1.value, '>');
    primaryCtlPhone1.value = CleanString(primaryCtlPhone1.value, '<');
    primaryCtlPhone2.value = CleanString(primaryCtlPhone2.value, '>');
    primaryCtlPhone2.value = CleanString(primaryCtlPhone2.value, '<');
    primaryCtlPhone3.value = CleanString(primaryCtlPhone3.value, '>');
    primaryCtlPhone3.value = CleanString(primaryCtlPhone3.value, '<');

    primaryCtlPhone1.value = trim(primaryCtlPhone1.value);
    primaryCtlPhone2.value = trim(primaryCtlPhone2.value);
    primaryCtlPhone3.value = trim(primaryCtlPhone3.value);

	var phoneValue = primaryCtlPhone1.value + primaryCtlPhone2.value + primaryCtlPhone3.value;  	            
    if (phoneValue < 1)
    {
        tempMessage = 'Please fill in all required fields.';
        errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
        errorCount++;
    }
    // does this field match its regex?
    if ( false == IsPhone( phoneValue ) )
    {
        errorMessages = AddMessage( phoneErrorMessage, errorMessages, errorMessageDelimiter );		
        errorCount++;
    }			         
    
    if(0 == errorCount)
    {    
        // ****************************************
        // ** Validate Order Number
        // ****************************************
        if(true == secondaryCtlSelect.checked)
        {
            secondaryCtl.value = CleanString(secondaryCtl.value, '>');
            secondaryCtl.value = CleanString(secondaryCtl.value, '<');
            secondaryCtl.value = trim(secondaryCtl.value);
            
            if (secondaryCtl.value < 1)
            {
                tempMessage = 'Please fill in all required fields.';
                errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
                errorCount++;
            }
            // does this field match its regex?
            if ( false == MatchRegEx( secondaryCtl.value, orderNumberRegEx ) )
            {	
                errorMessages = AddMessage( orderNumberErrorMessage, errorMessages, errorMessageDelimiter );		
                errorCount++;
            }			 
        }
        
        // ****************************************
        // ** Validate Zip + Email
        // ****************************************
        if(true == tertiaryCtlSelect.checked)
        {
            tertiaryCtl1.value = CleanString(tertiaryCtl1.value, '>');
            tertiaryCtl1.value = CleanString(tertiaryCtl1.value, '<');
            tertiaryCtl2.value = CleanString(tertiaryCtl2.value, '>');
            tertiaryCtl2.value = CleanString(tertiaryCtl2.value, '<');
            
            tertiaryCtl1.value = trim(tertiaryCtl1.value);
            tertiaryCtl2.value = trim(tertiaryCtl2.value);
            
            if (tertiaryCtl1.value < 1)
            {
                tempMessage = 'Please fill in all required fields.';
                errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
                errorCount++;
            }
            else if (tertiaryCtl2.value < 1)
            {
                tempMessage = 'Please fill in all required fields.';
                errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
                errorCount++;
            }
            else
            {
                // does this field match its regex?
                if ( false == IsEmail( tertiaryCtl1.value ) )
                {
                    errorMessages = AddMessage( emailErrorMessage, errorMessages, errorMessageDelimiter );		
                    errorCount++;
                }	
                else if ( false == IsZip( tertiaryCtl2.value ) )
                {
                    errorMessages = AddMessage( zipErrorMessage, errorMessages, errorMessageDelimiter );		
                    errorCount++;
                }	
            }
        }
    }
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;			    
}
function validateOrderLookupData( summaryId, validationData )
{ 
    // if the item is not required, we should still check to see if it is currently selected (if selected -> required)
    var isValid = true;
    
    var summaryCtl      = document.getElementById(summaryId);
    var blockInfo       = validationData.split('$$');
  
	var wordInfo;
	var currentCtl;
	var currentCtl2;
	var currentCtl3;
	var tempRadio;
    var reqCtlTemplate;
    var reqIndex;
    var reqCtlPrefix;

	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;
    
    for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
	{
		wordInfo		= blockInfo[blockIndex].split('$');

		currentCtl		= document.getElementById(wordInfo[0]);
        if(null != currentCtl)
        {
            if('text' == wordInfo[4])
            {
                // is this field required?
  	            currentCtl.value = CleanString(currentCtl.value, '>');
  	            currentCtl.value = CleanString(currentCtl.value, '<');
  	            currentCtl.value = trim(currentCtl.value);
  	            
		        if( 'true' == wordInfo[1] )
		        {
			        if (currentCtl.value < 1)
			        {
			            tempMessage = 'Please fill in all required fields.';
    		            errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			            errorCount++;
				        break;
			        }
		            // does this field match its regex?
		            if ( false == MatchRegEx( currentCtl.value, wordInfo[2] + '$' ) )
		            {	
	                    errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
		                errorCount++;
			            break;
		            }			        
		        }
		        else
		        {
		            // TODO this can be consolidated by settinga single "validate the field" boolean, then running the validation based on that
		            // (vs. duping the validation code twice)
		            // I left it this way for now, because currently there is no concept of filling in a non-required field...if it's not required
		            // we will ignore it at the app layer (so we might as well blank it.)
		            
		            // can we somehow determine if this field is selected?
		            // what if we assume the previous ctl# is the radio button? (seems dangerous)
			        var reqCtlTemplate = wordInfo[0];
      		        var reqIndex = reqCtlTemplate.substring((reqCtlTemplate.lastIndexOf('ctl') + 3));
	    	        var reqCtlPrefix = reqCtlTemplate.substring(0,(reqCtlTemplate.lastIndexOf('ctl') + 3));
                    
                    if(0 != reqIndex)
                    {
                        reqIndex = Number(reqIndex - 1);
                        tempRadio = document.getElementById(reqCtlPrefix + reqIndex);
                        
                        if(true == tempRadio.checked)
                        {
                            // it's checked we better validate the original (required and otherwise)
			                if (currentCtl.value < 1)
			                {
			                    tempMessage = 'Please fill in all required fields.';
    		                    errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			                    errorCount++;
				                break;
			                }
        			        
		                    // does this field match its regex?
		                    if ( false == MatchRegEx( currentCtl.value, wordInfo[2] + '$' ) )
		                    {	
	                            errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
		                        errorCount++;
			                    break;
		                    }			                                    
                        }
                    }
		        }   
		    }
		    else if('phone' == wordInfo[4])
		    {
		        // we got to grab the other phone fields and concat!
		        // we trust that the next two fields are the phone legs
		        var phoneCtlTemplate = wordInfo[0];
		        var phoneIndex = phoneCtlTemplate.substring((phoneCtlTemplate.lastIndexOf('ctl') + 3));
		        var phoneCtlPrefix = phoneCtlTemplate.substring(0,(phoneCtlTemplate.lastIndexOf('ctl') + 3));
                
		        phoneIndex = Number(phoneIndex) + 1;
		        currentCtl2		= document.getElementById(phoneCtlPrefix + phoneIndex);

		        phoneIndex = Number(phoneIndex) + 1;
		        currentCtl3		= document.getElementById(phoneCtlPrefix + phoneIndex);
		        		        
	            // is this field required?
  	            currentCtl.value = CleanString(currentCtl.value, '>');
  	            currentCtl.value = CleanString(currentCtl.value, '<');
  	            currentCtl2.value = CleanString(currentCtl2.value, '>');
  	            currentCtl2.value = CleanString(currentCtl2.value, '<');
  	            currentCtl3.value = CleanString(currentCtl3.value, '>');
  	            currentCtl3.value = CleanString(currentCtl3.value, '<');
            
  	            currentCtl.value = trim(currentCtl.value);
  	            currentCtl2.value = trim(currentCtl2.value);
  	            currentCtl3.value = trim(currentCtl3.value);

            	var phoneValue = currentCtl.value + currentCtl2.value + currentCtl3.value;  	            
		        if( 'true' == wordInfo[1] )
		        {
			        if (phoneValue < 1)
			        {
			            tempMessage = 'Please fill in all required fields.';
    		            errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			            errorCount++;
				        break;
			        }
		            // does this field match its regex?
	                if ( false == IsPhone( phoneValue ) )
	                {
	                    errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
		                errorCount++;
			            break;
		            }			        
		        }
		        else
		        {
  		            // can we somehow determine if this field is selected?
		            // what if we assume the previous ctl# is the radio button? (seems dangerous)
			        var reqCtlTemplate = wordInfo[0];
      		        var reqIndex = reqCtlTemplate.substring((reqCtlTemplate.lastIndexOf('ctl') + 3));
	    	        var reqCtlPrefix = reqCtlTemplate.substring(0,(reqCtlTemplate.lastIndexOf('ctl') + 3));
                    
                    if(0 != reqIndex)
                    {
                        reqIndex = Number(reqIndex - 1);
                        tempRadio = document.getElementById(reqCtlPrefix + reqIndex);
                        
                        if(true == tempRadio.checked)
                        {
			                if (phoneValue < 1)
			                {
			                    tempMessage = 'Please fill in all required fields.';
    		                    errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			                    errorCount++;
				                break;
			                }
		                    // does this field match its regex?
	                        if ( false == IsPhone( phoneValue ) )
	                        {
	                            errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
		                        errorCount++;
			                    break;
		                    }
		                }
		            }                        
		        } 
		    }
		}
	}
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;			    
}
function validateStoreReturnsData(summaryId, validationData, buttonId)
{
    // if the item is not required, we should still check to see if it is currently selected (if selected -> required)
    var isValid = true;
    
    // disable the button while we figure things out
    disableAndWait(buttonId);
    
    var summaryCtl      = document.getElementById(summaryId);
    var blockInfo       = validationData.split('::');
  
	var wordInfo;
	var currentCtl;
	var currentCtl2;
	var currentCtl3;
	var currentCtl4;
    var reqCtlTemplate;
    var reqIndex;
    var reqCtlPrefix;

	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

    for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
    {
	    wordInfo		= blockInfo[blockIndex].split(':');
	    currentCtl		= document.getElementById(wordInfo[0]);
        if(null != currentCtl)
        {
            if('text' == wordInfo[4])
            {
                // is this field required?
                currentCtl.value = CleanString(currentCtl.value, '>');
                currentCtl.value = CleanString(currentCtl.value, '<');
                currentCtl.value = trim(currentCtl.value);
  	            
	            if (currentCtl.value != null && currentCtl.value.length < 1)
	            {
	                if( 'true' == wordInfo[1] )
	                {
	                    //tempMessage = 'Please fill in all required fields.';
	                    tempMessage = wordInfo[5];
	                    errorMessages = AddMessage(tempMessage, errorMessages, errorMessageDelimiter);
	                    errorCount++;
	                    break;
		            }
	            }
	            else
	            {
	                if( '' != wordInfo[2])
	                {
	                    // validate content
	                    // does this field match its regex?
	                    if ( false == MatchRegEx( currentCtl.value, wordInfo[2]) )
	                    {	
                            errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
	                        errorCount++;
		                    break;
	                    }
	                }			        		            
	            }
	        }
	    }
    }

	
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
		
		enable(buttonId);
	}
	return isValid;			  
}

function validateAccountInformationData( summaryId, validationData )
{ 
    // if the item is not required, we should still check to see if it is currently selected (if selected -> required)
    var isValid = true;
    
    var summaryCtl      = document.getElementById(summaryId);
    var blockInfo       = validationData.split('::');
  
	var wordInfo;
	var currentCtl;
	var currentCtl2;
	var currentCtl3;
	var currentCtl4;
    var reqCtlTemplate;
    var reqIndex;
    var reqCtlPrefix;

	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

    for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
    {
	    wordInfo		= blockInfo[blockIndex].split(':');
	    currentCtl		= document.getElementById(wordInfo[0]);
        if(null != currentCtl)
        {
            if('text' == wordInfo[4])
            {
                // is this field required?
                currentCtl.value = CleanString(currentCtl.value, '>');
                currentCtl.value = CleanString(currentCtl.value, '<');
                currentCtl.value = trim(currentCtl.value);
  	            
	            if (currentCtl.value < 1)
	            {
	                if( 'true' == wordInfo[1] )
	                {
	                    tempMessage = 'Please fill in all required fields.';
	                    errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
	                    errorCount++;
		                break;
		            }
	            }
	            else
	            {
	                if( '' != wordInfo[2])
	                {
	                    // validate content
	                    // does this field match its regex?
	                    if ( false == MatchRegEx( currentCtl.value, wordInfo[2]) )
	                    {	
                            errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
	                        errorCount++;
		                    break;
	                    }
	                }			        		            
	            }
	        }
	        else if('phone' == wordInfo[4])
	        {
	            // we got to grab the other phone fields and concat!
	            // we trust that the next two fields are the phone legs
	            var phoneCtlTemplate = wordInfo[0];
	            var phoneIndex = phoneCtlTemplate.substring((phoneCtlTemplate.lastIndexOf('ctl') + 3));
	            var phoneCtlPrefix = phoneCtlTemplate.substring(0,(phoneCtlTemplate.lastIndexOf('ctl') + 3));
                
	            phoneIndex = Number(phoneIndex) + 1;
	            currentCtl2		= document.getElementById(phoneCtlPrefix + phoneIndex);

	            phoneIndex = Number(phoneIndex) + 1;
	            currentCtl3		= document.getElementById(phoneCtlPrefix + phoneIndex);
		        		        
                // is this field required?
                currentCtl.value = CleanString(currentCtl.value, '>');
                currentCtl.value = CleanString(currentCtl.value, '<');
                currentCtl2.value = CleanString(currentCtl2.value, '>');
                currentCtl2.value = CleanString(currentCtl2.value, '<');
                currentCtl3.value = CleanString(currentCtl3.value, '>');
                currentCtl3.value = CleanString(currentCtl3.value, '<');

                currentCtl.value = trim(currentCtl.value);
                currentCtl2.value = trim(currentCtl2.value);
                currentCtl3.value = trim(currentCtl3.value);
            
        	    var phoneValue = currentCtl.value + currentCtl2.value + currentCtl3.value;  	            
	            if (phoneValue < 1)
	            {
                    if( 'true' == wordInfo[1] )
                    {			        
	                    tempMessage = 'Please fill in all required fields.';
	                    errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
	                    errorCount++;
		                break;
		            }
	            }
	            else
	            {
                    // does this field match its regex?
                    if ( false == IsPhone( phoneValue ) )
                    {
                        errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
                        errorCount++;
                        break;
                    }
	            }
	        }
	        else if('phoneext' == wordInfo[4])
	        {
	            // we got to grab the other phone fields and concat!
	            // we trust that the next two fields are the phone legs
	            var phoneCtlTemplate = wordInfo[0];
	            var phoneIndex = phoneCtlTemplate.substring((phoneCtlTemplate.lastIndexOf('ctl') + 3));
	            var phoneCtlPrefix = phoneCtlTemplate.substring(0,(phoneCtlTemplate.lastIndexOf('ctl') + 3));

	            phoneIndex = Number(phoneIndex) + 1;
	            currentCtl2		= document.getElementById(phoneCtlPrefix + phoneIndex);

	            phoneIndex = Number(phoneIndex) + 1;
	            currentCtl3		= document.getElementById(phoneCtlPrefix + phoneIndex);
		        
	            phoneIndex = Number(phoneIndex) + 2;
	            currentCtl4     = document.getElementById(phoneCtlPrefix + phoneIndex);
                // is this field required?
                currentCtl.value = CleanString(currentCtl.value, '>');
                currentCtl.value = CleanString(currentCtl.value, '<');
                currentCtl2.value = CleanString(currentCtl2.value, '>');
                currentCtl2.value = CleanString(currentCtl2.value, '<');
                currentCtl3.value = CleanString(currentCtl3.value, '>');
                currentCtl3.value = CleanString(currentCtl3.value, '<');
                currentCtl4.value = CleanString(currentCtl4.value, '>');
                currentCtl4.value = CleanString(currentCtl4.value, '<');
            
                currentCtl.value = trim(currentCtl.value);
                currentCtl2.value = trim(currentCtl2.value);
                currentCtl3.value = trim(currentCtl3.value);
                currentCtl4.value = trim(currentCtl4.value);
            
        	    var phoneValue = currentCtl.value + currentCtl2.value + currentCtl3.value + currentCtl4.value;  	
	            if (phoneValue < 1)
	            {
                    if( 'true' == wordInfo[1] )
                    {			        
	                    tempMessage = 'Please fill in all required fields.';
	                    errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
	                    errorCount++;
		                break;
		            }
	            }
	            else
	            {
                    // does this field match its regex?
                    if ( false == IsPhone( phoneValue ) )
                    {
                        errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
                        errorCount++;
                        break;
                    }
	            }
            }
	    }
    }

	
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;			    
}
// used by both Order Details (RCv2) and Item Selection (RCv3)
// if changes are made, may need to factor into two methods!
function validateOrderData( summaryId, validationData, errorMessage )
{
	var isValid = true;

	var summaryCtl		= document.getElementById(summaryId);
	var blockInfo		= validationData.split('$$');
	var wordInfo;
	var currentCtl;
	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

	for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
	{
		wordInfo		= blockInfo[blockIndex].split('$');
		currentCtl		= document.getElementById(wordInfo[0]);
		
        if(null != currentCtl)
        {
            // is this field required?
  	        currentCtl.value = CleanString(currentCtl.value, '>');
  	        currentCtl.value = CleanString(currentCtl.value, '<');
  	        currentCtl.value = trim(currentCtl.value);
  	        
		    if( 'true' == wordInfo[1] )
		    {
			    if ((currentCtl.value.length < 1) || (currentCtl.value < 0))
			    {
			        tempMessage = 'Please fill in all required fields.';
    		        errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			        errorCount++;
				    break;
			    }
		    }
		    // does this field match its regex?
		    if ( false == MatchRegEx( currentCtl.value, wordInfo[2] + '$' ) )
		    {	
		        // Dell/DHL weight collection needs a fresh error message
		        if(-1 != wordInfo[0].indexOf('weightValue'))
		        {
		            errorMessages = AddMessage( 'Please enter a whole number or decimal weight in lbs in the weight field (e.g. 13 or 3.5)', errorMessages, errorMessageDelimiter );		
		        }
		        else
		        {
		            errorMessages = AddMessage( errorMessage, errorMessages, errorMessageDelimiter );		
		        }
		        errorCount++;
			    break;
		    }
		}
	}
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;	
}
function validateOrderDataWithDisable( summaryId, validationData, errorMessage, buttonId )
{
	var isValid = true;

    // disable the button while we figure things out
    disableAndWait(buttonId);

	var summaryCtl		= document.getElementById(summaryId);
	var blockInfo		= validationData.split('$$');
	var wordInfo;
	var currentCtl;
	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

	for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
	{
		wordInfo		= blockInfo[blockIndex].split('$');
		currentCtl		= document.getElementById(wordInfo[0]);
		
        if(null != currentCtl)
        {
            // is this field required?
  	        currentCtl.value = CleanString(currentCtl.value, '>');
  	        currentCtl.value = CleanString(currentCtl.value, '<');
  	        currentCtl.value = trim(currentCtl.value);
  	        
		    if( 'true' == wordInfo[1] )
		    {
			    if ((currentCtl.value.length < 1) || (currentCtl.value < 0))
			    {
			        tempMessage = 'Please fill in all required fields.';
    		        errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
			        errorCount++;
				    break;
			    }
		    }
		    // does this field match its regex?
		    if ( false == MatchRegEx( currentCtl.value, wordInfo[2] + '$' ) )
		    {	
		        // Dell/DHL weight collection needs a fresh error message
		        if(-1 != wordInfo[0].indexOf('weightValue'))
		        {
		            errorMessages = AddMessage( 'Please enter a whole number or decimal weight in lbs in the weight field (e.g. 13 or 3.5)', errorMessages, errorMessageDelimiter );		
		        }
		        else
		        {
		            errorMessages = AddMessage( errorMessage, errorMessages, errorMessageDelimiter );		
		        }
		        errorCount++;
			    break;
		    }
		}
	}
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
		
	    // reset mouse pointer and submit
		enable(buttonId);
	}
	return isValid;	
}
function validateCustomerAddress( summaryId, fNameId, lNameId, a1Id, a2Id, cId, sId, zId,
                                  fNameLabel, lNameLabel, a1Label, a2Label, cLabel, sLabel, zLabel )
{

	var isValid = true;
	// get references to each control
	//custInfoLastName
	// custInfoSummary
	var summaryCtl		= document.getElementById(summaryId);
	
	var firstNameCtl	= document.getElementById(fNameId);
	var lastNameCtl		= document.getElementById(lNameId);
	var address1Ctl		= document.getElementById(a1Id);
	var address2Ctl		= document.getElementById(a2Id);
	var cityCtl			= document.getElementById(cId);
	var stateCtl		= document.getElementById(sId);
	var zipCtl			= document.getElementById(zId);
	
	var tempMessage = '';
    var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;
	
	// kill any unsafe characters
	// '>'
	firstNameCtl.value = CleanString(firstNameCtl.value, '>');
	lastNameCtl.value = CleanString(lastNameCtl.value, '>');
	address1Ctl.value = CleanString(address1Ctl.value, '>');
	address2Ctl.value = CleanString(address2Ctl.value, '>');
	cityCtl.value = CleanString(cityCtl.value, '>');
	stateCtl.value = CleanString(stateCtl.value, '>');
	zipCtl.value = CleanString(zipCtl.value, '>');

	// '<'
	firstNameCtl.value = CleanString(firstNameCtl.value, '<');
	lastNameCtl.value = CleanString(lastNameCtl.value, '<');
	address1Ctl.value = CleanString(address1Ctl.value, '<');
	address2Ctl.value = CleanString(address2Ctl.value, '<');
	cityCtl.value = CleanString(cityCtl.value, '<');
	stateCtl.value = CleanString(stateCtl.value, '<');
	zipCtl.value = CleanString(zipCtl.value, '<');
		
	// ' '
	firstNameCtl.value = trim(firstNameCtl.value);
	lastNameCtl.value = trim(lastNameCtl.value);
	address1Ctl.value = trim(address1Ctl.value);
	address2Ctl.value = trim(address2Ctl.value);
	cityCtl.value = trim(cityCtl.value);
	stateCtl.value = trim(stateCtl.value);
	zipCtl.value = trim(zipCtl.value);

	// validate first name required
	if ( firstNameCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < fNameLabel.indexOf(':'))
		    fNameLabel = fNameLabel.substring(0, fNameLabel.indexOf(':'));
			
		tempMessage = '- ' + fNameLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	}
	
	// validate last name required
	if ( lastNameCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < lNameLabel.indexOf(':'))
		    lNameLabel = lNameLabel.substring(0, lNameLabel.indexOf(':'));
			
		tempMessage = '- ' + lNameLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	}
	
	// validate address 1 required
	if ( address1Ctl.value < 1 )
	{
		// trim off ':'
		if(-1 < a1Label.indexOf(':'))
		    a1Label = a1Label.substring(0, a1Label.indexOf(':'));
			
		tempMessage = '- ' + a1Label + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	}
	
	// validate city required
	if ( cityCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < cLabel.indexOf(':'))
		    cLabel = cLabel.substring(0, cLabel.indexOf(':'));
			
		tempMessage = '- ' + cLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	}
	
	//validate state required
	if ( stateCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < sLabel.indexOf(':'))
		    sLabel = sLabel.substring(0, sLabel.indexOf(':'));
			
		tempMessage = '- ' + sLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	}
	// validate zip required
	if ( zipCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < zLabel.indexOf(':'))
		    zLabel = zLabel.substring(0, zLabel.indexOf(':'));
			
		tempMessage = '- ' + zLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		errorCount++;
	}

	// validate zip regex
	if ( false == IsZip( zipCtl.value ) )
	{
		// trim off ':'
		if(-1 < zLabel.indexOf(':'))
		    zLabel = zLabel.substring(0, zLabel.indexOf(':'));

		tempMessage = '- ' + zLabel + ' must be of format: 12345 or 12345-6789';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}

	return isValid;
}

// updated version of address validation function for RCv3
function validateCustomerAddress_v3( summaryId, fNameId, lNameId, a1Id, a2Id, cId, sId, zId, eId, pId1, pId2, pId3, 
						fNameLabel, lNameLabel, a1Label, a2Label, cLabel, sLabel, zLabel, eLabel, pLabel )
{

	var isValid = true;
	// get references to each control
	var summaryCtl		= document.getElementById(summaryId);
	
	var firstNameCtl	= document.getElementById(fNameId);
	var lastNameCtl		= document.getElementById(lNameId);
	var address1Ctl		= document.getElementById(a1Id);
	var address2Ctl		= document.getElementById(a2Id);
	var cityCtl			= document.getElementById(cId);
	var stateCtl		= document.getElementById(sId);
	var zipCtl			= document.getElementById(zId);
	var emailCtl		= document.getElementById(eId);
	var phoneCtl1		= document.getElementById(pId1);
	var phoneCtl2		= document.getElementById(pId2);
	var phoneCtl3		= document.getElementById(pId3);

	
	var tempMessage = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;

	// kill any unsafe characters
	// '>'
	firstNameCtl.value = CleanString(firstNameCtl.value, '>');
	lastNameCtl.value = CleanString(lastNameCtl.value, '>');
	address1Ctl.value = CleanString(address1Ctl.value, '>');
	address2Ctl.value = CleanString(address2Ctl.value, '>');
	cityCtl.value = CleanString(cityCtl.value, '>');
	stateCtl.value = CleanString(stateCtl.value, '>');
	zipCtl.value = CleanString(zipCtl.value, '>');
	emailCtl.value = CleanString(emailCtl.value, '>');
	phoneCtl1.value = CleanString(phoneCtl1.value, '>');
	phoneCtl2.value = CleanString(phoneCtl2.value, '>');
	phoneCtl3.value = CleanString(phoneCtl3.value, '>');

	// '<'
	firstNameCtl.value = CleanString(firstNameCtl.value, '<');
	lastNameCtl.value = CleanString(lastNameCtl.value, '<');
	address1Ctl.value = CleanString(address1Ctl.value, '<');
	address2Ctl.value = CleanString(address2Ctl.value, '<');
	cityCtl.value = CleanString(cityCtl.value, '<');
	stateCtl.value = CleanString(stateCtl.value, '<');
	zipCtl.value = CleanString(zipCtl.value, '<');
	emailCtl.value = CleanString(emailCtl.value, '<');
	phoneCtl1.value = CleanString(phoneCtl1.value, '<');
	phoneCtl2.value = CleanString(phoneCtl2.value, '<');
	phoneCtl3.value = CleanString(phoneCtl3.value, '<');
	
	// ' '
	firstNameCtl.value = trim(firstNameCtl.value);
	lastNameCtl.value = trim(lastNameCtl.value);
	address1Ctl.value = trim(address1Ctl.value);
	address2Ctl.value = trim(address2Ctl.value);
	cityCtl.value = trim(cityCtl.value);
	stateCtl.value = trim(stateCtl.value);
	zipCtl.value = trim(zipCtl.value);
	emailCtl.value = trim(emailCtl.value);
	phoneCtl1.value = trim(phoneCtl1.value);
	phoneCtl2.value = trim(phoneCtl2.value);
	phoneCtl3.value = trim(phoneCtl3.value);
	
	// validate first name required
//	if ( trim(firstNameCtl.value) < 1 )
//	{
//		// trim off ':'
//		if(-1 < fNameLabel.indexOf(':'))
//		    fNameLabel = fNameLabel.substring(0, fNameLabel.indexOf(':'));
//					
//		tempMessage = '- ' + fNameLabel + ' is a required field.';
//		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
//		errorCount++;
//	}

	// validate last name required
//	if ( trim(lastNameCtl.value) < 1 )
//	{
//		// trim off ':'
//		if(-1 < lNameLabel.indexOf(':'))
//		    lNameLabel = lNameLabel.substring(0, lNameLabel.indexOf(':'));
//		
//		tempMessage = '- ' + lNameLabel + ' is a required field.';
//		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
//		errorCount++;
//	}
	
	// validate address 1 required
	if ( address1Ctl.value < 1 )
	{
		// trim off ':'
		if(-1 < a1Label.indexOf(':'))
		    a1Label = a1Label.substring(0, a1Label.indexOf(':'));

		tempMessage = '- ' + a1Label + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}
	
	// validate city required
	if ( cityCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < cLabel.indexOf(':'))
		    cLabel = cLabel.substring(0, cLabel.indexOf(':'));

		tempMessage = '- ' + cLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}
	
	//validate state required
	if ( stateCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < sLabel.indexOf(':'))
		    sLabel = sLabel.substring(0, sLabel.indexOf(':'));

		tempMessage = '- ' + sLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}

	// validate zip required
	if ( zipCtl.value < 1 )
	{
		// trim off ':'
		if(-1 < zLabel.indexOf(':'))
		    zLabel = zLabel.substring(0, zLabel.indexOf(':'));

		tempMessage = '- ' + zLabel + ' is a required field.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}
	// validate zip regex
	if ( false == IsZip( zipCtl.value ) )
	{
		// trim off ':'
		if(-1 < zLabel.indexOf(':'))
		    zLabel = zLabel.substring(0, zLabel.indexOf(':'));
	
		tempMessage = '- ' + zLabel + ' must be of format: 12345 or 12345-6789';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}

	// validate email regex
	if ( false == IsEmail( emailCtl.value ) )
	{
		// trim off ':'
		if(-1 < eLabel.indexOf(':'))
		    eLabel = eLabel.substring(0, eLabel.indexOf(':'));

		tempMessage = '- ' + eLabel + ' must be of format: name@address.suffix';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}
	
	// validate phone regex
	var phoneValue = phoneCtl1.value + phoneCtl2.value + phoneCtl3.value;
	if ( false == IsPhone( phoneValue ) )
	{
		// trim off ':'
		if(-1 < pLabel.indexOf(':'))
		    pLabel = pLabel.substring(0, pLabel.indexOf(':'));
		
		tempMessage = '- Please enter ' + pLabel + ' as a ten digit value with no special characters.';
		errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );				
		errorCount++;
	}
	
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}

	return isValid;
}
function validateChangePassword( summaryId, validationData )
{ 
    // if the item is not required, we should still check to see if it is currently selected (if selected -> required)
    var isValid = true;
    
    var summaryCtl      = document.getElementById(summaryId);
    var blockInfo       = validationData.split('::');
  
	var wordInfo;
	var currentCtl;
	var currentCtl2;
	var currentCtl3;
	var currentCtl4;
    var reqCtlTemplate;
    var reqIndex;
    var reqCtlPrefix;

	
	var tempError = '';
	var errorMessages	= '';
	var errorMessageDelimiter = '|';
	var errorCount		= 0;
    
    var newPassword = 'n';
    var newPasswordConfirm = 'c';
    
    for( blockIndex=0; blockInfo.length > blockIndex; blockIndex++ )
	{
		wordInfo		= blockInfo[blockIndex].split(':');
		currentCtl		= document.getElementById(wordInfo[0]);
        if(null != currentCtl)
        {
            if('text' == wordInfo[4])
            {
                // is this field required?
  	            currentCtl.value = CleanString(currentCtl.value, '>');
  	            currentCtl.value = CleanString(currentCtl.value, '<');
  	            currentCtl.value = trim(currentCtl.value);
  	            
		        if (currentCtl.value < 1)
		        {
		            if( 'true' == wordInfo[1] )
		            {
		                tempMessage = 'Please fill in all required fields.';
		                errorMessages = AddMessage( tempMessage, errorMessages, errorMessageDelimiter );		
		                errorCount++;
			            break;
			        }
		        }
		        else
		        {
		            if(1 == blockIndex)
		            {
		                newPassword = currentCtl.value;
		            }
		            else if (2 == blockIndex)
		            {
		                newPasswordConfirm = currentCtl.value;
		            }
		            if( '' != wordInfo[2])
		            {
		                // validate content
		                // does this field match its regex?
		                if ( false == MatchRegEx( currentCtl.value, wordInfo[2]) )
		                {	
	                        errorMessages = AddMessage( wordInfo[3], errorMessages, errorMessageDelimiter );		
		                    errorCount++;
			                break;
		                }
		            }			        		            
		        }
		    }
		}
	}

    if( errorCount == 0)
    {
        if ( newPassword != newPasswordConfirm )
        {	
            errorMessages = AddMessage( 'Values entered for password do not match, please try again.', errorMessages, errorMessageDelimiter );		
            errorCount++;
        }
    }
	// check error count
	if ( errorCount > 0 )
	{
		var errors = errorMessages.split('|');
		var text = '<ul>';
		for ( index=0;index < errors.length;index++ )
		{
			text = text + '<li>' + errors[index] + '</li>';
		}
		text = text + '</ul>';
		// populate the summary message control
		summaryCtl.innerHTML = text;
		// fail validation
		isValid = false;
	}
	return isValid;			    
}
function ValidateTrackingInput(summaryId, elId)
{
    var isValid = true;
    var summaryCtl      = document.getElementById(summaryId);
    var currentCtl      = document.getElementById(elId);

    currentCtl.value = trim(currentCtl.value);
    if (currentCtl.value < 1)
    {
        summaryCtl.innerHTML = '***';
        isValid = false;
    }
    else
    {
        summaryCtl.innerHTML = '';
    }
    return isValid;
} 
function CleanString( dirty, unsafe )
{
    var unsafeIndex = dirty.indexOf(unsafe);
	var safeValue = dirty;
    while(-1 != unsafeIndex)
	{
	    safeValue = safeValue.substring(0,unsafeIndex) + safeValue.substring(unsafeIndex+1);
	    unsafeIndex = safeValue.indexOf(unsafe);
	}
	
	return safeValue;
}
function AddMessage( msg, msgs, delim )
{
	if ( msgs.length < 1 )
		msgs = msg;
	else
		msgs = msgs + delim + msg;
		
	return msgs;
} 
function MatchRegEx( val, expr )
{
	var isValid = true;
	if ( val.length > 0 )
	{
		var re = new RegExp( expr, "g" );
		
		val = val.match( re );
		if( null == val )
		{
			isValid = false;
		}
	}
	return isValid;
}
function IsAlphaNumeric( val )
{
	return MatchRegEx( val, "^[\\w ]+$" );
}
function IsZip( val )
{
	return MatchRegEx( val, "^\\d{5}$|\\d{5}\\-\\d{4}$" );
}
function IsEmail( val )
{
	return MatchRegEx( val, "^[^@ ]+@[^@ ]+\\.[^@ \\.]+$" );
}
function IsPhone( val )
{
	return MatchRegEx( val, "^\\d{10}$|\\d{13}$|\\d{14}$|\\d{15}$" );
}
// method for handling changing of selected radio button on order lookup
function UpdateSelectedOrderLookupField( objId, count )
{
	var button = document.getElementById(objId);
	var otherButton;
	
	var pos = objId.lastIndexOf('_ctl') + 4;
	var selected = objId.substring(pos);
    // ucOrderLookup__ctl3
    // ucOrderLookup__ctl5
	var preButton = 'ucOrderLookup__ctl';
    // start with 0, ignore non-radios
    for ( index=0; index<count; index++ )
    {
		if( selected != index )
		{
			targetId = preButton + index;
			otherButton = document.getElementById(targetId);
			if( "radio" == otherButton.type )
			{
    		    otherButton.checked = false;
		    }
		}    
	}    
}
// method for handling changing of selected radio button
function UpdateSelectedShippingOption( objId, count )
{
	var button = document.getElementById(objId);
	var otherButton;

	// get the id numeric value from the passed in object id
	var selected = objId.substring(45,48);
	if (0 < selected.indexOf('_'))
	{
	    selected = selected.substring(0, selected.indexOf('_'));
	}
		
	var preButton = 'ucLabelShippingMethod_shippingMethodGrid__ctl';
	var postButton = '_selectShippingOption';
	var targetId = '';
	// we start with 2, and go up to 2 + count options
	for( index=2; index< (2 + (count * 1)); index++ )
	{
		if( selected != index )
		{
			targetId = preButton + index + postButton;
			otherButton = document.getElementById(targetId);
			if( null != otherButton)
				otherButton.checked = false;
		}
	}
}
// method for handling changing of selected radio button
function UpdateSelectedOrderOption( objId, count )
{
	var button = document.getElementById(objId);
	var otherButton;

	// get the id numeric value from the passed in object id
	var selected = objId.substring(30,33);
	if (0 < selected.indexOf('_'))
	{
	    selected = selected.substring(0, selected.indexOf('_'));
	}

	var preButton = 'ucOrderList_orderListList__ctl';
	var postButton = '_selectOrder';
	var targetId = '';
	// we start with 2, and go up to 2 + count options
	for( index=2; index< (2 + (count * 1)); index++ )
	{
		if( selected != index )
		{
			targetId = preButton + index + postButton;
			otherButton = document.getElementById(targetId);
			if( null != otherButton)
				otherButton.checked = false;
		}
	}
}

// cursor methods (disable on submission type stuff)
// TODO update for firefox, etc. (non-ie)
function setPointer() 
{ 
	if (document.all) 
	{
		for (var i=0;i < document.all.length; i++) 
		{
			document.all(i).style.cursor = 'wait';
		}
	}
} 

function resetPointer() 
{ 
	if (document.all) 
	{
		for (var i=0;i < document.all.length; i++)
		{	
			document.all(i).style.cursor = 'default';
		}
	}
}

function disableControl(elID)
{
	document.getElementById(elID).disabled = true;
}
function enableControl(elID)
{
	document.getElementById(elID).disabled = false;
}

var submitted = false;
function disableAndWait(elID)
{
	if (submitted == true)
	{
		disableControl(elID);
		return false;
	}
	// change cursor to hour glass
	setPointer();
	submitted = true;
}
function enable(elID)
{
    resetPointer();
    submitted = false;
}
function hideElement(elID,doHide)
{
    var content = document.getElementById(elID);
    if(true == doHide)
    {
        content.style.display = 'none'
    }
    else
    {
        content.style.display = 'block'    
    }
}

function autoTab(me,e) 
{
    var element;
    if(me.value.length == me.getAttribute("maxlength") && 
        e.keyCode != 8 && e.keyCode != 16 && e.keyCode != 9 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode !=39 && e.keyCode != 40) {
            //new Field.activate(findNextElement(me.getAttribute("tabindex")));
            element = findNextElement(me.getAttribute("tabindex"));
            element.focus();
            element.select();
        }
}

function findNextElement(index) 
{
    
    //elements = new Form.getElements('Form1');
    elements = document.getElementsByTagName('input');
    for(i = 0; i < elements.length; i++) {
        element = elements[i];
        if(parseInt(element.getAttribute("tabindex")) == (parseInt(index) + 1)) {
            return element;
        }
    }
    return elements[0];
}

function moveItems(sourceId, targetId, isAdd, hiddenId)
{
    // we are either pushing all remaining brands into user brands
    // OR
    // removing all brands from user brands (and putting them back into brands)
    var sourceList = document.getElementById(sourceId);
    var targetList = document.getElementById(targetId);

    if('true' == isAdd)
    {
        // add all to user brands
        for(i=(sourceList.length-1);i>-1;i--)
        {
            targetList.appendChild(sourceList.options.item(i));  
        }
        sortlist(targetId);
        sourceList.selectedIndex = -1;
        targetList.selectedIndex = -1;
    }
    else
    {
        // add all to user brands
        for(i=(targetList.length-1);i>-1;i--)
        {
            sourceList.appendChild(targetList.options.item(i));  
        }
        sortlist(sourceId);
        sourceList.selectedIndex = -1;
        targetList.selectedIndex = -1;
    }
    
    if('' != hiddenId)
    {
        var hiddenList = document.getElementById(hiddenId);
        var hiddenValue = '';
        for(i=0; i<targetList.length; i++)  
        {
            if(i == 0)
                hiddenValue = targetList.options[i].text + ':' + targetList.options[i].value;
            else
                hiddenValue = hiddenValue + '|' + targetList.options[i].text + ':' + targetList.options[i].value;      
        }
        hiddenList.value = hiddenValue;
    }
}
function moveItem(sourceId, targetId, isAdd, hiddenId)
{
    var sourceList = document.getElementById(sourceId);
    var targetList = document.getElementById(targetId);
    
    if('true' == isAdd)
    {
        for(i=0; i<sourceList.options.length; i++)
        {
            if(sourceList.options[i].selected == true)
            {
                targetList.appendChild(sourceList.options[i]);
                --i;
            }
	    }

        sortlist(targetId);
        sourceList.selectedIndex = -1;
        targetList.selectedIndex = -1;
    }
    else
    {
        for(i=0; i<targetList.options.length; i++)
        {
            if(targetList.options[i].selected == true)
            {
                sourceList.appendChild(targetList.options[i]);
                --i;
            }
	    }

        sortlist(sourceId);
        sourceList.selectedIndex = -1;
        targetList.selectedIndex = -1;
    }
    
    if('' != hiddenId)
    {
        var hiddenList = document.getElementById(hiddenId);
        var hiddenValue = '';
        for(i=0; i<targetList.length; i++)  
        {
            if(i == 0)
                hiddenValue = targetList.options[i].text + ':' + targetList.options[i].value;
            else
                hiddenValue = hiddenValue + '|' + targetList.options[i].text + ':' + targetList.options[i].value;      
        }
        hiddenList.value = hiddenValue;
    }
}

function sortlist(elId) 
{
    var lb = document.getElementById(elId);
    arrTexts = new Array();

    for(i=0; i<lb.length; i++)  
    {
      arrTexts[i] = lb.options[i].text + '::' + lb.options[i].value;
    }

    arrTexts.sort(sortLowerCase);

    for(i=0; i<lb.length; i++)  
    {
      var tempItem = arrTexts[i].split('::');
      lb.options[i].text = tempItem[0];
      lb.options[i].value = tempItem[1];
    }
}

function sortLowerCase(a, b)
{
    var x = a.toLowerCase();
    var y = b.toLowerCase();
    
    return ((x<y)? -1:((x>y) ? 1 : 0));
}

var ajxmlHttp;
var ajreqURL;
var ajlastReq;
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
//netscape, safari, mozilla behave the same??? 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 

function validateInputField(fieldName, elID, errID, server)
{
    var control = document.getElementById(elID);
    //alert('field: ' + fieldName + ' elID: ' + elID + ' value: ' + control.value);    
  	var address = 'http://' + server + '/AccountHelper.aspx?fn=' + fieldName + '&fv=';
  	
  	if(0 < control.value.length)
  	{
  	    if(true == IsAlphaNumeric(control.value))
  	    {
  	        if(ajlastReq != control.value.toLowerCase())
  	        {
  	            ajlastReq = control.value.toLowerCase();
  	            
  	            address = address + control.value;
          	    
  	            ajxmlHttp = GetXmlHttpObject(function(){stateChangeHandler(errID);});
          	    
  	            xmlHttp_Get(ajxmlHttp, address);
  	        }
  	    }
  	    else
  	    {
  	        // TODO not trapping this now, will be caught by submit press client-side validation
  	        //alert('invalid username value');
  	    }
  	}
}

function stateChangeHandler(elID) 
{ 
    //readyState of 4 or 'complete' represents that data has been returned 
    if (ajxmlHttp.readyState == 4 || ajxmlHttp.readyState == 'complete')
    { 
        //Gather the results from the callback 
        var response = ajxmlHttp.responseText; 
        var ctl = document.getElementById(elID);
        if(0 < response.length)
        {
            if(0 < ctl.innerHTML.length)
                ctl.innerHTML = ctl.innerHTML + '<br/>' + response;
            else
                ctl.innerHTML = response;
            document.getElementById(elID).style.display = 'block';
        }
        else
        {
            document.getElementById(elID).innerHTML = '';
            document.getElementById(elID).style.display = 'none';
        }
    } 
} 

function xmlHttp_Get(xmlhttp, url) 
{ 
    xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
}
        
function GetXmlHttpObject(handler) 
{ 
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    if (is_ie)
    { 
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
             
        //Attempt to create the object 
        try
        { 
            objXmlHttp = new ActiveXObject(strObjName); 
            objXmlHttp.onreadystatechange = handler; 
        } 
        catch(e)
        { 
            //Object creation errored 
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
            return; 
        } 
    } 
    else if (is_opera)
    { 
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.'); 
        return; 
    } 
    else
    { 
        // Mozilla | Netscape | Safari 
        objXmlHttp = new XMLHttpRequest(); 
        objXmlHttp.onload = handler; 
        objXmlHttp.onerror = handler; 
    } 
    
    //Return the instantiated object 
    return objXmlHttp; 
} 

var plusImage = new Image();
var minusImage = new Image();

plusImage.src = "../images/pluso_sm.gif";
minusImage.src = "../images/minuso_sm.gif";

function expandDataBlock(elID, theImage)
{
    // flip the image
    if(plusImage.src == theImage.src)
    {
        theImage.src = minusImage.src;
    }
    else
    {
        theImage.src = plusImage.src;
    }
    // toggle the display
    toggleDisplay(elID);
}
function remoteExpandDataBlock(elID, theImageID)
{
    // flip the image
    var theImage = document.getElementById(theImageID);
    if(plusImage.src == theImage.src)
    {
        theImage.src = minusImage.src;
    }
    else
    {
        theImage.src = plusImage.src;
    }
    // toggle the display
    toggleDisplay(elID);
}
function toggleDisplay(elID)
{
    var content = document.getElementById(elID);
    if(content.style.display != 'none')
    {
        content.style.display = 'none';
    }
    else
    {
        content.style.display = 'block';
    }
}

