﻿var nCustomerID = 0;
var sPassword = ""; 

function loginCustomer(strEmail, strPassword)
{
	returnObj('txtLoginPassword').obj.value="";

	sPassword = strPassword;  
	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetCustomer";

	var nBrokerID = readCookie("BrokerID");
	var strSessionID = readCookie("SessionGUID");

	var strParams = "BrokerID="+nBrokerID+"&SessionID="+strSessionID+"&Email="+strEmail+"&Password="+strPassword;
	ajaxPost(strParams,strServiceURL,"setCustomerFields");
}

function logoutCustomer() {
	var customerId = (arguments[0]) ? arguments[0] : 0;

	createCookie("CustomerID",0,0);
	eraseCookie("CustomerEmail");
   
	returnObj("tdLoggedIn").obj.innerHTML="";
	returnObj("divAccountLogout").style.display="none";
		
	if(window.location.pathname.toString().substring(window.location.pathname.toString().lastIndexOf('/') + 1).toUpperCase()=="CHECKOUT.HTML")
	{	/*checkout page*/
		try
		{
			returnObj("hidEmail").obj.value="";
			
			returnObj("tblContactPrefs").style.display="";
			returnObj("tblLoginRegisterHeader").style.display="";
			returnObj("divCCOptions").obj.innerHTML="";
			returnObj("divCCOptions").style.display="none";
			returnObj("rdoCC0").obj.checked=true;
		}
		catch(ex){/*carry on*/}
		if (customerId > 0) {
			/*customer was logged in, so take them back to login view*/
			cartView("LOGIN", "<");
		}
		return;
	}

	try /*these are specifically on the your account page*/
	{
        $("#btnLogout1").hide();

		returnObj("divForgotPassword").style.display="none";
		returnObj("divAccountLogin").style.display="";
	 
		returnObj("divAddressInfo").style.display="none";
		returnObj("divPreferences").style.display="none";
	}
	catch(ex){/*carry on*/}
   
}

function setCustomerFields(xml) {
	var bActiveX=true;
	if (document.implementation && document.implementation.createDocument)
	{
		bActiveX=false;
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		try { showHideModal("hide"); } catch (ex) { /**/ }
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}
	
	try /*these are specifically on the checkout page*/
	{
		returnObj("selectReferral").obj.selectedIndex=0;
		returnObj("selectReferral").style.display="none";
		returnObj("chkJoinEmail").obj.checked="checked";
		returnObj("chkJoinMail").obj.checked="checked";
	}
	catch(ex){/*carry on*/}

	switch(xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("StatusCode"))
	{
	    case "0":
	        createCookie("CustomerID", xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("ID"), 0);
	        createCookie("CustomerEmail", xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("Email"), 0);

	        /*new login/register cart window*/
	        try {
	            if (window.bConnectLogin) {
	                window.location.href = "https://" + location.hostname + "/checkout.html?cv=s";
	                break;
	            }
	        } catch (ex) { /**/alert(ex); }

	        try { /* only applies to checkout */
	            $('.hidEmail').val() = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("Email");
	        } catch (ex) { /* carry on */ }

	        returnObj("divForgotPassword").style.display = "none";
	        returnObj("divAccountLogin").style.display = "none";
	        returnObj('txtLoginEmail').obj.value = "";

	        try { /* only applies to checkout */
	            returnObj("tblContactPrefs").style.display = "none";
	            returnObj("tblLoginRegisterHeader").style.display = "none";
	            returnObj("divAccountType").style.display = "none";
	            returnObj("txtEmail").obj.value = "";
	            returnObj("tdLoggedIn").obj.innerHTML = "<span style=\"color:#008800;\">" + readCookie("CustomerEmail") + "</span>";
	        } catch (ex) { /* carry on */ }

	        try { /*these are specifically on the your account page*/
	            returnObj("txtCurEmail").obj.value = readCookie("CustomerEmail");
	            returnObj("divAddressInfo").style.display = "";
	            returnObj("tblContactPrefs").style.display = "";
	            returnObj("tdLoggedIn").obj.innerHTML = "Logged in as <span style=\"color:#008800;\">" + readCookie("CustomerEmail") + "</span>";

	            if (xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("ReceiveEmail") == "True") {
	                returnObj('chkJoinEmail').obj.checked = true;
	            }
	            else {
	                returnObj('chkJoinEmail').obj.checked = false;
	            }

	            if (xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("ReceiveMail") == "True") {
	                returnObj('chkJoinMail').obj.checked = true;
	            }
	            else {
	                returnObj('chkJoinMail').obj.checked = false;
	            }
	        } catch (ex) { /*carry on*/ }

	        returnObj("divAccountLogout").style.display = "";
	        try {
	            $("#btnLogout1").show();
	        } catch (ex) {/*only on acct page*/}

	        returnObj("txtFirstName").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("FirstName");
	        returnObj("txtLastName").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("LastName");
	        returnObj("txtAddress1").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("Address1");
	        returnObj("txtAddress2").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("Address2");
	        returnObj("txtCity").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("City");

	        setCountryState(xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("CountryID"), xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("StateID"));

	        returnObj("txtBillingPostalCode").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("PostalCode");
	        try { returnObj("hidBillingPostalCode").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("PostalCode"); } catch (ex) { }

	        returnObj("txtDayPhone").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("DayPhone");
	        returnObj("txtNightPhone").obj.value = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("NightPhone");

	        nodeCCs = xmlDoc.getElementsByTagName("CreditCard");
	        var strCCHTML = "";
	        for (n = 0; n < nodeCCs.length; n++) {
	            strCCHTML += "<table id=\"tblCC" + nodeCCs[n].getAttribute("CCID").toString() + "\" cellpadding=\"5\" cellspacing=\"0\" class=\"tblCC\"><tr><td valign=\"top\" class=\"tdUseThisCard\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"middle\" style=\"padding:2px;\"><input type=\"radio\" name=\"rdoCC\" id=\"rdoCC" + nodeCCs[n].getAttribute("CCID").toString() + "\" /></td><td valign=\"middle\"><label for=\"rdoCC" + nodeCCs[n].getAttribute("CCID").toString() + "\">use this card</label></td></tr></table></td><td valign=\"top\" class=\"tdCardType\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" style=\"padding:2px;\">" + nodeCCs[n].getAttribute("CCTypeName").toString() + "</td></tr></table></td><td valign=\"top\" class=\"tdNameOnCard\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" style=\"padding:2px;\">" + nodeCCs[n].getAttribute("CCHolderName").toString() + "</td></tr></table></td><td valign=\"top\" class=\"tdCardNumber\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" style=\"padding:2px;\">" + nodeCCs[n].getAttribute("CCNumber").toString() + "</td></tr></table></td><td valign=\"top\" class=\"tdExpiration\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" style=\"padding:2px;\" nowrap=\"nowrap\">" + nodeCCs[n].getAttribute("CCExpireMonth").toString() + "/" + nodeCCs[n].getAttribute("CCExpireYear").toString() + "</td></tr></table></td><td valign=\"top\" style=\"bacground-color:#ff00ff;\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" style=\"padding:2px;\"><input type=\"text\" id=\"txtCVV" + nodeCCs[n].getAttribute("CCID").toString() + "\" maxlength=\"4\" size=\"4\" /><div id=\"divErr_txtCVV" + nodeCCs[n].getAttribute("CCID").toString() + "\" class=\"divError\" style=\"display:none;\">&#160;</div></td></tr></table></td></tr></table>";
	        }
	        try { /* only applies to checkout */
	            returnObj("divCCOptions").obj.innerHTML = strCCHTML;
	            returnObj("divCCOptions").style.display = "";
	        } catch (ex) { /* carry on */ }

	        nCustomerID = xmlDoc.getElementsByTagName("GetCustomer")[0].getAttribute("ID");
	        getRecentOrders(nCustomerID); //since we're already logged in//

	        break;
			
		default:
			try{ /* only applies to checkout */        
			returnObj("txtEmail").obj.value=returnObj("txtLoginEmail").obj.value;}catch(ex){/**/}
			returnObj('txtLoginPassword').obj.value="";
			
			/*alert("Failed to login!\n\nEither the email address or password you entered is not in our records.\n\nIf you forgot your password click the 'Forgot password' link and have a reminder emailed to you.\n\n");*/
			returnObj("divFailedLoginMsg").style.display="";
			/*setTimeout("returnObj('divFailedLoginMsg').style.display='none'",5000);*/
			break;
	}
	try { showHideModal("hide"); } catch (ex) { /**/ }
}


function preferenceSearch(CustomerID)
{
	if (returnObj("qPref").obj.value == "" || returnObj("qPref").obj.value == "find performers, venues, or cities")
	{ return; }
	
	// check the radio buttons and set QueryType    
	var QueryType=0;
	if (returnObj("radioPerformer").obj.checked) {
		QueryType=2;
	}
	else if (returnObj("radioVenue").obj.checked) {
		QueryType=4;
	}
	else if (returnObj("radioCity").obj.checked) {
		QueryType=7;
	}   
	
	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/UpdateCustomerPreference";             
	var strParams = "strAction=NONE&nCustomerID="+CustomerID+"&nRTTID=0&nETID=0&strQuery="+returnObj("qPref").obj.value+"&nQueryType="+QueryType+"&bTransform=true";
	ajaxPost(strParams,strServiceURL,"renderPreferences");
}

function editPreference(strAction,CustomerID,ETID,RTTID,QueryString,QueryType)
{
	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/UpdateCustomerPreference";             
	var strParams = "strAction="+strAction+"&nCustomerID="+CustomerID+"&nRTTID="+RTTID+"&nETID="+ETID+"&strQuery="+QueryString+"&nQueryType="+QueryType+"&bTransform=true";
	ajaxPost(strParams,strServiceURL,"renderPreferences");
}

function renderPreferences(xml)
{
	var bActiveX=true;
	if (document.implementation && document.implementation.createDocument)
	{
		bActiveX=false;
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}
	
	try{ /* only applies to Your-Account */
	returnObj("divCustomerPreferences").obj.innerHTML=xml;
	returnObj("divCustomerPreferences").style.display="";
	}catch(ex){/* carry on */}
	filter_OnClick(readCookie("prefRadio"));
}

function getRecentOrders(CustomerID)
{
	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetRecentOrders";             
	var strParams = "nCustomerID="+CustomerID+"&strPassword="+sPassword+"&bTransform=true";
	ajaxPost(strParams,strServiceURL,"renderOrders");
}


function renderOrders(xml)
{
	var bActiveX=true;
	if (document.implementation && document.implementation.createDocument)
	{
		bActiveX=false;
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}
	
	try{ /* only applies to Your-Account */
	returnObj("divOrderSummary").obj.innerHTML=xml;
	returnObj("divOrderSummary").style.display="";
	}catch(ex){/* carry on */}

	try{editPreference("NONE",nCustomerID,0,0,"",0);}catch(ex){/**/}
}

function printOrder() {
    top.winPrintable = window.open('', 'Printable', 'status=0,toolbar=1,location=0,menubar=1,directories=0,resizable=1,scrollbars=1,width=800,height=580');
    top.winPrintable.document.write('<html><head><title>Print Order Confirmation!</title></head><body onload=\"window.print();\"><div id=\"divPrintPic\"><img src=\"/site-images/global/header_logo.gif\" /></div>' + document.getElementById("divOrderContent").innerHTML + '</body></html>');
    top.winPrintable.document.close();
    return false;
}

function customerCat_onClick(RTTID,CustomerID,QueryString,QueryType)
{
	if (returnObj("chk_"+RTTID).obj.checked)
	{
		editPreference("ADD",CustomerID,0,RTTID,QueryString,QueryType);
	}
	else
	{    
		editPreference("REMOVE",CustomerID,0,RTTID,QueryString,QueryType);
	}   
}     

function sendPassword(strEmail)
{
	returnObj('txtLoginPassword').obj.value="";

	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/SendPasswordReminder";

	var nBrokerID = readCookie("BrokerID");

	var strParams = "brokerId="+nBrokerID+"&emailAddress="+strEmail;
	ajaxPost(strParams,strServiceURL,"sentPasswordMsg");
}

function sentPasswordMsg() {
	try { showHideModal("hide"); } catch (ex) { /**/ }
	
	returnObj('txtLoginEmail').obj.value=returnObj('txtReminderEmail').obj.value;
	returnObj('txtReminderEmail').obj.value="";
	returnObj("divForgotPassword").style.display="none";
	returnObj("divAccountLogin").style.display="";
	returnObj("divSentPwdMsg").style.display="";
	
	/*divAccountType only on popup login*/
	try	{returnObj("divAccountType").style.display="";}catch(ex){/**/}
	
	setTimeout("returnObj('divSentPwdMsg').style.display='none'",5000);
}

function loadStates(id,value)
{
	/* clear all the options that were previously set */
	while(returnObj(id).obj.options.length>0)
	{
		 returnObj(id).obj.options[0]=null;
	}
   
	returnObj(id).obj.options[0] = new Option("",0); 
	  
	var x;
	var i = 1; 
	for(x in strStates)
	{
		if(strStates[x].substring(0,strStates[x].indexOf(","))==value)
		{
			var strStateInfo = strStates[x].split(",");
			returnObj(id).obj.options[i] = new Option(strStateInfo[2],strStateInfo[1]);
			i++;
		}
	}

	if(i==1)
	{
		returnObj(id).style.display="none";
		returnObj("spanNO"+id).style.display="";
	}
	else
	{
		returnObj(id).style.display="";
		returnObj("spanNO"+id).style.display="none";
	}
   
	var strPostalInput = "txtBillingPostalCode";
	if(id.indexOf("Billing") == -1)
	{
		strPostalInput = "txtDeliveryPostalCode";
	}
	/* elseif needed for shipping field */

	if(strNoPostal.indexOf("|"+value+"|")>=0)
	{
		returnObj(strPostalInput).style.display="none";
		try{returnObj("spanNO"+strPostalInput).style.display="";}catch(ex) {}
	}
	else
	{
		returnObj(strPostalInput).style.display="";
		try{returnObj("spanNO"+strPostalInput).style.display="none";}catch(ex) {}
	}  
}

function setCountryState(nCountryID,nStateID)
{
	var x = 0;
	if(nCountryID!=0)
	{
		var nCountries = document.forms[0].selectBillingCountry.length;
		while(x < nCountries)
		{
			if(document.forms[0].selectBillingCountry.options[x].value==nCountryID)
			{
				 returnObj("selectBillingCountry").obj.options[x].selected=true;
				 x=nCountries;
			}
			x++;
		}
	}
	returnObj("selectBillingCountry").obj.onchange();
	
	if(nStateID!=0)
	{
		var nStates = document.forms[0].selectBillingState.length;
		x=0;
		while(x < nStates)
		{
			if(document.forms[0].selectBillingState.options[x].value==nStateID)
			{
				 returnObj("selectBillingState").obj.options[x].selected=true;
				 x=nStates;
			}
			x++;
		}
	}
	try{returnObj("hidBillingState").obj.value=nStateID;}catch(ex) {}
}


function updateCustomer_OnClick(SessionID,BrokerID) {
    showHideModal("show", "<h3 class=\"modal_header\">Updating Your Information</h3><hr /><img src=\"/site-images/global/ajax-preloader.gif\" alt=\"\" />");
	if (returnObj("txtCurEmail").obj.value=="")
	{
	    returnObj("trCurEmailErr").style.display = "";
	    showHideModal("hide");
	    return;
	}
	var strPwd="";
	if (returnObj("txtPassword1").obj.value == returnObj("txtPassword2").obj.value) {
	    returnObj("trPasswordsErr").style.display = "none";
	    strPwd = returnObj("txtPassword1").obj.value;
	}
	else {
	    returnObj("trPasswordsErr").style.display = "";
	    showHideModal("hide");
	    return;
	}

	//returnObj('divSettingsUpdateMsg').style.display="";  
	createCookie("CustomerEmail",returnObj("txtCurEmail").obj.value,0);
	createCookie("StateID",returnObj("selectBillingState").obj.options.selectedIndex,0);
	createCookie("CountryID",returnObj("selectBillingCountry").obj.options.selectedIndex,0);
	
	var emailChecked="false";
	var mailChecked="false";           
	if (returnObj('chkJoinEmail').obj.checked == true){ emailChecked="true"; }    
	if (returnObj('chkJoinMail').obj.checked == true){ mailChecked="true"; }
		
	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/UpdateCustomer";             
	var strParams = "&strSessionID="+SessionID+"&nBrokerID="+BrokerID+"&nCustomerID="+readCookie("CustomerID")+"&strFirstName="+returnObj("txtFirstName").obj.value+"&strLastName="+returnObj("txtLastName").obj.value+"&strAddress1="+returnObj("txtAddress1").obj.value+"&strAddress2="+returnObj("txtAddress2").obj.value+"&strCity="+returnObj("txtCity").obj.value+"&nCountryID="+returnObj("selectBillingCountry").obj.options[returnObj("selectBillingCountry").obj.options.selectedIndex].value+"&nStateID="+returnObj("selectBillingState").obj.options[returnObj("selectBillingState").obj.options.selectedIndex].value+"&strPostal="+returnObj("txtBillingPostalCode").obj.value+"&strPhoneDay="+returnObj("txtDayPhone").obj.value+"&strPhoneEve="+returnObj("txtNightPhone").obj.value+"&bEmailList="+emailChecked+"&bMailList="+mailChecked+"&strEmail="+returnObj("txtCurEmail").obj.value+"&strNewPassword="+strPwd+"&bTransform=true";
	ajaxPost(strParams,strServiceURL,"renderAccountSettings");
}

function renderAccountSettings(xml) {
	var bActiveX=true;
	if (document.implementation && document.implementation.createDocument)
	{
		bActiveX=false;
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}
	
	returnObj("divAccountSettings").obj.innerHTML=xml;
	returnObj("divAccountSettings").style.display = "";
	returnObj("divAddressInfo").style.display = "";

	showHideModal("show", "<h3 class=\"modal_header\">Your information has been updated!</h3><hr />", "true", 5000);
	
	/* these are safe to call since this can't get called without being logged in */
	try{ 
	returnObj('selectBillingCountry').obj.options.selectedIndex=readCookie("CountryID");    
	returnObj("selectBillingCountry").obj.onchange();
	returnObj('selectBillingState').obj.options.selectedIndex=readCookie("StateID");    
	}catch(ex){}
}

function filter_OnClick(id,customerID)
{            
	switch(id)
	{
	case "Perf":
		try{
		returnObj("radioPerformer").obj.checked = true;
		returnObj("radioVenue").obj.checked = false;
		returnObj("radioCity").obj.checked = false;
		createCookie("prefRadio","Perf",0);
		} catch (ex) {}
	break;
	case "Venue":
		try{
		returnObj("radioPerformer").obj.checked = false;
		returnObj("radioVenue").obj.checked = true; 
		returnObj("radioCity").obj.checked = false;
		createCookie("prefRadio","Venue",0);
		} catch (ex) {}
	break;
	case "City":
		try{
		returnObj("radioPerformer").obj.checked = false;
		returnObj("radioVenue").obj.checked = false;
		returnObj("radioCity").obj.checked = true;
		createCookie("prefRadio","City",0);
		} catch (ex) {}
	break;
	}   
	 
}

function redirectToSpecials(PageName)
{
	window.location.href= "http://" + document.domain + PageName;
}

function trackFedEx(strRef)
{
	//if (returnObj("div" + strRef).style.display == "none")
	//{ 
		var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetFedexTracking";
		var strParams = "strTrackingNumber="+strRef; 
		ajaxPost(strParams,strServiceURL,"renderFedEx");
	 //}
	 //else
	 //{
		//returnObj("div" + strRef).style.display ="none";
	 //}
}

var strRowBegin = "<tr class=\"rowEven\">";
function renderFedEx(xml)
{
	var bActiveX=true;
	if (document.implementation && document.implementation.createDocument)
	{
		bActiveX=false;
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}
	
	var iSteps = parseFloat(xmlDoc.getElementsByTagName("FedEx_TrackStatus")[0].getAttribute("steps")); 
	var strTrackingNumber = xmlDoc.getElementsByTagName("FedEx_TrackStatus")[0].getAttribute("TrackingNumber"); 
	var strTableBegin = "<table class=\"fedExTracking\" cellpadding=\"0\" cellspacing=\"0\">";
	var strRowCellBegin = "<td align=\"left\" width=\"25%\">"; 
	var strRowEnd = "</td></tr>"; 
	var strTableCell = "</td><td align=\"left\" width=\"25%\">";
	var strTableEnd = "</table>"; 
	var strHeaderRow = "<tr style=\"background: #CCCC00;\"><td width=\"25%\"><u>Date/Time</u>" + strTableCell + "<u>Activity</u>" + strTableCell + "<u>Location</u>" + strTableCell + "<u>Details</u>" + strRowEnd; 
	var sb = new StringBuilder(); 
	
	for (var i = 0; i < iSteps; i++) 
	{
		sb.append(strRowBegin); 
		sb.append(strRowCellBegin); 
		sb.append(xmlDoc.getElementsByTagName("Step_" + i)[0].getAttribute("Date"));
		sb.append(strTableCell + xmlDoc.getElementsByTagName("Step_" + i)[0].getAttribute("Status"));
		sb.append(strTableCell + xmlDoc.getElementsByTagName("Step_" + i)[0].getAttribute("Location"));
		sb.append(strTableCell + xmlDoc.getElementsByTagName("Step_" + i)[0].getAttribute("Description")); 
		sb.append(strRowEnd); 
		
		toggleRowClass();
	}
    
    var s = strTableBegin + strHeaderRow + sb.toString() + strTableEnd;
    showHideModal("show", "<h3 class=\"modal_header\">FedEx Tracking Details</h3><hr />" + s, "true");
}

function toggleRowClass()
{
	if (strRowBegin == "<tr class=\"rowEven\">")
	{
		strRowBegin = "<tr class=\"rowOdd\">"; 
	}
	else
	{
		strRowBegin = "<tr class=\"rowEven\">";
	}   
}

function registerMember(EmailAddress,nBrokerID)
{
	var strParams = "EmailAddress="+EmailAddress+"&nBrokerID="+nBrokerID+"&strCB=";
	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogNewsLetter";
	ajaxPost(strParams,strServiceURL,"memberRegistered");
}
function memberRegistered()
{
	xml = arguments[0];

	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}

	var strEmailAddress = xmlDoc.getElementsByTagName("LogNewsLetter")[0].getAttribute("EmailAddress");
	var strCustomerID = xmlDoc.getElementsByTagName("LogNewsLetter")[0].getAttribute("CustomerID");

	if(xmlDoc.getElementsByTagName("LogNewsLetter")[0].getAttribute("NewCustomer")=="true")
	{
		cmCreateRegistrationTag(strCustomerID, strEmailAddress, null, null, null, null, "Newsletter", "true");
		loginCustomer(strEmailAddress,xmlDoc.getElementsByTagName("LogNewsLetter")[0].getAttribute("Password"));
	}
	else
	{
		alert("The email address you've entered may already be associated with an account.\n\nIf so, a password reminder has been emailed to you.");
	}

}
function showHideConnect(strType)
{
	showHide('divFailedLoginMsg','hide');
	showHide('divFailedRegisterMsg','hide');
	switch(strType)
	{
		case "REGISTER":
			showHide('divAccountType','show');
			showHide('divJoinEmail','show');
			showHide('divNewAccount','show');
			showHide('divAccountLogin','hide');
			showHide('spanPassLater','hide');
			showHide('divForgotPassword','hide');
			break;
		case "LOGIN":
			showHide('divNewAccount','hide');
			showHide('divAccountLogin','show');
			showHide('spanPassLater','show');
			showHide('divForgotPassword','hide');
			showHide('divJoinEmail','hide');
			break;
	}
}
function continueConnect()
{
	try
	{
		showHide('divFailedLoginMsg','hide');
		showHide('divFailedRegisterMsg','hide');
	}catch(ex){/**/}
	
	window.bConnectLogin = false;
	var bContinue = true;
	if(returnObj("divForgotPassword").style.display=="")
	{
		/* SEND PASSWORD */
	    showHideModal("show", "<h3 class=\"modal_header\">Sending Password</h3><hr /><img src=\"/site-images/global/ajax-preloader.gif\" alt=\"\" />");
		sendPassword(returnObj('txtReminderEmail').obj.value);
	}
	else if(returnObj("divAccountLogin").style.display=="")
	{
		/* LOGIN RETURN CUSTOMER */
		window.bConnectLogin = true;
		showHideModal("show", "<h3 class=\"modal_header\">Logging In</h3><hr /><img src=\"/site-images/global/ajax-preloader.gif\" alt=\"\" />");
		loginCustomer(returnObj('txtLoginEmail').obj.value, returnObj('txtLoginPassword').obj.value);
	}
	else if(returnObj("divNewAccount").style.display=="") {
		/* REGISTER NEW CUSTOMER */
	    showHideModal("show", "<h3 class=\"modal_header\">Creating Your New Account</h3><hr /><img src=\"/site-images/global/ajax-preloader.gif\" alt=\"\" />");
		createCookie("CustomerID",0,0);
		/* validate email */
		if (validateValue("txtEmail", /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/, false) == false)
		{
			bContinue = false;
			returnObj("spanErr_txtEmail").obj.innerHTML = "* Required";
			returnObj("spanErr_txtEmail").obj.style.display="";
			showHideModal("hide");
			returnObj("txtEmail").obj.focus();
		}
		else
		{
			returnObj("spanErr_txtEmail").obj.innerHTML = "&#160;"; 
			returnObj("spanErr_txtEmail").obj.style.display="none";
		}
		if(bContinue){registerEmail();}
	}
	else {
		showHideModal("hide");
		alert('There is a technical problem with your browser. Please contact customer service for assistance.');
	}
}
function validateValue(id,strRegExp,bNegate)
{
	var regex = new RegExp(strRegExp);
	if(regex.test(returnObj(id).obj.value)!=bNegate)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function registerEmail() {
	var BrokerID = readCookie("BrokerID");
	var SessionID = readCookie("SessionGUID");
	var strEmail = returnObj("txtEmail").obj.value;
	var strNotify = (returnObj('chkJoinEmail').obj.checked == true) ? "true" : "false";

	var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/RegisterEmail";
	var strParams = "strSessionID="+SessionID+"&nBrokerID="+BrokerID+"&strEmail="+strEmail+"&bEmailList="+strNotify+"&bTransform=false";
	ajaxPost(strParams,strServiceURL,"emailLoggedIn");
}

function emailLoggedIn() {
	xml = arguments[0];

	var bActiveX=true;
	if (document.implementation && document.implementation.createDocument)
	{
		bActiveX=false;
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		try { showHideModal("hide"); } catch (ex) {/**/}
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}
	switch(xmlDoc.getElementsByTagName("RegisterEmail")[0].getAttribute("StatusCode"))
	{
		case "0":
			createCookie("CustomerID", xmlDoc.getElementsByTagName("RegisterEmail")[0].getAttribute("ID"), 0);
			createCookie("CustomerEmail", returnObj("txtEmail").obj.value, 0);
			var strNotify = false;
			try { strNotify = (returnObj('chkJoinEmail').obj.checked == true) ? "true" : "false"; } catch (ex) { }
			cmCreateRegistrationTag(readCookie("CustomerID"), readCookie("CustomerEmail"), null, null, null, null, "Cart Register", strNotify);
			/*closeModalPop('LOGIN');
			window.location = "https://" + location.hostname + "/checkout.html";*/
			cartView("SUBMIT");
			break;
		default: /* no customer record found */
			returnObj("divFailedRegisterMsg").style.display="";
			
			/* set return cust radio rdoReturnCustomer, show login div with email, hide reg div*/
			returnObj("rdoReturnCustomer").obj.checked = true;
			returnObj("divAccountLogin").style.display="";
			returnObj("divNewAccount").style.display="none";
			returnObj("txtLoginEmail").obj.value=returnObj("txtEmail").obj.value;
 
			break;
	}
	try { showHideModal("hide"); } catch (ex) {/**/}
}

$(document).ready(function () { /* update various email inputs when any are changed */
    $("#txtEmail").bind("change blur keyup mouseup", function (e) {
        try { $("#txtLoginEmail").val($("#txtEmail").val()); } catch (e) { /**/ }
        try { $("#txtReminderEmail").val($("#txtEmail").val()); } catch (e) { /**/ }
    });
    $("#txtLoginEmail").bind("change blur keyup mouseup", function (e) {
        try { $("#txtEmail").val($("#txtLoginEmail").val()); } catch (e) { /**/ }
        try { $("#txtReminderEmail").val($("#txtLoginEmail").val()); } catch (e) { /**/ }
    });
    $("#txtReminderEmail").bind("change blur keyup mouseup", function (e) {
        try { $("#txtLoginEmail").val($("#txtReminderEmail").val()); } catch (e) { /**/ }
        try { $("#txtEmail").val($("#txtReminderEmail").val()); } catch (e) { /**/ }
    });
});


/*set up tabs to show/hide content*/
$(document).ready(function () {
    var allTCcontent = $('.myTC_tabContent');



    /*following 3 lines are temp. dev changes*/
    $("#myTC_welcomeContent").hide();                   /*uncomment to hide tabs*/
    $("#myTC_leftNav ul").hide();                       /*uncomment to hide tabs*/
    $('#myTC_leftNav').css('marginTop', '24px');        /*uncomment to hide tabs*/
    /*allTCcontent.hide();*/                                    /*comment to hide tabs*/
    /*$('#myTC_welcomeContent').fadeIn(210);*/                  /*comment to hide tabs*/
    
       
    
    /*make call for data --> do we want to grab it all here, or just grab a summary for the welcome tab, then load individual data on the tabs (i.e. 1 big ajax call or 6 smaller calls)*/

    /*will probably get an ajax call built in*/
    function writeMyTCtabContent(tabHeader, tabContent) {
        allTCcontent.hide();
        var updatedHeaderText = $('#myTC_header .white');

        updatedHeaderText.hide();
        updatedHeaderText.html(tabHeader).fadeIn(200);
        $(tabContent).fadeIn(240);
    }

    var clickedTab = $("#myTC_leftNav ul li");

    clickedTab.live("click", function () {
        clickedTab.removeClass('selected_myTC_tab');
        $(this).addClass('selected_myTC_tab');

        if ($('#myTC_accountTab').hasClass('selected_myTC_tab')) {
            writeMyTCtabContent('Account Info', '#myTC_billingAddress');
        }
        else if ($('#myTC_ordersTab').hasClass('selected_myTC_tab')) {
            writeMyTCtabContent('Orders & Shipping', '#divOrderSummary');
        }
        else if ($('#myTC_preferencesTab').hasClass('selected_myTC_tab')) {
            writeMyTCtabContent('Preferences', '#myTC_emails');
        }
        else if ($('#myTC_reviewsTab').hasClass('selected_myTC_tab')) {
            writeMyTCtabContent('Reviews', '#myTC_reviews');
        }
        else {
            writeMyTCtabContent('Welcome!', '#myTC_welcomeContent');
        }

    });
});
