/*dup.js - www.instabook.com/design/credcont/dup.js & www.FreeFair.connectfree.co.uk/dup.js */

Warn=-1;
Suspend=-1;

GlobalCheck=0;

function PayTerms(URL,day,month,year,terms,no,fee,mail) {
	this.Title=document.title;
	this.PageURL=URL;
	this.Day=day;
	this.Month=month;
	this.Year=year;
	this.Wait=terms;
	this.InvNo=no;
	this.Amount=fee;
	this.EMailAddr=mail;
	this.RemDay=day+this.Wait;
	this.RemMonth=month;
	this.RemYear=year;
	this.Call='';
	while(this.RemDay>(((this.RemMonth%12)==2)?28:30)){
		this.RemDay-=((this.RemMonth%12)==2)?28:30;
		this.RemMonth++;
	}
	while(this.RemMonth>12) {
		this.RemMonth-=12;
		this.RemYear++;
	}
	this.WarnDay=this.RemDay+15;
	this.WarnMonth=this.RemMonth;
	this.WarnYear=this.RemYear;
	this.Call='';
	while(this.WarnDay>((this.WarnMonth==2)?28:30)){
		this.WarnDay-=(this.WarnMonth==2)?28:30;
		this.WarnMonth++;
	}
	if(this.WarnMonth>12) {
		this.WarnMonth-=12;
		this.WarnYear++;
	}
	this.ExpDay=this.WarnDay+15;
	this.ExpMonth=this.WarnMonth;
	this.ExpYear=this.WarnYear;
	if((this.ExpDay>28 && this.ExpMonth==2) || (this.ExpDay>30)){
		this.ExpDay-=(this.ExpMonth==2)?28:30;
		this.ExpMonth++;
	}
	if(this.ExpMonth>12){
		this.ExpMonth-=12;
		this.ExpYear++;
	}

	this.SetCall=SetCall;
	this.WarnMail=Warnmail;
	this.Expire=Expired;
}

function SetCall(){
	this.Call="http://gif.instabook.com/credcont/enforce.cgi?"+this.PageURL+"!"+this.Title+"!"+this.Day+"!"+this.Month+"!"+this.Year+"!"+this.ExpDay+"!"+this.ExpMonth+"!"+this.ExpYear+"!"+this.InvNo+"!"+this.Amount+"!"+this.EMailAddr;
}

function Warnmail(w){
	if(Warn){
		Message=new Image;
		Message.src= this.Call +((w=='R')?'!R':'!W');
	}
}

function Expired(){
	if(Suspend){
/*		window.location="expired.htm";
*/		window.location=this.Call+'!E';
	}
	else{
		this.WarnMail();
	}
}

function DupToday() {
	var dat = new Date();
	this.Year = dat.getYear();
	this.Month = dat.getMonth()+1;
	this.DayNumber = dat.getDate();
}

function PayCheck() {
	var TermsValid=0;
	var i=0;
	while ((InfoTable[i]!='EndInfo')&&(InfoTable[i]!=null)) {
		Terms = new PayTerms(InfoTable[i],InfoTable[i+1],InfoTable[i+2],InfoTable[i+3],InfoTable[i+4],InfoTable[i+5],InfoTable[i+6],InfoTable[i+7]);
		if(Terms.PageURL==window.location){
			TermsValid=-1;
			break;
		}
		delete Terms;
		i+=8;
	}
	if(TermsValid) {
		CurDate=new DupToday();
		Terms.SetCall();
		if((CurDate.Year>Terms.ExpYear)||((CurDate.Year==Terms.ExpYear)&&(CurDate.Month>Terms.ExpMonth))||((CurDate.Year==Terms.ExpYear)&&(CurDate.Month==Terms.ExpMonth)&&(CurDate.DayNumber>Terms.ExpDay))) {
			Terms.Expire();		}
		else{
			if((CurDate.Year>Terms.WarnYear)||((CurDate.Year==Terms.WarnYear)&&(CurDate.Month>Terms.WarnMonth))||((CurDate.Year==Terms.WarnYear)&&(CurDate.Month==Terms.WarnMonth)&&(CurDate.DayNumber>Terms.WarnDay))) {
				Terms.WarnMail('W');
			}
			else{
				if((CurDate.Year>Terms.RemYear)||((CurDate.Year==Terms.RemYear)&&(CurDate.Month>Terms.RemMonth))||((CurDate.Year==Terms.RemYear)&&(CurDate.Month==Terms.RemMonth)&&(CurDate.DayNumber>Terms.RemDay))) {
					Terms.WarnMail('R');
				}
			}
		}
	}
}			
		
function Print(two,one,three){ // for compatibility. Use Out
	if(GlobalCheck==0){
		PayCheck();
		GlobalCheck=-1;
	}
	document.write(one,two,three);
}
		
function Out(two,four,one,three){
	if(GlobalCheck==0){
		PayCheck();
		GlobalCheck=-1;
	}
	PageCode.HTML+=one+two+three+four;
}

function OutNow(two,four,one,three){
	if(GlobalCheck==0){
		PayCheck();
		GlobalCheck=-1;
	}
	document.write(one+two+three+four);
}

/*Data*/
InfoTable= new Array('EndInfo');

