//This will fill the background of the missing informatio in the forms
var missingValuesBColor = 'FFC59F'
var _configPhones_Is_FormChanged = false;
var _configPhones_Is_FormUpdated = false;
var selectPlanFlag;
var productHasPlan;
var allowPlanSelection;

function basket_switchBasket(obj){
	var basketId = obj[obj.selectedIndex].value;
	if(basketId != ''){
		window.location = globalFilePath2 + '?_function=shoppingCart&bid=' + basketId  + '&' + globalKey;
	}
}

function getAccessories(basid,key){
//Called by link "Add Accessories"
//DO THE AJAX CALL use phoneConfig div
	setDivSize('blockerDiv');
	positionDiv('phoneConfigBkg');
	positionDiv('phoneConfig');
	blockerDiv.style.display = '';
	blockerDiv.style.visibility = 'visible';
	phoneConfig.style.display = '';
	phoneConfig.style.visibility = 'visible';
	phoneConfigBkg.style.display = '';
	phoneConfigBkg.style.visibility = 'visible';

	var url = "ajax/ajax_accessories.taf?basid=" + basid + "&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("phoneConfig").update(response.responseText)
	  }
	});
	
}

function getAccessoriesByPID(pid,key){
//get Accessories By Phone
	
	var url = "ajax/ajax_getPhoneInfobyPID.taf?method=addAccessories&pid=" + pid + "&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("accessoriePhoneInfo").update(response.responseText)

	  }
	});	
		
	url = "ajax/ajax_getAccessoriesbyPID.taf?pid=" + pid + "&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("accessorieConfig").update(response.responseText)
			if(response.responseText.length==0){
			document.getElementById("bttnBasketAccSave").style.display  = 'none';
		}else{
			document.getElementById("bttnBasketAccSave").style.display = '';
		}
	  }
	});
}

function basketAccSave(key){
	var qtySelected = 0
	$('accessorieConfig').select('.basketAddMore').each(function(element) {
		if(element.value>0) {
			qtySelected = 1	
		}
	})
	
	var url = 'ajax/ajax_updateAccessories.taf?method=addMultipleItems&qtySelected='+ qtySelected +'&_UserReference=' + globalKeyRef 
	new Ajax.Request(
      url,
      {
         method: 'post',
         parameters: Form.serialize(document.accessoriesForm),
         onComplete: function(response) {
			 if(response.responseText!='') {
					alertAddAcc(key);
					document.accessoriesForm.reset();
			 }
		 }
      });
}

function basketEmptyCurrentCart(removeBasketId,key){
		window.location = globalFilePath2 + '?_function=shoppingCart&removeBasketId=' + removeBasketId  + '&_UserReference=' + globalKeyRef ;
}

function basketAccUpdateItem(basketAccessoryId,key){
	var accessoryQty = document.getElementById("basketAccQty_" + basketAccessoryId).value;
	if(accessoryQty < 1){
		basketAccRemoveItem(basketAccessoryId,key);
	}else{
		var url = 'ajax/ajax_updateAccessories.taf?method=updateItem&basketAccessoryId=' + basketAccessoryId + '&accessoryQty=' + accessoryQty + '&_UserReference=' + globalKeyRef 
		new Ajax.Request(url, {
		  onSuccess: function(response) {

			if(response.responseText=="OK"){ myMsgBoxSaved(); }
		  }
		});		
	}
}

function basketAccRemoveItem(basketAccessoryId,key){
	var url = 'ajax/ajax_updateAccessories.taf?method=removeItem&basketAccessoryId=' + basketAccessoryId +'&_UserReference=' + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("phoneConfig").update(response.responseText)
		if(response.responseText=="OK"){	
				document.getElementById("trBasketAcc_" + basketAccessoryId).style.display = 'none';
				var numRowsBasketAcc = document.getElementById("numRowsBasketAcc").value - 1;		
				if(numRowsBasketAcc==0){
					document.getElementById("divAccInCart").innerHTML = '';
					document.getElementById("bttnCheckout").innerHTML = '';
				}
				else{
					document.getElementById("numRowsBasketAcc").value = numRowsBasketAcc;
				}
			}
	  }
	});	
	
}

// **************************** FOR JAMES GOT THIS FROM BELL START ****************************************
function updatePhoneQty(pid,num) {
	var myField = $('qty'+num)
	var myName = $('qty'+num).name.split("_")
	if(checkQTY(myField)) {
		if(myField.value==0) {
			//removeItem
			//showDialog("delAcc("+myName[1]+")","",2,"Setting quantity to zero will delete this item.")
		}
		else {
			startSpinner('qty'+num)
			exFetch('ajax/ajax_basket.taf?method=adjQty&pid='+myName[1]+'&qty='+myField.value+'&qtyField='+num,'',function(){updatePhoneQuantityCB(pid,num,myField.value)});
		}
	}
}
// **************************** FOR JAMES GOT THIS FROM BELL END ****************************************


function addQty(pid,basid,elementId,key){
	var qty = parseInt(document.getElementById(elementId).value);
	if(qty > 0){
		window.location = globalFilePath2 + "?_function=shoppingCart&qty="+ qty + "&pid=" + pid + "&basid=" + basid + "&" + globalKey;
	}else{
		document.getElementById(elementId).value = 0;
	}
}

numRowsBasketPhones = "";

function removeAllOfPhone(pid,key){
	if(numRowsBasketPhones == ""){
		numRowsBasketPhones =document.getElementById("numRowsBasketPhones").value;
	}

	var url = "ajax/ajax_basket_removePID.taf?removePID=" + pid + "&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("phoneConfig").update(response.responseText)
		var theResponse = response.responseText.replace(/^\s+|\s+$/g,"");	
		if(theResponse == 'OK' || theResponse == 'OK_BASKET_COMPLETED'){
			numRowsBasketPhones = numRowsBasketPhones - 1;
	
			if(numRowsBasketPhones==0){
				
				window.location = globalFilePath2 + '?_function=shoppingCart&' + globalKey;	
			}else{
				//determine if this is the only item for this network.
				var myNames = $("trBasketPID_" + pid).classNames().toArray()

				var myNet = ""
				for(var x=0;x<myNames.length;x++) {
					if(myNames[x].indexOf("netPhone_")>-1) {
						myNet = myNames[x]						
					}
				}
				var mySibs = $(document.body).select("."+myNet).toArray()
				//find siblings
				if(mySibs.length<2) {
					var headSelect = myNet.split("_")
					$("trBasketPID_" + pid).previous('.netHead_'+headSelect[1]).hide()
				}
				
				
				//remove item
				$("trBasketPID_" + pid).remove()
				
				
				
				$("numRowsBasketPhones").value = numRowsBasketPhones;
				if(response.responseText=="OK_BASKET_COMPLETED"){
				 document.getElementById("bttnCheckout").innerHTML = '' +
					'<a href=' + globalFilePath2 + '?_function=shoppingCart&cmd=checkout&_UserReference=' + globalKeyRef  + '>' + 
					'<img border=0 src=\"BasketImages/checkoutOn.gif\" width=145 height=21 onmouseover=\"this.src=\'BasketImages/checkoutOnMO.gif\'\" onmouseout=\"this.src=\'BasketImages/checkoutOn.gif\'\"></a>';
				}
			}
		}
	
		  }
	});
	
}

function closeDivAndRefresh(){
	window.location = globalFilePath2 + '?_function=shoppingCart&' + globalKey;
}

function configPhonesCloseDiv(key){
	if(configPhones_IsFormChanged()){
		var strJSYes = "SaveSelection('" + globalKeyRef  + "')";
		var strJSNo = "configPhonesFormNoChange();configPhonesCloseDivProceed()";
		alertConfigPhoneSaveSelection(strJSYes,strJSNo);
	}else{
		configPhonesCloseDivProceed();
	}
}

function configPhonesCloseDivProceed(){
	var blockerDiv = document.getElementById("blockerDiv")
	var phoneConfig = document.getElementById("phoneConfig")
	var phoneConfigBkg = document.getElementById("phoneConfigBkg")
	if(_configPhones_Is_FormUpdated){ //if form was saved at least once
		window.location = globalFilePath2 + '?_function=shoppingCart&' + globalKey + "&now=" + new Date()
	}else{
		_configPhones_Is_FormUpdated = false;
		blockerDiv.style.display = 'none';
		blockerDiv.style.visibility = 'hidden';
		phoneConfig.style.display = 'none';
		phoneConfig.style.visibility = 'hidden';
		phoneConfigBkg.style.display = 'none';
		phoneConfigBkg.style.visibility = 'hidden';
	}
}

function configPhonesProxy(pid,basid,obj,ptype,key){
	var selection = obj[obj.selectedIndex].value;
	if(selection!=""){
		var bpid = selection;
		configPhones(pid,basid,bpid,ptype,key);
	}
	obj.selectedIndex = 0;
}

function setTerms(obj){
	provinceId = obj[obj.selectedIndex].value;
	if(provinceId != ''){
		getTerms(provinceId);
	}
}

function getTerms(obj,pid,key){
	var provId = obj[obj.selectedIndex].value;
	document.getElementById("hiddennew").style.display = 'none';	
	document.getElementById("hiddenupgrade").style.display = 'none';
	document.getElementById("hiddenwnp").style.display = 'none';
	
	if(provId == ''){
	  document.configForm.termNewOrReplace.value = '';
	  document.getElementById("variantDiv").innerHTML = "select a province to view options";
	}
	else{
		var url = "ajax/ajax_getTermsByProvIdPidUID.taf?provid=" + provId + "&pid=" + pid + "&_UserReference=" + globalKeyRef 
		new Ajax.Request(url, {
		  onSuccess: function(response) {
			$("variantDiv").update(response.responseText)
			document.configForm.variantId.style.background = missingValuesBColor
		  }
		});


		
	}
}

function openHiddenOptions(obj,key){
	var hiddenNew = document.getElementById("hiddennew");
	var hiddenUpgrade = document.getElementById("hiddenupgrade");
	var hiddenWNP = document.getElementById("hiddenWNP")||document.getElementById("hiddenwnp");
	
	selectedTerm = obj[obj.selectedIndex].value;

	if(selectedTerm != ''){
		variantLength = document.configForm.varianttype.length;
		
		if(variantLength != undefined){
			for(i=0;i<variantLength;i++){
				thisVariantId = document.configForm.varianttype[i].id;
				if(thisVariantId == selectedTerm){
					thisNewOrReplace = document.configForm.varianttype[i].value;
					document.configForm.termNewOrReplace.value = thisNewOrReplace;
					break
				}
			}			
		}
		//this is incase there is only one hidden field for varianttype
		else{
			thisNewOrReplace = document.configForm.varianttype.value;
			document.configForm.termNewOrReplace.value = thisNewOrReplace;			
		}

		if(thisNewOrReplace == 1){
			// new activation;			
			hiddenNew.style.display = '';
			hiddenUpgrade.style.display = 'none';
			
			if($("hiddenWNP")) {
				hiddenWNP.style.display = '';
			}
			

			//ADDED SO WHEN YOU MAKE A TERM CHANGE FROM NEW ACCTIVATION TO UPGRADE AND YOU GO TO THE NEXT TAB WITHOUT SAVING IT WILL NOT TAKE OFF THE PLANS TAB
			document.getElementById("newOrReplaceFlag").value = 1
			
			//CALL AJAX TO GET CITIES
			var objProvince = document.getElementById("provinceId");
			provinceId = objProvince[objProvince.selectedIndex].value;
			cityId=0;
			if(document.getElementById("cityId")){
				var objCity = document.getElementById("cityId");
				cityId = objCity[objCity.selectedIndex].value;
			}
			if(provinceId != ''){
				var url = "ajax/ajax_getCitiesByProvinceId.taf?provid=" + provinceId + "&cityid=" + cityId + "&_UserReference=" + globalKeyRef 
				new Ajax.Request(url, {
				  onSuccess: function(response) {
					$("cityDiv").update(response.responseText)			
				  }
				});

				
				
			}
			
			//NEW ADDITION
			if(document.configForm.cityId.value == ''){
				document.configForm.cityId.style.background = missingValuesBColor
			}
		}
		else if(thisNewOrReplace == 2){
			// upgrade;
			hiddenUpgrade.style.display = '';
			hiddenNew.style.display = 'none';
			hiddenWNP.style.display = 'none';
			
	
			//ADDED SO WHEN YOU MAKE A TERM CHANGE FROM NEW ACCTIVATION TO UPGRADE AND YOU GO TO THE NEXT TAB WITHOUT SAVING IT WILL NOT TAKE OFF THE PLANS TAB			
			document.getElementById("newOrReplaceFlag").value = 2

			//NEW ADDITION - 4/10/07
			document.getElementById("wnpFlag").checked = false
			document.getElementById("WNPCheckedStatus").value = ''			
		}
		else{
			alert('????');
		}
	}
	else{
		//do clear
		document.configForm.termNewOrReplace.value = '';
		hiddenUpgrade.style.display = 'none';	
		hiddenNew.style.display = 'none';
		hiddenWNP.style.display = 'none';
		document.getElementById("termNewOrReplace_PH").value = ''
	}
	
	
	
	//////////////////// UPGRADE ELIGIBILITY START ///////////////////////////
	if(thisNewOrReplace == 2){
		document.configForm.replacementFlag.value = eval('document.getElementById("replacementFlag_'+thisVariantId+'").value');
	}
	else{
		document.configForm.replacementFlag.value = "";
	}
	
	if(document.configForm.termNewOrReplace.value == 2 && document.configForm.replacementFlag.value == 0 && document.configForm.companyUpgradeEligibiltyFlag.value == 1){
		document.getElementById("eligibilityDiv").style.display = "";
		document.getElementById("eligibilityDiv").style.display = "inline";
		document.getElementById("eligibilityDiv").innerHTML = document.getElementById("verifyEle").innerHTML;
		document.configForm.eligibilityPass.value = 0;
	}
	else{
		document.getElementById("eligibilityDiv").innerHTML = "";
		document.configForm.eligibilityPass.value = 1;	
	}
	//////////////////// UPGRADE ELIGIBILITY END ///////////////////////////
	
	
}

//////////////////// UPGRADE ELIGIBILITY START ///////////////////////////
//STAND ALONE INE HOME PAGE
function checkEligibilitySA(key){
	var obj = document.getElementById("existingNumber");

	if(obj.value == ''){
		alert('Please enter an existing cell number!')	
		obj.focus();
		return
	}
	var url = "ajax/ajax_checkEligibility.taf?existingNumber=" + obj.value + "&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    		tmpString = response.responseText.split('_');
			document.getElementById("eligibilityDivSA").style.visibility = "hidden";		
			if(tmpString[0] == 1){
				document.getElementById("eligibilityDivSA").style.visibility = "visible";
			}
			else if(tmpString[0] == 2){
				alert('The number specified is not eligible for re-contract today. \rThis number is eligible on '+tmpString[1]+'.')
			}
			else{
				alert('We do not have records of this number in our system at this time. \rPlease contact TELUS to confirm if this number is eligible for re-contact.')
			}
	  }
	});



}

function checkEligibility(obj, key, bpid){
	
	var findField = $(document.body).select(".existingNumber").toArray()
	
	var obj = findField[0]

	
	if(obj.value == ''){
		alert('Please enter an existing cell number!')	
		obj.focus();
		return
	}

	var url = "ajax/ajax_checkEligibility.taf?existingNumber=" + obj.value + "&_UserReference=" + globalKeyRef  + "&bpid=" + bpid
	new Ajax.Request(url, {
	  onSuccess: function(response) {		
			tmpString = response.responseText.split('_');

			if(tmpString[0] == 1){
				document.getElementById("eligibilityDiv").innerHTML = document.getElementById("verifiedEle").innerHTML;
				document.configForm.eligibilityPass.value = 1;
				document.configForm.eligibilityExistingNumber.value = obj.value;
			}
			else if(tmpString[0] == 2){
				alert('The number specified is not eligible for re-contract today. \rThis number is eligible on '+tmpString[1]+'.')
				document.configForm.eligibilityPass.value = 0;
			}
			else if(tmpString[0] == 3){
				//THIS WAS COMMENTENTED OUT AS PER CHRIS'S  REQUEST AND THE BELOW IS USED
			
				alert('We do not have records of this number in our system at this time. \rIn case there is an upgrade issue our sales department will contact you.')
				document.getElementById("eligibilityDiv").innerHTML = '';
				document.configForm.eligibilityPass.value = 1;
				document.configForm.eligibilityExistingNumber.value = obj.value;						
			}
			else{
				alert('We do not have records of this number in our system at this time. \rIn case there is an upgrade issue our sales department will contact you.')
				document.getElementById("eligibilityDiv").innerHTML = '';
				document.configForm.eligibilityPass.value = 1;
				document.configForm.eligibilityExistingNumber.value = obj.value;		
			}

		

	  }
	});
}

//When they type in the existing number
function checkChangedEligibility(obj){
	if(document.configForm.termNewOrReplace.value == 2 && document.configForm.replacementFlag.value == 0 && document.configForm.companyUpgradeEligibiltyFlag.value == 1 && document.configForm.eligibilityExistingNumber.value != ""){
		if(document.configForm.eligibilityExistingNumber.value == obj.value){
			document.getElementById("eligibilityDiv").innerHTML = document.getElementById("verifiedEle").innerHTML;
			document.configForm.eligibilityPass.value = 1;
		}else{
			document.getElementById("eligibilityDiv").innerHTML = document.getElementById("verifyEle").innerHTML;
			document.configForm.eligibilityPass.value = "";
		}		
	}
}
//////////////////// UPGRADE ELIGIBILITY END ///////////////////////////

function ResetWPNFields(key){
	document.configForm.wnpAuth.checked = false;
	document.configForm.wnpBillingPrvdr.selectedIndex = 0;
	document.configForm.wnpProvince.selectedIndex = 0;
	document.configForm.wnpAuthFN.value = '';
	document.configForm.wnpAuthLN.value = '';
	document.configForm.wnpPhNumber.value = '';
	document.configForm.wnpAddress1.value = '';
	document.configForm.wnpAddress2.value = '';
	document.configForm.wnpCity.value = '';
	document.configForm.wnpPostalCode.value = '';
	document.configForm.wnpESN.value = '';
	document.configForm.wnpAccNumber.value = '';
	document.configForm.wnpPassword.value = '';
	SaveSelection(key);
}

function repopulateUserDD(key){
	var url = "ajax/ajax_getConfigPhoneUsers.taf?_UserReference=" + globalKeyRef
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("jumpToUser").update(response.responseText)

	  }
	});

}

function reCalcPhonePrice(key){
	var basketPhoneId = document.configForm.basketPhoneId.value

	var url = "ajax/ajax_getPhonePrice.taf?basketPhoneId=" + basketPhoneId + "&_UserReference=" + globalKeyRef
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("phonePrice").update(response.responseText)

	  }
	});

}

//This will be used to enable disable the warranty div
function getProductPriceForWarranty(key){
	var basketPhoneId 	= document.configForm.basketPhoneId.value
	var provinceId 		= document.configForm.provinceId.value
	var variantId 		= document.configForm.variantId.value
	var warrantyId 		= document.configForm.savedWarrantyId.value

	if(variantId != ''){
		var url = "ajax/ajax_getProductPriceForWarranty.taf?basketPhoneId=" + basketPhoneId + "&variantId=" + variantId + "&provinceId=" + provinceId + "&warrantyId=" + warrantyId + "&_UserReference=" + globalKeyRef
		new Ajax.Request(url, {
		  onSuccess: function(response) {
			$("phoneConfig").update(response.responseText)
				if(response.responseText() != ''){
					document.getElementById("warrantyTR").style.display = '';
					document.getElementById("warrantyDiv").innerHTML = oAjaxPhonePrice.Response()
				} else {
					document.getElementById("warrantyDiv").innerHTML = ''
					document.getElementById("warrantyTR").style.display = 'none';			
				}
			
			
	
		  }
		});


	
	}else{
		document.getElementById("warrantyDiv").innerHTML = ''
		document.getElementById("warrantyTR").style.display = 'none';
	}
}




function RemoveSelection(key){
		var bpid = document.configForm.bpid.value;
		var pos = document.configForm.thisPosition.value;
		var listLen = document.configForm.listLength.value;
		var nextBpid = document.configForm.nextBPID.value;
		var lastBpid = document.configForm.lastBPID.value;
		var currentPid = document.configForm.currentPid.value;
		var currentPType = document.configForm.currentPType.value;	
		 ajaxTrace(arguments.callee.name)	
		var oAjaxKillPhone = new myAjax();
		oAjaxKillPhone.Send("ajax/ajax_removePhone.taf?pos=" + pos + "&bpid=" + bpid + "&bid=" + globalActiveBasketId + "&_UserReference=" + globalKeyRef);
		_configPhones_Is_FormUpdated = true;
		configPhonesFormNoChange();
		
		if(nextBpid > 0 && nextBpid != ''){
			// go to next record
			configPhones(currentPid,globalActiveBasketId,nextBpid,currentPType,key)
			
		}
		else if(((nextBpid == 0) || (nextBpid == '')) && ((lastBpid > 0) && (lastBpid != ''))){
			// drop back one record
			configPhones(currentPid,globalActiveBasketId,lastBpid,currentPType,key)
		}
		else{
			// close layer
			configPhonesCloseDiv();
			
		}
}

//REMOVE SPECIFIC USER FROM LIST NEW ADDITION APRIL 12th 07
function removePhoneUser(bpid,currRow,key){

	var totalUserlist 	= eval('document.basketForm.totalPhoneUsers'+currRow+'.value')
	var phoneId			= eval('document.basketForm.phoneId'+currRow+'.value')

	var url = "ajax/ajax_removePhone.taf?bpid=" + bpid + "&bid=" + globalActiveBasketId + "&currRow=" + currRow +"&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	_configPhones_Is_FormUpdated = true;
		configPhonesFormNoChange();

		//New we need this to refresh the page so in case there is an incomplete user and the rest are complete then when remove it will enable the continue button
		window.location = globalFilePath2 + "?_function=shoppingCart&" + globalKey;

	  }
	});
	
}


//GET ALL THE USERS PER PHONE NEW ADDITION APRIL 12th 07
function getPhoneUsers(currRow,phoneId,key,fromRemove){
	if(eval('document.getElementById("menuImg'+currRow+'").src.indexOf("plus") != -1') || fromRemove == 1){
		var url = "ajax/ajax_basketPhoneUsers.taf?phoneId=" + phoneId + "&currRow="+ currRow +"&_UserReference=" + globalKeyRef
		new Ajax.Request(url, {
		  onSuccess: function(response) {
			$('phoneUserDiv'+currRow).update(response.responseText)
			var theSrc = $('menuImg'+currRow).src.replace("plus","minus")
			$('menuImg'+currRow).src = theSrc
			$('phoneUserTr'+currRow).style.display = ""
			
	
		  }
		})
		

	}
	else{
		var theSrc = eval('document.getElementById("menuImg'+currRow+'").src.replace("minus","plus")')
		
		eval('document.getElementById("menuImg'+currRow+'").src = theSrc')
		eval('document.getElementById("phoneUserTr'+currRow+'").style.display = "none"')
	}
}

function getPlanInfo(obj){
	var planId = obj[obj.selectedIndex].value;
	if(planId ==''){
		document.getElementById("planDetailsDiv").innerHTML = '';
	}
	else{
		var bpid = document.configForm.bpid.value;
		eval('var planMSF = document.configForm.tmpPlanMSF_'+planId+'.value')
		var url = "ajax/ajax_getPlanDetails.taf?planId=" + planId  + "&bpid=" + bpid + "&planMSF="+ planMSF +"&_UserReference=" + globalKeyRef
		new Ajax.Request(
		  url,
		  {
			 method: 'post',
			 onComplete: function(response) {
				$("planDetailsDiv").update(response.responseText)
		
			  }
		  });
	}
}

var hardwareACT 	= "BasketImages/Tabs/ACT/hardware.gif";
var hardwareREG 	= "BasketImages/Tabs/REG/hardware.gif";
var hardwareREGIN 	= "BasketImages/Tabs/REG/hardwareIncomplete.gif";

var planACT 		= "BasketImages/Tabs/ACT/plan.gif";
var planREG 		= "BasketImages/Tabs/REG/plan.gif";
var planREGIN 		= "BasketImages/Tabs/REG/planIncomplete.gif";

var featureACT 		= "BasketImages/Tabs/ACT/feature.gif";
var featureREG 		= "BasketImages/Tabs/REG/feature.gif";
var featureREGIN 	= "BasketImages/Tabs/REG/featureIncomplete.gif";

var accessoryACT 	= "BasketImages/Tabs/ACT/accessory.gif";
var accessoryREG 	= "BasketImages/Tabs/REG/accessory.gif";

var wnpACT 			= "BasketImages/Tabs/ACT/wnp.gif";
var wnpREG 			= "BasketImages/Tabs/REG/wnp.gif";
var wnpREGIN 		= "BasketImages/Tabs/REG/wnpIncomplete.gif";

var currentTab = 'hardware';
//var currentTab = 't1';


// OLD
function toggleTabs(tabClicked){
	var UserStatus = document.configForm.hUserStatus.value;
	var PlanStatus = document.configForm.hPlanStatus.value;
	var FeatureStatus = document.configForm.hFeatureStatus.value;
	var WNPStatus = document.configForm.hWNPStatus.value;
	
	// FLIP ACTIVE TAB
	if(tabClicked == 'hardware'){
		hardwareImageId.src = hardwareACT;
	}
	if(tabClicked == 'plan'){
		planImageId.src = planACT;
	}
	if(tabClicked == 'feature'){
		featureImageId.src = featureACT;
	}
	if(tabClicked == 'accessory'){
		accessoryImageId.src = accessoryACT;
	}
	if(tabClicked == 'wnp'){
		wnpImageId.src = wnpACT;
	}
	
	// SWITCH TO NOT ACTIVE
	var inactive = '';
	if(currentTab == 'hardware' && tabClicked != 'hardware'){
		if(UserStatus != 1) inactive = 'IN';
		hardwareImageId.src = eval('hardwareREG' + inactive);
	}
	if(currentTab == 'plan' && tabClicked != 'plan'){
		if(PlanStatus != 1) inactive = 'IN';
		planImageId.src = eval('planREG' + inactive);
	}
	if(currentTab == 'feature' && tabClicked != 'feature'){
		if(FeatureStatus != 1) inactive = 'IN';
		featureImageId.src = eval('featureREG' + inactive);
	}
	if(currentTab == 'accessory' && tabClicked != 'accessory'){
		accessoryImageId.src = accessoryREG;
	}
	if(currentTab == 'wnp' && tabClicked != 'wnp'){
		if(WNPStatus != 1) inactive = 'IN';
		wnpImageId.src = eval('wnpREG' + inactive);
	}	
	
	currentTab = tabClicked;
}
 
 function configPhonesFormChanged(){
	 _configPhones_Is_FormChanged = true;
 }
  function configPhonesFormNoChange(){
	 _configPhones_Is_FormChanged = false;
 }
 function configPhones_IsFormChanged(){
	 return _configPhones_Is_FormChanged;
 }
 

//ON KEYUP ENTERS ONLY THE NUMERIC CHARACTERS - NEW ADDITION
function IsNumeric(obj){
	var strString = obj.value
	var strValidChars = "0123456789";
	var strChar;
	var outputString = ''
	
	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length; i++){
		strChar = strString.charAt(i);

		if (strValidChars.indexOf(strChar) != -1){
			outputString += strValidChars.indexOf(strChar)
		}
	}
	obj.value = outputString
}

//WNP TOOL TIP
function openPopUp(which){
	hideMe();

	if(which == 1){
		var lang = ''
	}
	else{
		var lang = 'fr_'
	}	
	eval("window.open('/customattachments/"+lang+"portYourNumber.html','transferInfo','fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,top=200,left=300,scrollbars=1,resizable=0,height=600,width=900,resizable=no')");	
}

function hideMe(){
	document.getElementById("toolTipBox").style.height = 0
	document.getElementById("toolTipBox").style.visibility = "hidden"
}

function toolTip(lang) {
	var toolTipText 	= '';
	var theObj			= '';

	if(lang == ''){
		var toolTipHeader 	= "Bring your number to Telus";
		var toolTipBody 	= "Enables clients to keep their local phone number from within the same\nmetropolitan area when transferring from one wireless service provider to another.";
		var toolTipClose 	= 'Close X';
	}
	else{
		var toolTipHeader 	= "Transf\351rant votre num\351ro chez Telus";
		var toolTipBody 	= "Permet aux clients de conserver leur num\351ro de t\351l\351phone local au sein d'une\n m\352me r\351gion m\351tropolitaine lorsqu'ils passent d'un fournisseur de service sans fil \340 un autre.";
		var toolTipClose 	= 'Fin X';	
	}

	toolTipText += '<div style="border-collapse: collapse; border: 1px; border-color: #C0C0C0; border-style: solid; border-width: thin">'
	toolTipText += '<table border="0" width="500" cellspacing="0" cellpadding="5" style="background-color: #76d200">'
	toolTipText += '<tr>'
	toolTipText += '<td width="80%" style="font-family: Arial; font-size: 14px; background-color: #76d200"><font color="#FFFFFF"><b>'+toolTipHeader+'</b></font></td>'
	toolTipText += '<td width="20%" align="right" style="font-family: Verdana; font-size:10px; background-color: #76d200"><a href="javascript:top.hideMe()"><img src="images/close.gif" border="0"></a></td>'
	toolTipText += '</tr>'
	toolTipText += '</table>'
	toolTipText += '<table border="0" width="500" cellspacing="0" cellpadding="10" bgcolor="#FFFFFF">'
	toolTipText += '<tr>'
	toolTipText += '<td style="font-family: Verdana;font-size:12px;padding-bottom:7"><font color="#000000">'+toolTipBody+'<BR><BR></font></td>'
	toolTipText += '</tr>'
	toolTipText += '</table>'
	toolTipText += '</div>'

	document.getElementById('toolTipBox').style.top  =  200
	document.getElementById('toolTipBox').style.left =  100
	
	toolTipBox.innerHTML = toolTipText
	toolTipBox.style.visibility = 'visible'	
}


function recheckStatus(bpid,key,method){
	var url = "ajax/ajax_getCurrentBPIDStatus.taf?bpid=" + bpid + "&_UserReference=" + globalKeyRef 

	new Ajax.Request(url, {
	  asynchronous: false,
	  onSuccess: function(response) {
		$("hiddenStatus").update(response.responseText)
	  }
	});
	
}


function resetStatusValues(){
	//RESET VALUES IN shoppingCart.taf
	document.getElementById("provinceId_PH").value 			= ''
	document.getElementById("termNewOrReplace_PH").value 	= ''
	document.getElementById("WNPCheckedStatus_PH").value 	= ''
	document.getElementById("hUserStatus_PH").value 		= ''
	document.getElementById("hPlanStatus_PH").value 		= ''
	document.getElementById("hFeatureStatus_PH").value 		= ''
	document.getElementById("hWNPStatus_PH").value 			= ''
	document.getElementById("hReqFeatureStatus_PH").value 	= ''	
	document.getElementById("guidedSetUp").value 			= ''
}



// OLD 
function configPhones(pid,basid,bpid,ptype,key,sPlanFlag){
	//TABLETS
		allowPlanSelection = document.getElementById("productAllowPlanSelection_"+pid).value;
		productHasPlan = document.getElementById("productHasPlan_"+pid).value
		document.getElementById("productAllowPlanSelection").value = allowPlanSelection;
		selectPlanFlag = sPlanFlag;
		
		if(productHasPlan == 0){
			selectPlanFlag = 0;
			allowPlanSelection = 1;
		}
	//TABLETS END
	
	//RESET VALUES IN shoppingCart.taf
	resetStatusValues();
	
	if(bpid == 0){
		configPhonesProceed(pid,basid,bpid,ptype,globalKeyRef,sPlanFlag);
	}else{
		if(configPhones_IsFormChanged()){
			var strJSYes = "SaveSelection('" + globalKeyRef  + "')";
			var strJSNo = "configPhonesFormNoChange();configPhonesProceed(" + pid + "," + basid + "," + bpid + ",'" + ptype + "','" + globalKeyRef  + "," + sPlanFlag+"')";
			alertConfigPhoneSaveSelection(strJSYes,strJSNo);
		}else{
			configPhonesProceed(pid,basid,bpid,ptype,key,sPlanFlag);
		}
	}

}

function configPhonesProceed(pid,basid,bpid,ptype,key){
	//RESET VALUES IN shoppingCart.taf
	resetStatusValues()
	// ptype: 1= all; 2 = complete; 3 = incomplete
	//bpid - basket phone ID
	var url = "ajax/ajax_configphones.taf?method=hardwareOptions&ptype="+ ptype + "&basid=" + basid + "&pid=" + pid+ "&bpid=" + bpid+ "&_UserReference=" + globalKeyRef
	new Ajax.Request(url, {
	  onSuccess: function(response) {
			$("phoneConfig").update(response.responseText);
			window.setTimeout(function(){configPhonesProceed2(pid,basid,bpid,ptype,key);},300);
	  }
	});
}

function configPhonesProceed2(pid,basid,bpid,ptype,key) {
	var blockerDiv = document.getElementById("blockerDiv")
	var phoneConfig = document.getElementById("phoneConfig")
	var phoneConfigBkg = document.getElementById("phoneConfigBkg")
	if(bpid == 0 || document.getElementById("enableDiv") && document.getElementById("enableDiv").value == 1){
		setDivSize('blockerDiv');
		positionDiv('phoneConfigBkg');
		positionDiv('phoneConfig');	


		blockerDiv.style.display = '';
		blockerDiv.style.visibility = 'visible';
		phoneConfig.style.display = '';
		phoneConfig.style.visibility = 'visible';
		phoneConfigBkg.style.display = '';
		phoneConfigBkg.style.visibility = 'visible';
	}
	
	//JUST PASS THE FORM NAME - NEW ADDITION
	highlightMandatoryFields("configForm")	

	document.getElementById("hUserStatus_PH").value 			= document.configForm.userComplete.value
	document.getElementById("provinceId_PH").value 		 		= document.configForm.provinceId.value
	
	if(document.configForm.variantId){
		document.getElementById("termNewOrReplace_PH").value 	= document.configForm.termNewOrReplace.value
		/*
		//Warranty drop down
			getProductPriceForWarranty(key)
		*/
	}
	
	document.getElementById("hPlanStatus_PH").value 			= document.configForm.planComplete.value
	document.getElementById("hFeatureStatus_PH").value 			= document.configForm.featuresComplete.value
	document.getElementById("hWNPStatus_PH").value 				= document.configForm.wnpComplete.value
	document.getElementById("WNPCheckedStatus_PH").value 		= document.configForm.WNPCheckedStatus.value
	document.getElementById("hReqFeatureStatus_PH").value 		= document.configForm.ReqFeatureStatus.value
	if((document.getElementById("provinceId_PH").value == '' && selectPlanFlag == 1) || (document.getElementById("provinceId_PH").value == '' && allowPlanSelection == 0) || (document.getElementById("provinceId_PH").value == '' && selectPlanFlag == -1)){
		//This is in the shoppingCart.taf and sets the default language
		
		var lang = document.getElementById("lang").value
	
		//DEFAULT SUBMIT IMAGE
		document.getElementById("saveConfigImg").value="Save and Continue";
		document.getElementById("guidedSetUp").value 			= 1
		document.getElementById("plan").style.display 			= 'none'
		document.getElementById("feature").style.display 		= 'none'
		document.getElementById("accessory").style.display 		= 'none'
		document.getElementById("wnp").style.display 			= 'none'
	}
	else{
		generateTabDisplay('hardwareOptionsOnly')
	}
	
	switchTab("hardware");
	//Sliding or not completion image in cart - 1: basket link, 2: tabs, 3: save and continue 
	checkCompletionStatus(1)

	//ONT GOV
	if(document.configForm.defaultProvinceId.value != '' && document.configForm.provinceId.value == '')
	{
		for(i=0;i<document.configForm.provinceId.length;i++)
		{
			if(document.configForm.provinceId.options[i].value == document.configForm.defaultProvinceId.value)
			{
				document.configForm.provinceId.selectedIndex = i;
				getTerms(document.configForm.provinceId,document.configForm.tmpPhoneId.value,key)
				break;
			}
		}
	}
}


function SaveSelection(key){
    //tablets module
	var allowPlanSelection=0;	
	if(document.getElementById('productAllowPlanSelection')!=null){
		allowPlanSelection = document.getElementById("productAllowPlanSelection").value;
	}			
	
	if(document.configForm.saveMethod.value == 'hardwareOptionsOnly' && allowPlanSelection==1){	
		if(document.getElementById('selectPlanCheck').checked){
				selectPlanFlag = 1
			}else
			{
				selectPlanFlag = 0
			}
	}
	
	if(allowPlanSelection == 0){
		selectPlanFlag = 3;
	}
	
	if(productHasPlan==0){
		selectPlanFlag = 0;
	}
	
	SetSelectPlanFlag(document.configForm.bpid.value)	
	//tablets module
	
	//ADDED SO WHEN YOU MAKE A TERM CHANGE FROM NEW ACTIVATION TO UPGRADE AND YOU GO TO THE NEXT TAB WITHOUT SAVING IT WILL NOT TAKE OFF THE PLANS TAB
	
	if(document.configForm.saveMethod.value == 'hardwareOptionsOnly'){
		if(document.configForm.termNewOrReplace.value != ''){
			document.getElementById("termNewOrReplace_PH").value = document.configForm.termNewOrReplace.value
		}
		else{
			document.getElementById("termNewOrReplace_PH").value = document.getElementById("newOrReplaceFlag").value
		}
		
		////////////////// ELIGIBILITY CHECK START //////////////////////////
		if(document.configForm.companyUpgradeEligibiltyFlag.value == 1 && document.configForm.termNewOrReplace.value == 2 && document.configForm.replacementFlag.value == 0 && document.configForm.eligibilityPass.value == 0){
			alert('Please click on the "Verify upgrade eligibility" link beside the existing phone number field!')
			return
		}
		////////////////// ELIGIBILITY CHECK END ////////////////////////////
	}

	//STOP GUIDED SET IN CASE IT IS MISSING TERM
	var stopProcess = 0
	if(document.configForm.saveMethod.value == 'hardwareOptionsOnly'){
		if(document.configForm.variantId){
			if(document.configForm.variantId.value == ''){
				var stopProcess = 1
			}
		}
		else{
			var stopProcess = 1
		}
	}
	//TABLETS -  if Select Plan Checkbox is unchecked then don't stop the process

	if(productHasPlan==0){
		selectProductFlag=0
		var stopProcess=0;		
	}
	
	if(selectPlanFlag!=0){
		SetTabsForTablets(document.configForm.bpid.value,document.configForm.saveMethod.value,key);
	}
	//TABLETS

	if(stopProcess == 1){ 
		alertProvinceTermRequired()

		//JUST PASS THE FORM NAME - NEW ADDITION
		highlightMandatoryFields("configForm")
		return
	}

	var method = document.configForm.saveMethod.value;
	
	//Email validation
	if(method == 'hardwareOptionsOnly' && document.configForm.employeeEmail.value != ''){
		var emailCheck = checkmail(document.configForm.employeeEmail);
		if(emailCheck == false){
			alert("Please enter a valid email address")
			return
		}
	}

	if(stopProcess==0){
		document.getElementById("guidedSetUp").value =  1
	}
	
	//This will update the hidden field
	
	if(method == 'hardwareOptionsOnly'){

		if(document.getElementById("termNewOrReplace_PH").value == 1 || document.getElementById("termNewOrReplace").value == 1){
			if(document.configForm.wnpFlag.checked){
				document.getElementById("WNPCheckedStatus_PH").value = 1
			}
			else{
				document.getElementById("WNPCheckedStatus_PH").value = 0
			}
		}
	}

	var ptid = document.getElementById("ptid").value;
	var url = 'ajax/ajax_updateBasket.taf?method=' + method + '&_UserReference=' + globalKeyRef + '&selectPlanFlag=' + selectPlanFlag + '&ptid=' + ptid //selectPlanFlag added for Tablets
	new Ajax.Request(url,{         
		 method: 'post',
		 parameters: Form.serialize($('configForm')),
         onComplete: 
			function(response) {	
				
				//JUST PASS THE FORM NAME - NEW ADDITION

				highlightMandatoryFields("configForm");
				if(true){
					
					_configPhones_Is_FormUpdated = true;
					configPhonesFormNoChange();

					//HARDWARE OPTIONS
						
					if(method == 'hardwareOptionsOnly' &&  document.configForm.tmpUserNumber.value > 1){
						
						var newName = document.configForm.employeeName.value;
						if(newName != ''){
							var nameDiv = document.getElementById('phoneUserName');
							nameDiv.innerHTML = newName;
						}
		
						// repopulate the user dropdown box
						repopulateUserDD(key);
					}
					
					//fix JM Aug 2010
					
					if(method == 'hardwareOptionsOnly'){
						// recalculate product price
						reCalcPhonePrice(key);
					}
					myMsgBoxSaved();
				}

				//GUIDED OR NOT SET UP
				var bpid 	= document.configForm.bpid.value;
				var key	= document.getElementById("key").value;
				var pid 	= document.configForm.currentPid.value;

				if(document.getElementById("guidedSetUp").value == 1) {
					if(document.getElementById("termNewOrReplace_PH").value == 1) {
						//Updated for TABLETS project
							if(method == 'hardwareOptionsOnly' && (allowPlanSelection==0 || selectPlanFlag==1) && productHasPlan!=0){
								phoneSetUp(pid,'plans',globalActiveBasketId,bpid,key)
							}
							if(method == 'hardwareOptionsOnly' && (allowPlanSelection==1 && selectPlanFlag!=1) || productHasPlan==0){
								SetTabsForTablets(bpid,method,key)
								phoneSetUp(pid,'accessory',globalActiveBasketId,bpid,key)
							}

						//END OF Updated for TABLETS project						
												
						if(method == 'plans'){
							phoneSetUp(pid,'features',globalActiveBasketId,bpid,key)
						}
						if(method == 'features'){
							phoneSetUp(pid,'accessory',globalActiveBasketId,bpid,key)
						}
						if(method == 'accessory' && document.getElementById("WNPCheckedStatus_PH").value == 1){
							phoneSetUp(pid,'wnp',globalActiveBasketId,bpid,key)
						}
						if(method == 'wnp'){
							phoneSetUp(pid,'wnp',globalActiveBasketId,bpid,key)
						}	
					}
					else{
						//TABLETS project 009
							if(method == 'hardwareOptionsOnly' && (allowPlanSelection==0 || selectPlanFlag==1)){
								phoneSetUp(pid,'plans',globalActiveBasketId,bpid,key)
							}
							
							if(method == 'hardwareOptionsOnly' && allowPlanSelection==1 && selectPlanFlag==0 || productHasPlan==0){
								document.getElementById("plan").style.display 		= 'none'
								document.getElementById("extra_plan").style.display 	= 'none'							
								document.getElementById("feature").style.display 		= 'none'
								document.getElementById("extra_feature").style.display 	= 'none'
								phoneSetUp(pid,'accessory',globalActiveBasketId,bpid,key)
							}
							
							if(method == 'hardwareOptionsOnly' && (allowPlanSelection==1 && selectPlanFlag==1)){
								document.getElementById("plan").style.display 		= ''
								document.getElementById("extra_plan").style.display 	= ''							
								document.getElementById("feature").style.display 		= ''
								document.getElementById("extra_feature").style.display 	= ''
								phoneSetUp(pid,'plans',globalActiveBasketId,bpid,key)							
							}

						//END OF TABLETS project part
						
						if(method == 'plans'){
							phoneSetUp(pid,'features',globalActiveBasketId,bpid,key)
						}
						if(method == 'features'){
							phoneSetUp(pid,'accessory',globalActiveBasketId,bpid,key)
						}
					}
				
				}
				else{
					generateTabDisplay(method)
				}
				
				//Sliding or not completion image in cart - 1: basket link, 2: tabs, 3: save and continue 
				window.setTimeout(function(){checkCompletionStatus(3)},1500)
			}
		})
		
}

function phoneSetUp(pid,method,basid,bpid,key,selectedFromTabs){

//This is for the sliding completion image in the cart
	if(typeof selectedFromTabs != "undefined"){
		fromTabs = 1
	}else{
		fromTabs = 0
	}

	
	
	if(configPhones_IsFormChanged()){
		var strJSYes = "SaveSelection('" + globalKeyRef  + "')";
		var strJSNo = "configPhonesFormNoChange();phoneSetUpProceed(" + pid + ",'" + method + "'," + basid + "," + bpid + ",'" + globalKeyRef  + "')";
		alertConfigPhoneSaveSelection(strJSYes,strJSNo);
	}else{
		phoneSetUpProceed(pid,method,basid,bpid,key);
	}
}


function phoneSetUpProceed(pid,method,basid,bpid,key){
	var url = "ajax/ajax_configphones.taf?method=" + method + "&basid=" + basid + "&pid=" + pid+ "&bpid=" + bpid+ "&_UserReference=" + globalKeyRef 
	new Ajax.Request(url, {
	  onSuccess: function(response) {
    	$("subPhoneConfig").update(response.responseText)
		//JUST PASS THE FORM NAME - NEW ADDITION
		highlightMandatoryFields("configForm");
		generateTabDisplay(method);

		if(fromTabs == 1){
			//Sliding or not completion image in cart - 1: basket link, 2: tabs, 3: save and continue 
			checkCompletionStatus(2)	
		}
	  }
	});
}

//NEW ADDITION
function highlightMandatoryFields(theForm){
	for(i=0;i<eval('document.'+theForm+'.length');i++){
		if (document[theForm].elements[i].type!='button'){
		if(eval('document.'+theForm+'.elements[i].id == "req" && document.'+theForm+'.elements[i].value == "" || document.'+theForm+'.elements[i].id == "provinceId" && document.'+theForm+'.elements[i].value == "" || document.'+theForm+'.elements[i].id == "reqCheckbox" && document.'+theForm+'.elements[i].checked == false')){
			eval('document.'+theForm+'.elements[i].style.background = "'+missingValuesBColor+'"')
		}
		else{
			eval('document.'+theForm+'.elements[i].style.background = "FFFFFF"')
		}
	}
		
	}
	
	if(document.getElementById("reqRule1") != null){
		if(document.getElementById("reqRule1").value == "" && document.getElementById("reqRule2").value == "" && document.getElementById("reqRule3").value == ""){
			document.getElementById("reqRule1").style.background = missingValuesBColor
		}
	}
}

function generateTabDisplay(tabClicked){
	//tablets module

	if(document.getElementById('productAllowPlanSelection')!=null){
		allowPlanSelection = document.getElementById("productAllowPlanSelection").value;
	}	

	if(selectPlanFlag==-1 && allowPlanSelection==1){
		selectPlanFlag = document.getElementById("selectPlanFlagValue").value;
	}
	
	if(allowPlanSelection==0){
		selectPlanFlag = 3;
	}

	if(productHasPlan==0){
		selectPlanFlag = 0;
		allowPlanSelection = 1;
	}
	//tablets module
	
	//GUIDED FOR THE SAVE AND CONTINUE OR SAVE SELECTIONS TEXT
	if(document.getElementById("saveSpanButton1")){
		if(document.getElementById("guidedSetUp").value == 1){
			if(document.configForm.saveMethod.value != 'accessory'){
				document.getElementById("saveSpanButton1").style.display = ''
			}
			else{
				if(document.getElementById("WNPCheckedStatus_PH").value == 1){
					document.getElementById("saveSpanButton1").style.display = ''
				}
				else{
					document.getElementById("saveSpanButton2").style.display = ''
				}
			}
		}
		//NOT GUIDED
		else{
			$("saveSpanButton2").show()
		}
	}

	var bpid 	= document.configForm.bpid.value;
	var key		= document.getElementById("key").value;
	var method	= document.configForm.saveMethod.value;
	

	//This is in the shoppingCart.taf and sets the default language
	var lang = document.getElementById("lang").value

	//DEFAULT SUBMIT IMAGE
	if(document.getElementById("guidedSetUp").value == 1){

		if(method == 'features' && document.configForm.noFeaturesAvailable.value == 1){
			document.getElementById("saveConfigImg").value = "Continue";
		}else{
			document.getElementById("saveConfigImg").value = "Save and Continue";	
		}

		if(tabClicked == 'accessory' && document.getElementById("termNewOrReplace_PH").value == 2){
			document.getElementById("saveConfigImg").value = "Save Selections";
		}
		
		if(tabClicked == 'accessory' && document.getElementById("WNPCheckedStatus_PH").value != 1){
			document.getElementById("saveConfigImg").value = "Save Selections";
		}
	}
	else{
		if(method == 'features' && document.configForm.noFeaturesAvailable.value == 1){
			document.getElementById("saveConfigImg").style.display = 'none';
		}else{
			document.getElementById("saveConfigImg").value = "Save Selections";
		}
	}

	if(tabClicked == 'accessory' && document.getElementById("WNPCheckedStatus_PH").value != 1){
		if($("backToCartDiv")) {
			document.getElementById("backToCartDiv").style.visibility = 'visible'
		}
	}
	
	
	recheckStatus(bpid,key,method)

	//NEW ADDITION - FUCTIONALITY FOR THE TABS
	var UserStatus 			= document.getElementById("hUserStatus_PH").value;
	var PlanStatus 			= document.getElementById("hPlanStatus_PH").value;
	var FeatureStatus 		= document.getElementById("hFeatureStatus_PH").value;
	var WNPStatus 			= document.getElementById("hWNPStatus_PH").value;
	var ReqFeatureStatus	= document.getElementById("hReqFeatureStatus_PH").value;
	var provinceId 			= document.getElementById("provinceId_PH").value
	var termNewOrReplace	= document.getElementById("termNewOrReplace_PH").value
	var WNPCheckedStatus 	= document.getElementById("WNPCheckedStatus_PH").value

	if(lang == ''){
		var langPath = ''
	}
	else{
		var langPath = 'fr_/'
	}



	//This controls if we show step 2 or not
	var allowPlanOnUpgrade = document.getElementById("allowPlanOnUpgrade").value

	//UPGRADE **************************************************************************
	if(termNewOrReplace == 2 && allowPlanOnUpgrade != 1){
		document.getElementById("plan").style.display 		= 'none'
		document.getElementById("extra_plan").style.display 	= 'none'

		//The following two lines will rename the steps
		document.getElementById("label_feature").innerHTML 	= 'STEP 2'
		document.getElementById("label_accessory").innerHTML 	= 'STEP 3'

		document.getElementById("wnp").style.display 		= 'none'	
		
		//TABLETS
		if(selectPlanFlag == 1){
			document.getElementById("feature").style.display 	= ''
		}
		//TABLETS
	
		document.getElementById("accessory").style.display 		= ''	

		//HARDWARE
		if(tabClicked == 'hardwareOptionsOnly'){
			switchTab("hardware")
			if(UserStatus == 1){
				 tabStatus("hardware",1)
			}
		else{
				tabStatus("hardware",0)
			}

			if(ReqFeatureStatus == 1){
				if(FeatureStatus == 1){
					tabStatus("feature",1)
				}
				else{
					tabStatus("feature",0)
				}
			}
			else{
				tabStatus("feature",1)
			}
			tabStatus("accessory",1)
		}


		//FEATURE
		if(tabClicked == 'features'){
			switchTab("feature")
			if(UserStatus == 1){
				 tabStatus("hardware",1)
			}
			else{
				 tabStatus("hardware",0)
			}
	
			if(ReqFeatureStatus == 1){
				if(FeatureStatus == 1){
					 tabStatus("feature",1)
				}
				else{
					 tabStatus("feature",0)
				}
			}
			else{
				 tabStatus("feature",1)
			}
			 tabStatus("accessory",1)
		}

		if(tabClicked == 'accessory'){
			switchTab("accessory")
			if(UserStatus == 1){
				tabStatus("hardware",1)
			}
			else{
				tabStatus("hardware",0)
			}

			if(ReqFeatureStatus == 1){
				if(FeatureStatus == 1){
					tabStatus("feature",1)
				}
				else{
					tabStatus("feature",0)
				}
			}
			else{
				tabStatus("feature",1)
			}
				tabStatus("accessory",1)
		}
		return
	}


	//NEW ACTIVATION **************************************************************************
	
	if(selectPlanFlag==1 || allowPlanSelection==0){
		document.getElementById("plan").style.display 		= '';
		document.getElementById("extra_plan").style.display = '';
		document.getElementById("feature").style.display 	= '';
	}
	
	document.getElementById("accessory").style.display 	= '';
	document.getElementById("wnp").style.display 		= '';
	if(tabClicked == 'hardwareOptionsOnly'){
		switchTab("hardware")
		if(UserStatus == 1){
			tabStatus("hardware",1)
		}
		else{
			tabStatus("hardware",0)
		}
		if(PlanStatus == 1){
			tabStatus("plan",1)
		}
		else{
			tabStatus("plan",0)
		}
		if(FeatureStatus == 1){
			tabStatus("feature",1)
		}
		else{
			tabStatus("feature",0)
		}
		tabStatus("accessory",1)
	
		if(termNewOrReplace == 1 && WNPCheckedStatus == 1){
			document.getElementById("wnp").style.display = ''
			if(WNPStatus == 1){
				tabStatus("wnp",1)
			}
			else{
				tabStatus("wnp",0)
			}
		}
		else{
			document.getElementById("wnp").style.display = 'none'
		}
		if(termNewOrReplace == 1){
			SetTabsForTablets(bpid,method,key)
		}
		return
	}

	//PLAN SELECTED
	if(tabClicked == 'plans'){
		switchTab("plan")
		//alert("plan status: "+PlanStatus)
		if(UserStatus == 1){
			tabStatus("hardware",1)
		}
		else{
			tabStatus("hardware",0)
		}
		if(PlanStatus == 1){
			tabStatus("plan",1)
		}
		else{
			tabStatus("plan",0)
		}
		if(FeatureStatus == 1){
			tabStatus("feature",1)
		}
		else{
			tabStatus("feature",0)
		}
		tabStatus("accessory",1)
		
		if(termNewOrReplace == 1 && WNPCheckedStatus == 1){
			document.getElementById("wnp").style.display = ''
			if(WNPStatus == 1){
				tabStatus("wnp",1)
			}
			else{
				tabStatus("wnp",0)
			}
		}
		else{
			document.getElementById("wnp").style.display = 'none'
		}
	}

	//FEATURE SELECTED
	if(tabClicked == 'features'){
		switchTab("feature")
		if(UserStatus == 1){
			tabStatus("hardware",1)
		}
		else{
			tabStatus("hardware",0)
		}
		if(PlanStatus == 1){
			tabStatus("plan",1)
		}
		else{
			tabStatus("plan",0)
		}
		if(FeatureStatus == 1){
			tabStatus("feature",1)
		}
		else{
			tabStatus("feature",0)
		}
		tabStatus("accessory",1)

		if(termNewOrReplace == 1 && WNPCheckedStatus == 1){
			document.getElementById("wnp").style.display = ''
			if(WNPStatus == 1){
				tabStatus("wnp",1)
			}
			else{
				tabStatus("wnp",0)
			}
		}
		else{
			document.getElementById("wnp").style.display = 'none'
		}
	}

	//ACCESSORY SELECTED
	if(tabClicked == 'accessory'){
		switchTab("accessory")
		if(UserStatus == 1){
			tabStatus("hardware",1)
		}
		else{
			tabStatus("hardware",0)
		}
		if(PlanStatus == 1){
			tabStatus("plan",1)
		}
		else{
			tabStatus("plan",0)
		}
		if(FeatureStatus == 1){
			tabStatus("feature",1)
		}
		else{
			tabStatus("feature",0)
		}		
		tabStatus("accessory",1)

		if(termNewOrReplace == 1 && WNPCheckedStatus == 1){
			tabStatus("accessory",1)
		
			document.getElementById("wnp").style.display = ''
			if(WNPStatus == 1){
				tabStatus("wnp",1)
			}
			else{
				tabStatus("wnp",0)
			}
		}
		else{
			document.getElementById("wnp").style.display = 'none'
		}
	}

	//WNP SELECTED
	if(tabClicked == 'wnp'){
		switchTab("wnp")
		if(UserStatus == 1){
			tabStatus("hardware",1)
		}
		else{
			tabStatus("hardware",0)
		}
		if(PlanStatus == 1){
			tabStatus("plan",1)
		}
		else{
			tabStatus("plan",0)
		}
		if(FeatureStatus == 1){
			tabStatus("feature",1)
		}
		else{
			tabStatus("feature",0)
		}
		tabStatus("accessory",1)

		if(WNPStatus == 1){
			tabStatus("wnp",1)
		}
		else{
			tabStatus("wnp",0)
		}		
	}
}

function tabStatus(tab,dir){
	//alert("tab status:" + tab + ", " +dir)
	if (dir==1){
		d.getElementById(tab+"_bg").style.backgroundImage="url(images/complete.gif)";
	}else{
		d.getElementById(tab+"_bg").style.backgroundImage="url(images/incomplete.gif)";
	}
}

//SUBMIT BUTTONS
function imageSwap(which){
	var tabClicked = document.configForm.saveMethod.value

	//This is in the shoppingCart.taf and sets the default language
	var lang = document.getElementById("lang").value

	//MOUSEOVER
	if(which == 1){
		if(document.getElementById("guidedSetUp").value == 1){
			document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveContinueMO.gif"')

			if(tabClicked == 'accessory' && document.getElementById("termNewOrReplace_PH").value == 2){
				document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveSelectionsMO.gif"')
			}
			
			if(tabClicked == 'accessory' && document.getElementById("WNPCheckedStatus_PH").value != 1){
				document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveSelectionsMO.gif"')
			}
		}
		else{
			document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveSelectionsMO.gif"')
		}
	}
	//MOUSEOUT
	else{
		if(document.getElementById("guidedSetUp").value == 1){
			document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveContinue.gif"')

			if(tabClicked == 'accessory' && document.getElementById("termNewOrReplace_PH").value == 2){
				document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveSelections.gif"')
			}
			
			if(tabClicked == 'accessory' && document.getElementById("WNPCheckedStatus_PH").value != 1){
				document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveSelections.gif"')
			}
		}
		else{
			document.getElementById("saveConfigImg").src = eval('"BasketImages/'+lang+'saveSelections.gif"')
		}		
	}
}

//****************** BUNDLES IN THE BASKET FOR ACCESSORIES **************************************
totalSelected = 0

function bundleAndAccSelection(obj){
	var totalAccRows = document.getElementById("totalAccRows").value

	for(x=1;x<=totalAccRows;x++){
		if(obj.value == eval('document.getElementById("accessoryList'+x+'").value')){
			if(obj.checked){
				eval('document.getElementById("accessoryList'+x+'").checked=false')
				eval('document.getElementById("accessoryList'+x+'").disabled=true')
			}else{
				eval('document.getElementById("accessoryList'+x+'").disabled=false')
			}
			break
		}
	}

	if(obj.checked){
		totalSelected++
	}else{
		totalSelected--
	}

	if(document.getElementById("maxItems").value == totalSelected){
		for(i=1;i<=document.getElementById("totalBundleRows").value;i++){
			if(eval('document.getElementById("bundleOpt'+i+'").checked == false')){
				eval('document.getElementById("bundleOpt'+i+'").disabled = true')
			}
		}
	}else{
		for(i=1;i<=document.getElementById("totalBundleRows").value;i++){
			if(eval('document.getElementById("bundleOpt'+i+'").disabled == true')){
				eval('document.getElementById("bundleOpt'+i+'").disabled = false')
			}
		}
	}
}




//Email Validation
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
	var returnval=emailfilter.test(e.value)
	if (returnval==false){
		e.select()
	}
	return returnval;
}

//Sliding or not completion image in cart - 1: basket link, 2: tabs, 3: save and continue
function checkCompletionStatus(which){
	var UserStatus 			= document.getElementById("hUserStatus_PH").value;
	var PlanStatus 			= document.getElementById("hPlanStatus_PH").value;
	var FeatureStatus 		= document.getElementById("hFeatureStatus_PH").value;
	var WNPStatus 			= document.getElementById("hWNPStatus_PH").value;
	var ReqFeatureStatus	= document.getElementById("hReqFeatureStatus_PH").value;
		
		
	//TABLETS
	if(selectPlanFlag != 1 && selectPlanFlag!=3){
		PlanStatus = 1;
		FeatureStatus = 1;
		WNPStatus = 1;
	}
	//TABLETS

	var isComplete			= parseFloat(UserStatus) + parseFloat(PlanStatus) + parseFloat(FeatureStatus) + parseFloat(WNPStatus);
	
	
		
	var tmpStatusDiv = document.getElementById("productStatusDiv");

	if(isComplete == 4){
		if(tmpStatusDiv.style.visibility == "visible"){
			cartCompletionImage(1);
			return;
		}
		
		tmpStatusDiv.style.visibility = "visible";
		if(document.getElementById("guidedSetUp").value == 1){
			cartCompletionImage(1);
		}else{
			if(which == 3){
				cartCompletionImage(2);
			}else{
				cartCompletionImage(1);
			}
		}
	}else{
		tmpStatusDiv.style.visibility = "hidden";	
	}

}

function cartCompletionImage(which){
	var tmpStatusDiv = document.getElementById("productStatusDiv");

	if(which == 1){
		tmpStatusDiv.innerHTML = "<img style='cursor:hand' onClick='configPhonesCloseDiv(key)' src='images/allStepsCompleted_Static.gif' border='0'>";
		$("productStatusDiv").show()
	}else{
		tmpStatusDiv.innerHTML = "<img style='cursor:hand' onClick='configPhonesCloseDiv(key)' src='images/allStepsCompleted_Sliding.gif' border='0'>"
	}
}

function ajaxTrace(fName) {
	alert("Ajax Trace: " + fName)
}

function hideLoading() {
		
}


function checkBD() {
	orderForm.dateOfBirth.value=""
	var y = $('bYear').value
	var m = $('bMonth').value
	var d = $('bDay').value
	if(y==''||m==''||d=='') {
		return
	}
	var valid = Date.parse(y+"/"+m+"/"+d)+""
	if(valid=='null') {
		alert("Invalid Date")
		return;
	}
	orderForm.dateOfBirth.value=m+"/"+d+"/"+y

}


//TABLETS MODULE BLOCK

function HidePlansAndFeatures(){
	document.getElementById("plan").style.display 			= 'none'
	document.getElementById("extra_plan").style.display 		= 'none'
	document.getElementById("feature").style.display 		= 'none'
	document.getElementById("extra_feature").style.display 	= 'none'
	document.getElementById("accessory").style.display 		= ''			
	document.getElementById("label_accessory").innerHTML 		= 'STEP 2'		
	document.getElementById("label_wnp").innerHTML 			= 'STEP 3'				
}

function ShowPlansAndFeatures(){
	document.getElementById("plan").style.display 			= ''
	document.getElementById("extra_plan").style.display 		= ''
	document.getElementById("feature").style.display 		= ''
	document.getElementById("extra_feature").style.display 	= ''
	document.getElementById("accessory").style.display 		= ''			
	document.getElementById("label_accessory").innerHTML 		= 'STEP 4'		
	document.getElementById("label_wnp").innerHTML 			= 'STEP 5'		
}

function selectPlanClick(){
	if(document.getElementById('selectPlanCheck').checked){
		selectPlanFlag = 1
	}else{
		selectPlanFlag = 0
	}
}

function planSelectedDisplay(hideShow){
	if(hideShow==0){
		$$('.planSelected').each(function(element){
			element.setStyle({ display: 'none' });
		});
	}else{
		$$('.planSelected').each(function(element){
			element.setStyle({ display: '' });
		});		
	}
}

function SetTabsForTablets(bpid,method,key)
{	
	if(document.getElementById('productAllowPlanSelection')!=null){
		allowPlanSelection = document.getElementById("productAllowPlanSelection").value;
	}
	
	if(allowPlanSelection==1){
		planSelectedDisplay(selectPlanFlag);
		if(selectPlanFlag==0){
			HidePlansAndFeatures();
		}else{
			
			recheckStatus(bpid,method,key)
			/*
			if(method=="hardwareOptions" || method=="hardwareOptionsOnly"){
				document.getElementById("hPlanStatus_PH").value 			= document.configForm.planComplete.value
				document.getElementById("hFeatureStatus_PH").value 			= document.configForm.featuresComplete.value
				document.getElementById("hWNPStatus_PH").value 				= document.configForm.wnpComplete.value
				document.getElementById("WNPCheckedStatus_PH").value 		= document.configForm.WNPCheckedStatus.value
				document.getElementById("hReqFeatureStatus_PH").value 		= document.configForm.ReqFeatureStatus.value			
			}
			*/
				
			var UserStatus 			= document.getElementById("hUserStatus_PH").value;
			var PlanStatus 			= document.getElementById("hPlanStatus_PH").value;
			var FeatureStatus 		= document.getElementById("hFeatureStatus_PH").value;
			var ReqFeatureStatus	= document.getElementById("hReqFeatureStatus_PH").value;
			
			if(document.getElementById("hPlanStatus_PH").value == 1){
				 tabStatus("plan",1)
			}
			else{
				tabStatus("plan",0)
			}			

			if(UserStatus == 1){
				 tabStatus("hardware",1)
			}
			else{
				tabStatus("hardware",0)
			}

			if(ReqFeatureStatus == 1){
				if(FeatureStatus == 1){
					tabStatus("feature",1)
				}
				else{
					tabStatus("feature",0)
				}
			}
			else{
				tabStatus("feature",1)
			}
			tabStatus("accessory",1)		
			ShowPlansAndFeatures();
		}
	}	
}

function GetSelectPlanFlag(bid,bpid){
	var now = "&now=" + new Date();
	var url = "ajax/ajax_basket.taf?getPlanFlag=1&bid=" + bid + "&bpid=" + bpid + now;

	new Ajax.Request(url, {
	  onSuccess: function(response) {
		window.setTimeout(function(){selectPlanFlag = response.responseText},300);
	  }
	});	
}

function SetSelectPlanFlag(bpid){
	var url = "ajax/ajax_basket.taf?setPlanFlag=1&bpid=" + bpid+"&selectPlanFlag=" + selectPlanFlag;
	new Ajax.Request(url, {
	  onSuccess: function(response) {
		window.setTimeout(function(){response.responseText},300);
	  }
	});		
}
//TABLETS END
