function sortFunction(D,C){var B=0;
var A=D.id;
var G=C.id;
var F=Number(A.substring(A.lastIndexOf("_")+1));
var E=Number(G.substring(G.lastIndexOf("_")+1));
if(F>E){B=1
}else{if(F<E){B=-1
}}return B
}function createList(E,B,G,A){if(typeof (A)=="undefined"){A=true
}var F=document.createElement("div");
$(F).addClass(B);
$(F).attr("id",B);
if(G.length>0){G.sort(sortFunction);
for(var D=0;
D<G.length;
D++){$(F).append(G[D]);
if(A&&D>1&&((D+1)%2)===0){var C=document.createElement("br");
$(C).css("clear","both");
$(F).append(C)
}}}$(E).append(F)
}function organizeFields(B){var D=$("#large_center_div_"+B);
var A=$("."+B+"_group_1").get();
var F=$("."+B+"_group_2").get();
var E=$("."+B+"_group_3").get();
var C=$("."+B+"_group_99").get();
createList(D,"group1_"+B,A,false);
createList(D,"group2_"+B,F);
createList(D,"group3_"+B,E,false);
createList(D,"group99_"+B,C)
}var offerMap=new Object();
var selectedOffers=new Object();
function showLargeOfferWindow(D,E,F,B,G,H,A){var C="";
showLargeOfferWindowPt(D,E,F,B,G,H,A,C)
}function doScriptExecution(C,B,H,E,F,G,A,D){organizeFields(C);
var J={beforeSubmit:onBeforeSubmit,success:function(K){var L=K.offerid;
$(".checkable").removeAttr("disabled");
$(".checkable").removeAttr("disabled");
$(".error").empty();
if(K.status==1){$("#submit_button_"+L).removeAttr("disabled");
$("#nothanks_"+L).removeAttr("disabled");
$("#status_"+L).empty();
$("#status_"+L).text(K.data);
showOfferRuleMismatchErrors(K,L);
I.focusInvalid();
window.scroll(0,0)
}else{$("#status_"+L).empty();
$("#status_"+L).text(K.data);
$("#templateOfferWindow_"+L).hide();
if(G&&G!="false"){document.getElementById("payload").value=K.payload;
document.getElementById("responsecode").value=K.responsecode;
document.getElementById("url").value=K.url;
document.getElementById("responsedetails").value=K.responsedetails;
$("#debuglog").text(K.debuglog)
}closeLargeOfferWindow(L,B,H,E,F,G,true,D);
selectedOffers[L]="true";
if(D=="SINGLE_COREG"){if(K.data.indexOf("Thank you!")>=0){document.nextform.action="/path.html";
document.nextform.method="post";
document.nextform.submit()
}}}},dataType:"json"};
var I=$("#form_"+C).validate({errorPlacement:function(L,M){var N="#field_label_"+M[0].id;
var K=$(N);
$(K).after(L)
},submitHandler:function(K){$(K).ajaxSubmit(J)
}});
if(A){Date.format=A.toLowerCase()
}$(".date-pick_"+C).datepicker({changeYear:true,dateFormat:"dd/mm/yy",yearRange:"1920:2040"});
$("#nothanks_"+C).bind("click",{offerId:C,pageType:D},customNoThanks)
}function showLargeOfferWindowPt(C,B,I,F,G,H,A,D){var E="offerId="+C+"&preview="+G+"&test="+H+"&pageType="+D+"&curPathId="+B+"&curLeadId="+I+"&curViewedPages="+F;
if(!offerMap[C]){$.ajax({url:"/template.html",type:"GET",dataType:"html",data:E,success:function(J){offerMap[C]=J;
$(J).appendTo("#templateOfferWindow_"+C);
doScriptExecution(C,B,I,F,G,H,A,D);
$("#templateOfferWindow_"+C).slideDown("slow")
}})
}else{$("#templateOfferWindow_"+C).slideDown("slow")
}}function showOfferRuleMismatchErrors(A,B){var F=A.fieldErrors;
for(var C in F){var E=F[C];
var D=document.getElementById("field_label_"+C+"_"+B);
D.innerHTML+=" <span id='offerRuleErrors'  class='error' style='font-weight:normal; ' >"+E+"</span>"
}}function onBeforeSubmit(C,D,B){var A=D[0].offerId.value;
$(".checkable").attr("disabled","disabled");
$(".checkable").attr("disabled","disabled");
$("#submit_button_"+A).attr("disabled","disabled");
$("#nothanks_"+A).attr("disabled","disabled");
selectedOffers[A]="submitted"
}var page_type="";
function rejectOffer(C,D,F,A,G,H,B){page_type=B;
var E="offerId="+C+"&preview="+G+"&test="+H+"&curPathId="+D+"&curLeadId="+F+"&curViewedPages="+A;
$(".checkable").attr("disabled","disabled");
$(".checkable").attr("disabled","disabled");
$.ajax({url:"/validatesubmitoffer/validatesubmitoffer.html?action=rejectOffer",type:"GET",dataType:"json",data:E,success:function(I){var J=I.offerid;
$("#status_"+J).empty();
$("#status_"+J).text(I.data);
$(".checkable").removeAttr("disabled");
$(".checkable").removeAttr("disabled");
if(page_type=="SINGLE_COREG"){if($.inArray("submit",$("#nextform").data("events"))){document.nextform.action="/path.html";
document.nextform.method="post";
document.nextform.submit()
}}else{$("#submit_button_"+J).removeAttr("disabled");
$("#nothanks_"+J).removeAttr("disabled")
}}});
$("#templateOfferWindow_"+C).hide();
selectedOffers[C]="false"
}function closeLargeOfferWindow(D,E,F,B,G,H,A,C){if(typeof (C)=="undefined"){C="SINGLE_COREG"
}if(!A){$("#yes_"+D).removeAttr("checked","checked");
$("#no_"+D).attr("checked","checked");
rejectOffer(D,E,F,B,G,H);
selectedOffers[D]="nothanks"
}else{$("#templateOfferWindow_"+D).hide()
}}function customNoThanks(B){var E=B.data.offerId;
var F=B.data.pageType;
var C=B.data.curPathId;
var J=B.data.curLeadId;
var H=B.data.curViewedPages;
var G="offerId="+E+"&curPathId="+C+"&curLeadId="+J+"&curViewedPages="+H+"&preview=false&test=false";
var A=B.data.popUnder;
if(A&&$("#addEmail").length){var K="scrollbars=1, resizable=1, toolbar=0, location=1, menubar=1, status=1, directories=0",I=$("#addEmail").val();
var D=null;
D=window.open(I,"",K);
if(D===null){D=window.open(whereto,"",K)
}D.blur();
window.focus()
}$.ajax({url:"/validatesubmitoffer/validatesubmitoffer.html?action=rejectOffer",type:"GET",dataType:"json",data:G,success:function(L){$("#status_"+E).empty();
$("#status_"+E).text(L.data);
if(F=="SINGLE_CUSTOM_CREATIVE"||F=="SINGLE_COREG"){if($.inArray("submit",$("#nextform").data("events"))){document.nextform.action="/path.html";
document.nextform.method="post";
document.nextform.submit()
}}}});
$("#templateOfferWindow_"+E).hide();
selectedOffers[E]="true"
}function isAllAcceptedRejected(F,C){var A=0;
var E=0;
var H=0;
var D=0;
var G=0;
if(selectedOffers){var B;
for(B in selectedOffers){var I=selectedOffers[B];
if(I=="false"){H++
}else{if(I=="true"){E++
}else{if(I=="nothanks"){H++;
D++
}else{if(I=="submitted"){G++
}}}}A++
}if(A>1&&A!==0){if(E===0&&D===0&&G===0){alert(F);
return false
}}if(A==offerCount){return true
}}alert(C);
return false
}function submitOffer(B,C,D){var A="";
submitOffer(B,C,D,A)
}function clickCPAOffer(C,B,D,E,A,F,G){selectedOffers[C]="true";
if(!B||B=="false"){window.open("/cpa.html?offerId="+C+"&curPathId="+D+"&curLeadId="+E+"&curViewedPages="+A)
}else{}}function submitOffer(B,D,E,A){var C="offerId="+B+"&preview="+D+"&test="+E;
$(".checkable").attr("disabled","disabled");
$(".checkable").attr("disabled","disabled");
$("#submit_button_"+B).attr("disabled","disabled");
$("#nothanks_"+B).attr("disabled","disabled");
$.ajax({url:"/validatesubmitoffer/validatesubmitoffer.html?action=acceptOffer",type:"GET",dataType:"json",data:C,success:function(F){var G=F.offerid;
$(".error").empty();
if(F.status==1){$("#submit_button_"+G).removeAttr("disabled");
$("#nothanks_"+G).removeAttr("disabled");
$("#status_"+G).empty();
$("#status_"+G).text(F.data);
showOfferRuleMismatchErrors(F,G);
validator.focusInvalid()
}else{$("#status_"+G).empty();
$("#status_"+G).text(F.data);
$("#templateOfferWindow_"+G).hide()
}if(E&&E!="false"){$("#payload").text(F.payload);
$("#responsecode").text(F.responsecode);
$("#url").text(F.url);
$("#responsedetails").text(F.responsedetails)
}$(".checkable").removeAttr("disabled");
$(".checkable").removeAttr("disabled")
}});
selectedOffers[B]="true";
if(A=="SINGLE_COREG"){if($.inArray("submit",$("#nextform").data("events"))){setTimeout(function(){document.nextform.action="/path.html";
document.nextform.method="post";
document.nextform.submit()
},3000)
}}}function clearLoadingIcon(){$("#loadingIconDiv").empty()
}function offerTestResults(A,B){clearLoadingIcon();
if(A.status==1){$("#status_${offer.id}").empty();
$("#status_${offer.id}").text(A.data)
}else{$("#status_${offer.id}").empty();
$("#status_${offer.id}").text(A.data);
$("#payload").text(A.payload);
$("#responsecode").text(A.responsecode);
$("#url").text(A.url);
$("#responsedetails").text(A.responsedetails);
$("#debuglog").html(A.debuglog)
}}function addLoadingIcon(C,B,A){$("#loadingIconDiv").empty();
var D=document.createElement("img");
$(D).attr("src","/images/loading_red.gif");
$(D).attr("alt","loading");
$(D).appendTo("#loadingIconDiv")
}function customSubmitButton(C,D,B){var A=D[0].offerId.value;
$("#submitloadingspinner").show();
document.getElementById("submit_button_"+A).disabled=true;
document.getElementById("nothanks_"+A).disabled=true
}function bindLargeCustomOffer(B,C,A,G,D,F){if(typeof (F)=="undefined"){F=false
}else{if(F=="true"){F=true
}else{F=false
}}var E=$("#form_"+B).get();
organizeFields(B);
$("#templateOfferWindow_"+B).show();
document.getElementById("templateOfferWindow_"+B).style.display="block";
var I={beforeSubmit:customSubmitButton,success:function(J){$("#submitloadingspinner").hide();
var K=J.offerid;
$(".error").empty();
if(J.status==1){$("#submit_button_"+K).removeAttr("disabled");
$("#nothanks_"+K).removeAttr("disabled");
$("#status_"+K).empty();
$("#status_"+K).text(J.data);
showOfferRuleMismatchErrors(J,K);
H.focusInvalid()
}else{$("#submit_button_"+K).removeAttr("disabled");
$("#nothanks_"+K).removeAttr("disabled");
$("#status_"+K).empty();
$("#status_"+K).text(J.data);
selectedOffers[K]="true";
if(C=="SINGLE_CUSTOM_CREATIVE"||C=="SINGLE_COREG"){if($.inArray("submit",$("#nextform").data("events"))){document.nextform.action="/path.html";
document.nextform.method="post";
document.nextform.submit()
}}}if(F&&F!="false"){document.getElementById("payload").value=J.payload;
document.getElementById("responsecode").value=J.responsecode;
document.getElementById("url").value=J.url;
document.getElementById("responsedetails").value=J.responsedetails;
$("#debuglog").text(J.debuglog)
}},dataType:"json",error:function(){$("#submitloadingspinner").hide()
}};
$("#nothanks_"+B+",#addEmail").bind("click",{offerId:B,pageType:C,curPathId:A,curLeadId:G,curViewedPages:D,popUnder:($(this).attr("id")=="addEmail")?true:false},customNoThanks);
var H=$("#form_"+B).validate({errorPlacement:function(K,L){var M="#field_label_"+L[0].id;
var J=$(M);
$(J).after(K)
},submitHandler:function(J){if($(".blocCoregPI").size()>0){if($('input[id*="repOui"]').is(":checked")){$(J).ajaxSubmit(I)
}else{$("#nothanks_"+B).trigger("click")
}}else{if($("#popLinkValue").length){window.open($("#popLinkValue").val(),"offerWindow")
}$(J).ajaxSubmit(I)
}}});
$(".date-pick_"+B).datepicker({changeYear:true,dateFormat:"dd/mm/yy",yearRange:"1920:2040"})
}function beforeNoThanks(C,D,B){var A=D[0].offerId.value;
document.getElementById("submit_button_"+A).disabled=true;
document.getElementById("nothanks_"+A).disabled=true
}var once_per_session=0;
var winfeatures="scrollbars=1, resizable=1, toolbar=0, location=1, menubar=1, status=1, directories=0";
var popunder="";
var pathid="";
function get_cookie(A){var B=A+"=";
var C="";
if(document.cookie.length>0){offset=document.cookie.indexOf(B);
if(offset!=-1){offset+=B.length;
end=document.cookie.indexOf(";",offset);
if(end==-1){end=document.cookie.length
}C=unescape(document.cookie.substring(offset,end))
}}return C
}function loadpopunder(){if(popunder==""||pathid==""){return false
}var A="";
if(!popunder.match(/http|html/)){var B="";
if(typeof (royalmail_leadid)!="undefined"&&royalmail_leadid!=""){B=royalmail_leadid
}else{if(typeof (aussiemail_leadid)!="undefined"&&aussiemail_leadid!=""){B=aussiemail_leadid
}}if(B!=""&&pathid!=""){popunder="/cpa.html?offerId="+popunder+"&curPathId="+pathid+"&curLeadId="+B+"&curViewedPages=0&ispopunder=true"
}A=popunder
}else{A=popunder+"&first="+document.getElementById("firstName").value+"&last="+document.getElementById("lastName").value+"&email="+document.getElementById("email").value
}var C=null;
C=window.open(A,"",winfeatures);
if(C===null){C=window.open(A,"",winfeatures)
}C.blur();
window.focus()
}function loadornot(){if(get_cookie("popunder")==""){loadpopunder();
document.cookie="popunder=yes"
}}function pop(){if(once_per_session===0){loadpopunder()
}else{loadornot()
}}function appendScriptElement(B,C){var A=document.createElement("script");
A.type="text/javascript";
A.src=C;
$("#optInHere").replaceWith(A)
}$().ready(function(){$(".smallConfirm input").dblclick(function(){return false
});
$(".smallConfirm input").click(function(){var C=$(this).siblings("input"),B=C.attr("class"),A=C.val().replace(/[ ']/g,"").split(",");
if(B=="reject"){rejectOffer(A[0],A[1],A[2],A[3],A[4],A[5],A[6])
}else{clickCPAOffer(A[0],A[1],A[2],A[3],A[4],A[5],A[6])
}})
})
