function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;

function preloadImages() {
	if (document.images) {
		menu_01_over = newImage("images/menu_01-over.gif");
		menu_01_down = newImage("images/menu_01-down.gif");
		menu_02_over = newImage("images/menu_02-over.gif");
		menu_02_down = newImage("images/menu_02-down.gif");
		menu_03_over = newImage("images/menu_03-over.gif");
		menu_03_down = newImage("images/menu_03-down.gif");
		menu_04_over = newImage("images/menu_04-over.gif");
		menu_04_down = newImage("images/menu_04-down.gif");
		menu_05_over = newImage("images/menu_05-over.gif");
		menu_05_down = newImage("images/menu_05-down.gif");
		menu_06_over = newImage("images/menu_06-over.gif");
		menu_06_down = newImage("images/menu_06-down.gif");
		preloadFlag = true;
	}
}

preloadImages();

function DD_hours()
{
	var	form=window.document.ahdh;
	var cr=0,hr=0;
	cr=DD_get_max_credits(1);
	if (form.endhour.value-form.starthour.value!=0) hr=cr/((form.endhour.value-form.starthour.value)*form.tdays.value);
	form.hitamt.value=Math.floor(hr);
}
function DD_popin_hours()
{
	var	form=window.document.ahdh;
	var type=form.dd_type.selectedIndex;
	var cr=0,hr=0;	
	cr=DD_get_max_credits();
	if (form.endhour.value-form.starthour.value!=0) hr=cr/((form.endhour.value-form.starthour.value)*form.tdays.value);
	form.hitamt.value=Math.floor(hr);
}
function DD_get_max_credits(popunder)
{
	var type=window.document.ahdh.dd_type.selectedIndex;
	if (popunder)
	{
		if (type==0) return credits;
		if (type==1) return cscredits;
		if (type==2) return adcredits;
	}
	var itemp=!window.document.ahdh.itemp.checked;
	if (itemp)
	{
		if (type==0) return pitcredits;
		if (type==1) return pitcscredits;
		if (type==2) return pitadcredits;
	} else {
		if (type==0) return picredits;
		if (type==1) return picscredits;
		if (type==2) return piadcredits;
	}

}
function DD_help(tag,cdir)
{
	help_win=window.open(cdir+'help.php'+tag,'dd_help_win','scrollbars=yes,resizable=yes,width=300,height=400,left=15,top=20');
}
function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function test_window(form,silent)
{
	var s,r="",w='',h='',t='',l='',cr;
	/*if (isNumberFloat(form.wwidth.value)) w=',width='+form.wwidth.value;
	if (isNumberFloat(form.wheight.value))	h=',height='+form.wheight.value;
	if (isNumberFloat(form.wtop.value)) t=',top='+form.wtop.value;
	if (isNumberFloat(form.wleft.value)) l=',left='+form.wleft.value;
	if (form.wresizable.checked) s="yes";
	else s="no";
	if (form.wscrollbars.checked) r=",scrollbars";
	if (form.wmenubar.checked) r+=",menubar";
	if (form.wstatus.checked) r+=",status";
	if (form.wtoolbar.checked) r+=",toolbar";
	form.wf.value='resizable='+s+r+w+h+t+l;*/
	if ( (form.clickurl.value=="") || (form.clickurl.value=="http://") ) form.clickurl.value="http://yahoo.com";
	if (silent!=1)	{
		open_fbTest(form.clickurl.value,form.wf.value);
		return true;
	}
	if (form.hitamt.value<=0) {alert("The number of visitors per hour must be a positive number"); return false;}
	if (form.tdays.value<=0) {alert("The number of days must be a positive number"); return false;}
	if (form.endhour.value-form.starthour.value<=0) {alert("The time interval is invalid!"); return false;}
	cr=DD_get_max_credits(1);
	//if (confirm ("Starting this campaign will take "+(form.hitamt.value*form.tdays.value*(form.endhour.value-form.starthour.value))+" credits from\nthe total of "+cr+" credits for this type of traffic.\nAre you sure you want to continue?") ) return true;
	return true;
}

function open_fbTest(url,props) {
	if (props=='') props='scrollbars=yes,resizable=yes,width=900,height=700';
	win=window.open('advverify.php?url='+escape(url),'fbTest',props);
	win.focus();
}

function dd_transfer_fields(form1,form2)
{
	for (var i=0; i<form2.elements.length; i++)
		if (form1.elements[form2.elements[i].name].type!="checkbox") {
			form2.elements[i].value=form1.elements[form2.elements[i].name].value;
		} else {
			form2.elements[i].value=form1.elements[form2.elements[i].name].checked;
		}
}
function test_popin(form,silent)
{
	var cr,picr,c_rate,pins,addt;
	if ( (form.ilink.value=="") || (form.ilink.value=="http://") ) form.ilink.value="images/banner1.jpg";
	if ( (form.iclickurl.value=="") || (form.iclickurl.value=="http://") ) form.iclickurl.value="http://yahoo.com";
	if (silent!=1)
	{
		if (!document.once) { alert ("A new browser window will be open.\nYou`ll be able to see the test PopIn floating over it."); document.once=true; }
		dd_transfer_fields(form,window.document.popintestform);
		window.document.popintestform.submit(); 
		return true; 
	}
	if (form.hitamt.value<=0) {alert("The number of visitors per hour must be a positive number"); return false;}
	if (form.tdays.value<=0) {alert("The number of days must be a positive number"); return false;}
	if (form.endhour.value-form.starthour.value<=0) {alert("The time interval is invalid!"); return false;}
	picr=DD_get_max_credits();
	cr=DD_get_max_credits(1);
	c_rate=cr/picr;
	pins=(form.hitamt.value*form.tdays.value*(form.endhour.value-form.starthour.value));
	if (form.itemp.checked) addt= ' permanent';
	else addt='';
	
	if (form.ititle.value=="") {alert("The PopIn title is invalid!"); return false;}
	if (confirm ("Starting this campaign will take "+Math.floor(pins*c_rate)+" credits (for "+pins+addt+" PopIns)\nfrom the total of "+cr+" credits ("+picr+addt+" PopIns) for this type of traffic.\nAre you sure you want to continue?") ) return true;
	return false;
}
function isNumberFloat(inputString)
{
  return ( (inputString<0) || (!isNaN(parseInt(inputString)))) ? true : false;
  //return true;
}

var once=0;
