function Calc_Price()
{
	var PricePerClick	= 1000;
	
	var ddlMonth		= MM_findObj("ddlMonth");
	var ddlDuration		= MM_findObj("ddlDuration");
	
	var ClickNumber		= ddlMonth.value  * ddlDuration.value  ;
	
	if ( ClickNumber >= 3000 ) 
		DiscountRate = .25
	else if ( ClickNumber >= 2500 ) 
		DiscountRate = .20		
	else if ( ClickNumber >= 2000 )
		DiscountRate = .15
	else if ( ClickNumber >= 1500 ) 
		DiscountRate = .10		
	else if ( ClickNumber >= 1000 ) 
		DiscountRate = .05
	else if ( ClickNumber >= 500 ) 
		DiscountRate = .02
	else 
		DiscountRate = 0
		
	var lblOrder			= MM_findObj("lblOrder");
	var lblDiscount			= MM_findObj("lblDiscount");
	var lblDiscountPrice	= MM_findObj("lblDiscountPrice");
	var lblPrice			= MM_findObj("lblPrice");
	

	lblOrder.innerHTML			= FormatNumber( ""+ClickNumber );
	lblDiscount.innerHTML		= FormatNumber( ""+DiscountRate * 100 );
	lblPrice.innerHTML			= FormatNumber( ""+Math.round( ClickNumber * PricePerClick) );
	lblDiscountPrice.innerHTML	= FormatNumber( ""+Math.round( ClickNumber * PricePerClick - (ClickNumber * PricePerClick *DiscountRate)) );	
	
	MM_findObj("txtPriceClick").value		= lblDiscountPrice.innerHTML;
	MM_findObj("txtPriceClickInt").value	= Math.round( ClickNumber * PricePerClick - (ClickNumber * PricePerClick *DiscountRate));
}

function Calc_Price_View()
{

	var PricePerView		= 40;
	
	var ddlDailyView		= MM_findObj("ddlDailyView");
	var ddlDurationView		= MM_findObj("ddlDurationView");
	
	var OrderViews			= ddlDailyView.value  * ddlDurationView.value ;
	var DiscountRate;
	
	if ( OrderViews >= 40000 ) 
		DiscountRate = .25
	else if ( OrderViews >= 30000 ) 
		DiscountRate = .20		 
	else if ( OrderViews >= 20000 ) 
		DiscountRate = .15
	else if ( OrderViews >= 10000 ) 
		DiscountRate = .10		
	else if ( OrderViews >= 5000 ) 
		DiscountRate = .05		
	else
		DiscountRate = 0

	var lblOrderView		= MM_findObj("lblOrderView");
	var lblDiscountView		= MM_findObj("lblDiscountView");
	var lblTotalView		= MM_findObj("lblTotalView");
	var lblPriceView		= MM_findObj("lblPriceView");
		
	lblOrderView.innerHTML			= FormatNumber(""+OrderViews);
	lblDiscountView.innerHTML		= FormatNumber(""+Math.round( 100 * DiscountRate) );
	lblPriceView.innerHTML			= FormatNumber(""+Math.round( OrderViews * PricePerView) );
	lblDiscountPriceView.innerHTML	= FormatNumber(""+Math.round( OrderViews * PricePerView - (OrderViews * PricePerView *DiscountRate) ) );
		
	MM_findObj("txtPriceView").value	= lblDiscountPriceView.innerHTML;		
	MM_findObj("txtPriceViewInt").value	= Math.round( OrderViews * PricePerView - (OrderViews * PricePerView *DiscountRate) );		
	
}


function FormatNumber(str)
{
var temp	= "";
var i		= 0;
var length	= str.length;
for (i=length; i>=0; i--)
{
	temp = PerianNumber(str.charAt(i)) +temp;
	if ( ((length-i)%3==0) & (i!=length) & (i!=0) )
		temp = "," +temp;
}
return temp;
}

function PerianNumber(digit)
{
var output	= "";
switch (digit)
{
	case "0":
		output = "\u0660";
		break;
	case "1":
		output = "\u0661";
		break;
	case "2":
		output = "\u0662";
		break;
	case "3":
		output = "\u0663";
		break;
	case "4":
		output = "\u0664";
		break;
	case "5":
		output = "\u0665";
		break;
	case "6":
		output = "\u0666";				
		break;
	case "7":
		output = "\u0667";
		break;
	case "8":
		output = "\u0668";
		break;
	case "9":
		output = "\u0669";
		break;
	default:
		output = digit;
		break;																																						
}
return output;
}

function ChangeViewTableAccessibility(accessibility)
{
			var status			= !accessibility;
			var table			= MM_findObj("tblAdsbyView");
			var ddlDailyView	= MM_findObj("ddlDailyView");
			var ddlDurationView	= MM_findObj("ddlDurationView");
			if (table!=null)			table.disabled				= status;
			if (ddlDailyView!=null)		ddlDailyView.disabled		= status;
			if (ddlDurationView!=null)	ddlDurationView.disabled	= status;
}

function ChangeClickTableAccessibility(accessibility)
{
			var status			= !accessibility;
			var table			= MM_findObj("tblAdsbyClick");
			var ddlMonth		= MM_findObj("ddlMonth");
			var ddlDuration		= MM_findObj("ddlDuration");
			if (table!=null)		table.disabled			= status;
			if (ddlMonth!=null)		ddlMonth.disabled		= status;
			if (ddlDuration!=null)	ddlDuration.disabled	= status;
}

function GroupClick(chk)
{
	var PricePerGroup		= 100000;
	var DiscountRate		= 0;
	var count				= 0;
	
	var chkAll				= MM_findObj("chkAll");	
	var chkFamily			= MM_findObj("chkFamily");
	var chkChildren			= MM_findObj("chkChildren");
	var chkNews				= MM_findObj("chkNews");
	var chkBuy				= MM_findObj("chkBuy");
	var chkReference		= MM_findObj("chkReference");
	var chkMedical			= MM_findObj("chkMedical");
	var chkSience			= MM_findObj("chkSience");
	var chkArt				= MM_findObj("chkArt");
	var chkEntertainment	= MM_findObj("chkEntertainment");
	var chkIndustry			= MM_findObj("chkIndustry");
	var chkSport			= MM_findObj("chkSport");
	var chkSociety			= MM_findObj("chkSociety");
	var chkComputer			= MM_findObj("chkComputer");
	
	if ((chk.checked)&(chkAll.checked))
	{
		chkFamily.checked			= true;
		chkChildren.checked			= true;
		chkNews.checked				= true;
		chkBuy.checked				= true;
		chkReference.checked		= true;
		chkMedical.checked			= true;
		chkSience.checked			= true;
		chkArt.checked				= true;
		chkEntertainment.checked	= true;
		chkIndustry.checked			= true;
		chkSport.checked			= true;
		chkSociety.checked			= true;
		chkComputer.checked			= true;
		
		count	= 13;
	}
	else if ((chk.id=="chkAll") & (!chk.checked))
	{
		chkFamily.checked			= false;
		chkChildren.checked			= false;
		chkNews.checked				= false;
		chkBuy.checked				= false;
		chkReference.checked		= false;
		chkMedical.checked			= false;
		chkSience.checked			= false;
		chkArt.checked				= false;
		chkEntertainment.checked	= false;
		chkIndustry.checked			= false;
		chkSport.checked			= false;
		chkSociety.checked			= false;
		chkComputer.checked			= false;
		
		count	= 0;
	}
	else 
	{
		if (!chk.checked)				{chkAll.checked = false};
		if (chkFamily.checked)			{count++};
		if (chkChildren.checked)		{count++};
		if (chkNews.checked)			{count++};
		if (chkBuy.checked)				{count++};
		if (chkReference.checked)		{count++};
		if (chkMedical.checked)			{count++};
		if (chkSience.checked)			{count++};
		if (chkArt.checked)				{count++};
		if (chkEntertainment.checked)	{count++};
		if (chkIndustry.checked)		{count++};
		if (chkSport.checked)			{count++};
		if (chkSociety.checked)			{count++};
		if (chkComputer.checked)		{count++};
	}
	
	if ( count >= 10 ) 
		DiscountRate = .25
	else if ( count >= 8 ) 
		DiscountRate = .20		 
	else if ( count >= 6 ) 
		DiscountRate = .15
	else if ( count >= 4 ) 
		DiscountRate = .10		
	else if ( count >= 2 ) 
		DiscountRate = .05		
	else
		DiscountRate = 0

	var lblDiscountText			= MM_findObj("lblDiscountText");
	var lblPriceText			= MM_findObj("lblPriceText");
	var lblDiscountPriceText	= MM_findObj("lblDiscountPriceText");
	
	lblDiscountText.innerHTML		= FormatNumber( ""+Math.round(100 * DiscountRate) );
	lblPriceText.innerHTML			= FormatNumber( ""+Math.round( count * PricePerGroup) );
	lblDiscountPriceText.innerHTML	= FormatNumber( ""+Math.round( count * PricePerGroup - (count * PricePerGroup * DiscountRate) ) );
	
	MM_findObj("txtPriceText").value	= lblDiscountPriceText.innerHTML;
	MM_findObj("txtPriceTextInt").value	= Math.round( count * PricePerGroup - (count * PricePerGroup * DiscountRate) );	
}


function ChangeTableDisplay(id,display)
{
	var table = MM_findObj(id);
	table.style.display		= display;
}

function ValidateGraphic(source, arguments)
{
	var result = false;
	var chkGraphic = MM_findObj("chkGraphic");
	if (chkGraphic.checked)
	{
		var txtFile			= MM_findObj("fBanner");
		var txtGraphicLink	= MM_findObj("txtGraphicLink");
		if ((txtFile.value != "") & (txtGraphicLink.value!=""))
			result = true;
		else
			result = false;
	}
	else
		result = true;
	arguments.IsValid = result;
}

function ValidateText(source, arguments)
{
	var result = false;
	var chkText = MM_findObj("chkText");
	if (chkText.checked)
	{
		var txtTextTitle			= MM_findObj("txtTextTitle");
		var txtTextDescription		= MM_findObj("txtTextDescription");
		var txtTextLink				= MM_findObj("txtTextLink");
		var txtTextURL				= MM_findObj("txtTextURL");
		if ((txtTextTitle.value != "") & (txtTextDescription.value!="") & (txtTextLink.value!="") & (txtTextURL.value!="") )
			result = true;
		else
			result = false;
	}
	else
		result = true;
	arguments.IsValid = result;
}

function ExpandTables()
{
	var chkGraphic	= MM_findObj("chkGraphic");	
	var tblGraphic	= MM_findObj("tblGraphic");		
	var chkText		= MM_findObj("chkText");	
	var tblText		= MM_findObj("tblText");	
	if (chkGraphic.checked)
		tblGraphic.style.display	= "block";
	if (chkText.checked)
		tblText.style.display		= "block";		
}

function ChangeDisabled(id,status)
{
	var item = MM_findObj(id);
	if (item != null)
		item.disabled = status;
}

