var buyjobads; function buyJobAdsLoad(){ var current = window.onload; window.onload = function(){ current(); buyjobads = new BuyJobAds(); } } function BuyJobAds(){ this.initiate(); } BuyJobAds.prototype.discounted = 0; BuyJobAds.prototype.values = new Array(new Array('174.56','307','750','1000'), new Array('174.56','289','715','950'), new Array('174.56','276','675','900'), new Array('174.56','263','630','850')); BuyJobAds.prototype.maximum = 25; BuyJobAds.prototype.locale = 0; //--BuyJobAds.prototype.promo_amount = 0; BuyJobAds.prototype.day14_job_volume = 0; BuyJobAds.prototype.standard_job_volume = 0; BuyJobAds.prototype.top_job_volume = 0; BuyJobAds.prototype.priority_job_volume = 0; BuyJobAds.prototype.total_job_volume = 0; BuyJobAds.prototype.day14_job_discount = 0; BuyJobAds.prototype.standard_job_discount = 0; BuyJobAds.prototype.top_job_discount = 0; BuyJobAds.prototype.priority_job_discount = 0; BuyJobAds.prototype.total_sub_discount = 0; BuyJobAds.prototype.total_vat_discount = 0; BuyJobAds.prototype.total_job_discount = 0; //--BuyJobAds.prototype.standard_job_promo = 0; //--BuyJobAds.prototype.top_job_promo = 0; //--BuyJobAds.prototype.priority_job_promo = 0; //--BuyJobAds.prototype.total_sub_promo = 0; //--BuyJobAds.prototype.total_vat_promo = 0; //--BuyJobAds.prototype.total_job_promo = 0; BuyJobAds.prototype.day14_job_total = 0; BuyJobAds.prototype.standard_job_total = 0; BuyJobAds.prototype.top_job_total = 0; BuyJobAds.prototype.priority_job_total = 0; BuyJobAds.prototype.total_sub_total = 0; BuyJobAds.prototype.total_vat_total = 0; BuyJobAds.prototype.total_job_total = 0; BuyJobAds.prototype.initiate = function(){ this.maximum = document.getElementById('maximum').value; this.locale = document.getElementById('locale').value; if(this.locale == '1'){ this.hide4International(); } this.get_job_volumes(); } BuyJobAds.prototype.hide4International = function(){ $("#frmbuyjobads").find("ul").each(function(){ //$(this).children("li:nth-child(5)").hide(); $(this).children("li:nth-child(6)").hide(); $(this).children("li:nth-child(7)").hide(); }); } // Job Count BuyJobAds.prototype.get_job_volumes = function(){ this.day14_job_volume = parseInt(document.getElementById('day14_job_volume').value); this.standard_job_volume = parseInt(document.getElementById('standard_job_volume').value); this.top_job_volume = parseInt(document.getElementById('top_job_volume').value); this.priority_job_volume = parseInt(document.getElementById('priority_job_volume').value); this.total_job_volume = this.day14_job_volume + this.standard_job_volume + this.top_job_volume + this.priority_job_volume; document.getElementById('total_job_volume').innerHTML = this.total_job_volume; this.set_job_volumes(); this.set_job_totals(); } BuyJobAds.prototype.set_job_volumes = function(){ this.correct_job_volumes('day14_job_volume', this.day14_job_volume); this.correct_job_volumes('standard_job_volume', this.standard_job_volume); this.correct_job_volumes('top_job_volume', this.top_job_volume); this.correct_job_volumes('priority_job_volume', this.priority_job_volume); } BuyJobAds.prototype.correct_job_volumes = function(select, value){ var element = document.getElementById(select); var variable = this.maximum - this.total_job_volume; for(loop=this.maximum;loop>(value+variable);loop--){ if(element.length >= loop){ element.remove(loop); } } for(loop=(element.length);loop<=(value+variable);loop++){ this.add_job_volume(element, loop) } if(document.all) element.outerHTML = element.outerHTML; } BuyJobAds.prototype.add_job_volume = function(element, value){ var option = document.createElement('option'); option.innerHTML = value + " Ads"; option.value = value; element.add(option, null); } // Sub Totals + Total BuyJobAds.prototype.set_job_totals = function(){ this.discounted = 0; if(this.total_job_volume > 20){ this.discounted = 3; } else if(this.total_job_volume > 10){ this.discounted = 2; } else if(this.total_job_volume > 5){ this.discounted = 1; } this.day14_job_total = new Number((this.day14_job_volume*this.values[this.discounted][0])); this.standard_job_total = new Number((this.standard_job_volume*this.values[this.discounted][1])); this.top_job_total = new Number((this.top_job_volume*this.values[this.discounted][2])); this.priority_job_total = new Number((this.priority_job_volume*this.values[this.discounted][3])); this.total_sub_total = this.day14_job_total + this.standard_job_total + this.top_job_total + this.priority_job_total; //prolem occurs here //alert(Math.round(this.total_sub_total)); this.total_vat_total = Math.round(this.total_sub_total*0.14); //this.total_job_total = this.total_sub_total + this.total_vat_total; this.total_job_total = Math.round(this.total_sub_total*1.14); this.total_vat_total = this.total_job_total - this.total_sub_total; this.correct_job_totals(); this.set_job_discounts(); } BuyJobAds.prototype.correct_job_totals = function(){ this.adjust_cost_details('day14_job_total', this.adjust_for_vat(this.day14_job_total)); this.adjust_cost_details('standard_job_total', this.adjust_for_vat(this.standard_job_total)); this.adjust_cost_details('top_job_total', this.adjust_for_vat(this.top_job_total)); this.adjust_cost_details('priority_job_total', this.adjust_for_vat(this.priority_job_total)); this.adjust_cost_details('total_sub_total', this.total_sub_total); this.adjust_cost_details('total_vat_total', this.total_vat_total); this.adjust_cost_details('total_job_total', this.total_job_total); } // Discounts BuyJobAds.prototype.set_job_discounts = function(){ this.day14_job_discount = new Number(((this.day14_job_volume*this.values[0][0])-this.day14_job_total)); this.standard_job_discount = new Number(((this.standard_job_volume*this.values[0][1])-this.standard_job_total)); this.top_job_discount = new Number(((this.top_job_volume*this.values[0][2])-this.top_job_total)); this.priority_job_discount = new Number(((this.priority_job_volume*this.values[0][3])-this.priority_job_total)); this.total_sub_discount = this.day14_job_discount + this.standard_job_discount + this.top_job_discount + this.priority_job_discount; this.total_vat_discount = this.total_sub_discount*0.14; this.total_job_discount = this.total_sub_discount + this.total_vat_discount; this.correct_discount_details(); } BuyJobAds.prototype.correct_discount_details = function(){ this.adjust_cost_details('day14_job_discount', this.adjust_for_vat(this.day14_job_discount)); this.adjust_cost_details('standard_job_discount', this.adjust_for_vat(this.standard_job_discount)); this.adjust_cost_details('top_job_discount', this.adjust_for_vat(this.top_job_discount)); this.adjust_cost_details('priority_job_discount', this.adjust_for_vat(this.priority_job_discount)); this.adjust_cost_details('total_sub_discount', this.total_sub_discount); this.adjust_cost_details('total_vat_discount', this.total_vat_discount); this.adjust_cost_details('total_job_discount', this.total_job_discount); } // Promotional BuyJobAds.prototype.set_job_promos = function(){ this.standard_job_promo = new Number(this.standard_job_volume*this.promo_amount); this.top_job_promo = new Number(this.top_job_volume*this.promo_amount); this.priority_job_promo = new Number(this.priority_job_volume*this.promo_amount); this.total_sub_promo = this.standard_job_promo + this.top_job_promo + this.priority_job_promo; this.total_vat_promo = this.total_sub_promo*0.14; this.total_job_promo = this.total_sub_promo + this.total_vat_promo; this.correct_promo_details(); } BuyJobAds.prototype.correct_promo_details = function(){ this.adjust_cost_details('standard_job_promo', this.standard_job_promo); this.adjust_cost_details('top_job_promo', this.top_job_promo); this.adjust_cost_details('priority_job_promo', this.priority_job_promo); this.adjust_cost_details('total_sub_promo', this.total_sub_promo); this.adjust_cost_details('total_vat_promo', this.total_vat_promo); this.adjust_cost_details('total_job_promo', this.total_job_promo); } // Adjust Spans BuyJobAds.prototype.adjust_cost_details = function(span, value){ var element = document.getElementById(span); element.innerHTML = value.toFixed(2); } // Financials BuyJobAds.prototype.adjust_for_vat = function(value){ //to ceil or to round that is the question return Math.round(value*1.14); } // Misc function check_values() { var day14_job = parseInt(document.getElementById('day14_job_volume').value); var standard_job = parseInt(document.getElementById('standard_job_volume').value); var priority_job = parseInt(document.getElementById('priority_job_volume').value); var top_job = parseInt(document.getElementById('top_job_volume').value); if (day14_job === 0 && standard_job === 0 && priority_job === 0 && top_job === 0) { alert('You have to choose a Job Ad Volume'); } else { submitForm('frmbuyjobads'); } }