﻿var iMade = 0;
var iOrigin = 0;

function window_load( )
{
	if ( document.getElementById( "price" ) != null )
	{
		
		if ( document.getElementById( "time" ) != null && document.getElementById( "slots" ) != null )
		{
			startPrice( );
		}
		if ( document . getElementById( "add" ) != null )
		{
			document . getElementById( "add" ) . style . display = "none";
			document . getElementById( "add2" ) . style . display = "";
		}
	}
	
	if ( document.getElementById( "gmMax" ) != null )
	{
		iMade = parseInt( document . getElementById( "gmMax" ) . innerHTML );
		iOrigin = parseInt( document . getElementById( "gmMax" ) . innerHTML );
	}
	
	positionFooter( );

}

function positionFooter( )
{
	if ( document.getElementById( "containerDiv" ) != null && document.getElementById( "containerFooter" ) != null )
	{
		if ( document.getElementById( "containerContent" ).offsetHeight +410 > 820 )
			document.getElementById( "containerFooter" ).style.top = document.getElementById( "containerContent" ).offsetHeight +410 + "px";
		else
			document.getElementById( "containerFooter" ).style.top = 820 + "px";
	}
}

function startPrice( )
{
	oAjax = new ajaxReq( ); 
	var oTime = document.getElementById( "time" );
	var oSlots = document.getElementById( "slots" );
	var oId = document.getElementById( "server_id" );
	oAjax . sendReq( '/java/do/price/' + oId . value + '/' + oTime . value + '/' + oSlots . value + '/', setPrice );

}

function setPrice( fAmount )
{
	var oPrice = document.getElementById( "price" );
	oPrice . innerHTML = fAmount;
}

function addCart( sTime, sSlots, sServer, sName )
{
	oTime = typeof( sTime ) != 'undefined' ? sTime : document.getElementById( "time" ).value;
	oSlots = typeof( sSlots ) != 'undefined' ? sSlots : document.getElementById( "slots" ).value;
	oId = typeof( sServer ) != 'undefined' ? sServer : document.getElementById( "server_id" ).value;
	sOptional = typeof( sName ) != 'undefined' ? sName : '';
	

	
	var cart=document.getElementById( "cart" );
	cart.innerHTML += '<br /><br /><img src="images/loading.gif" alt="Loading" />';
	if ( document.getElementById( 'add2' ) ) document.getElementById( 'add2' ).disabled = true;

	oAjax = new ajaxReq( ); 
	//var oTime = document.getElementById( "time" );
	//var oSlots = document.getElementById( "slots" );
	//var oId = document.getElementById( "server_id" );

	oAjax . sendReq( '/java/do/addcart/' + oId + '/' + oTime + '/' + oSlots +  ( sOptional != '' ? '/' + sOptional : '' ) + '/?show=true', updateCart );
	
	//oAjax = new ajaxReq( ); 
	//oAjax . sendReq( '/java/do/showcart/', updateCart );
	//alert( "Item added to cart" );
}

function delCart( iId )
{
	
	var cart=document.getElementById( "cart" );
	cart.innerHTML += '<br /><br /><img src="images/loading.gif" alt="Loading" />';
	if ( document.getElementById( 'add2' ) ) document.getElementById( 'add2' ).disabled = true;
	
	oAjax = new ajaxReq( ); 
	oAjax . sendReq( '/java/do/delcart/' + iId + '/?show=true', updateCart );
	
	//oAjax = new ajaxReq( ); 
	//oAjax . sendReq( '/java/do/showcart/', updateCart );
	return false;
}

function setLoc( iId, iLoc )
{
	var cart=document.getElementById( "finalCart" );
	cart.innerHTML += '<br /><br /><img src="images/loading.gif" alt="Loading" />';

	
	oAjax = new ajaxReq( ); 
	oAjax . sendReq( '/java/do/setcartlocation/' + iId + '/' + iLoc + '/?show=true', function( sString ) { document.getElementById( 'finalCart' ).innerHTML = sString; } );

	return false;
}

function updateCart( sString )
{
	var cart=document.getElementById( "cart" );
	cart.innerHTML = sString; 
	if ( document.getElementById( 'add2' ) ) document.getElementById( 'add2' ).disabled = false;
}

function addGameMode( )
{

	var aGm = document . getElementById( "parentThing" );
	var aGmNew = document . createElement( "div" );
	
	//var iId = document . getElementById( "gmMax" ) . innerHTML;
	iMade = iMade + 1;
	iId = iMade + '';
	aGm.appendChild( aGmNew );

	aGmNew.setAttribute( "id", "p_gm" + iId );
	document . getElementById( "gm" ) . id = "gm" + iId;
	document . getElementById( "gm" + iId ) . name = "gm" + iId;
	document . getElementById( "t_gm" ) . name = "t_gm" + iId;
	document . getElementById( "t_gm" ) . id = "t_gm" + iId;
	
	if ( document . getElementById( "t_pro" ) )
	{
		document . getElementById( "t_pro" ) . name = "t_pro" + iId;
		document . getElementById( "t_pro" ) . id = "t_pro" + iId;
	}
	
	var sSource = document . getElementById( "p_gm" ) . innerHTML;
	sSource = sSource . replace( "p-gm", "p_gm" + iId  );
	document . getElementById( "gm" + iId ) . id = "gm";
	document . getElementById( "gm" ) . name = "gm";
	document . getElementById( "t_gm" + iId ) . name = "t_gm";
	document . getElementById( "t_gm" + iId ) . id = "t_gm";
	
	if ( document . getElementById( "t_pro" ) )
	{
		document . getElementById( "t_pro" + iId ) . name = "t_pro";
		document . getElementById( "t_pro" + iId ) . id = "t_pro";
	}
	aGmNew . innerHTML = sSource;
	positionFooter( );


}

function delGameMode( sId )
{

	var aGm2 = document . getElementById( sId );
	var aGm = aGm2 . parentNode;
	
	aGm . removeChild( aGm2 );
	positionFooter( );

}


function showInvoice( iId )
{
	var oObject = document . getElementById( "invoice_" + iId );
	if ( oObject . style . display == 'none' )
	{
		oObject . style . display = '';
	}
	else
	{
		oObject . style . display = 'none';
	}
	positionFooter( );

}

function showTicket( iId )
{
	var oObject = document . getElementById( "tick_" + iId );
	if ( oObject . style . display == 'none' )
	{
		oObject . style . display = '';
	}
	else
	{
		oObject . style . display = 'none';
	}
	positionFooter( );

}

function showSupport( iId )
{
	var oObject = document . getElementById( "reply_" + iId );
	if ( oObject . style . display == 'none' )
	{
		oObject . style . display = '';
	}
	else
	{
		oObject . style . display = 'none';
	}
	positionFooter( );

}

function showNew( )
{
	var oObject = document . getElementById( "new_ticket" );
	if ( oObject . style . display == 'none' )
	{
		oObject . style . display = '';
		positionFooter( );
	}
	else
	{
		oObject . style . display = 'none';
		positionFooter( );
	}

}




/*
	This is the javascript for moving our cart/Account thing
*/


		function displaySwitch( oObject )
		{
			if ( oObject . style . display == 'none' )
			{
				oObject . style . display = '';
			}
			else
			{
				oObject . style . display = 'none';
			}

		}
		 
		 
		function setMove( bGrow )
		{
			var oObj = document.getElementById( "contentRight" );
			var oObjB = document.getElementById( "contentLeft" );
			var oObjC = document.getElementById( "contentSplitter" );
			var oObjD = document.getElementById( "arrowContent" );

			if ( ! oObj || ! oObjB )
			 return ;

			if ( bGrow == true )
			{
				var iWidth = parseInt( oObj.style.width ); // removes the "px" at the end
				var iWidthB = parseInt( oObjB.style.width ); // removes the "px" at the end
				var iWidthD = parseInt( oObjD.style.left ); // removes the "px" at the end
				
				
				if ( parseInt( oObj . style  . width ) <= 215 )
					oObj.style.width = ( iWidth  + 20 ) + "px";

				if ( parseInt( oObjB . style  . width ) >= 690 )
				{
					oObjB.style.width = ( iWidthB  - 10 ) + "px";
					oObjD.style.left = ( iWidthD  - 10 ) + "px";
				}

				oObjC.style.backgroundPosition = ( iWidthB + 9 ) + "px 0px";
				
				if ( parseInt( oObjB . style  . width ) <= 710 )
				{
					oObj.style.display='';
					oObj.style.opacity = parseFloat( oObj.style.opacity ) + .3;
					
				}

				if ( parseFloat( oObj.style.opacity ) >= .9 )
				{
					oObjD.innerHTML = '<a href="#" onclick="enableMove( false ); return false;"><img src="images/arrow_right.png" alt=">" /></a>'
					clearInterval( iScaleTimerB );
				}
			}
			else if ( bGrow == false )
			{

				var iWidth = parseInt( oObj.style.width ); // removes the "px" at the end
				var iWidthB = parseInt( oObjB.style.width ); // removes the "px" at the end
				var iWidthD = parseInt( oObjD.style.left ); // removes the "px" at the end
				
				
				if ( parseFloat( oObj.style.opacity ) >= 0 )
					oObj.style.width = ( iWidth  - 20 ) + "px";
				oObjB.style.width = ( iWidthB  + 10 ) + "px";
				oObjD.style.left = ( iWidthD  + 10 ) + "px";

				oObjC.style.backgroundPosition = ( iWidthB + 15 ) + "px 0px";
				oObj.style.opacity = parseFloat( oObj.style.opacity ) - .2;
				
				if ( parseFloat( oObj.style.opacity ) <= 0 )
					oObj.style.display='none';
				
				if ( parseInt( oObjB . style  . width ) > 890 )
				{
					oObjD.innerHTML = '<a href="#" onclick="enableMove( true ); return false;"><img src="images/arrow_left.png" alt="<" /> </a>'
					clearInterval( iScaleTimerB );
				}
			}
			else
			{

				var iWidth = parseInt( oObj.style.width ); // removes the "px" at the end
				var iWidthB = parseInt( oObjB.style.width ); // removes the "px" at the end
				var iWidthD = parseInt( oObjD.style.left ); // removes the "px" at the end
				
				
				if ( parseFloat( oObj.style.opacity ) >= 0 )
					oObj.style.width = ( iWidth  - 20 ) + "px";
				oObjB.style.width = ( iWidthB  + 10 ) + "px";
				oObjD.style.left = ( iWidthD  + 10 ) + "px";

				oObjC.style.backgroundPosition = ( iWidthB + 15 ) + "px 0px";
				oObj.style.opacity = parseFloat( oObj.style.opacity ) - .2;
				
				if ( parseFloat( oObj.style.opacity ) <= 0 )
					oObj.style.display='none';
				
				if ( parseInt( oObjB . style  . width ) > 890 )
				{
					oObjD.innerHTML = ''
					clearInterval( iScaleTimerB );
					oObj.innerHTML = '';
				}
			}
		}
		
		function enableMove( bGrow )
		{
			iScaleTimerB = setInterval( "setMove( " + bGrow + " )", 40 );
		}
		
		function enableMoveStay(  )
		{
			iScaleTimerB = setInterval( "setMove( -1 )", 40 );
		}
		
		
		function setHideShow( bShow )
		{
			var oObj = document.getElementById( "account" );

			if ( ! oObj )
			 return ;

			if ( bShow )
			{
				oObj.style.right = "-20px";
				oObj.style.display = '';
				oObj.style.opacity = parseFloat( oObj.style.opacity ) + .2;

				if ( oObj.style.opacity >= 1 )
				{
					clearInterval( iScaleTimer );
					document.getElementById( "accountLink" ).innerHTML = '<a href="#" onclick="enableHideShow( false ); return false;"><img width="91" height="86" src="images/navi/account.png" alt="About Us" /></a>'
				}
			}
			else
			{

				
				oObj.style.opacity = parseFloat( oObj.style.opacity ) - .2;

				if ( oObj.style.opacity <= 0 )
				{
					oObj.style.right = "-2000px";
					oObj.style.display = 'none';
					document.getElementById( "accountLink" ).innerHTML = '<a href="#" onclick="enableHideShow( true ); return false;"><img width="91" height="86" src="images/navi/account.png" alt="About Us" /></a>'
					clearInterval( iScaleTimer );
				}
			}
		}
		
		function enableHideShow( bGrow )
		{
			iScaleTimer = setInterval( "setHideShow( " + bGrow + " )", 100);
		}
		
function clearMe( sWhere, sDefault )
{
	oWhere = document.getElementById( sWhere );
	if ( oWhere.value == sDefault || oWhere.value == '' )
	{
		oWhere.value = '';
	}
	
}

function fixValue( sWhere, sDefault )
{
	oWhere = document.getElementById( sWhere );
	if ( oWhere.value == '' )
	{
		oWhere.value = sDefault;
	}
	else if ( oWhere.value == sDefault )
	{
		oWhere.value = '';
	}
}


function insertText( iWhich )
{
	if ( iWhich == 1 )
	{
		document.getElementById( 'comment' ) . value = "Hello ^NAME, \nOne of our support people are assisting you right now, and require you to identify yourself before further assistance is allowed. Please repeat the code below so you may continue with finding a solution. \n\nYour code is: '" + randomString( 5 ) + "-" + randomString( 4 ) + "'\n\nThank you,\ndabberz.com Autobot Sender";

	}
	else if ( iWhich == 2 )
	{
		document.getElementById( 'comment' ) . value = "Hello ^NAME, \nOne of your ordered servers has been activated! \nThe server id is: (INSERT ID HERE).\n\nYou can now login to your account and manage your server in our control panel!\nhttp://www.dabberz.com/cp/\n\nExtra Information:\nProduct Type: (INSERT TYPE HERE)\nSlots: (INSERT SLOTS HERE)\nTime: (INSERT MONTHS HERE) Months\nThank you,\ndabberz.com Autobot Sender";
	}
	else if ( iWhich == 3 )
	{
		document.getElementById( 'comment' ) . value = "Hello ^NAME, \n\n\nThank you,\n\ndabberz.com Autobot Sender";
	}
	else
	{
		
	}
}


function randomString( iLength )
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
	var string_length = iLength;
	var randomstring = '';
	for ( var i = 0; i<string_length; i++ )// >
	{
		var rnum = Math.floor( Math.random( ) * chars.length );
		randomstring += chars.substring( rnum,rnum + 1 );
	}
	return randomstring;
}