function MyJax(){
var customize = '';
var dimension = '250x250';
var affiliateId = 'CD687';
var DGFilename = 'components/gen_engine.php';
var baseUrl = 'http://3g-tech.3-mobile-affiliate.com/dealgenerator-beta/';
var styleLink = {
elementType : 'link',
elementAtts : {
id : 'dgStyleTag',
href : '',
rel : 'stylesheet',
type : 'text/css'
}
}// End of tag array
var scriptTag = {
elementType : 'script',
elementAtts : {
src : '',
type : 'text/javascript',
rel : 'stylesheet'
}
}// End of tag array
var deal_Generator =
"
"
+"
"
+"
\n\n"
+"
\n"
+"Genre \n"
+"\n"
+"Smartphone \n"
+"Cameraphone \n"
+"Social Networking Phone \n"
+"Simple Phone \n"
+"SIM \n"
+"Refurbished \n"
+"Laptop/Dongle/Modem \n"
+" \n"
+"Plan \n"
+"\n"
+"Texter Plan \n"
+"Talker Plan \n"
+"Pay As You Go \n"
//+" \n"
+" \n"
+"Price \n"
+"\n"
+"Any \n"
+"10-15 \n"
+"15-20 \n"
+"20 Plus \n"
//+" \n"
+" \n"
+"
"
+"
\n"
+"
"
+"\n
"
+"
\n";
function getById(id){
return document.getElementById(id);
}
function keyValPair(key, value){
return encodeURIComponent(key) + "=" + encodeURI(value);
}
function getTarget(e){
var target = (window.event ? window.event.srcElement : (e ? e.target : null));
if (!target){
throw 'Could not return target';
}
return target;
}
function getOptions() {
var qString = "?" + keyValPair('afid', affiliateId)
+ '&' + keyValPair('dimension', dimension);
var selectArray = new Array();
selectArray.push(getById('dealGenHandset'));
var tmpPlan = getById('dealGenPlan');
if(tmpPlan.disabled==false)
selectArray.push(tmpPlan);
var tmpPrice = getById('dealGenPrice');
if(tmpPrice.disabled==false)
selectArray.push(tmpPrice);
for (var i = 0; i < selectArray.length; i++)
{
var selectIndex = selectArray[i].selectedIndex;
qString += '&' + keyValPair(selectArray[i].id , selectArray[i].options[selectIndex].text);
}
if(customize.length > 0) qString += '&customisation=' + customize;
return qString;
}
function createTag(hashArray){
var tag = document.createElement(hashArray['elementType']);
var elementAtts = hashArray['elementAtts'];
try{
for(var key in elementAtts){
tag.setAttribute(key, elementAtts[key]);
}
if (hashArray['htmlText'])
tag.innerHTML = hashArray['htmlText'];
}
catch (e){
alert('Err: problem building tag: ' + e.toString());
}
return tag;
}
function onSelectChange(e){
var select = getTarget(e);
var selectText = select.options[select.selectedIndex].text;
resetOpts();
switch(selectText){
case 'SIM':
var plan = getById('dealGenPlan');
var price = getById('dealGenPrice');
newOpt(plan, '', 'blank', true, plan.options[0]);
plan.disabled = true;
newOpt(price, '', 'blank', true, price.options[0]);
price.disabled = true;
break;
case 'Laptop/Dongle/Modem':
var plan = getById('dealGenPlan');
newOpt(plan, '', 'blank', true, plan.options[0]);
plan.disabled = true;
break;
case 'Pay As You Go':
var price = getById('dealGenPrice');
newOpt(price, '', 'blank', true, price.options[0]);
price.disabled = true;
break;
default:
//Do nothing...
break;
}
}
function newOpt(select, text, val, selected, position){
text = text||'';
val = val||'';
selected = selected||false;
try{
select.add(new Option(text, val, false, selected), position);
}
catch(e){ //in IE, try the below version instead of add()
select.add(new Option(text, val, false, selected), 0);
}
}
function remFirstOpts(selectArr){
for(var i = 0, len=selectArr.length; i < len; i++){
if(selectArr[i].options[0].value=='blank'){
selectArr[i].remove(0);
}
}
}
function resetOpts(){
var selects = [];
selects.push(getById('dealGenHandset'),getById('dealGenPlan'),getById('dealGenPrice'));
remFirstOpts(selects);
for(var i = 0, len = selects.length; i < len; i++){
selects[i].disabled = false;
}
}
function onCustomize(e){
try{
var select = getById('dealGenHandset');
//Remove SIM, Refurb. & Dongles from genre select
for(var i=0; i < 3; i++){
select.remove(select.options.length-1);
}
//Remove Mix & Match from contracts
select = getById('dealGenPlan');
select.remove(1);
}catch(e){alert(e.toString())}
}
this.qServ = function(){
var genDivElm = getById('genDiv');
var url = DGFilename;
url += getOptions();
scriptTag.elementAtts.src = baseUrl + url;
try{
genDivElm.replaceChild(createTag(scriptTag), genDivElm.firstChild);
}catch(e){
alert('Err: whilst injecting script\n' + e.toString());
}
return true;
}
this.addEvent = function(elm, evType, fn, useCapture) {
try{
if (window.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
}
else if (window.attachEvent) {
elm.attachEvent('on'+ evType, fn);
}
else {
elm['on' + evType] = fn;
}
}
catch(e){
alert('Err: in addEvent; ' + e.toLocaleString());
}
}
this.domReady = function(initFunc){
if (document.addEventListener){
document.addEventListener("DOMContentLoaded", initFunc, false);
}
else {
window.attachEvent("onload", initFunc);
// if (document.documentElement.doScroll){
// try{
// document.documentElement.doScroll("left");
// }
// catch(e){
// window.setTimeout(domReady(initFunc), 0);
// return;
// }
// }
// else {
// window.attachEvent("onload", initFunc);
// return;
// }
// initFunc.apply();
}
}
this.init = function(){
var dgb = getById('dealGenBox');
var theHead = document.getElementsByTagName('head');
styleLink.elementAtts.href =
baseUrl
+ 'styles/deal_gen_style_250x250.css?customisation=';
var link = createTag(styleLink);
theHead[0].appendChild(link);
dgb.innerHTML = deal_Generator;
var gb = getById('goButton');
this.addEvent(gb, 'click', this.qServ, false);
var sel = getById('dealGenHandset');
this.addEvent(sel, 'change', onSelectChange, false);
sel2 = getById('dealGenPlan');
this.addEvent(sel2, 'change', onSelectChange, false);
if(customize =='refurbished'){
onCustomize();
}
}
}
var myjax = new MyJax();
myjax.domReady(function(){
myjax.init();
myjax.qServ();
});