var kwcallback=function(results)
{
	g('keywordsvalid').innerHTML = results;
	if ( g('loading') ) g('loading').style.display = 'none';
}

function checkkeywords(k1,k2)
{
	ajax.post("index.php",kwcallback,"zajax=true&kw1="+k1+"&kw2="+k2);
	g('loading').style.display = 'inline';
}
var joincallback=function(results)
{
	g('validusername').innerHTML = results;
	if ( g('loading') ) g('loading').style.display = 'none';
}

function checksitename(uname)
{
	ajax.post("index.php",joincallback,"zajax=true&rcsite="+uname);
	g('loading').style.display = 'inline';
}
var checkvaluecallback=function(results)
{
	g('valuecheck').innerHTML = results;
	if ( g('loading2') ) g('loading2').style.display = 'none';
}
var checkusercallback=function(results)
{
	g('usercheck').innerHTML = results;
	if ( g('loading') ) g('loading').style.display = 'none';
}

function checkvalueonly(val)
{
	ajax.post("index.php",checkvaluecallback,"zajax=true&value_check="+val+"&nobal=1");
	g('loading2').style.display = 'inline';
}

function checkvalue(val)
{
	ajax.post("index.php",checkvaluecallback,"zajax=true&value_check="+val);
	g('loading2').style.display = 'inline';
}

function checkuserexists(user)
{
	ajax.post("index.php",checkusercallback,"zajax=true&user_check="+user);
	g('loading').style.display = 'inline';
}
var checkcreateusercallback=function(results)
{
	g('createusercheck').innerHTML = results;
	if ( g('createloading') ) g('createloading').style.display = 'none';
}

function checkcreateuserexists(user)
{
	ajax.post("index.php",checkcreateusercallback,"zajax=true&user_check="+user);
	g('createloading').style.display = 'inline';
}

function checkusercard(user)
{
	if( user.length == 16 )
	{
		ajax.post("index.php",checkusercallback,"zajax=true&secure=true&user_card="+user);
		g('loading').style.display = 'inline';
	}
}
var statescallback=function(results)
{
	g('statelistdiv').innerHTML = results;
	if ( g('loading2') ) g('loading2').style.display = 'none';
}

function getstatelist(country)
{
	ajax.post("index.php",statescallback,"zajax=true&country="+country);
	g('loading2').style.display = 'inline';
}

function getbusinessstatelist(country,title)
{
	ajax.post("index.php",statescallback,"zajax=true&country="+country+"&title="+title);
	g('loading2').style.display = 'inline';
}
var inventorycallback=function(results)
{
	g('inventorydiv').innerHTML = results;
	if ( g('loading2') ) g('loading2').style.display = 'none';
}

function getinventorylist(manager)
{
	ajax.post("index.php",inventorycallback,"zajax=true&manager_id="+manager);
	g('loading2').style.display = 'inline';
}

function recalc()
{
	you = gv('b1')*gv('tx1')*2;
	tier1 = gv('t1')*gv('b1')*gv('tx1');
	tier2 = gv('t1')*gv('t2')*gv('b1')*gv('tx1');
	tier3 = gv('t1')*gv('t2')*gv('t3')*gv('b1')*gv('tx1')*0.5;
	calc = (you/100) + (tier1/100) + (tier2/100) + (tier3/100);
	g('i1').innerHTML = calc;
}

function recalcmobileold()
{
	base = (gv('c1')*gv('m1')*2) + (1*(gv('tx1')));
	you = base*gv('t0')*2; // 2 cents
	tier1 = gv('t0')*gv('t1')*base; // 1 cent
	tier2 = gv('t0')*gv('t1')*gv('t2')*base; // 1 cent
	tier3 = gv('t0')*gv('t1')*gv('t2')*gv('t3')*base; // 1 cent
	calc = (you/100) + (tier1/100) + (tier2/100) + (tier3/100);
	g('i1').innerHTML = calc;
}

function recalcmobileold2()
{
	base = (gv('c1')*gv('m1')*2) + (1*(gv('tx1')));
	personal = (base*2)/100;
	g('p1').innerHTML = personal;
	you = base*gv('t0')*2; // 2 cents
	tier1 = gv('t0')*gv('t1')*base; // 1 cent
	tier2 = gv('t0')*gv('t1')*gv('t2')*base; // 1 cent
	/*tier3 = gv('t0')*gv('t1')*gv('t2')*gv('t3')*base; // 1 cent*/
	calc = (you/100) + (tier1/100) + (tier2/100);/* + (tier3/100);*/
	g('i1').innerHTML = calc;
}

function recalcmobile()
{
	base = (gv('c1')*gv('m1')*2.0) + (1.0*(gv('tx1')));
	you = base*gv('t0')*0.02; // 2 cents
	g('p1').innerHTML = Math.round(you*100)/100;
	tier1 = gv('a1')*gv('t1')*base*0.01; // 1 cent
	tier2 = gv('a1')*gv('t1')*gv('t2')*base*0.01; // 1 cent
	tier3 = gv('a1')*gv('t1')*gv('t2')*gv('t3')*base*0.005; // 0.5 cent*/
	calc = tier1 + tier2 + tier3;
	g('i1').innerHTML = Math.round(calc*100)/100;
}

function recalconlinesms()
{
	base = gv('tx1');
	you = (base*gv('t0')*0.02) + (gv('t0')); // 2 cents + dollar
	g('p1').innerHTML = Math.round(you*100)/100;
	tier1 = (gv('a1')*gv('t1')*base*0.01) + (gv('t1')) + (gv('t1')*gv('a1')*0.2); // 1 cent
	tier2 = (gv('a1')*gv('t1')*gv('t2')*base*0.01) + (gv('t2')*0.2) + (gv('t1')*gv('t2')*gv('a1')*0.1); // 1 cent
	tier3 = (gv('a1')*gv('t1')*gv('t2')*gv('t3')*base*0.005) + (gv('t3')*0.1); // 0.5 cent*/
	calc = tier1 + tier2 + tier3 + you;
	g('i1').innerHTML = Math.round(calc*100)/100;
}

function recalcfounder()
{
	base = (gv('c1')*gv('m1')*0.5) + (0.5*(gv('tx1')));
	month = gv('s1');
	total = month*base;
	growth = gv('g1');
	first = 0;
	for(i=0;i<23;i++)
	{
		month += month*growth/100;
		total += month*base;;
		if( i==11 ) first = Math.round(total*100)/100;
	}
	g('p1').innerHTML = Math.round(first/100,2);
	total = Math.round(total*100)/100;
	g('p2').innerHTML = Math.round((total-first)/100,2);
	g('p3').innerHTML = Math.round(total/100,2);
	g('p4').innerHTML = Math.round(month,2);
}

function g(elem)
{
	return document.getElementById(elem);
}

function gv(elem)
{
	if( g(elem).value )	
		return parseFloat(g(elem).value);
	return 0.0;
}

function showhide(elem)
{
	if( g(elem) && g(elem).style.display=="none" )
		g(elem).style.display="";
	else
		g(elem).style.display="none";
}
