var theDefault;
var theErrCount=0;
var theAttemptCount=0;
var theSearchMethod;
addEvent(window,'onload',doPageLoad);

function showDetails (order_no, dt, order_id, counter, oType)
{
	var wTop,wLeft,wOptions;

    if (eval(window.screenY))
    {
		wTop=window.screenY+150;
        wLeft=window.screenX+217;
	}
    else if (eval(window.screenTop))
    {
	    wTop=window.screenTop+150;
        wLeft=window.screenLeft+217;
	}
    else
    {
	    wTop=400;
        wLeft=600;
	}
    wOptions="width=375, height=375";
    wOptions+=", left="+wLeft;
    wOptions+=", top="+wTop;
    wOptions+=", menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no";

	var detailwin = window.open ("pop_AccountDetail.asp?order_no="+order_no+"&order_date="+dt+"&order_id="+order_id+"&index="+counter+"&order_type="+oType, "detailwin", wOptions);
	detailwin.focus();
}
function retrieveOrders()
{
	if (validateCriteria())
	{
		var theField=document.getElementById('searchBy');
		if (theField)
		{
			var theMethod=theField.options[theField.options.selectedIndex].value;
			theField=document.getElementById('searchCriteria');
			if (theField)
			{
				var theCriteria=theField.value;
				var theURL='/fsg/accountlink/AccountLinkServer.asp';
				theURL+='?Mode='+theMethod+'&Criteria='+theCriteria;
				toggleBlock('retrieveOrdersResults',false);
				toggleBlock('retrievedOrder',false);
				toggleBlock('securityFormDiv',false);
				toggleBlock('securityErrorDiv',false);
				
				//assign global value for search method
				theSearchMethod = theMethod;
				
				//track the query in SiteCatalyst
				sc_trackQuery(theMethod);
				
				// HBX Call Here
				_hbSet('cv.c1', getSearchModeString());
				_hbSend();
				appendDebug('HBSend:'+getSearchModeString());
				PassAjaxResponseToFunction(theURL,'retrieveOrdersCallback','');
			}
		}
	}
	else
	{
		alert('Please enter your search criteria.');
	}
}
function getSearchModeString()
{
	var theRet='Unknown';
	var theField=document.getElementById('searchBy');
	if (theField)
	{
		var theMethod=theField.options[theField.options.selectedIndex].value;
		switch (theMethod)
		{
			case '1':
				theRet='OrderNumber';
			break;
			case '2':
				theRet='PhoneNumber';
			break;
			case '5':
				theRet='BankAccount';
			break;
			case '6':
				theRet='Email';
			break;
		}
	}
	return theRet;
}
function retrieveOrdersCallback(theRet)
{
    //determine origin of the request
    var thePageName = getRequestOrigin();
    
	if (theRet)
	{
		var theTarget=document.getElementById('retrieveOrdersResults');

		if (theTarget)
		{
			if (theRet.responseText.length > 1)
			{
				// HBX Call Here - My Retrieved Orders Search Results
				_hbPageView('My Retrieved Orders', "/fsg/accountlink");
				appendDebug('HBPageView:My Retrieved Orders');

				toggleBlock('headingText',true);
				theAttemptCount=0;
				var theHTML ="<div class='homelink' style='cursor:pointer;padding-top:10px;padding-bottom:10px;color:#336699;'>";
				theHTML+="<a href='/fsg/accountlink/RetrieveOrders.asp' onclick='javascript:sc_sendLink_cantFind();'>Can't find the order you're looking for? Try again.</a></div>";
				theHTML+=theRet.responseText;
				theTarget.innerHTML=theHTML;
				
				// clear error message
				var theErrMsg=document.getElementById('errorMsg');
				theErrMsg.innerHTML="";
								
				//previous orders exist - hide search div
				toggleBlock('searchDiv', false);
				
				//site catalyst tracking for successful query
				var theSearchMethodString;
				if (theSearchMethod)
				{
				    theSearchMethodString = getSearchMethodString(theSearchMethod);				
				    
				}
				else
				{
				    //if coming from my accounts page
				    if (thePageName == 'my account no history')
				    {
				        var tempStr = getSearchModeString();
				        switch(tempStr)
				        {
				            case 'OrderNumber':
				                theSearchMethodString='order number';
			                break;
			                case 'PhoneNumber':
				                theSearchMethodString='phone number';
			                break;
			                case 'BankAccount':
				                theSearchMethodString='bank account number';
			                break;
			                case 'Email':
				                theSearchMethodString='email address';
			                break;
				        }
				    }
				    //else coming from reorder login
				    else
				    {
				        theSearchMethodString = getSearchMethodString(getParam('searchBy'));
				    }
				}
				
				s.prop36 = thePageName + ":" + theSearchMethodString;
				s.eVar36 = thePageName + ":" + theSearchMethodString;
			}
			else
			{
				toggleBlock('headingText',false);
				theAttemptCount++;
				
				// set error message
				theTarget=document.getElementById('errorMsg');
				theTarget.innerHTML=getRetrieveErrMsg();
				if (theAttemptCount > 1){ setChatVar(); }
				
				//previous orders doesn't exist - display search div
				toggleBlock('searchDiv', true);
				
				//site catalyst tracking for unsuccessful query
				//s.prop36 = thePageName;
				//s.eVar36 = thePageName;
				
			}
			s.tl(this, "o", "retrieve my order");
			
			theTarget.style.display='block';
			toggleBlock('resultPane',true);
			refreshPageTitle();
		}
	}
}
function getRetrieveErrMsg()
{
	var theRet;
	theRet="<div style='padding:0px;color:red;font-size:12px;'>We were unable to retrieve previous orders with the information you provided.</div>";
	theRet+="<div style='padding-bottom:10px;color:red;font-size:12px;'>Please try to search again or call us for assistance.</div>";
	
	// hide search header
	toggleBlock('searchHeader', false);
	
	//theRet+="<div style='padding:8px;color:red;font-size:12px;'>If you still have a problem, please call us at 1-800-955-8890 and we will be happy to assist you.</div>";
	if (theAttemptCount > 100)
	{
		theRet+="<div class='homelink' style='padding:8px;'><a href='#' onClick='toggleDiv(\"cantFind\");'>Can't find your order?</a></div>";
		theRet+="<div id='cantFind' style='font-size:12px;padding:8px;display:none;'>Please call us at 1-800-955-8890 and we will be happy to assist you.</div>";
	}
	return theRet;
}
function doCancel()
{
	toggleBlock('retrievedOrder',false);
	toggleBlock('searchDiv',true);
	toggleBlock('securityFormDiv',false);
	toggleBlock('headingText',true);
	toggleBlock('retrieveOrdersResults',true);
	toggleBlock('securityErrorDiv',false);
    toggleBlock('resultPane', false);
}
function toggleBlock(theBlock,theState)
{
	var theTarget=document.getElementById(theBlock);
	if (theBlock)
	{
		if (theState){ theTarget.style.display='block'; }
		else { theTarget.style.display='none'; }
	}
}
function retrieveSecurityForm(theOrderID)
{
	var theURL='/fsg/accountlink/AccountLinkServer.asp';
	theURL+='?Mode=4&OrderID='+theOrderID;
	toggleBlock('searchDiv',false);
	toggleBlock('headingText',false);
	toggleBlock('retrieveOrdersResults',false);
	toggleBlock('retrievedOrder',false);
	PassAjaxResponseToFunctionParams(theURL,'retrieveSecurityFormCallback',"'"+theOrderID+"'",'searchBy,searchCriteria');
}
function retrieveSecurityFormCallback(theRet,theOrderID)
{
	var theTarget=document.getElementById('securityFormDiv');
	if (theTarget)
	{
		if (theRet.responseText > '')
		{
			theTarget.innerHTML=theRet.responseText;
			theTarget.style.display='block';
		}
		else
		{
			// No Security Questions Needed
			retrieveSingleOrder(theOrderID,true);
		}
		// HBX Tag Here - Failure
		_hbPageView('My Retrieved Orders - Security', "/fsg/accountlink");
		appendDebug('HBPageView:My Retrieved Orders - Security');
		
		refreshVerificationPageTitles();
	}

}
function refreshVerificationPageTitles()
{
    var thePageTitle=document.getElementById('pageTitleSpan');

    var theTarget=document.getElementById('securityFormDiv');
	if (theTarget)
	{
		var theRoutNum=document.getElementById('routingNumber');
		var theAcctNum=document.getElementById('accountNumber');
		var theLastChkNum=document.getElementById('lastCheckNumber');
		var theErrorDiv=document.getElementById('securityErrorDiv');		
		
		//set the verification page title
		if (thePageTitle)
		{
		    thePageTitle.innerHTML='Order Verification';
		}
		
		if (theLastChkNum)
		{
		    if (theAcctNum)
		    {
		        //Routing + Acct + LastChkNum
		        document.title='Intuit Checks, Forms & Supplies -  Retrieve Orders Verification A';
		        
		        if (theErrorDiv.style.display=='block')
		        {
		            //has error
		            document.title='Intuit Checks, Forms & Supplies -  Order Verification  Failure A';
		        }
		    }
		    else
		    {
		        //Routing + LastChkNum
		        document.title='Intuit Checks, Forms & Supplies -  Retrieve Orders Verification B';
		        
		        if (theErrorDiv.style.display=='block')
		        {
		            //has error
		            document.title='Intuit Checks, Forms & Supplies -  Order Verification  Failure B';
		        }
		    }
		}
		else
		{
			if (theAcctNum)
		    {
		        if (theRoutNum)
		        {
		            //Routing + Acct 
		            document.title='Intuit Checks, Forms & Supplies -  Retrieve Orders Verification C';
		            
		            if (theErrorDiv.style.display=='block')
		            {
		                //has error
		                document.title='Intuit Checks, Forms & Supplies -  Order Verification  Failure C';
		            }
	}
		        else
		        {
		            //Acct 
		            document.title='Intuit Checks, Forms & Supplies -  Retrieve Orders Verification D';

		            if (theErrorDiv.style.display=='block')
		            {
		                //has error
		                document.title='Intuit Checks, Forms & Supplies -  Order Verification  Failure D';
		            }
		        }
		        
		    }
		    else
		    {
		        //Routing
		        document.title='Intuit Checks, Forms & Supplies -  Retrieve Orders Verification E';
		        
		        if (theErrorDiv.style.display=='block')
	            {
	                //has error
	                document.title='Intuit Checks, Forms & Supplies -  Order Verification  Failure E';
	            }
		    }
		}
		
		//site catalyst track order verification
	    sc_trackOrderVerification();
	}
	
    theTarget=document.getElementById('retrievedOrder');
    if (theTarget)
    {
        if (theTarget.style.display=='block')
        {
            document.title='Intuit Checks, Forms & Supplies -  Reorder Previous Orders';
        }
        if (thePageTitle)
        {
            thePageTitle.innerHTML='Previous Orders';
        }
    }
}
function validateNotEmpty(theIds)
{
	var theIdArray=theIds.split(',');
	var theRet=true;
	var theField;
	for (var i=0;i<theIdArray.length;i++)
	{
		theField=document.getElementById(theIdArray[i]);
		if (theField)
		{
			theRet=(theRet && (theField.value > ' '));
		}
	}
	return theRet;
}
function retrieveSingleOrder(theOrderID,bypass)
{
	if (bypass || validateNotEmpty('routingNumber,accountNumber,lastCheckNumber'))
	{
		var theURL='/fsg/accountlink/AccountLinkServer.asp';
		theURL+='?Mode=3&OrderID='+theOrderID;
		toggleBlock('headingText',true);
		
		//override header text
		var theHeader=document.getElementById('headingText');
		if (theHeader)
		{
		    theHeader.innerHTML='Click "Reorder" next to the item you would like to reorder.<br /><br />';
		}
		
		toggleBlock('retrieveOrdersResults',false);
		toggleBlock('retrievedOrder',false);
		toggleBlock('securityFormDiv',false);
		toggleBlock('securityErrorDiv',false);
		PassAjaxResponseToFunctionParams(theURL,'retrieveSingleOrderCallback','','searchBy,searchCriteria,routingNumber,accountNumber,lastCheckNumber');
	}
	else
	{
		alert('Please answer the security question(s).');
	}
}
function retrieveSingleOrderCallback(theRet)
{
	var theTarget=document.getElementById('retrievedOrder');
	if (theTarget)
	{
		if ((theRet.responseText.length > 0) && (theRet.responseText.toString().indexOf('{') != 0))
		{
			theErrCount=0;
			toggleBlock('headingText',true);
			theTarget.innerHTML=theRet.responseText;
			theTarget.style.display='block';
			// HBX Tag Here - Success
			_hbPageView('My Retrieved Orders - Success', "/fsg/accountlink");
			appendDebug('HBPageView:My Retrieved Orders - Success');
			sendAnswerStat();
		}
		else
		{
			theErrCount++;
			toggleBlock('headingText',false);
			setErrorMessage();
			toggleBlock('securityErrorDiv',true);
			toggleBlock('securityFormDiv',true);
			if (theErrCount > 1){ setChatVar(); }
			sendHBXResults(theRet.responseText);
		}
		
		refreshVerificationPageTitles();
	}
}

function sendAnswerStat()
{
	var theTarget;
	var theVal='';

	theTarget=document.getElementById('accountNumber');
	if (theTarget){ theVal+='account_number|True,'; }
	theTarget=document.getElementById('routingNumber');
	if (theTarget){ theVal+='routing_number|True,'; }
	theTarget=document.getElementById('lastCheckNumber');
	if (theTarget){ theVal+='check_start_no|True,'; }

	if (theVal > '')
	{
		theVal=theVal.substring(0,theVal.length-1);
		appendDebug('HBSend:'+theVal);
		// HBX Call Here
		_hbSet('cv.c2', theVal);
		_hbSend();
	}
}
function sendHBXResults(theString)
{
	var theStats=eval('('+theString+')');
	var theVal='';
	if (theStats)
	{
		for (var x in theStats)
		{
			theVal+=x+'|'+theStats[x]+',';
		}
		theVal=theVal.substring(0,theVal.length-1);
		appendDebug('HBSend:'+theVal);
		// HBX Call Here
		_hbSet('cv.c2', theVal);
		_hbSend();
	}
}
function setChatVar()
{
	// TODO
}
function setErrorMessage()
{
	var theMsg;
	var theTarget=document.getElementById('securityErrorDiv');
	if (theTarget)
	{
		theMsg='The information you provided does not match the information in this order. Please review your answers and try again, or call 1-800-955-8890 for assistance.'
		if (theErrCount > 1)
		{
			theMsg+='<div style="padding-top:10px;color:black;">';
			theMsg+='Need Help?</div><div style="padding-top:10px;color:black;">Please call us at 1-800-955-8890 and we will be happy to assist you.</div>';
		}
		theTarget.innerHTML=theMsg;
	}
}
// Add event handler with preserve
function addEvent(obj, eventName, fn)
{
    var prev = obj[eventName];
    obj[eventName] = prev ? function() { fn() ; prev() } : fn;
}

function doPageLoad()
{
	refreshPageTitle();
	document.onkeypress = checkKeyPress;
	if (document.layers) { document.captureEvents(Event.KEYPRESS || Event.CLICK); }
	initDefaults();
	refreshSearchCriteria();
	setRadio('searchByRadio','1');
	clearSearchCriteria(false);
}
function checkKeyPress(e)
{
	if ( !e ) var e = window.event;

	var theTarget=document.getElementById('searchDiv');
	var pK;

	pK = document.all? window.event.keyCode:e.which;
	if (pK==13)
	{
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();

		var theTarget=document.getElementById('searchDiv');
		if (theTarget && theTarget.style.display != 'none')
		{
			retrieveOrders();
		}
		else
		{
			theTarget=document.getElementById('securityFormDiv');
			if (theTarget && theTarget.style.display != 'none')
			{
				var theButton=document.getElementById('secSubmit');
				if (theButton){ theButton.onclick(); }
			}
		}
		return false;
	}
}
function initDefaults()
{
	theDefault=new Object();
	theDefault['1']='Enter Order Number';
	theDefault['2']='Enter Phone Number';
	theDefault['5']='Enter Bank Account';
	theDefault['6']='Enter Email';
}
function getCurrentDefault()
{
	var theTarget=document.getElementById('searchBy');
	var theMsg='';
	if (theTarget)
	{
		var theVal=theTarget.options[theTarget.options.selectedIndex].value;
		theMsg=theDefault[theVal];
	}
	return theMsg;
}
// Search Criteria
function refreshSearchCriteria()
{
	var theTarget=document.getElementById('searchBy');
	var theField=document.getElementById('searchCriteria');
	if ((theAttemptCount==0) && theTarget && theField)
	{
		var theMsg;
		var theVal=theTarget.options[theTarget.options.selectedIndex].value;
		theMsg=theDefault[theVal];

		if (theMsg)
		{
			theField.style.color='gray';
			theField.value=theMsg;
		}
	}
}
function selectFieldValue(theField)
{
	var theTarget=document.getElementById('searchBy');
	if (theTarget && theField)
	{
		var theVal=theTarget.options[theTarget.options.selectedIndex].value;
		if (theField.value==theDefault[theVal])
		{
			theField.value='';
			theField.style.color='black';
		}
	}

}
function validateCriteria()
{
	var theRet;
	var theField=document.getElementById('searchCriteria');
	checkCriteria();
	if (theField)
	{
		if ((theField.value > ' ') && (theField.value != getCurrentDefault()))
		{
			theRet=true;
		}
		else
		{
			theRet=false;
		}
	}
	else
	{
		theRet=true;
	}
	return theRet;
}
function refreshPageTitle()
{
	var theTarget=document.getElementById('pageTitleSpan');
	var errDiv=document.getElementById('errorMsg')
	if (theTarget)
	{
		var theResults=document.getElementById('resultPane');
		if (theResults && theResults.style.display=='block')
		{
		    if (errDiv && errDiv.innerHTML == '')
		    {
			theTarget.innerHTML='Previous Orders';
			    document.title='Intuit Checks, Forms & Supplies -  Previous Orders Found';
			}
			else
			{
			    theTarget.innerHTML='Previous Orders Not Found';
			    document.title='Intuit Checks, Forms & Supplies -  Previous Orders Not Found';
			}
		}
		else
		{
			theTarget.innerHTML='Retrieve Order';
			document.title='Intuit Checks, Forms & Supplies -  Retrieve Order';
		}
	}
}
function toggleDiv(theID)
{
	var theTarget=document.getElementById(theID);
	if (theTarget)
	{
		if (theTarget.style.display=='block')
		{
			theTarget.style.display='none';
		}
		else
		{
			theTarget.style.display='block';
		}
	}
}
function appendDebug(theString)
{
	var theTarget=document.getElementById('debug');
	var theTargetTxt=document.getElementById('debugtxt');
	if (theTarget)
	{
		var theLine=document.createElement('li');
		theLine.appendChild(document.createTextNode(theString));
		theTarget.appendChild(theLine);
		//theTarget.innerHTML+='<li>'+theString+'</li>';
	}
	if (theTargetTxt)
	{
		theTargetTxt.value+=theString+'\n';
	}
}
function checkCriteria()
{
	var theTarget=document.getElementById('searchBy');
	var theField=document.getElementById('searchCriteria');
	if (theTarget && theField)
	{
		theField.value=getCurrentCriteria();
		var theVal=theTarget.options[theTarget.options.selectedIndex].value;
		switch (theVal)
		{
			case '1':
			case '5':
				theField.value=stripAlphaChars(theField.value);
				break;
			case '2':
				if (theField.value != theDefault[2])
				{ theField.value=stripSpecialChars(theField.value);	}
			break;
			case '6':
				if (theField.value != theDefault[6])
				{ theField.value=stripWhitespace(theField.value); }
			break;
		}
	}
}
function stripAlphaChars(pstrSource)
{
	var m_strOut = new String(pstrSource);
    m_strOut = m_strOut.replace(/[^0-9]/g, '');

    return m_strOut;
}
function stripSpecialChars(pstrSource)
{
	var m_strOut = new String(pstrSource);
    m_strOut = m_strOut.replace(/[^0-9a-z]/gi, '');

    return m_strOut;
}
function stripWhitespace(pstrSource)
{
	var m_strOut = new String(pstrSource);
    m_strOut = m_strOut.replace(/\s+/g, '');

    return m_strOut;
}
function doReorder(theSku,theImpId,theCheckStartNum,theCalledFrom, thePFID)
{
    //site catalyst reorder tracking
    sc_accountReorderLink(thePFID);

	var theLocation;
	if (theCalledFrom == "retrieveOrders")
	{
	    theLocation='/fsg/xt_orderform_reorderitem.asp?sku='+theSku+'&order_imprint_id='+theImpId+'&called_from='+theCalledFrom;	
	}
	else
	{
	    theLocation='/fsg/xt_orderform_reorderitem.asp?sku='+theSku+'&order_imprint_id='+theImpId;	
	}
	
	_hbLink('retrievereorder','myretrievedorders');
	//document.location=theLocation;
	
	if (theImpId == "0") //ie not a customizable product
	{
	document.location=theLocation;
}
	else //if its a customizable product, check if it has a check no. If no check, no pop-up
	{   
	    if (theCheckStartNum > " ")
	    {
	        popupReorderStartNum(theLocation);	        
	    }
	    else
	    {
	        document.location=theLocation;
	    }	    
	}	
}

function popupReorderStartNum(strUrl)
{
	if(strUrl=="#"){return false;}
	//var win = window.parent.window.open(strUrl,'win','toolbar=0,location=0,menubar=0,resizable=1,width=650,height=475,top=200,left=300');
	window.parent.location.href = strUrl;
}

function setMenuFromRadio(theRadio)
{
	if (theRadio && (theRadio.checked))
	{
		var theMenu=document.getElementById('searchBy');
		if (theMenu)
		{
			setMenu(theMenu,theRadio.value);
			theMenu.onchange();
		}
	}
}
function setMenu(theMenu,theValue)
{
	if (theMenu)
	{
		for (var i=0;i<theMenu.options.length;i++)
		{
			if (theMenu.options[i].value==theValue)
			{
				theMenu.options.selectedIndex=i;
				break;
			}
		}	
	}
}

function evalSearchCriteria(theField)
{
	
}
function radioOnClick(theField)
{
	var theTxtField=document.getElementById('searchByTxt_'+theField.value);
	if (theTxtField)
	{
		if (theTxtField.value=='')
		{
			theTxtField.value=theDefault[theField.value];
			theTxtField.style.color='gray';
		}
		clearSearchCriteria(false);	
	}
	setMenuFromRadio(theField);
}

function txtFieldOnFocus(theField)
{
	if (theField)
	{
		var theRadioVal=theField.getAttribute('radioval');
		setRadio('searchByRadio',theRadioVal);
		theField.style.color='black';
		if (theField.value==theDefault[theRadioVal]){ theField.value=''; }
	}
}
function criteriaOnChange(theField)
{
	cleanCriteria(theField);
	var theVal=theField.getAttribute('radioval');
	if (theVal > '')
	{
		
		setRadio('searchByRadio',theVal);
		clearSearchCriteria(true);
		var theTarget=document.getElementById('searchCriteria');
		if (theTarget)
		{
			theTarget.value=theField.value;
		}
	}
}
function clearSearchCriteria(clearAll)
{
	var theRadios=document.getElementsByName('searchByRadio');
	var theField;
	if (theRadios)
	{
		for (var i=0;i<theRadios.length;i++)
		{
			theField=document.getElementById('searchByTxt_'+theRadios[i].value)
			if (!theRadios[i].checked)
			{
				if (theField && (theField.value==theDefault[theRadios[i].value] || clearAll))
				{
					theField.value='';
				}
			}
		}
	}
}
function setRadio(theName,theVal)
{
	var theTargets=document.getElementsByName(theName);
	if (theTargets)
	{
		for (var i=0;i<theTargets.length;i++)
		{
			if (theTargets[i].value==theVal)
			{
				theTargets[i].checked=true;
				radioOnClick(theTargets[i]);
				break;
			}
		}
	}	
}

function getCurrentCriteria()
{
	var theRadios=document.getElementsByName('searchByRadio');
	var theField;
	var theRet='';
	if (theRadios)
	{
		for (var i=0;i<theRadios.length;i++)
		{
			if (theRadios[i].checked)
			{
				theField=document.getElementById('searchByTxt_'+theRadios[i].value)
				if (theField)
				{
					theRet=theField.value;
					criteriaOnChange(theField);
				}
				break;
			}
		}
	}
	return theRet;
}
function displayALHelp(theID)
{
    var link = '/fsg/Help/accountlink/accountlink.htm#'+theID;
	childwin = window.open(link , "Help", "width=600,height=430,top=300,left=400,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,location=no, addressbar=no");
}

function cleanCriteria(theField)
{
	if (theField)
	{
		var theVal=theField.getAttribute('radioval');
		switch (theVal)
		{
			case '1':
			case '5':
				theField.value=stripAlphaChars(theField.value);
				break;
			case '2':
				if (theField.value != theDefault[2])
				{ theField.value=stripSpecialChars(theField.value);	}
			break;
			case '6':
				if (theField.value != theDefault[6])
				{ theField.value=stripWhitespace(theField.value); }
			break;
		}
	}
}

//------------------------------------------------------------------------//
//Site Catalyst related code
function sc_accountReorderLink(pf_id)
{  
   var pid = pf_id;
   var file = "";
   if(window.parent)
   {
    file = window.parent.getFilename();
   }
   //alert(file);
   var trackVars= "prop9,eVar9,prop10,eVar10,prop13,eVar13,events";
   var trackEvents = "event18";
   var lnkname = "Reorder"
   var trackVarsValue = "prop9=" + file + ",";
   trackVarsValue += "eVar9=" + file + "," ; 
   trackVarsValue += "prop10=" + lnkname + ":" + file + ":" + pid + ",";
   trackVarsValue += "eVar10=" + lnkname + ":" + file + ":" + pid + ",";     
   trackVarsValue += "prop13=" + pid + ",";   
   trackVarsValue += "eVar13=" + pid;  
   trackVarsValue += "events=event18";
    
   sendLinkToSC(trackVars,trackVarsValue,trackEvents,lnkname);
}
 
function sc_trackOrderVerification()
{
    var pageTitle = document.title;
    var pageName;
    
    if (pageTitle.indexOf('Verification A') != -1 || pageTitle.indexOf('Failure A') != -1)
        pageName="order verification a";
    else if (pageTitle.indexOf('Verification B') != -1 || pageTitle.indexOf('Failure B') != -1)
        pageName="order verification b";
    else if (pageTitle.indexOf('Verification C') != -1 || pageTitle.indexOf('Failure C') != -1)
        pageName="order verification c";
    else if (pageTitle.indexOf('Verification D') != -1 || pageTitle.indexOf('Failure D') != -1)
        pageName="order verification d";
    else if (pageTitle.indexOf('Verification E') != -1 || pageTitle.indexOf('Failure E') != -1)
        pageName="order verification e";
    
    var isSuccess = false;
    if (pageTitle.indexOf('Failure') == -1)
        isSuccess = true;
    
    s.linkTrackVars="prop35,eVar35,prop36,eVar36";
    s.linkTrackEvents="None";
    s.prop35=pageName;
    s.eVar35=pageName;
    if(isSuccess)
    {
        s.prop36=pageName;
        s.eVar36=pageName;
    }
    
    s.tl(this, "o", "next");  
}

function sc_trackQuery(theMethod)
    {
    //determine origin of the request
    var thePageName = getRequestOrigin();
    
        var toggle;
        
        switch(theMethod)
        {   
            case "1":
                toggle="order number";
                break;
            case "2":
                toggle="phone number";
                break;
            case "5":
                toggle="bank account number";
                break;
            case "6":
                toggle="email address";
                break;
        }
                
        s.linkTrackVars="prop35,eVar35,prop36,eVar36";
        s.linkTrackEvents="None";
    s.prop35= thePageName + ":" + toggle;
    s.eVar35= thePageName + ":" + toggle;
        
    //s.tl(this, "o", "retrieve my order");
    }


// *******************  helper functions  **************************
//retrieve querystring variable
function getParam(arg)
{
    var q = location.search;
    
    if (q.indexOf(arg) >= 0) 
    {
        var pntr = q.indexOf(arg) + arg.length + 1;
        if (q.indexOf("&", pntr) >= 0) 
        {
            return q.substring(pntr, q.indexOf("&", pntr));
        } 
        else 
        {
            return q.substring(pntr, q.length);
        }
    } 
    else 
    {
        return null;
    }   

}

function getSearchMethodString(theMethod)
{
	var theRet='Unknown';
	switch (theMethod)
	{
		case '1':
			theRet='order number';
		break;
		case '2':
			theRet='phone number';
		break;
		case '5':
			theRet='bank account number';
		break;
		case '6':
			theRet='email address';
		break;
	}
	
	return theRet;
}

function getRequestOrigin()
{
    //determine origin of the request
    var theSource = document.referrer;
    var thePageName = 'Unknown';
    if (theSource)
    {
        if (theSource.indexOf('reorder_login') != -1)
        {
            thePageName = 'reorder login failed';
        }
        else if (theSource.indexOf('MyAccount_OrderHistory') != -1)
        {
            thePageName = 'my account no history';
        }
        else 
        {
            thePageName = 'retrieve orders';
        }
    }
    else
    {
        thePageName = 'retrieve orders';
    }
    
    return thePageName;
}
