function isIE(){
if(document.all){
return true;
}else{
return false;
}
}
function wpoffer(WPid, index) {
var tForm = document.getElementById('offerForm'+index);
var element_to_remove ;
if (element_to_remove = document.getElementById('WelcomePack'+index)) {
tForm.removeChild(element_to_remove);
}
var hiddenWPcode = document.createElement("input");
hiddenWPcode.setAttribute('type','hidden');
hiddenWPcode.setAttribute('name','WelcomePack');
hiddenWPcode.setAttribute('id','WelcomePack'+index);
hiddenWPcode.setAttribute('value', WPid );
tForm.appendChild(hiddenWPcode);
}
function setOfferHiddenField(fieldName, fieldValue, index) {
var tForm = document.getElementById('offerForm'+index);
var element_to_remove ;
if (element_to_remove = document.getElementById(fieldName+index)) {
tForm.removeChild(element_to_remove);
}
if (fieldValue != '' ){
var hiddenField = document.createElement("input");
hiddenField.setAttribute('type','hidden');
hiddenField.setAttribute('name',fieldName);
hiddenField.setAttribute('id',fieldName+index);
hiddenField.setAttribute('value', fieldValue );
tForm.appendChild(hiddenField);
}
}
function setOfferHiddenFields(index, welcomePackValue, cosIdValue, COSIdIkeyValue, ticketValue, maxIKeyValue, iKeyProductIdValue, ikeyProductDescValue, ikeyOptValue, simProductIdValue, maxSimValue, enableRechargeValue, sim_thresholdsValue, offerimageValue, ticketIdValue, dealerValue) {
//alert('setOfferHiddenFields');
var superMaxSim = $('#super_maxSim_'+index).val(); // valore della select sovrascrive maxSimValue
if (superMaxSim > 0){ var maxSimValue = ''; }
var superMaxIkey = $('#super_maxIkey_'+index).val(); // valore della select sovrascrive maxIKeyValue
if (superMaxIkey > 0){ var maxIKeyValue = ''; }
setOfferHiddenField('WelcomePack' , welcomePackValue , index);
setOfferHiddenField('COSId' , cosIdValue , index);
setOfferHiddenField('COSIdIkey' , COSIdIkeyValue , index);
setOfferHiddenField('ticket' , ticketValue , index);
setOfferHiddenField('ticketId' , ticketIdValue , index);
setOfferHiddenField('maxIkey' , maxIKeyValue , index);
setOfferHiddenField('iKeyProductId' , iKeyProductIdValue , index);
setOfferHiddenField('ikeyProductDesc' , ikeyProductDescValue , index);
setOfferHiddenField('ikeyOpt' , ikeyOptValue , index);
setOfferHiddenField('simProductId' , simProductIdValue , index);
setOfferHiddenField('maxSim' , maxSimValue , index);
setOfferHiddenField('recharge' , enableRechargeValue , index);
setOfferHiddenField('sim_thresholds' , sim_thresholdsValue , index);
setOfferHiddenField('offerimage' , offerimageValue , index);
setOfferHiddenField('dealer' , dealerValue , index);
}
/**
* Imposta i parametri selfcare legati alla option
*/
function setOptionHiddenFields(index, welcomePackValue, offerimageValue, ticketValue){
setOfferHiddenField('WelcomePack' , welcomePackValue , index);
setOfferHiddenField('offerimage' , offerimageValue , index);
setOfferHiddenField('ticket' , ticketValue , index);
$('#offerForm'+index+'_ticket').remove();
}
/**
* Imposta i parametri selfcare legati alla SIM
* @param index id form
* @param id id element chiamante
* @param simProductIdValue
* @param cosIdValue
* @param maxSimValue
* @param enableRechargeValue ricarica contestuale
*/
function setSimHiddenFields(index, id, simProductIdValue, cosIdValue, maxSimValue, enableRechargeValue, sim_thresholdsValue, dealerValue){
var superMaxSim = $('#super_maxSim_'+index).val(); // valore della select sovrascrive maxSimValue
if (superMaxSim > 0){ var maxSimValue = ''; }
if (id.checked == true){
setOfferHiddenField('COSId' , cosIdValue , index);
setOfferHiddenField('maxSim' , maxSimValue , index);
setOfferHiddenField('recharge' , enableRechargeValue , index);
setOfferHiddenField('sim_thresholds' , sim_thresholdsValue , index);
setOfferHiddenField('dealer' , dealerValue , index);
// setOfferHiddenField('simProductId' , simProductIdValue , index);
} else {
setOfferHiddenField('COSId' , '' , index);
setOfferHiddenField('maxSim' , '' , index);
setOfferHiddenField('recharge' , '' , index);
setOfferHiddenField('sim_thresholds' , '' , index);
setOfferHiddenField('dealer' , '' , index);
// setOfferHiddenField('simProductId' , '' , index);
}
}
/**
* Imposta i parametri selfcare legati alla Internet Key
* @param index id form
* @param id id element chiamante
* @param iKeyProductIdValue
* @param ikeyProductDescValue
* @param COSIdIkeyValue
* @param maxIKeyValue
* @param ikeyOptValue
*/
function setIkeyHiddenFields(index, id, iKeyProductIdValue, ikeyProductDescValue, COSIdIkeyValue, maxIKeyValue, ikeyOptValue ){
//alert(id.checked);
var superMaxIkey = $('#super_maxIkey_'+index).val(); // valore della select sovrascrive maxIKeyValue
if (superMaxIkey > 0){ var maxIKeyValue = ''; }
if (id.checked == true){
setOfferHiddenField('ikeyProductDesc' , ikeyProductDescValue , index);
setOfferHiddenField('COSIdIkey' , COSIdIkeyValue , index);
setOfferHiddenField('maxIkey' , maxIKeyValue , index);
setOfferHiddenField('ikeyOpt' , ikeyOptValue , index);
// setOfferHiddenField('iKeyProductId' , iKeyProductIdValue , index);
} else {
setOfferHiddenField('ikeyProductDesc' , '', index);
setOfferHiddenField('COSIdIkey' , '', index);
setOfferHiddenField('maxIkey' , '', index);
setOfferHiddenField('ikeyOpt' , '', index);
// setOfferHiddenField('iKeyProductId' , '', index);
}
}
/**
* Imposta i parametri selfcare legati al Fax
* @param index id form
* @param id id element chiamante
* @param faxProductIdValue
* @param faxProductDescValue
* @param faxFreeProductCodeValue
* @param faxNGProductCode
*/
function setFaxHiddenFields(index, id, faxProductIdValue, faxProductDescValue, faxFreeProductCodeValue, faxNGProductCodeValue){
//alert(id.checked);
// if (id.checked == true){
setOfferHiddenField('faxProductDesc' , faxProductDescValue , index);
setOfferHiddenField('faxFreeProductCode', faxFreeProductCodeValue , index);
setOfferHiddenField('faxNGProductCode' , faxNGProductCodeValue , index);
/* } else {
setOfferHiddenField('faxProductDesc' , '', index);
setOfferHiddenField('faxFreeProductCode' , '', index);
setOfferHiddenField('faxNGProductCode' , '', index);
}
*/
}
function composeTicket(idForm){
var ticket = '';
// scorre tutti gli input checkati del form idForm
$('#'+idForm+' input:checked').each(function() {
var checkID = $(this).attr('id');
//alert('checkID = ' + checkID);
if (checkID != ''){
// scorre tutti gli input hidden il cui ID comincia con 'ticket_'+checkID
$('input:hidden[id^="ticket_'+checkID+'"]').each(function() {
// Prints the value of each input.
// alert($(this).val());
// alert( $(this).attr('id') );
// ricava la label del componente dall'id dell item
var prefix = 'ticket_' + checkID + '_' ;
var label = $(this).attr('id');
label = label.replace(prefix, '');
ticket += $(this).attr('value') ;
});
}
});
var idFormNum = idForm.split('offerForm')[1];
//alert (idFormNum);
var ticketForm = $('#ticketForm'+idFormNum).attr('value');
ticket = ticket + ticketForm;
//alert(ticket);
//$('#'+idForm+' input:hidden[name="ticket"]').remove(); // rimuove ticket concatenato form/option
// $('#ticket'+idFormNum).attr('disabled', 'true');
// sostituisce ticket generato via JS
$('#'+idForm+'_ticket').remove();
$('#'+idForm).append('');
}
/**
* Compone nuovo parametro ticketId sostitutivo del ticket
* @param {type} idForm
* @returns {undefined}
*/
function composeTicketId(idForm){
var ticketId_item = '';
var ticketId = '';
// scorre tutti gli input checkati del form idForm
$('#'+idForm+' input:checked').each(function() {
var checkID = $(this).attr('id');
//alert('checkID = ' + checkID);
if (checkID != ''){
// scorre tutti gli input hidden il cui ID comincia con 'ticket_'+checkID
$('input:hidden[id^="ticketId_'+checkID+'"]').each(function() {
// Prints the value of each input.
// alert($(this).val());
// alert( $(this).attr('id') );
// ricava la label del componente dall'id dell item
var prefix = 'ticketId_' + checkID + '_' ;
var label = $(this).attr('id');
label = label.replace(prefix, '');
ticketId_item += $(this).attr('value') ;
});
}
});
var idFormNum = idForm.split('offerForm')[1];
//alert (idFormNum);
var ticketIdForm = $('#ticketIdForm'+idFormNum).attr('value');
//ticketId = ticketId + ticketIdForm;
if (ticketId_item == ''){
ticketId = ticketIdForm;
} else {
ticketId = ticketId_item;
}
//alert(ticketId);
// $('#'+idForm+' input:hidden[name="ticket"]').remove(); // rimuove ticket concatenato form/option
// $('#ticketId'+idFormNum).attr('disabled', 'true');
// sostituisce ticket generato via JS
$('#_ticketId'+idForm).remove();
$('#_ticketId'+idForm).append('');
}
function uncheckSibling(itemId, componentePilota){
$('input[id!="'+itemId+'"][name="'+componentePilota+'"]').attr('checked', false);
}
/**
* deselezione i checkbox alternativi a quello selezionato
* @param {type} $input
* @returns {undefined}
*/
function uncheckSiblings($input){
/// $($input).siblings().find('input[type="checkbox"]').attr('checked', false);
$($input).parent().siblings("div").children("input").attr("checked",
this.checked || $(this).siblings("input[checked]").length>0
);
}
/**
* combina i valori dei checkbox nei fieldset e li assegna a paramName
* @param string $formId
* @param string $paramName
* @param string $fieldset1
* @param string $fieldset2
* @returns {undefined}
*/
function combineParam($formId, $paramName, $fieldset1, $fieldset2, $fieldset3, $fieldset4 ){
//verifica che il nodo $paramName esista, altrimenti lo aggiunge al form
//var paramExist = ($($formId).find($paramName).length > 0);
var paramExist = ($($formId).find("input[name='"+$paramName+"']").length > 0);
if (paramExist == false){
$('').attr({
type: 'hidden',
id: $paramName+'_id',
name: $paramName
}).appendTo($formId)
}
// imposta in una costante il valore originale del parametro
const origParamVal = $($formId + " input[name='"+$paramName+"']").val();
//alert('Param: '+ $paramName +' - origParamVal: '+origParamVal);
//const origParamVal = $($paramName).val();
$($formId + ' :checkbox').click(function() { // modificato :checkbox
//$($formId + $( $fieldset1,$fieldset2,$fieldset3,$fieldset4) +' :checkbox').click(function() {
uncheckSiblings($(this));
var val1 = $($fieldset1+ " :checked").val();
var val2 = $($fieldset2+ ' :checked').val();
var val3 = $($fieldset3+ ' :checked').val();
var val4 = $($fieldset4+ ' :checked').val();
var newVal = '|';
if (origParamVal ==''){
newVal = '';
}
if (val1 !== undefined){
newVal = val1;
// alert(val1);
}
if (val2 !== undefined){
newVal += '|'+ val2;
}
if (val3 !== undefined){
newVal += '|'+ val3;
}
if (val4 !== undefined){
newVal += '|'+ val4;
}
//assegna il valore al parametro
$($formId +" input[name='"+$paramName+"']").val(origParamVal + newVal);
});
}
function combineQtyParams($formId, $paramName, $paramsParent){
var params =[];
var combine = '';
$( $paramsParent+' .qtyParams ').each(function() {
var splitted = $(this).val().split(',');
//console.log(splitted);
if (splitted[3] > 0){
combine += splitted.join(',');
}
});
//console.log(params);
//console.log(combine);
return combine;
}
function replaceStringElement(string , elemNum, newValue){
array = string.split(",");
array[elemNum] = newValue;
newString = array.join(",");
return newString;
}
function sliderPackHandle(paramsParentID, formId, paramName ){
$( paramsParentID +" > div > div" ).each(function() {
// read initial values from markup and remove that
var value = parseInt( $( this ).children("span").text(), 10 );
$( this ).empty().slider({
value: value,
range: "max",
animate: true
});
// popola slider in prima istanza
$(this).children("span").html( " 0 " );
$(this).on( "slidechange", function( event, ui ) {
var newQty = parseInt((ui.value /10)); //valore corrente sullo slider
// aggiorna quantity sullo span dello slider
$(this).children("span").html( " " + newQty +" " );
//ottiene valore impostato su hidden associato allo slider
var thisID = $(this).attr("id"); console.log(thisID);
var sbl_id = thisID.replace("span_", "");
var old_val = $("#" + sbl_id).val(); console.log(old_val);
// sostituisce quantity (ultimo elemento del PID) con valore corrente dello slider
//var splitOldVal = old_val.split(","); console.log(splitOldVal);
//splitOldVal[3] = newQty;
//newVal =
//$("#" + sbl_id).val( splitOldVal.join(",") );
var newX = replaceStringElement(old_val , 3, newQty);
$("#" + sbl_id).val(newX) ;
var paramNameNewVal = combineQtyParams(formId, paramName, paramsParentID)
//combineQtyParams("#'.$html_form_id.'" , "'.$SF_PARAM_KEY.'", "fieldset_pack_' .$packet['UID'].'");
$(formId +" input[name='"+paramName+"']").val(paramNameNewVal);
});
});
}
function checkSelfcareSubmit(formID){
$('#'+formID).submit(function (e) {
e.preventDefault();
var MandatoryOriginalExist = ($('#'+formID+ ' #ID_originalMandatoryProductID').length >0);
console.log('MandatoryOriginalExist: '+ MandatoryOriginalExist);
if (MandatoryOriginalExist==false){
//if ($('#'+formID+ ' #ID_originalMandatoryProductID').length ==0){
const Mandatory_ProductID_original = $('#'+formID).find("input[name='Mandatory_ProductID']").val();
console.log("Mandatory_ProductID_original: " + Mandatory_ProductID_original);
$('#'+formID).append('');
console.log('Added mandatory original');
}
const Mandatory_ProductID_original = $('#ID_originalMandatoryProductID').val();
var SmarthomeFreeExist = ($('#'+formID).find("input[name='Smarthome_free']").length > 0);
var SmarthomePaidExist = ($('#'+formID).find("input[name='Smarthome_paid']").length > 0);
var newMandatoryValue = Mandatory_ProductID_original;
if(SmarthomeFreeExist){
var SM_freeValue = $('#'+formID).find("input:checked[name='Smarthome_free']").val();
console.log(SM_freeValue);
if (typeof SM_freeValue != 'undefined'){
newMandatoryValue += SM_freeValue;
}
console.log(newMandatoryValue);
}
if (SmarthomePaidExist){
var SM_paidValue = $('#'+formID).find("input[name='Smarthome_paid']").val();
console.log(SM_paidValue);
if (typeof SM_paidValue != 'undefined'){
newMandatoryValue += SM_paidValue;
}
console.log(newMandatoryValue);
}
$('#'+formID).find("input[name='Mandatory_ProductID']").val(newMandatoryValue);
e.currentTarget.submit();
});
} //end checkSelfcareSubmit
function donor_operator_change(formID){
var donorSelectExist = ($('#'+formID+ ' #MNC_selector').length >0);
// console.log("donorSelectExist:"+ donorSelectExist);
if(donorSelectExist){
// console.log("if enter");
var operatorName = $('#'+formID+' #MNC_selector option:selected' ).text();
$('#'+formID+' #MNC_operator').val(operatorName);
}
}