var host_domain = "http://"+document.location.host+"/";
//alert(host_domain);
var parameters = "";
var source_url = "";


function checkChecks(num_to_do)
{
		checkAll(num_to_do);
}

function uncheckChecks(num_to_do)
{
		uncheckAll(num_to_do);
}

function checkAll(num_to_do)
{
	for (i = 0; i < num_to_do; i++)
	{
		str = "che" + i;
		document.getElementById(str).checked = true ;
	}

}

function uncheckAll(num_to_do)
{
	for (i = 0; i < num_to_do; i++)
	{
		str = "che" + i;
		document.getElementById(str).checked = false ;
	}
	// Select none

}
function selectPack(checkb)
{
	if($('input[@name='+checkb+']:checked').size() != 0)
	{
		//make all other packs not checkable
		$(".packdisplay").addClass("grayedout");
		$("#pack_"+checkb).removeClass("grayedout");
		$(".packcheck").attr('disabled', true);
		$("#c"+checkb).removeAttr('disabled');		
	}
	else 
	{
		//make all other packs checkable
		$(".packdisplay").removeClass("grayedout");
		$(".packcheck").removeAttr('disabled');		
	}
}
function checkallrecruit(max, status, page, action, sid) 
{
	if (action == 'NEWORDER')
	{
		displayiFrame('recruit/iframes/new_order.php','','New Order');
	}
	else if (action == 'NEWPROSPECT')
	{
		displayiFrame('recruit/iframes/new_prospect.php','','New Prospect');
	}
	else if (action == 'RCM1')
	{
		status = 'PRA';
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=recruit_prospect&status=PRA&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_email_status.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
	else if (action == 'ADCENTREPROSPECTSTATUS')
	{
		if (status == 'AD1')
		{
			status = 'AD2';
			mail_id = 'ADC01';
		}
		else if (status == 'AD5')
		{
			status = 'AD6';
			mail_id = 'ADC01';
		}
		else
		{
			status = 'AD2';
			mail_id = 'ADC01';
		}
		
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=recruit_prospect&status=" + status + "&length=" + checkedItems.length + "&action=" + mail_id + "&sendhtml=1";

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_email_status.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
	else if (action == 'RCM10' || action == 'RCM29' || action == 'RCM33' || action == 'RCM35' || action == 'RCM30' || action == 'RCM34' || action == 'ADCENTREPROSPECTREMINDER')
	{
		//multi_inc_change. .... TODO
		new_status = "";
		
		if (action == 'RCM10') new_status = "ACO";
		if (action == 'RCM29') new_status = "FRD";
		if (action == 'RCM33') new_status = "A1A";
		if (action == 'RCM30') new_status = "A1A";
		if (action == 'RCM35') new_status = "A2A";
		if (action == 'RCM34') new_status = "A2A";
		if (action == 'ADCENTREPROSPECTREMINDER') new_status = "AD4";
		
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=recruit_prospect&status="+new_status+"&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_email_inc.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
	else if (action == 'DELETE')
	{
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=recruit_prospect&status=DEL&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_status_change.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
	else
	{
		var checkedItems = new Array ();
		for (m = 0; m < max; m++) 
		{
				if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)
				{
					checkedItems.push (document.getElementById("id" + m).value);
				}
		}
		var param = "&table=recruit_prospect&status=" + escape (status) + "&length=" + checkedItems.length + "&action=" + action;
			
		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);
			
		url = host_domain + "actions/send_to_all.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
}

function checkallretail(max, status, page, action, sid) 
{
	if (action == 'NEWORDER')
	{
		displayiFrame('retail/iframes/new_order.php','','New Order');
	}
	else if (action == 'NEWPROSPECT')
	{
		displayiFrame('retail/iframes/new_prospect.php','','New Prospect');
	}
	else if (action == 'RTM02')
	{
		status = 'PRA';
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=retail_prospect&status=PRA&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_email_status.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
	else if (action == 'RTM12')
	{
		//multi_inc_change. .... TODO
		new_status = "";
		
		if (action == 'RTM12') new_status = "OAR";
		
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=retail_prospect&status="+new_status+"&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_email_inc.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
	else if (action == 'DELETE')
	{
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=retail_prospect&status=DEL&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);
		
		url = host_domain + "actions/multi_status_change.php?sid=" + sid + param;
		myurl = host_domain + "actions/multi_status_change.php?sid=" + sid + param;
		//alert(host_domain);
		//alert("http://"+document.location.host+"/" + "actions/multi_status_change.php?sid=" + sid + param);
		window.location = url;

	}
	else if (action == 'ARCHIVECONTACTREQUESTS')
	{
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=retail_contact_request&status=CRA&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_status_change.php?sid=" + sid + param;
		window.location = url;
	}
	else if (action == 'DELETECONTACTREQUESTS')
	{
		var checkedItems = new Array ();
		n = 0;
		for (m = 0; m < max; m++) 
		{
				//if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)

				if($('#che'+m).is(':checked')) 
				{
					checkedItems.push (document.getElementById("id" + m).value);

					param += "&var" + n + "=" + escape (document.getElementById("id" + m).value);
					n = n + 1;
				}
		}

		var param = "&table=retail_contact_request&status=DEL&length=" + checkedItems.length + "&action=" + action;

		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);

		
		url = host_domain + "actions/multi_status_change.php?sid=" + sid + param;
		window.location = url;
	}
	else
	{
		var checkedItems = new Array ();
		for (m = 0; m < max; m++) 
		{
				if (document.getElementsByName('che' + m).item(0) != null && document.getElementsByName('che' + m).item(0).checked)
				{
					checkedItems.push (document.getElementById("id" + m).value);
				}
		}
		var param = "&table=retail_prospect&status=" + escape (status) + "&length=" + checkedItems.length + "&action=" + action;
			
		for (n = 0; n < checkedItems.length; n++) 
			param += "&var" + n + "=" + escape (checkedItems[n]);
			
		url = host_domain + "actions/send_to_all.php?sid=" + sid + param;
		//alert(url);
		window.location = url;
	}
}

function displayiFrame(source,params,title,height)
{
	source_url = source;
	parameters = params;
	source_url = host_domain + source_url + "?" + parameters;
	window.location.href = '#back_to_top';
	/*document.getElementById("disable_div").style.display = "block";
	document.getElementById("myiframe").style.display = "block";
	document.getElementById('myiframe').src = source_url;*/
	document.getElementById('myiframe').src = source_url;
	$('#dialog').dialog('option', 'title', title);
	if (height != "")
	{
		$('#dialog').dialog('option', 'height', height);
		document.getElementById('myiframe').style.height = height;
	}
	$("#dialog").dialog("open") ;
}

function closeMyFrame()
{	
  // var iframe = document.getElementById('myiframe');
  // iframe.style.display = "none";
  var slocation = window.location.href;
  slocation = slocation.replace("#back_to_top","");
  
 // if ($('#dialog').dialog('option', 'title') != "Add Calendar Event")
	window.location.href = slocation;
   //document.getElementById("disable_div").style.display = "none";
}

function closeMyFrameWithoutReload()
{	
	$("#dialog").dialog("close") ;
   //document.getElementById("disable_div").style.display = "none";
   
}

function checkForSelect()
{
	if (document.getElementById("for").value == "Let me choose specific affiliates")
	{
		displayiFrame("promotions/iframes/choose_affiliates.php","",'Choose Affiliates',"450");
	}
}
