$.ajaxSetup ({   
    cache: false  
});
var superarray=new Array ();
var promoarray=new Array ();
var adagency = 0;
var paypal = 0;
var salestax = 0;
var nonprofit = 0;
var audioprice = 0;
var sameweekextra = 0;
var juneautotal = 0;
var morefactor = 1;
sar = new Array();//promocode array
adsarray = new Array();
adsarray[2] = "Double Exposure";
adsarray[3] = "Triple Exposure";
adsarray[4] = "4x Exposure";
 
//database table columns
dtc = 9;
dtc1 = 4;

 

 

  function limitChars(textid, limit, infodiv)

  {

  var text = $('#'+textid).val(); 

  var textlength = text.length;

  if(textlength > limit)

  {

  $('#' + infodiv).html('You cannot write more then '+limit+' characters!');

  $('#'+textid).val(text.substr(0,limit));

  return false;

  }

  else

  {

  $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');

  return true;

  }

  }

 

function checkemail(){
var str = $("input[name=Email]").val()
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{

testresults=false
}
return (testresults)
}

function checkform2()
{

required = new Array('Bname' , 'Fname', 'Lname',   'Baddy', 'Bcity', 'Bzip', 'Phone1', 'Email');

for ( var i in required )
{

    if ( $("input[name="+required[i]+"]").val() == null || $("input[name="+required[i]+"]").val() == '')
	{
	//alert(required[i]);
	return false;
	}
}

return true;
}

function getweekindex(weeks)
{
var weekindex = 0;
//alert("weeks"+weeks);
if (weeks >= 1 && weeks <= 3)
{
weekindex = 1;
}
else if (weeks >= 4 && weeks <= 15)
{
weekindex = 2;
}
else if (weeks >= 16 && weeks <= 29)
{
weekindex = 3;
}
else if (weeks >= 30 && weeks <= 43)
{
weekindex = 4;
}
else if (weeks >= 44)
{
weekindex = 5;
}
//alert("weekindex"+weekindex);
return weekindex;
}


function gettotalprice(rate, screens, weeks)
{
//alert(rate);

total = rate * screens * weeks;

return total;
}

function getpromovalue(code)
{

//alert (seconds);
//alert (screens);
//alert (weekindex);
tva = new Array();
for (x = 0;x<promoarray.length;x++)
{
if (promoarray[x][0] == code)
{
tva[0] = promoarray[x][1];
tva[1] = promoarray[x][2];
return tva;
}
}
return tva;
}


function getrawrate(seconds, screens, weekindex)
{
weekindex = weekindex + 3;
//alert (seconds);
//alert (screens);
//alert (weekindex);

 
for (x = 0;x<superarray.length;x++)
{

if (superarray[x][1] == seconds && screens >= superarray[x][2] && screens <= superarray[x][3] )
{

return superarray[x][weekindex];
}
}

}

function assignpromoarray(rt)
{

var sa=rt.split(",");
var yy = -1;
var z = 0;
for (x = 0;x<sa.length;x++)
{
if (x == 0 || ((x % dtc1) == 0 ))
{
z=0;
yy++;
promoarray[yy] = new Array(dtc1);
}
promoarray[yy][z] = sa[x];
//alert(promoarray[yy][z]);
z++;
}

return promoarray;
}


function assignsuperarray(rt)
{
//alert(rt);
var sa=rt.split(",");
var yy = -1;
var z = 0;
for (x = 0;x<sa.length;x++)
{
if (x == 0 || ((x % dtc) == 0 ))
{
z=0;
yy++;
superarray[yy] = new Array(dtc);
}
superarray[yy][z] = sa[x];
z++;
}

return superarray;
}



function screens()

{
sp = 0;
juneauscreens = 0;
sg = new Array();
for (varc=1;varc<=6;varc++)
{
if ($('#screen'+varc).is(':checked'))
{
   $("#spanscreen"+varc).show();
//alert($('#screenradio1').val());
if ($('input[name=screenradio'+varc+']:checked').val() != null)
{
full = $('input[name=screenradio'+varc+']:checked').val();
aa = full.split("#");
sp += Number(aa[0]);
if(varc == 1 || varc == 2)
{
juneauscreens += Number(aa[0]);
}
}
else
{
$('input[name=screenradio'+varc+']:nth(0)').attr("checked", true); 
full=$('input[name=screenradio'+varc+']:nth(0)').val();
aa = full.split("#");
sp += Number(aa[0]);
if(varc == 1 || varc == 2)
{
juneauscreens += Number(aa[0]);
}
}
}
else
{
$("#spanscreen"+varc).hide();
}
}
sg[0] = sp;
sg[1] = juneauscreens;
return sg;
}

function bonusweeks (weeks)

{

if (weeks > 15 && weeks < 30)
{
return 4;
}
else if (weeks > 29 && weeks < 43)
{
return 6;
}
else if (weeks > 43)
{
return 8;
}
return 0;
}

function printarray(arraya)
//2d array ..This is for debugging
{
arrayb = new Array();
arrayb = arraya;
var df= 'xyz';

for (x = 0;x<arrayb.length;x++)
{
for (y = 0; y<4; y++)
{
df = df + "\n"+ arrayb[x][y];
}
}
alert(arrayb.length);
array1 = new Array();
alert ("baba");

alert (df);
}

