var newScWalletAccountBalance = null;
var browser = "";
var browserVersion = "";
var paymod ="purchaseWithCC";
jQuery.each(jQuery.browser, function(i, val) {
	if(i != "version" && val == true) {
		browser = i;
	}
	if(i == "version") {
		browserVersion = val;
	}
});
var purchaseEntire = 'purchase';
var gender = '';
if(disabledButton==null && enabledButton==null) {
	var disabledButton=null;
	var enabledButton=null;
}

function getURLParamByName(name, url) {
	
	if(url == null) 
		url = window.location.href;
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	if(url != null)
		var results = regex.exec( url );
	else
		var results = regex.exec( url );
	if( results == null )
		return null;
	else
		return results[1];
}

function triggerClick(id) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	
	if(document.getElementById(id) != null) {
		if(isIE)
			document.getElementById(id).click();
		else
			$('#'+id).click();
	}
}
function toggleButtonOnOff(disableId, enableId, counter,eadmLink) {
	if(($('#downloadIams')!=null && $('#downloadIams').length>0) || ($('#priusV')!=null 
			&& $('#priusV').length>0)){
		if(document.getElementById(disableId) != null && disableId == "buyNowLink"){
			$('#buyNowLink').hide();
			$('#disabledLink').show();
		}
		if(document.getElementById(disableId) != null && disableId == "buyNowLinkUp"){
			$('#buyNowLinkUp').hide();
			$('#disabledLinkUp').show();
		}
	}else{
		if($('#buyNowLinkUp')!=null && $('#disabledLinkUp')!=null){
			$('#buyNowLinkUp').hide();
			$('#disabledLinkUp').show();
		}
		if($('#buyNowLinkDown')!=null && $('#disabledLinkDown')!=null){
			$('#buyNowLinkDown').hide();
			$('#disabledLinkDown').show();
		}
		if(document.getElementById(disableId) != null && document.getElementById(enableId) != null) {
			disabledButton = disableId;
			enabledButton = enableId;
			var associateCounter = $('#associatedProd_id').val();
			if(associateCounter != 0 || associateCounter > 0)
				{
				for(var i=1;i<=associateCounter;i++)
				{
        	       var checkedImg = $('#checkedImg'+i).val();
        	        $('#associtedObject'+i).attr("src",checkedImg);
					$('#assoProdNotOwned'+i).hide();
					$('#assoProdOwned'+i).show();
				 }
				}
			document.getElementById(disableId).style.display='none';
			document.getElementById(enableId).style.display='block';	
		    if(counter >= 0) {
				var enableImg="MainClothImg"+counter;
				var disableImg="MainClothCheckedImg"+counter;
				if(document.getElementById(enableImg)!=null && document.getElementById(disableImg)!=null && document.getElementById('SimsPointDiv'+counter)!=null){
					document.getElementById(enableImg).style.display='none';
					document.getElementById(disableImg).style.display='block';
				}
				
			}
		}
	}
}

function hideCartIcon(disableId) {
	if(document.getElementById(disableId) != null) {
		document.getElementById(disableId).style.display='none';
	}	
	
}

function hideCartIconIfProductOwned(isOwned){
	if(isOwned){
		if($("#addToCart").length > 0){
			$('#addToCart').hide();
		}		
	}	
}
	
function hideTryItLinkDiv(tryItDiv) {
	if(document.getElementById(tryItDiv) != null) {
		document.getElementById(tryItDiv).style.display='none';
	}
}

function showBuyNowLoading(loadingText,divId, check) {
	
	var html = "<div style='color:#3572C3;font-weight:bold;text-align:center'>"+loadingText+"</div>";
	html += "<div style='text-align:center'><br/><img id='ajaxIcon1' src='images/ajaxBig.gif'/></div>";
	document.getElementById('layerPopContent').innerHTML = html;
	
	
}
function hide()
{
	
	if(document.getElementById("hideSubmit")!=null)
	{
		document.getElementById("hideSubmit").style.display='none';
	}
	if(document.getElementById("disableSubmit")!=null)
	{
		document.getElementById("disableSubmit").style.display='block';
	}
}

function downloadNow(userEmail, eadmLink) {

	mac = /mac/i;
	
	if(mac.test(navigator.platform)) {
		day0Cookie = $.cookie('dontShowAgain');
		if(day0Cookie == null || day0Cookie == 'null' || day0Cookie == '' || day0Cookie == 'false') {
			$('#eadmInstalledDiv').hide();
			$('#macDay0WarningDiv').show();
		}
	}
	else {
		setSims3Cookie('sims3_installed_'+userEmail, 'true', 99999);
		displaySuccessDiv(eadmLink);
	}
}

function macDayZeroLayerOK(sims3InstalledCookie, eadmLink) {
	
	$('#macDay0WarningDiv').hide(); 
	if($.cookie(encodeURIComponent(sims3InstalledCookie)) == 'true') {
		displaySuccessDiv(eadmLink);
	}
	else {
		$('#eadmDownloadLaterDiv').show();
	}
}

function displaySuccessDiv(eadmLink)
{	
	document.getElementById('eadm_iframe').innerHTML = "<iframe id='eadmframe' src='"+eadmLink+"' style='display:none;width:0px; height:0px; border: 0px;'></iframe>";
    if(document.getElementById('eadmInstalledDiv')!=null){
		document.getElementById('eadmInstalledDiv').style.display = 'none';
	}
	document.getElementById('successMessageDiv').style.display = 'block';
}

function launchEADM(eadmLink){
document.getElementById('eadm_downloadiframe').innerHTML = "<iframe id='eadmframe' src='"+eadmLink+"' style='display:none;width:0px; height:0px; border: 0px;'></iframe>";
}

function displayDiv(divId){
	$('#'+divId).modal();  
	document.getElementById(divId).style.display='block';
}

function hideyDiv(divId){
	if(document.getElementById(divId)!=null)
		$.modal.close();
		document.getElementById(divId).style.display='none';
}

function redirectPage(redirectURL){
	window.location = redirectURL;
}
function displayDownloadLaterDiv()
{
	document.getElementById('eadmInstalledDiv').style.display = 'none';
	document.getElementById('eadmDownloadLaterDiv').style.display = 'block';
}

/*
 * This function is give border on items on purchase history page
 */

$(document).ready ( function () {
  $('.PurcheseImage').hover ( function () {
    $(this).css('border','1px solid #ffffff')
    $('p', this).css("display","block");
   }, function() {
   $(this).css('border','1px solid #ffffff');
    $('p', this).css("display","none");
   });
});

/*
 * This function is give border on items on product detail page
 */

$(document).ready ( function () {
  $('.SubImgWrapper').hover ( function () {
    $(this).css('border','1px solid #9ccb44')
    $('p', this).css("display","block");
   }, function() {
   $(this).css('border','1px solid #ffffff');
    $('p', this).css("display","none");
   });
});

$(document).ready ( function () {
  $('.BlueBorder').hover ( function () {
    $(this).css('border','1px solid #9ccb44')
    $('p', this).css("display","block");
   }, function() {
   $(this).css('border','1px solid #ffffff');
    $('p', this).css("display","none");
   });
});
/*
 * This function is give for layer check box event change text
 */
function DownChk() {
	$("#DownL").toggle();
	$("#DownN").toggle();
}

$(document).ready ( function () {
	readyTextureHover();
});

function readyTextureHover() {
	$('.TextureImgSmall').hover ( function () {
    $('.TextureImgBig', this).css("display","block");
  }, function() {
   $('.TextureImgBig', this).css("display","none");
 });
}

/*
 * This function is called from My Account page to show /hide modules 
 * Also add/removed border on the page to maintain the design
 * 
 */

function toggleAccount(divShow, divHide){
	if(divHide == 'RedeemHeader'){
		updateCSS(divHide);
		
	}
	if(divShow=='RedeemHeader'){
		updateCSS(divHide);
	}
	if(divHide == 'PurchasingHeader'){
		updateCSS(divHide);
		
	}
	if(divShow=='PurchasingHeader'){
		updateCSS(divHide);
	}
	if(divHide == 'billingHeaderNonUS'){
		updateCSSNonUs(divHide);
	}
	if(divShow == 'billingHeaderNonUS'){
		updateCSSNonUs(divHide);
	}
	
	if(divHide == 'PayPalHeader'){
		updateCSSPayPal(divHide);
		
	}
	if(divShow=='PayPalHeader'){
		updateCSSPayPal(divHide);
	}
	
	document.getElementById(divShow).className='active';
	document.getElementById(divHide).className='inactive';
}
function updateCSS(obj){
	if (obj == 'RedeemHeader') {
		$('#billingHeader').css("border-bottom", "0px");
		$('#billingHeader').css("padding-bottom", "0px");
		//$('#PurchasingHeader').css("border-top", "0px");
		//$('#PurchasingHeader').css("padding-top", "0px");
	}
	else if (obj == 'PurchasingHeader') {
		if((document.getElementById('RedeemHeader')==null)){
			$('#billingHeader').css("border-bottom", "0px");
			$('#billingHeader').css("padding-bottom", "0px");
			$('#PurchasingHeader').css("border-top", "10px");
			$('#PurchasingHeader').css("padding-top", "10px");
		}else
		{
		  $('#RedeemHeader').css("border-bottom", "10px");
		  $('#RedeemHeader').css("padding-bottom", "10px");
		}
	}
	else if (obj == 'PurchasingPrefDetail') {
		if((document.getElementById('RedeemHeader')==null)){
			$('#billingHeader').css("border-bottom", "1px solid #cccccc");
			$('#billingHeader').css("padding-bottom", "10px");
			$('#PurchasingHeader').css("border-top", "1px solid #cccccc");
			$('#PurchasingHeader').css("padding-top", "10px");
		}else
		{
		  $('#RedeemHeader').css("border-bottom", "0px");
		  $('#RedeemHeader').css("padding-bottom", "10px");
		}
	}
	else{
		$('#billingHeader').css("border-bottom", "0px");
		$('#billingHeader').css("padding-bottom", "0px");
		$('#PurchasingHeader').css("border-top", "1px solid #cccccc");
		$('#PurchasingHeader').css("padding-top", "10px");
		$('#RedeemHeader').css("border-bottom", "0px");
	}
}

function updateCSSNonUs(obj){
	if (obj == 'billingHeaderNonUS') {
		$('#PurchasingHeader').css("border-top", "1px solid #cccccc");
		$('#PurchasingHeader').css("padding-top", "10px");
	}
	else{
		$('#PurchasingHeader').css("border-top", "1px solid #cccccc");
		$('#PurchasingHeader').css("padding-top", "10px");
	}
}

function updateCSSPayPal(obj){
	if (obj == 'PayPalHeader') {
		$('#PurchasingHeader').css("border-bottom", "0px");
		$('#PurchasingHeader').css("padding-bottom", "10px");
	}
	else{
		$('#PurchasingHeader').css("border-bottom", "1px solid #cccccc");
		$('#PurchasingHeader').css("padding-bottom", "10px");
	}
}

function submitBuySimPoints(form,updateDiv) {
	 var paymentAction = document.getElementById('action').value;
	    var eventId = null;
	    if(paymentAction != null && paymentAction == 'purchaseWithCC') {
	    	eventId = 'creditCardPaymentSubmit';
	    } else if(paymentAction == 'purchaseWithPP') {
	    	eventId = 'payPalPaymentSubmit';
	    } else if(paymentAction == 'purchaseAll' || paymentAction == 'purchase') {
	    	eventId = 'eaAccountBalancePaymentSubmit';
	    }
	    var _eventIdEle=document.getElementById('_eventId');
	    if(_eventIdEle==null){
	    var myAction = document.createElement('input');
	    myAction.setAttribute('name', '_eventId'); 
	    myAction.setAttribute('id', '_eventId');
	    myAction.setAttribute('type', 'hidden');       
	    myAction.setAttribute('value', eventId); 
	    document.buyMoreSimPoints.appendChild(myAction); 
	    }
	    document.buyMoreSimPoints.submit(); 
	
}

function swapRAFSteps(closeId, showId){
	if(document.getElementById('digitalAgreement').checked) {
	 	document.getElementById('digitalAgreement').checked = false;
	   	var ButtonSubmit = document.getElementById('ButtonSubmitBuyMore');
	  	var ButtonSubmitGray =document.getElementById('ButtonSubmitGray');
	    ButtonSubmitGray.style.display="block";
	 	ButtonSubmit.style.display="none"; 	 
	 }
	$('#'+closeId).hide();
	$('#'+showId).show();
	for (i=0;i<document.rafBuyMoreSimPoints.productId.length;i++)
	{
		if (document.rafBuyMoreSimPoints.productId[i].checked==true)
		{
			document.getElementById('promoProductId').value=document.rafBuyMoreSimPoints.productId[i].value;
			document.getElementById('selectedBundleCount').value=i+1;
		}
	}
	
}

function submitRAFBuySimPoints() {
	 var paymentAction = document.getElementById('action').value;
	    var eventId = null;
	    if(paymentAction != null && paymentAction == 'purchaseWithCC') {
	    	eventId = 'creditCardPaymentSubmit';
	    }
	    var myAction = document.createElement('input');
	    myAction.setAttribute('name', '_eventId'); 
	    myAction.setAttribute('type', 'hidden');       
	    myAction.setAttribute('value', eventId); 
	    document.rafBuyMoreSimPoints.appendChild(myAction); 
	    document.rafBuyMoreSimPoints.submit(); 
	
}

function submitgiftMessage(eventId) {
	    var myAction = document.createElement('input');
	    myAction.setAttribute('name', '_eventId'); 
	    myAction.setAttribute('type', 'hidden');       
	    myAction.setAttribute('value', eventId); 
	    document.giftMessage.appendChild(myAction); 
	    document.giftMessage.submit(); 
	
}

function changeCoupnCodeStatus()
{
	document.getElementById('applyDiscountCoupn').value="false";
}

function submitBuySimPointsWithDiscountCoupn(form,updateDiv,msg) {
    var action=document.getElementById('action');
    var isGiftSimpointFlow=document.getElementById('isGiftSimpointFlow').value;
    if(document.getElementById('_eventId')==null)
    {
    var myAction = document.createElement('input');
    myAction.setAttribute('name', '_eventId');
    myAction.setAttribute('id', '_eventId'); 
    myAction.setAttribute('type', 'hidden'); 
    myAction.setAttribute('value', "checkPromoType"); 
    document.buyMoreSimPoints.appendChild(myAction);
    }
      if(action.value=='purchaseWithPP' && document.getElementById('payPalAccountId')!=null && document.getElementById('payPalAccountId').value=='' )
      {
           submitPayPalAddressInfo('payPalAddressForm','add');
      }else
      {
            if(document.getElementById('applyDiscountCoupn')!=null&&document.getElementById('promoCouponCode')!=null)
            {
                  if(document.getElementById('promoCouponCode').value=="")
                  {
                	  	if(action.value!='purchaseWithCC'||isGiftSimpointFlow)//As only credit card flow is refactored for stet 3 to 4
                		{
                			document.getElementById('_eventId').value='checkPromoType';
                		}
                        document.buyMoreSimPoints.submit();
                  }
                  else if(document.getElementById('promoCouponCode').value!=""&&document.getElementById('applyDiscountCoupn').value=="false")
                  {
                        simsPopup('discountCouponConfirmation');
                  }else if(document.getElementById('applyDiscountCoupn').value!=""&&document.getElementById('applyDiscountCoupn').value=="true")
                  {
                	  	if(action.value!='purchaseWithCC'||isGiftSimpointFlow)//As only credit card flow is refactored for stet 3 to 4
	              		{
	              			document.getElementById('_eventId').value='checkPromoType';
	              		}
                	  	else
	              		{
	              			document.getElementById('_eventId').value='withCouponCode';
	              		}
                        document.getElementById('applyDiscountCoupn').value=="false"
                        document.buyMoreSimPoints.submit();
                  }
            }else
            {
            	if(action.value!='purchaseWithCC'||isGiftSimpointFlow)//As only credit card flow is refactored for stet 3 to 4
          		{
          			document.getElementById('_eventId').value='checkPromoType';
          		}
                  document.buyMoreSimPoints.submit();
            }
      }
}

function resetCoupnCode() 
{
	  document.getElementById('promoCouponCode').value="";  
	  document.getElementById('transBlockUI').style.display='';
      document.getElementById('applyDiscountCoupn').value="true";
      $(".ClickHide").show();
      $(".ClickShow").hide();
      
}

function applyCoupnCode() 
{
      document.getElementById('transBlockUI').style.display='';
      $(".ClickHide").show();
      $(".ClickShow").hide();
      redeemSims3StorePromoCouponCode();
}



function submitDealBuySimPoints(form,updateDiv,msg) {
    var action=document.getElementById('action');
    if(action.value!='purchaseWithCC')
	{
		document.getElementById('_eventId').value='dealPayment';
	}
	if(action.value=='purchaseWithPP' && document.getElementById('payPalAccountId')!=null && document.getElementById('payPalAccountId').value=='' )
	{
	     submitPayPalAddressInfo('payPalAddressForm','add');
	}else
	{			
		document.buyMoreSimPoints.submit();
	}
}

function submitRafBuySimPointsOnPaymentSummary() {
    var myAction = document.createElement('input');
    myAction.setAttribute('name', '_eventId'); 
    myAction.setAttribute('type', 'hidden'); 
    myAction.setAttribute('value', "confirmPayment"); 
    document.rafBuyMoreSimPoints.appendChild(myAction); 
    document.rafBuyMoreSimPoints.submit(); 
}

function refreshPaymentSummaryPage() {
	var action=document.getElementById('action');
	action.value="purchaseAll";
	var myAction = document.createElement('input');
    myAction.setAttribute('name', '_eventId'); 
    myAction.setAttribute('type', 'hidden'); 
    myAction.setAttribute('value', "redeemEntire"); 
    document.buyMoreSimPoints.appendChild(myAction); 
	document.buyMoreSimPoints.submit();
}
function submitMyAccount(serverName, actionValue) {
    var action=document.getElementById('action');
	action.value=actionValue;
	redeemCashCode(serverName,'myAccountForm');
}
function submitMyAccountBillingInfo(serverName, actionValue) {
    var action=document.getElementById('action');
	action.value=actionValue;
	document.myAccountForm.submit();
}
function hideState(countryDiv,stateDiv,stateBox,showTabs) 
{
  var cId = document.getElementById(countryDiv);
  var value = cId.options[cId.selectedIndex].value;
  var stateBox=document.getElementById(stateBox);
  if(stateBox!='' && stateBox!=null)
  	stateBox.style.display = 'none'
  $('#'+stateDiv).load('stateList.html?countryCode='+value+'&showTabs='+showTabs);
}

function checkisPPPayment()
{
	var paymentOptionPP = document.getElementById('isPPPayment');
	
	
}

function changeAction(actionValue)
{   
	 var action=document.getElementById('action');
	 var divId=document.getElementById('updateBillingDiv');
	 if(divId.style.display=='none')
	 {
	    action.value=actionValue;
	 }
	 else if( actionValue!='purchase')
	 {
          action.value=actionValue;
      }
       else if( action.value=='' || action.value==null)
	 {
          action.value=purchaseEntire;
      }
}

function hideOtherpaymentOptions(divId1,divId2)
{
	if(document.getElementById(divId1)!=null){
	document.getElementById(divId1).style.display="none";
	}
	if(document.getElementById(divId2)!=null){
	document.getElementById(divId2).style.display="none";
	}
}

function showHidepaymentOptions(divId1,divId2)
{
	if(document.getElementById(divId1)!=null){
		document.getElementById(divId1).style.display="inline";
	}
	if(document.getElementById(divId2)!=null){
	document.getElementById(divId2).style.display="none";
	}
}
function changeHiddenParameterForEAAccount(param)
{
	document.getElementById('eAAccountAParam').value=param;
	document.getElementById('selectedBundleCount').value=-1;
}

function changeActionForEAAccount()
{
	var action=document.getElementById('action');
	var eaParam=document.getElementById('eAAccountAParam').value
	 if(eaParam!='purchaseAll')
	 {
	    action.value='purchase';
	 }
	 else
	 {
		 action.value='purchaseAll';
	 }
}

function resetEAOption()
{
	document.getElementById('eAAccountAParam').value="";
}


function changePaymentMode(input){
	paymod = input;
}

function initStep2(eabalance)
{
	var eaParam=document.getElementById('eAAccountAParam').value;
	var selectedBundlePrice=document.getElementById('selectedBundlePrice').value;
	if(eaParam!='purchaseAll')
	 {
		if(parseFloat(eabalance)==0.0)
		{
			if(paymod=='purchaseWithCC')
			{
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";	
					document.getElementById('isCCPayment').checked="checked";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="inline";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="none";
				}
				changeAction('purchaseWithCC');
			}
			else
			{
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";	
					document.getElementById('isCCPayment').checked="";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="checked";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="none";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="inline";
				}
				changeAction('purchaseWithPP');
			}
		}
		else if(parseFloat(eabalance)!=0.0&&parseFloat(selectedBundlePrice)>parseFloat(eabalance))
		{
			if(document.getElementById('useEAWallet')!=null){
				document.getElementById('useEAWallet').disabled="disabled";
				document.getElementById('useEAWallet').checked="";
			}
			if(paymod=='purchaseWithCC')
			{
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";	
					document.getElementById('isCCPayment').checked="checked";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="inline";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="none";
				}
				changeAction('purchaseWithCC');
			}
			else
			{
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";	
					document.getElementById('isCCPayment').checked="";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="checked";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="none";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="inline";
				}
				changeAction('purchaseWithPP');
			}
		}
		else if(parseFloat(eabalance)!=0.0&&parseFloat(selectedBundlePrice)<=parseFloat(eabalance))
		{
			if(document.getElementById('useEAWallet')!=null){
				document.getElementById('useEAWallet').disabled="";
				document.getElementById('useEAWallet').checked="";
			}
			if(paymod=='purchaseWithCC')
			{
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";	
					document.getElementById('isCCPayment').checked="checked";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="inline";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="none";
				}
				changeAction('purchaseWithCC');
			}
			else if(paymod=='purchaseWithPP')
			{
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";	
					document.getElementById('isCCPayment').checked="";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="checked";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="none";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="inline";
				}
				changeAction('purchaseWithPP');
			}
			else if(paymod=='purchase'){
				if(document.getElementById('useEAWallet')!=null){
					document.getElementById('useEAWallet').disabled="";
					document.getElementById('useEAWallet').checked="checked";
				}
				if(document.getElementById('isCCPayment')!=null){
					document.getElementById('isCCPayment').disabled="";
					document.getElementById('isCCPayment').checked="";
				}
				if(document.getElementById('isPPPayment')!=null){
					document.getElementById('isPPPayment').disabled="";
					document.getElementById('isPPPayment').checked="";
				}
				if(document.getElementById('updateBillingInformationCCDiv')!=null){
					document.getElementById('updateBillingInformationCCDiv').style.display="none";
				}
				if(document.getElementById('updatePaypalDiv')!=null){
					document.getElementById('updatePaypalDiv').style.display="none";
				}
				changeAction('purchase');
			}
		}
		
		
	 }
	else// when user selects redeem entire in step 1
	{
		if(document.getElementById('useEAWallet')!=null){
			document.getElementById('useEAWallet').disabled="";
			document.getElementById('useEAWallet').checked="checked";
		}
		if(document.getElementById('isCCPayment')!=null){
			document.getElementById('isCCPayment').disabled="disabled";
			document.getElementById('isCCPayment').checked="";
		}
		if(document.getElementById('isPPPayment')!=null){
			document.getElementById('isPPPayment').disabled="disabled";
			document.getElementById('isPPPayment').checked="";
		}
		if(document.getElementById('updateBillingInformationCCDiv')!=null){
			document.getElementById('updateBillingInformationCCDiv').style.display="none";
		}
		if(document.getElementById('updatePaypalDiv')!=null){
			document.getElementById('updatePaypalDiv').style.display="none";
		}
		changeActionForEAAccount();
	}
}

function initStep2ForDeal()
{
	var eaBalanceOption=document.getElementById('useEAWallet');
	if(eaBalanceOption==null)
	{
		if(paymod=='purchaseWithCC')
		{
			if(document.getElementById('isCCPayment')!=null){
				document.getElementById('isCCPayment').disabled="";	
				document.getElementById('isCCPayment').checked="checked";
			}
			if(document.getElementById('isPPPayment')!=null){
				document.getElementById('isPPPayment').disabled="";
				document.getElementById('isPPPayment').checked="";
			}
			if(document.getElementById('updateBillingInformationCCDiv')!=null){
				document.getElementById('updateBillingInformationCCDiv').style.display="inline";
			}
			if(document.getElementById('updatePaypalDiv')!=null){
				document.getElementById('updatePaypalDiv').style.display="none";
			}
			changeAction('purchaseWithCC');
		}
		else
		{
			if(document.getElementById('isCCPayment')!=null){
				document.getElementById('isCCPayment').disabled="";	
				document.getElementById('isCCPayment').checked="";
			}
			if(document.getElementById('isPPPayment')!=null){
				document.getElementById('isPPPayment').disabled="";
				document.getElementById('isPPPayment').checked="checked";
			}
			if(document.getElementById('updateBillingInformationCCDiv')!=null){
				document.getElementById('updateBillingInformationCCDiv').style.display="none";
			}
			if(document.getElementById('updatePaypalDiv')!=null){
				document.getElementById('updatePaypalDiv').style.display="inline";
			}
			changeAction('purchaseWithPP');
		}
	}
	else
	{
		if(document.getElementById('useEAWallet')!=null){
			document.getElementById('useEAWallet').disabled="";
			document.getElementById('useEAWallet').checked="checked";
		}
		if(document.getElementById('isCCPayment')!=null){
			document.getElementById('isCCPayment').disabled="";
			document.getElementById('isCCPayment').checked="";
		}
		if(document.getElementById('isPPPayment')!=null){
			document.getElementById('isPPPayment').disabled="";
			document.getElementById('isPPPayment').checked="";
		}
		if(document.getElementById('updateBillingInformationCCDiv')!=null){
			document.getElementById('updateBillingInformationCCDiv').style.display="none";
		}
		if(document.getElementById('updatePaypalDiv')!=null){
			document.getElementById('updatePaypalDiv').style.display="none";
		}
		changeActionForEAAccount();
	}
}

function changeWalletChargeAmt(amtStr,isTaxMode) {
	var walletBal = parseFloat(document.getElementById('eaWalletBal').value);
	amt = parseFloat(amtStr);
	document.getElementById('amount').value=amt;
	document.getElementById('isTaxMode').value=isTaxMode;
	if(document.getElementById('isCCPayment')!=null){
	document.getElementById('isCCPayment').disabled="";	
	}
	if(document.getElementById('isPPPayment')!=null){
	document.getElementById('isPPPayment').disabled="";
	}
	if(amt > walletBal) {		
		$(".ccSection").fadeIn("slow");
		ccAmt = amt - walletBal;
		$('#selectedBundlePrice').val(amt);
	}
	else {
		$(".ccSection").fadeOut("slow");
		$('#selectedBundlePrice').val(amt);
	}
}

function hideBillingInfo()
{
	document.getElementById('isCCPayment').disabled="disabled";
	document.getElementById('isPPPayment').disabled="disabled";
	document.getElementById('updateBillingInformationCCDiv').style.display="none";
	document.getElementById('updatePaypalDiv').style.display="none";
}

function getAccountDetail(formName)
{
	var cId = document.getElementById('accountId');
  	var value = cId.options[cId.selectedIndex].value;
		$('#updateBillingInformationCCDiv').load('accountDetail.html?location='+formName+'&accountId='+value+'&r='+Math.random());
}
function getAccount(formName)
{
		$('#updateBillingInformationCCDiv').load('accountDetail.html?location='+formName+'&r='+Math.random());
}

function checkdigitalAgreement()
{
  	var digitalAgreement = document.getElementById('digitalAgreement');
  	var ButtonSubmit = document.getElementById('ButtonSubmitBuyMore');
  	var ButtonSubmitGray =document.getElementById('ButtonSubmitGray');
  	if(digitalAgreement!='' && digitalAgreement.checked)
  	{
  	  ButtonSubmitGray.style.display="none";
  	  ButtonSubmit.style.display="block";
  	  
  	}else
  	{
  	  ButtonSubmitGray.style.display="block";
  	  ButtonSubmit.style.display="none";
  	}
}


function checkAgreement()
{
  	var termsAgreement = document.getElementById('termsAgreement');
  	var redeemEnabled = document.getElementById('redeemEnabled');
  	var redeemDisabled =document.getElementById('redeemDisabled');
  	if(termsAgreement!='' && termsAgreement.checked)
  	{
  	  redeemDisabled.style.display="none";
  	  redeemEnabled.style.display="block";
  	  
  	}else
  	{
  	  redeemDisabled.style.display="block";
  	  redeemEnabled.style.display="none";
  	}
}

function showBillingSection(commandValue)
{  
   if(commandValue)
   {
   	    document.getElementById('updatePaypalDiv').style.display="none";
	    document.getElementById('updateBillingInformationCCDiv').style.display="inline";
   
   }else
   {
        document.getElementById('updatePaypalDiv').style.display="none";
	    document.getElementById('updateBillingInformationCCDiv').style.display="inline";
   }
}
function showAgreement()
{  
   var layerAgreement=document.getElmentById('layerAgreement');
   layerAgreement.style.display="block";
 }  

function redeemCashCode(serverName, formName) {
		$.get("https://"+serverName+"/jsonChkDefaultBillingAddr.html?r="+Math.random()+"&callback=",
		function(data){
			var result = eval(data);
			if(result.loggedIn == true) {
				if(result.hasDefaultBillingAddrId == true) {
					$('#redeemAjaxIcon').attr('src', 'images/ajexloading.gif');
					var myAction = document.createElement('input');
				    myAction.setAttribute('name', '_eventId'); 
				    myAction.setAttribute('type', 'hidden'); 
				    myAction.setAttribute('value', "checkPromoType"); 
				    document.forms[formName].appendChild(myAction); 
					document.forms[formName].submit();
				}
				else {
					tb_show(null,'zipCodeLayer.html?height=160&width=500&modal=true&formName='+formName,false);
				}
			}
			else {
				window.location = "/sessionExpired.html";
			}
        },
        'text'
        );
}

function redeemCashCodeWithoutDiscountCoupn(serverName, formName) {
	if(document.getElementById('_eventId')==null)
    {
    var myAction = document.createElement('input');
    myAction.setAttribute('name', '_eventId');
    myAction.setAttribute('id', '_eventId'); 
    myAction.setAttribute('type', 'hidden'); 
    myAction.setAttribute('value', "checkPromoType"); 
    document.buyMoreSimPoints.appendChild(myAction);
    }
	$.get("https://"+serverName+"/jsonChkDefaultBillingAddr.html?r="+Math.random()+"&callback=",
	function(data){
		var result = eval(data);
		if(result.loggedIn == true) {
			if(result.hasDefaultBillingAddrId == true) {
				$('#redeemAjaxIcon').attr('src', 'images/ajexloading.gif');
				document.forms[formName].submit();
			}
			else {
				tb_show(null,'zipCodeLayer.html?height=160&width=500&modal=true&formName='+formName,false);
			}
		}
		else {
			window.location = "/sessionExpired.html";
		}
    },
    'text'
    );
}


var redeemFormNames =new Array("buyMoreSimPoints","");

function doRedeem(formName) {
	parent.document.getElementById(formName).submit();
}

 function submitTBForm(form) {
		
	$.ajax({
	  type: "POST",
	  url: form.action,
	  data: joinPostData(form),
	  success: function(html){
	  		$("#TB_ajaxContent").html(html);
	  }
	});
}

function joinPostData(oForm) {

    var aParams = new Array();
	for (var i=0 ; i < oForm.elements.length; i++) {
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=";;
		if(oForm.elements[i].type == "checkbox") {
			if(oForm.elements[i].checked) {
				sParam += encodeURIComponent("true");
				aParams.push(sParam);
			}
			else {
				sParam += encodeURIComponent("false");
				aParams.push(sParam);
			}
		}
		else if(oForm.elements[i].type == "radio") {
			if(oForm.elements[i].checked) {
				sParam += encodeURIComponent(oForm.elements[i].value);
				aParams.push(sParam);
			}
		}
		else {
			sParam = encodeURIComponent(oForm.elements[i].name);
			sParam += "=";
			sParam += encodeURIComponent(oForm.elements[i].value);
			aParams.push(sParam);
		}
	}

    return aParams.join("&");
}

function showDigitalAgreementdiv(id,background)
{
 tb_show(null,'#TB_inline?height=430&width=600&newLayer='+background+'&inlineId='+id+'&modal=true',false);
}


function showDSAForBuyNow(type, locale){
	simsPopup('layerAgreementBuyNow');
}

var buyItNowUrl;
var mainDivId;
var mainServerName;
var mainOfbId;
var isDSADownload;
var mainHideDiv;
var ofbproductIds=new Array();
/*
 * url -> This is used to check whether user has accepted new DSA
 * isDownload -> This flag will be set when its download
 * urlBuyNow -> This value will be set when its buyNow and this URL will be set to global var to get the same value after accepting new DSA
 * divId -> This is the id of div where we will be showing confirm purchase popup
 * hideDiv -> This flag will be set for listing pages
 * serverName -> This will be set for download item
 * ofbId -> This will be set for download item
 */
function checkForDSAgreement(url, isDownload, urlBuyNow, divId, hideDiv, serverName, ofbId){
	var agreementAccepted;
	//Make a backend call to check whether user has already accepted agreement
	$.ajax({'type': 'GET', 'url': url ,cache:false,success: function(data){
		var result = eval('(' + data + ')');
		agreementAccepted = result.agreementAccepted;
		if(agreementAccepted == true){
			if(isDownload == false){
				scAjax(urlBuyNow, divId, 'GET', hideDiv);
			} else {
				startDownloadItem(serverName,ofbId);
			}
			
		} else {
			isDSADownload = isDownload;
			buyItNowUrl = urlBuyNow;
			mainDivId = divId;
			mainServerName = serverName;
			ofbproductIds[0] = ofbId;
			mainHideDiv = hideDiv;
			showDSAForBuyNow();
		}
	}});
}

function checkForDSASeriesagreement(url, isDownload, urlBuyNow, divId, hideDiv, serverName, ofbIds){
	var ids=ofbIds.replace("[","").replace("]","").split(",")
	//Make a backend call to check whether user has already accepted agreement
	$.ajax({'type': 'GET', 'url': url ,cache:false,success: function(data){
		var result = eval('(' + data + ')');
		agreementAccepted = result.agreementAccepted;
		if(agreementAccepted == true){
			if(isDownload == false){
				scAjax(urlBuyNow, divId, 'GET', hideDiv);
			} else {
				for (var i=0;i<ids.length;i++)
				{
					startDownloadItem(serverName,ids[i]);
				}
			}
			
		} else {
			isDSADownload = isDownload;
			buyItNowUrl = urlBuyNow;
			mainDivId = divId;
			mainServerName = serverName;
			for (var i=0;i<ids.length;i++)
			{
				ofbproductIds[i] = ids[i];
			}
			mainHideDiv = hideDiv;
			showDSAForBuyNow();
		}
	}});
}

function enableObject(objectId,conditionObjectId){
	if(document.getElementById(conditionObjectId).checked){
		document.getElementById(objectId).disabled=false;
		document.getElementById(objectId).style.opacity="1";
		document.getElementById(objectId).style.cursor="pointer";
	}
	else{
		document.getElementById(objectId).disabled=true;
		document.getElementById(objectId).style.opacity="0.5";
		document.getElementById(objectId).style.cursor="text";
	}
}

function acceptAgreement(id, conditionObjectId){
	if(document.getElementById(conditionObjectId).checked){
		if(isDSADownload == false){
			scAjax(buyItNowUrl, mainDivId, 'GET', mainHideDiv);
		} else {
			for(var i=0;i<ofbproductIds.length;i++){
				startDownloadItem(mainServerName,ofbproductIds[i]);
			}
		}	
		simsDSAPopupClose(id);
	} else {
		return false;
	}
}

function simsDSAPopupClose(popupId){
	buyItNowUrl = null;
	mainDivId = null;
	mainServerName = null;
	mainOfbId = null;
	isDSADownload = null;
	mainHideDiv = null;
	$.modal.close();
}

function goToProductDetailCallBack(id,startAt,back,isProductSet){	
	if(isProductSet)
		window.location.href="setsProductDetails.html?productId="+id+"&purchaseHistoryStartAt="+startAt+"&back="+back;	
	else
		window.location.href="productDetail.html?productId="+id+"&startAt="+startAt+"&back="+back;	
}

function goToCustomProductDetailCallBack(redirectUrl,id,back){
	if (redirectUrl.indexOf("?") != -1){
	window.location.href=redirectUrl+"&productId="+id+"&back="+back;	
	}else{
		window.location.href=redirectUrl+"?productId="+id+"&back="+back;
	}
}


function goToProductDetail(id){
	window.location.href="productDetail.html?productId="+id;
}

function goToCustomProductDetailPage(id){
	window.location.href=""+id;
}

function goToSetsProductDetailPage(id){
	window.location.href="setsProductDetails.html?productId="+id;
}

function goToSeriesProductDetailPage(id){
	window.location.href="seriesProductDetails.html?productId="+id;
}


function goToProductDetail(id,categoryId,scategoryId,pcategoryId,ppcategoryId,gender,startAt){
	
	if(categoryId!=null && scategoryId != null){
		var	url="productDetail.html?productId="+id + "&categoryId=" + categoryId + "&scategoryId=" + scategoryId + "&pcategoryId=" + pcategoryId + "&ppcategoryId=" + ppcategoryId;
		if(gender!='')
	      url+="&gender="+gender;
	    if(startAt!='' || startAt!=null ) 
	     url+="&startAt="+startAt;
		window.location.href=url;
	}
	else
		window.location.href="productDetail.html?productId="+id;	
}


function goToSetsProductDetail(id,categoryId,scategoryId,pcategoryId){	
	if(categoryId!=null && scategoryId != null){
		var	url = "setsProductDetails.html?categoryId="+categoryId+"&scategoryId="+scategoryId+"&pcategoryId="+pcategoryId+"&index=0&productId="+id;
		window.location.href=url;
	}
	else
		window.location.href="productDetail.html?productId="+id;	
}

function goToSeriesProductDetail(id,categoryId,scategoryId,pcategoryId){	
	if(categoryId!=null && scategoryId != null){
		var	url = "seriesProductDetails.html?categoryId="+categoryId+"&scategoryId="+scategoryId+"&pcategoryId="+pcategoryId+"&index=0&productId="+id;
		window.location.href=url;
	}
	else
		window.location.href="productDetail.html?productId="+id;	
}

function goToProductDetailPage(id,categoryId,gender,back,isSets){

	if(categoryId!=null && isSets != null && isSets == true) {
		goToSetsProductDetail(id,categoryId,categoryId,categoryId);
	}
	else if(categoryId!=null){
		var	url="productDetail.html?productId="+id + "&categoryId=" + categoryId +"&back="+back;
		if(gender!='')
	      url+="&gender="+gender;
			window.location.href=url;
	}
	else {
		window.location.href="productDetail.html?productId="+id;	
		}
}

function deleteAccount()
{
	var cId = document.getElementById('accountId');
	if(cId != null) {
	  	var value = cId.options[cId.selectedIndex].value;
	  	var formName = document.getElementById('formName').value;
	  	closePopup(divId);
	 	if(value!=null && value!='')
			$('#updateBillingInformationCCDiv').load('deleteAccount.html?location='+formName+'&r='+Math.random()+'&accountId='+value);
	}
}

function setFocus(){
	if(document.getElementById("emailBox").value!=""){
		$('#passwordBox').focus();
	}
	else{
		$('#emailBox').focus();
	}	
}

function getCategoryFeatureXmlUrl() {

	url = "categoryFeatureXml.html?r="+Math.random();	
	if(getURLParamByName("categoryId"))
		url = "categoryFeatureXml.html?categoryId=" + getURLParamByName("categoryId") + "&r="+Math.random();
	if(gender!='')
	   url+="&gender="+gender;
	return url;
}

function reloadFeatureXml() {

	getFlashMovie('CategoryModule').loadFlashFeatureXML();
}

function loadFeatureXMLComplete() {
	
	featureXMLComplete = true;
}

function enableButton(){ 
  var agreement=document.getElementById('agreement');
  if(agreement.checked){
       document.getElementById('BlueBtnTrans').style.display="none";
       document.getElementById('BlueBtn').style.display="block";
   }else{
       document.getElementById('BlueBtn').style.display="none";
       document.getElementById('BlueBtnTrans').style.display="block";
   }
}
function submitForm(divId,secure){
	$.ajax({'type': 'POST', 'url': 'productRegistration.html', 'data': $('#productForm').serialize(),async:false,success: function(data){$(divId).html(data);}});
}

function checkProductCode(){
 var productCode="";
 var completed=true;
  for(i=1;i<=5;i++){ 
    var tempProductCode=document.getElementById('productCodePart'+i).value;
	    if(tempProductCode!='' && tempProductCode.length == 4){
			completed=true;
	    }else{
	        completed=false;
	        document.getElementById('BlueBtn').style.display="none";
      		document.getElementById('BlueBtnTrans').style.display="block";
	        return false;
	    }
   }
   if(completed){
       document.getElementById('BlueBtnTrans').style.display="none";
       document.getElementById('BlueBtn').style.display="block";
   }else{
       document.getElementById('BlueBtn').style.display="none";
       document.getElementById('BlueBtnTrans').style.display="block";
   }

} 

function setCursorAtEnd(sTextboxID) {
 var oTextbox = document.all.item(sTextboxID);
  if (oTextbox .createTextRange) {
   var r = (oTextbox.createTextRange());
   r.moveStart('character', (oTextbox.value.length)); r.collapse(); r.select();
  }
 }

function checkRedeemCode(obj){
 var productCode="";
 var completed=true;
 var index=null;
  for(i=1;i<=4;i++){
    var tempProductCode=document.getElementById('couponCode'+i).value;
    if(document.getElementById('couponCode3').value.length == 4){
   	 document.getElementById('couponCode4').focus();
    }else if(document.getElementById('couponCode2').value.length == 4){
    	document.getElementById('couponCode3').focus();
    }else if(document.getElementById('couponCode1').value.length == 4){
    	document.getElementById('couponCode2').focus();
    }
    if(tempProductCode!='' && tempProductCode.length == 4){
		completed=true;
    }else{
        completed=false;
        document.getElementById('redeemProductCodeButton').style.display="none";
     	document.getElementById('redeemCouponCodeGreenTransButton').style.display="block";
        return false;
    }        
   }
   if(completed){
       document.getElementById('redeemCouponCodeGreenTransButton').style.display="none";
       document.getElementById('redeemProductCodeButton').style.display="block";
   }else{
       document.getElementById('redeemProductCodeButton').style.display="none";
       document.getElementById('redeemCouponCodeGreenTransButton').style.display="block";
   }
   
} 


function cancelProductRegistration(divId,secure){
  var finish=document.getElementById('_finish');
  finish.name="_cancel";
  finish.value="_cancel";
  submitForm(divId,secure);
}
function showBuyMoreSimPointsPage()
{
   window.parent.location.href='buyMoreSimPointsProduct.html';
}

function closeBuyMoreSimpointLayer(divName)
{
	if(document.getElementById(divName)!=null)
	{
		$.modal.close();
		document.getElementById(divName).style.display='none';
		document.getElementById('trans').style.display='none';
	}
}

function changeActionValue(actionValue)
{
	purchaseEntire = actionValue;
}


function changeSelectedBundleCount(count)
{
	document.getElementById('selectedBundleCount').value=count;
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	
	return (isIE) ? window[movieName] : document[movieName];
}

function reloadFeatureXml() {
	
	getFlashMovie('CategoryModule').loadFlashFeatureXML();
}

function updatePayPalModule(){
document.getElementById('isPPPayment').checked="checked";
changeAction('purchaseWithPP');
}
function showCurrencyMisMatchLayer()
{
 tb_show(null,'#TB_inline?height=200&width=300&inlineId=CurrencyMisMatchLayerId&modal=true',false);
}

function popup(layerName) {
	if(layerName == 'loginLayer') {
		tb_show(null,'login.html?height=463&width=456&modal=true',false);
	}
}

function isRequestSecure() {

	if(window.location.href.match(/^https/i))
		return true;
	
	return false;
}

function changeRadioCheck(){
	var paymentOptionCC=document.getElementById('isCCPayment');
	var paymentOptionPP=document.getElementById('isPPPayment');
	if(paymentOptionPP!=null && paymentOptionCC!=null ){
		paymentOptionPP.checked=true;
		paymentOptionCC.checked=false;
	}
}

function validateAndAssociatePP(serverName,email,location) 
{
	var random = Math.random();
	url = "https://"+serverName+"/jsonChkDefaultBillingAddr.html?email="+email+"&rndn="+random+"&callback=";
	$.get(url, function(data)
	{ 
		var result = eval(data);
		if(result.hasDefaultBillingAddrId == true) {
			if(result.fullInformationRequired == true){
				window.location.href="https://"+serverName+"/ppAddressDetail.html?rndn="+random+"&location="+location;
			}else{
			var email = document.getElementById("newEmail");
			flag=checkWhiteSpace(email.value);
			if(!flag){
				$('#payPalResponse').load("payPal.html?option=Add&email="+email.value+'&r='+Math.random());
			}else{
				$('#PayPalloginAjax').attr('src', 'images/trans.gif');
				document.getElementById("emailValidation").innerHTML= document.getElementById("emailhiddenDiv").innerHTML;
				document.getElementById("newEmail").value=email.value;				
				document.getElementById("successMessage").innerHTML='';
				document.getElementById('emailValidateDiv').style.display='block';
			}
			}			
		}else{
			window.location.href="https://"+serverName+"/ppAddressDetail.html?rndn="+random+"&location="+location;
		}
	},'text');	
}
function checkWhiteSpace(email){
	var l = email.length;
	var flag = false;
	var i= 0;
	while(i<l){
		var space = email.charAt(i);
		if(space == ' '){
				flag = true;
				break;
		}
		i++;
	}
	return flag;
}

function submitPayPalAddressInfo(formName,actionValue){
    document.getElementById('ppAction').value=actionValue;
    
    if(actionValue=="addAnother") {
    	$.ajax({'type': 'GET', 'url': 'ppAddressDetail.html?r='+Math.random(), success: function(data){$('#payPalDiv').html(data);}});
    }
    else if(actionValue == "showAccount") {
		$.ajax({'type': 'POST', 'url': 'ppAddressDetail.html?r='+Math.random(), 'data': $('#'+formName).serialize(),success: function(data){$('#payPalDiv').html(data);}});
	}
	else {
		$.ajax({'type': 'POST', 'url': 'ppAddressDetail.html?r='+Math.random(), 'data': $('#'+formName).serialize(),success: function(data){$('#payPalDiv').html(data);}});
	}
}

function redirectPageWithDisableTokenBundles(redirectURL,returnOption){
    if(redirectURL.indexOf('?')>0)
    {
         redirectURL=redirectURL+'&'+returnOption;
    }else
    {
            redirectURL+='?'+returnOption;
    }
	window.location = redirectURL;
}

function prevSlide(maxslides,smallImagesCount) {
    if(maxslides==0 || smallImagesCount==0)
        return false;
        if(document.images) {
        if(currentslide<=1)currentslide=maxslides+1;
            if(currentslide>=1)
            {   currentslide--;
                if(currentslide==0)
                 currentslide=1;
 				document.images['slide1'].src=smallImages['smallscreenshot'+currentslide].src; 
                currentslideImage=slide['largescreenshot'+currentslide].src;
                 if(currentslide==1)
                  currentslide--;
            }
            
        }
    }
    
function nextSlide(maxslides,smallImagesCount) {
    if(maxslides==0 || smallImagesCount==0)
        return false;
    if(document.images) {
    if(currentslide==0)
        currentslide++;
         currentslide++;
        if(currentslide>maxslides)currentslide=1;
        if(currentslide<=maxslides)
        {
			document.images['slide1'].src=smallImages['smallscreenshot'+currentslide].src; 
         	currentslideImage=slide['largescreenshot'+currentslide].src;
        }
        
    }
}

function changeSlide()
{
    if(maxslides==0 || smallImagesCount==0)
        return false;
  document.slideTop.src=currentslideImage;
}

function updateSimPointsBalance(newBalance)
{
  var updateSimPointsBalance = document.getElementById('updateSimPointsBalance');
  updateSimPointsBalance.innerHTML = newBalance;
  newScWalletAccountBalance = newBalance;
}
function updateDiv()
{
	var productOwned=document.getElementById('productOwned');
	var addGame=document.getElementById('addGame');
	if(productOwned!=null && productOwned!='' && addGame!=null && addGame!='')
	{
	   productOwned.style.display="block";
	   addGame.style.display="none";
	}
}
function disableContinueButton()
{
	document.getElementById('BlueBtn').style.display="none";
    document.getElementById('BlueBtnTrans').style.display="block";
}

function confirmPayPal(msg) {
    simsPopup('confirmPaypalLayer');
}

function isAddingNewPayPal() {
	if(document.getElementById('isPPPayment') != null && document.getElementById('isPPPayment').checked == true) {
		if($('#payPalAddressForm > #email').val() != "" && document.getElementById('ppaccountId').value == "") {
			return true;
		}
	}
	return false;
}

function updatePPAccountId()
{
  document.getElementById('payPalAccountId').value=document.payPalAddressForm.ppaccountId.value; 
}

function updateHeaderAccountBalance(){
	$.ajax({'type': 'GET', 'url': 'headerAccountBalance.html?r='+Math.random(), async:false,success: function(data){$('#headerAccountDiv').html(data);}});
}
function checkUncheckPaymentOptions(elementId)
{  
   var element= document.getElementById(elementId);
   if(elementId!='' && elementId!=''){
	   if(element!=null){
   	element.checked="";
	   }
   }
}
$(document).ready ( function () {
	$("body").ajaxComplete(function(request, settings) {
		document.getElementById('transBlockUI').style.display='none';
	});
});

$(document).ready ( function () {
	$("body").ajaxStart(function(request, settings) {
		//document.getElementById('transBlockUI').style.display='block';
	});
});

function checkForAlphaNumeric(o,w)
{
	var r={'special':/[\W]/g}
    o.value = o.value.replace(r[w],'');
    o.value = o.value.replace('_','');
}
function setSelectedSearch()
{
  var list = document.getElementById('headerSearchSelect');
  if(list!=null && list!=''){
       for(i=0;i<list.length;i++)
       {  
          if(list[i].value=='store'){
              list.selectedIndex=i;     
              break;
             } 
       }
    }   
}

function showLayer(elementId) {
	
	divId = elementId;
	if(document.getElementById('trans')!=null){
		checkScreenWidth();
		document.getElementById('trans').style.display='inline';
	}
	
	if(document.getElementById(elementId)!=null){
		document.getElementById(elementId).style.display='inline';
	}
	
}

function goToUrl(url) {
	if(url == null || url == '') {
		url = '/index.html';
	}
	
	window.location.href=url;
}

function downloadNowOrLater(checked, dlNowId, dlLaterId) {
	
	if(checked) {
		$('#'+dlNowId).show();
		$('#'+dlLaterId).hide();
	}
	else {
		$('#'+dlNowId).hide();
		$('#'+dlLaterId).show();
	}
}

function setSims3Cookie(name, value, expires) {
	
	deleteSims3Cookie(name);
	$.cookie(name, value, {expires: expires, domain: sims3CookieDomain});
}

function deleteSims3Cookie(name) {
	$.cookie(name, null, {domain: sims3CookieDomain});
}

function getDownloadAuthToken(serverName,ofbId) {
	startDownloadItem(serverName,ofbId);
}

function startDownloadItem(serverName,ofbId) {

	$.get("/jsonUserHelper/getSims3DownloadUrl.html?productId="+ofbId+"&r="+Math.random()+"&callback=",
	function(data){
		var result = eval(data);
		if(result.url != null) {
			launchEADM(result.url);
		}
    },
    'text'
    );
}

function sortProduct(sortMethod){
	
	url = window.location.href;
	url = url.replace(/\&sortCategory=[a-zA-Z]+/,"");
	window.location.href = url += "&sortCategory=" + sortMethod;

}

function toggleCheckAll(size, idPrefix, value) {

	for(i = 0;i < size;i++) {
		$('#'+idPrefix+i).attr('checked', value);
	} 
}

function downloadMultiple(downloadUrl){
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	if(isIE)
		document.getElementById('eadm_downloadiframe').innerHTML += "<iframe src='"+downloadUrl+"' style='display:none;width:0px; height:0px; border: 0px;'></iframe>";
	else
		document.getElementById('eadm_downloadiframe').innerHTML ="<iframe src='"+downloadUrl+"' style='display:none;width:0px; height:0px; border: 0px;'></iframe>";
}

function purchaseHistoryDownloadCheckedItems(size, idPrefix, serverName) {
	tb_show(null,'#TB_inline?height=463&width=500&inlineId=inProcessLayer&modal=true',false);
	$.get("http://"+serverName+"/jsonDownloadAuthToken.html?authTokeOnly=true&r="+Math.random()+"&callback=",
	function(data){
		var result = eval(data);
		if(result.sims3EADMProtocolLink != null && result.encryptedAuthToken != null) {
			for(i = 0;i < size;i++) {
				if($('#'+idPrefix+i).attr('checked') == true) {
					ofbId = $('#'+idPrefix+i).val();
					var downloadUrl = result.sims3EADMProtocolLink + "ofbId=" + ofbId + "&encryptedAuthToken=" + result.encryptedAuthToken;
					//simsinternet.sleep(0.5);
					downloadMultiple(downloadUrl);
				}
			}
			tb_remove();
		}
    },
    'text'
    );
}

/*
 * These functions are related to auto tab indexing for textboxes.
 */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
 var keyCode = (isNN) ? e.which : e.keyCode;
 var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
 if(input.value.length >= len && !containsElement(filter,keyCode)) {
 input.value = input.value.slice(0, len);
 input.form[(getIndex(input)+1) % input.form.length].focus();
 }

 function containsElement(arr, ele) {
 var found = false, index = 0;
 while(!found && index < arr.length)
 if(arr[index] == ele)
 found = true;
 else
 index++;
return found;
 }

 function getIndex(input) {
 var index = -1, i = 0, found = false;
 while (i < input.form.length && index == -1)
 if (input.form[i] == input)index = i;
 else i++;
 return index;
 }
 return true;
}

function toggleOnCheckBox(hideObjId, showObjId, checked) {

	if(checked) {
		$("#"+hideObjId).hide();
		$("#"+showObjId).show();
	}
	else {
		$("#"+hideObjId).show();
		$("#"+showObjId).hide();
	}
}

function changeItemsPerPage(value) {
	$.cookie("itemsPerPage", value, {expires: 9999, domain: sims3CookieDomain});
	url = window.location.href;
	url = url.replace(/\&startAt=[0-9]+/,"&startAt=0");
	window.location.href = url;
	
}

function check_TextArea_length(textArea,maxLen){
	if (textArea.value.length > maxLen) {		
		textArea.value = textArea.value.substring(0, maxLen);
	}
}

function fbs_click(share_url) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(share_url),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function openTwitterwindow(u)
{
	window.open(u, "shareOnTwitter","location=1,status=0,scrollbars=1,width=626,height=436");
} 

function bspWithMobilePayment() {
	$.get("/jsonUserHelper/getMobilePaymentUrl.html?r="+Math.random()+"&callback=",
	function(data){
		var result = eval(data);
		if(result != null && result.url != null) {
			window.location.href=result.url;
		}
    },
    'text'
    );
}

function buyIonSubscription(productId,gaikaiUrl) {
	$.get("/jsonUserHelper/getHeadlessLockBoxUrl.html?productId="+productId+"&gaikaiUrl="+gaikaiUrl+"&r="+Math.random()+"&callback=",
			function(data){
				var result = eval(data);
				if(result != null && result.url != null) {					
					window.location.href=result.url;
				}
		    },
		    'text'
		    );
	
}

function setShoppingCartCookie(name, value) {
	var cookieValue = $.cookie(name);
	if(cookieValue != null)
		{   
			if(cookieValue.indexOf(value)== -1){
				cookieValue = cookieValue+','+value;
		}
	}else{
			cookieValue = value;
	}
	var cookieMaxAge = 60 * 60 * 24* 365;
	setSims3Cookie(name, cookieValue, cookieMaxAge);
	if($('#addToCart') != null) {
		  $('#addToCart').css('display','none');
	}	
	if($('#addedToCart') != null) {
			$('#addedToCart').css('display','block');
	}
}


function setShoppingCartCookieForSeries(name, value) {
	var cookieValue = $.cookie(name);
	if(cookieValue != null)
		{   
			if(cookieValue.indexOf(value)== -1){
				cookieValue = cookieValue+','+value;
		}
	}else{
			cookieValue = value;
	}
	var cookieMaxAge = 60 * 60 * 24* 365;
	setSims3Cookie(name, cookieValue, cookieMaxAge);
	if($('#addToCartSeries') != null) {
		  $('#addToCartSeries').css('display','none');
	}	
	if($('#addedToCartSeries') != null) {
			$('#addedToCartSeries').css('display','block');
	}
}



function addToShoppingCart(value, count, cookieName){
	var cookieValue = $.cookie(cookieName);
	var newCookieValue = null;
	var cookieArray = cookieValue.split(',');
	for(var i=0; i<cookieArray.length;i++){
		if(cookieArray[i].indexOf(value)!= -1 ){
			if(count ==1 ){
				cookieArray[i] = value
			}else if(count >1){
				cookieArray[i] = value +'_' + count;
			}
		}
	}
	newCookieValue = cookieArray.join(",");
	var cookieMaxAge = 60 * 60 * 24* 365;
	setSims3Cookie(cookieName, newCookieValue, cookieMaxAge);
}

function simsPopup(popupId){
    jQuery('#'+popupId).modal();
}

function simsPopupClose(popupId){
	$.modal.close();
}


function giftThisProduct(productId, obj, productPrice, scWalletAccountBalance)
{
	var balance = newScWalletAccountBalance;
	if(newScWalletAccountBalance != null)
	{
		var splitBalance = newScWalletAccountBalance.split(" ");
		balance = splitBalance[0];
	}
	if(newScWalletAccountBalance == null)
	{
		balance = scWalletAccountBalance;
	}
	
	if(balance!=null && balance.indexOf(',') != -1)
	{
		balance = balance.replace(/\D/g, "");
		
	}
	
	if (Number(balance) < Number(productPrice))
	{
		giftThisItemProductDetails(productId, obj);
	}
	else
	{
		window.location.href = '/gift.html?productId='+productId;
	}
}
/* Gift Simpoints validation Start */
function giftSeriesProduct(productId)
{
	window.location.href = '/gift.html?productId='+productId;

}

function giftvalidate()
{
	//global vars
	var form = $("#giftMessage");
	var recipientName = $("#recipientName");
	var nameInfo1 = $("#nameInfo1");
	var recipientEmail = $("#recipientEmail");
	var emailInfo = $("#emailInfo");
	var reRecipientEmail = $("#reRecipientEmail");	
	var emailInfo1 = $("#emailInfo1");
	var yourName = $("#yourName");
	var nameInfo2 = $("#nameInfo2");
	
	//On blur
	recipientName.blur(validateName1);
	recipientEmail.blur(validateEmail1);
	reRecipientEmail.blur(validateEmail2);
	yourName.blur(validateName2);
	//On key press
	recipientName.keyup(validateName1);
	recipientEmail.blur(validateEmail1);
	reRecipientEmail.blur(validateEmail2);
	yourName.keyup(validateName2);
	//On Submitting
	form.submit(function(){
		if(validateName1() & validateEmail1() & validateEmail2() & validateName2())	
		{	
			submitgiftMessage('next');
			return true;
		}	
		else	
		{		
			return false;
		}
	});
	
	function validateName1(){
		//if it's NOT valid
		if(recipientName.val().length == 0){
			recipientName.addClass("error");
			nameInfo1.text("Please enter the recipient's Name.");
			nameInfo1.addClass("error");
			return false;
		}
		//if it's valid
		else{
			recipientName.removeClass("error");
			nameInfo1.text("");
			nameInfo1.removeClass("error");
			return true;
		}
	}
		
	//validation functions
	function validateEmail1(){
		var a = $("#recipientEmail");
		var b = $("#reRecipientEmail");
		//testing regular expression
		var a = $("#recipientEmail").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		//if it's valid email
		if(filter.test(a)){
			recipientEmail.removeClass("error");
			emailInfo.text("");
			emailInfo.removeClass("error");
			return true;
		}
		//if it's NOT valid
		else{
			recipientEmail.addClass("error");
			emailInfo.text("Please enter a valid email address.");
			emailInfo.addClass("error");
			return false;
		}
	}
	
	function validateEmail2(){
		var a = $("#recipientEmail");
		var b = $("#reRecipientEmail");
		//are NOT valid
		if( recipientEmail.val() != reRecipientEmail.val() ){
			reRecipientEmail.addClass("error");
			emailInfo1.text("Email addresses do not match.");
			emailInfo1.addClass("error");
			return false;
		}
		//are valid
		else{
			reRecipientEmail.removeClass("error");
			emailInfo1.text("");
			emailInfo1.removeClass("error");
			return true;
		}
	}
		
	function validateName2(){
		//if it's NOT valid
		if(yourName.val().length == 0 || yourName.val().length < 4){
			yourName.addClass("error");
			nameInfo2.text("Please enter your name.");
			nameInfo2.addClass("error");
			return false;
		}
		//if it's valid
		else{
			yourName.removeClass("error");
			nameInfo2.text("");
			nameInfo2.removeClass("error");
			return true;
		}
	}	
}	

/* Gift Simpoints validation End */
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function bspWithWallieOrPaySafePayment(prepaidPaymentURL) {
    $.get("/jsonUserHelper/" +prepaidPaymentURL + "?r="+Math.random()+"&callback=",
    function(data){
          var result = eval(data);
          if(result != null && result.url != null) {
                window.location.href=result.url;
          }
  },
  'text'
  );
}
function toggle(show, hide){
	$('#'+show).show();
	$('#'+hide).hide();
}


function triggerMailForEmailvalidation(){
	var params = 'action=triggerMail';
    $.ajax({
                 type:"GET",
                 cache:false,
                 url:"/verifyemail",
                 data:params,
                 dataType:"json",
                 success:function(sdata){
            			var response = eval(sdata);
            			if(response.isMailSent){
            				toggle('authenticateEmail','validateEmail')
            			}
    				}	              
      }); 
}
$(document).ready ( function () {
    $('.SubImgWrapper').hover ( function () {
      $(this).css('border','1px solid #9ccb44');
      $('div.quickViewBtn', this).css("display","block");

     }, function() {
     $(this).css('border','1px solid #ffffff');
     $('div.quickViewBtn', this).css("display","none");
     });
  });

function addScreenShotClick(img){
	$('img.thumb').removeClass("addScreenShotSelected");
    $('img.thumb').addClass("addScreenShotNotSelected");
	var imageName=$(img).attr('largeimgalt');
	$("#imgLarge").attr("src",""+imageName+"");
	$(img).removeClass("addScreenShotNotSelected");				
	$(img).addClass("addScreenShotSelected");
}

