//normal form - with serial no
var formType = 'normal';
var hasPiano=0;
max_qty=5; //settting
function initWarrantyForm()
{
survey_participation();
if( warrantyData != null )
{ alert(99090);
$('#sc_category_1').val(warrantyData.categoryname).trigger('change');
$('#sc_product_1').attr('rel',warrantyData.fk_product);
}
}
function survey_participation()
{
answering_survey();
$('#layerBtnSubmit').css('display','none'); //hide by default
$('#sectionSurvey').css('display','block'); //show survey section
if( formType == 'withoutserial')
{
$('#layerBtnSubmit').css('display','block'); //show the submit button
$('#sectionSurvey').css('display','none'); //hide survey section
return true;
}
var survey_participate="";
var getSelectedValue = document.querySelector( 'input[name="survey_participate"]:checked');
if(getSelectedValue != null)
{
survey_participate=document.querySelector('input[name="survey_participate"]:checked').value;
}
if(survey_participate=='Yes')
{
$('#layerBtnSubmit').css('display','none'); //hide the submit button
$('#sectionSurveyQuestions').css('display','block'); //show the survey question
if( $('#label_thank_you').css('display') != 'none' || $('#label_ymm_cass').css('display') != 'none')
{
$('#layerBtnSubmit').css('display','block');
}
}
if(survey_participate=='No')
{
$('#layerBtnSubmit').css('display','block'); //show the submit button
$('#sectionSurveyQuestions').css('display','none'); //hide survey questions
}
}
function answering_survey()
{
var getSelectedValue ="";
var first_purchase="";
getSelectedValue = document.querySelector( 'input[name="first_purchase"]:checked');
if(getSelectedValue != null)
{
first_purchase=document.querySelector('input[name="first_purchase"]:checked').value;
}
var has_experience="";
getSelectedValue = document.querySelector( 'input[name="has_experience"]:checked');
if(getSelectedValue != null)
{
has_experience=document.querySelector('input[name="has_experience"]:checked').value;
}
var know_service="";
getSelectedValue = document.querySelector( 'input[name="know_service"]:checked');
if(getSelectedValue != null)
{
know_service=document.querySelector('input[name="know_service"]:checked').value;
}
var rating="";
getSelectedValue = document.querySelector( 'input[name="rating"]:checked');
if(getSelectedValue != null)
{
rating=document.querySelector('input[name="rating"]:checked').value;
}
$('#label_thank_you').css('display','none');
$('#label_ymm_cass').css('display','none');
$('#layerBtnSubmit').css('display','none');
$('#q_know_service').css('display','none'); //hide
$('#q_has_experience').css('display','none'); //hide
$('#q_rating').css('display','none'); //hide
if(first_purchase=='Yes')
{
$('#q_know_service').css('display','block'); //show
$('#q_has_experience').css('display','none'); //hide
if(know_service=='Yes')
{
$('#label_thank_you').css('display','block');
}
if(know_service=='No')
{
$('#label_ymm_cass').css('display','block');
}
}
if(first_purchase=='No')
{
$('#q_know_service').css('display','none'); //hide
$('#q_has_experience').css('display','block'); //show
if(has_experience=='Yes')
{
$('#q_rating').css('display','block');
if(rating!='')
{
$('#label_thank_you').css('display','block');
}
}
if(has_experience=='No')
{
$('#q_know_service').css('display','block');
if(know_service=='Yes')
{
$('#label_thank_you').css('display','block');
}
if(know_service=='No')
{
$('#label_ymm_cass').css('display','block');
}
}
}
if( $('#label_thank_you').css('display') != 'none' || $('#label_ymm_cass').css('display') != 'none')
{
$('#layerBtnSubmit').css('display','block');
}
}
function loadModel( element )
{
//alert($(element).prop("name"));
//alert(element.value);
//$(element).prop("id");
document.getElementById("popup_title").innerHTML = "";
$('#success_ad').css('display','none');
if ($(element).prop("id") ===undefined ) //if no parameter passed
{
numberx = 1;
}
else
{
numberx = $(element).prop("id");
numberx = numberx.replace("sc_category_", "");
}
var category = $('#sc_category_'+numberx).val();
if( category == '' )
{
$('#sc_product_'+numberx).html('');
}
else
{
ajaxCall( {
type: "POST",
url: "a/Warranty/loadModel",
async:true,
data: 'productcategory=' + encodeURIComponent(category),
success: function(msg,ret) {
if( ret != 'success' )
{
document.getElementById("validation_msg").innerHTML = '
Network connection error, please try again later.
';
$("#modal-popup").modal("show");
return false;
}
try {
var result = eval( '(' + msg +')' );
if( result.status == '1' )
{
populateModel( result.data, numberx );
sampleImage( result.images );
var selectedProduct = $('#sc_product_'+numberx).attr('rel');
if( selectedProduct!= null && selectedProduct != '' )
{
$('#sc_product_'+numberx).val( selectedProduct ).removeAttr('rel');
}
}
else
{
document.getElementById("validation_msg").innerHTML = result.msg;
$("#modal-popup").modal("show");
return false;
}
}
catch(E)
{
document.getElementById("validation_msg").innerHTML = 'Network connection error, please try again later.
';
$("#modal-popup").modal("show");
return false;
}
}
});
}
}
function loadModel_trackregis( )
{
document.getElementById("popup_title").innerHTML = "";
$('#success_ad').css('display','none');
var category = $('#tr_category').val();
if( category == '' )
{
$('#tr_product').html('');
}
else
{
ajaxCall( {
type: "POST",
url: "a/Warranty/loadModel",
async:true,
data: 'productcategory=' + encodeURIComponent(category),
success: function(msg,ret) {
if( ret != 'success' )
{
document.getElementById("validation_msg").innerHTML = 'Network connection error, please try again later.
';
$("#modal-popup").modal("show");
return false;
}
try {
var result = eval( '(' + msg +')' );
if( result.status == '1' )
{
populateModel_trackregis( result.data );
//sampleImage( result.images );
var selectedProduct = $('#tr_product').attr('rel');
if( selectedProduct!= null && selectedProduct != '' )
{
$('#tr_product').val( selectedProduct ).removeAttr('rel');
}
}
else
{
document.getElementById("validation_msg").innerHTML = result.msg;
$("#modal-popup").modal("show");
return false;
}
}
catch(E)
{
document.getElementById("validation_msg").innerHTML = 'Network connection error, please try again later.
';
$("#modal-popup").modal("show");
return false;
}
}
});
}
}
function populateModel(data, numberx)
{
var str = '';
for(var i=0; i'+data[i].model+'';
}
$('#sc_product_'+numberx).html( str );
}
function populateModel_trackregis(data)
{
var str = '';
for(var i=0; i'+data[i].model+'';
}
$('#tr_product').html( str );
}
var sampleImages = null;
function sampleImage(images)
{
if (document.getElementById("sc_image") == null) {
return true; //not exist because homepage
}
var button = "";
sampleImages = images;
if( sampleImages !=null && sampleImages.length > 0 )
{
for(var i=0; i Serial Number Sample ';
}
else
{
button += '';
}
}
button += ''; //re-execute the file
document.getElementById("sc_image").style.display = "";
}
else
{
//hide button
button = null;
}
$('#sc_image').html( button );
}
function showSampleImage()
{
var api_images = sampleImages;
//if( sampleImages !=null && sampleImages.length > 0 )
//{
$.prettyPhoto.open(api_images);
//}
}
function proceedToRegister()
{
var url = window.location.pathname;
if( url.indexOf( '/warranty-registration') === -1 )
{
$('#fmSelectCat').submit();
}
}
function AddWarrantySection()
{
//max_qty=5; //settting
//check if there is deleted_ids
var deleted_ids = $('#warranty_qty').attr('data-deleted_ids');
var deleted_ids_array = deleted_ids.split(',');
var added_num ='';
//alert('deleted ids are'+deleted_ids);
for(var i = 0; i < deleted_ids_array.length; i++) {
//if there is any number, use it to add next section
if(deleted_ids_array[i]!='')
added_num = parseInt(deleted_ids_array[i]);
}
if(added_num !="") //there are some already deleted ids
{
var new_deleted_ids = deleted_ids.replace(added_num, "");
$('#warranty_qty').attr("data-deleted_ids",new_deleted_ids);
}
else
{
//if no deleted_ids
added_num = parseInt($('#warranty_qty').val())+1 || 2;
}
//alert('added num is'+added_num);
if(added_num >max_qty) //if 5 ++
{
$('#warranty_qty').val(max_qty);
return true;
}
else
{
var warranty_qty = parseInt($('#warranty_qty').val())+1;
$('#warranty_qty').val(warranty_qty);
}
var div = document.getElementById('section_1');
clone = div.cloneNode(true); // true means clone all childNodes and all event handlers
clone.innerHTML=clone.innerHTML.replaceAll('_1','_'+added_num);
clone.id = "section_"+added_num;
var warrantysections = document.getElementsByName("warrantysection");
var lastwarrantysection_num="1";
for (var i = 0; i < warrantysections.length; i++)
{
var warranty_id = warrantysections[i].id; //section_1
lastwarrantysection_num = warranty_id.replace('section_',''); //1
}
//$('#section_1').after(clone);
$('#section_'+lastwarrantysection_num).after(clone);
$('#deletewarranty_'+added_num).css('display','block'); //show the delete button
//changeDealer('fk_dealer_'+added_num);
$('#liOtherDealer_'+added_num).css('display','none');
$('#otherdealer_'+added_num).val('');
$('#sc_category_'+added_num).val('');
$('#sc_product_'+added_num).val('');
$('#sc_product_'+added_num).empty();
$('#sc_product_'+added_num).append('');
}
function DeleteWarrantySection(id)
{
//initialy will be _2 so remove _
id = id.replace("_", "");
var div = document.getElementById("section_"+id);
div.remove();
var new_deleted_ids = $('#warranty_qty').attr('data-deleted_ids')+','+id ;
$('#warranty_qty').attr("data-deleted_ids",new_deleted_ids); //setter
var warranty_qty = parseInt($('#warranty_qty').val())-1;
$('#warranty_qty').val(warranty_qty);
}
function GetFields(check_for)
{
var arr_field = ['contactname','mobilenumber','email']; //default for all
if(check_for=='POST')
{
arr_field.push('nric');
arr_field.push('passport');
arr_field.push('telephonenumber');
}
//For Warrantysection
if( formType == 'withoutserial')
{
arr_field.push('sc_product_1');
arr_field.push('invno_1');
arr_field.push('purchasedate_1');
if(check_for=='POST')
{
arr_field.push('fk_dealer_1');
arr_field.push('otherdealer_1');
}
}
else
{ //normal
join_fields = ['address','postcode','town','fk_state'];
arr_field = arr_field.concat(join_fields);
var warrantysections = document.getElementsByName("warrantysection");
for (var i = 0; i < warrantysections.length; i++)
{
var warranty_id = warrantysections[i].id; //section_1
var index_num = warranty_id.replace('section_',''); //1
arr_field.push('sc_product_'+index_num);
arr_field.push('serialno_'+index_num);
arr_field.push('invno_'+index_num);
arr_field.push('purchasedate_'+index_num);
if(check_for=='POST')
{
arr_field.push('fk_dealer_'+index_num);
arr_field.push('otherdealer_'+index_num);
}
}
}
if( $('#sectionTuning').css('display') != 'none')
{
var tuningFields = ['tncontactname','tntelephonenumber','tnmobilenumber','tnemail','tnaddress','tnpostcode','tntown','fk_tnstate'];
arr_field = arr_field.concat(tuningFields);
}
return arr_field;
}
function processRegister(fm)
{
var errormsg = '';
var sp = "
";
validateOb = new cntValidate(sp);
//errormsg += validateOb.required('sc_product_1','Item/ model',1,'');
var fields= GetFields('VALIDATION');
var completed = true;
for( var i=0; i*.'+sp;
}
else
{
errormsg += validateOb.email('email','Email','');
}
var survey_participate="";
var getSelectedValue = document.querySelector( 'input[name="survey_participate"]:checked');
if((getSelectedValue == '' || getSelectedValue == null) && formType=='normal' )
{
errormsg += "Please answer survey questions"+sp;
}
document.getElementById("popup_title").innerHTML = 'Form Validation';
$('#success_ad').css('display','none');
if( errormsg != '')
{
document.getElementById("validation_msg").innerHTML = errormsg;
$("#modal-popup").modal("show");
return false;
}
else if( !document.getElementById('agree').checked )
{
document.getElementById("validation_msg").innerHTML = 'Please agree that the use of the information you provide to Yamaha will be governed by the terms of the website\'s T&C';
$("#modal-popup").modal("show");
return false;
}
else
{
var postdata = 'id=' +getQueryString('id')+'&';
//var fields = ['serialno','invno','contactname','passport','nric','mobilenumber','email','telephonenumber','address','town','postcode','fk_state','fk_dealer','otherdealer'];
fields= GetFields('POST');
var purchasedate="";
for(var i=0; i' + result.msg + '' +successAds );
// not using window.setTimeout("window.location = baseUrl();",2000);
}
else
{
document.getElementById("validation_msg").innerHTML = result.msg;
$("#modal-popup").modal("show");
return false;
}
}
catch(E)
{
document.getElementById("validation_msg").innerHTML = 'Network connection error, please try again later.';
$("#modal-popup").modal("show");
return false;
}
}
});
}
return false;
}
function checkIfHasPianoCategory()
{
hasPiano = 0;
for(i = 0; i <= max_qty; i++) //max number of category tab
{
if( $('#sc_category_'+i).val() == 'Piano' )
{
hasPiano = 1;
break;
}
}
//alert(hasPiano);
return hasPiano;
}
function openTuningReg()
{
var hasPiano= checkIfHasPianoCategory();
if( formType == 'withoutserial')
return false;
//if( $('#sc_category_1').val() == 'Piano' )
if(hasPiano==1)
{
if( $('#sectionTuning').css('display') == 'none')
{
$('#layerBtnSubmit').css('display','none');
$('#sectionTuning').slideDown('slow',function() { $('#layerBtnSubmit').css('bottom','-30px').css('display','none')});
}
}
else
{
if( $('#sectionTuning').css('display') == 'block')
{
$('#layerBtnSubmit').css('display','none');
$('#sectionTuning').slideUp('slow',function() { $('#layerBtnSubmit').css('bottom','-30px').css('display','none')});
}
}
if( $('#sc_category_1').val() != '' )
{
$('#sc_image').css('display','block');
}
else
{
$('#sc_image').css('display','none');
}
survey_participation();
}
function copyInfoAbove()
{
var fields = ['contactname','mobilenumber','email','telephonenumber','address','town','postcode','fk_state'];
if( this.checked )
{
for( var i=0; i