﻿// JScript File
var bPopOffer = true;
function popUp(theURL,Win_Height,Win_Width,Win_Name) 
{         
window.open(theURL,Win_Name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=452,height=350");
}

function popUpHelp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=350,left = 10,top = 10');");
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function NeedHelp(i_type) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('help/help.aspx?id=" + i_type + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=350,left = 10,top = 10');");
}

function popUpExamp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=350,left = 10,top = 10');");
}

function AffiliateProgram(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=640,height=480,left = 0,top = 0');");
}

function popUpDoc(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=740,height=480,left = 0,top = 0');");
}

function popUpCalendar(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=290,left = 10,top = 10');");
}

function isGoodEmail(src) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.isGoodEmail(src);
}

function _ShowPopupCalendar( i_strFormName, i_strFieldName,i_blnHistory ) {
	var strURL = '/common/popcalendar.asp?FormName=' + i_strFormName + '&FieldName=' + i_strFieldName;
	if (i_blnHistory)
		strURL = strURL + '&History=on';
	else
		strURL = strURL + '&History=off';
	window.datefield = document.forms[i_strFormName][i_strFieldName]; 
	window.open( strURL + '&date=' + window.datefield.value, 'cal', 'WIDTH=295,HEIGHT=310' );
}      
	
var exit=false;	
function DontLeave(URL) {
	if (exit) {
		day = new Date();
		id = day.getTime();
		//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=275,left = 376,top = 294.5');");
	}
}	

var winCal = null;
function NewWindow(mypage,myname,w,h,scroll) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left=';
	settings = settings + LeftPosition+',scrollbars='+scroll+',resizable';
	winCal = window.open(mypage,myname,settings)
	if (winCal.window.focus) { winCal.window.focus(); }
}
function trim( i_value ) {
	return i_value.replace( /^[ ]+|[ ]+$/g, '' );
}
function AgeAtToday(i_strDOB) {
	//RETURNS AGE (AS INTEGER), GIVEN THE DOB AND ANOTHER DATE
	//WILL RETURN -1 IF ENCOUNTERS AN ERROR
	var dtDOB = new Date(i_strDOB);
	var dtDate = new Date();
	if (isNaN(dtDOB) || isNaN(dtDate)) { return -1; }
	var intAge;
	intAge = dtDate.getFullYear() - dtDOB.getFullYear();
	dtDOB.setYear(dtDate.getFullYear())
	dtDOB.setHours(0, 0, 0, 0);
	dtDate.setHours(0, 0, 0, 0);
	if (dtDate < dtDOB) { intAge --; }
	return intAge;
}
function ValidateCheck(sender, args) {
    var Container = new String;
    Container = sender.id;
    Container = Container.replace('cstAgree', '');
	args.IsValid = document.forms[0][Container + 'chkTerms'].checked;
}
function CheckAge(sender, args) {
    var Container = new String;
    Container = sender.id;
    Container = Container.replace('cstDOB', '');
	var ThisMonth = trim(document.forms[0][Container + 'cmbDOBMonth'].options[document.forms[0][Container + 'cmbDOBMonth'].options.selectedIndex].value);
	var ThisDay = trim(document.forms[0][Container + 'cmbDOBDay'].options[document.forms[0][Container + 'cmbDOBDay'].options.selectedIndex].value);
	var ThisYear = trim(args.Value);
	var FullDate = ThisMonth + '/' + ThisDay + '/' + ThisYear;
	if (!isNaN( new Date(FullDate))) {
		if (AgeAtToday(FullDate) < 18) {
			args.IsValid = false;
			return;
		}
	}
	args.IsValid = true;
}
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}
function ValidABA(sender, args) {
	var s = document.getElementById("txtABA").value;
	// Run through each digit and calculate the total.
	var c = 0;
	var i = 0;
	var n = 0;
	var t = "";
	try {
		for (i = 0; i < s.length; i++) {
			c = parseInt(s.charAt(i), 10);
			t = t + c;
		}

		// Check the length, it should be nine digits.
		if (t.length != 9)
			args.IsValid = false;

		// Now run through each digit and calculate the total.
		n = 0;
		for (i = 0; i < t.length; i += 3) {
			n += (parseInt(t.charAt(i), 10) * 3) + (parseInt(t.charAt(i + 1), 10) * 7) + parseInt(t.charAt(i + 2), 10);
		}

   		// If the resulting sum is an even multiple of ten (but not zero),
		// the aba routing number is good.
		args.IsValid = (n != 0 && n % 10 == 0);
	}
	catch(err) {
		args.IsValid = false;
	}
}
// BEGIN: Pop-up calendar code
var calendar_window;
var pay_struct = '';
function Get_Pay_Structure() {
	return pay_struct;
}
function Set_Pay_Structure(obj)
{
    pay_struct = obj.value;
}
function SetPayDates(iDtBox1, iDtBox2, iFrequencyID)
{
    var obj = document.getElementById(iDtBox1)
    var dDate = new Date(obj.value);
    var iFrequency = 0; //Frequency in secs
    var iSecs = 0;
    obj = document.getElementById(iFrequencyID)
    
    switch(obj.value) //Set Difference in Seconds
    {
        case '52': //weekly
            iFrequency =  604800000;    // 7 x 24 * 60 * 60 * 1000
            break;
        case '26': //biweekly
            iFrequency =  1209600000;   // 604800000 * 2
            break;
        // twice-a-month and monthly has too many scenerios
        // lets not do anything to confuse the customers
    }
    
    if (iFrequency > 0) //weekly or biweekly lets use the secs to calculate
    {
        iSecs = Number(dDate) + iFrequency; //new date in seconds
        var dDate = new Date(iSecs);
        obj = document.getElementById(iDtBox2);
        if (obj != null)
        {   obj.value = (dDate.getMonth() + 1) + '/' + dDate.getDate() + '/' + dDate.getFullYear();    } 
    }
}
// END: Pop-up calendar code

//this is for the offers pop up
function CancelPop()
{
	bPopOffer = false;
}
function PopOffer(sOffer)
{
    if (bPopOffer == true)
    {
        window.open(sOffer);
    }
}


//this closes popup window and goes to Contact page form
function gotoApply() {
	if (window.opener) {
		window.opener.location='/Default.aspx';
		self.close();
	}
	else {
		window.location = '/Default.aspx';
	}
}

//this closes popup window and goes to Contact page form in AUTO site
function gotoApply2() {
	if (window.opener) {
		window.opener.location='/proc/auto-leads-for-dealers.aspx';
		self.close();
	}
	else {
		window.location = '/proc/auto-leads-for-dealers.aspx';
	}
}

function ValidABA(sender, args) {
	var ctl = new String;
	ctl = sender.id;
	ctl = ctl.replace("CustomABA", "txtABA");
	var s  = document.getElementById(ctl).value;
	// Run through each digit and calculate the total.
	var c = 0;
	var i = 0;
	var n = 0;
	var t = "";
	try {
		for (i = 0; i < s.length; i++) {
			c = parseInt(s.charAt(i), 10);
			t = t + c;
		}

		// Check the length, it should be nine digits.
		if (t.length != 9)
			args.IsValid = false;

		// Now run through each digit and calculate the total.
		n = 0;
		for (i = 0; i < t.length; i += 3) {
			n += (parseInt(t.charAt(i), 10) * 3) + (parseInt(t.charAt(i + 1), 10) * 7) + parseInt(t.charAt(i + 2), 10);
		}

   		// If the resulting sum is an even multiple of ten (but not zero),
		// the aba routing number is good.
		args.IsValid = (n != 0 && n % 10 == 0);
	}
	catch(err) {
		args.IsValid = false;
	}
}
function ValidatePaydate(sender, args) {
    ctl = sender.id;
    alert(ctl);
}

/* hide button */
function DisableButton(obj)
{   obj.style.display = 'none'; }
function EnableButton(cid)
{    document.getElementById(cid).style.display = '';   }
