var handleSuccess = function(response)
	{
		if (response.responseText !== undefined)
		{
			document.getElementById('publicationOrderFormDiv').innerHTML = response.responseText;
		}
	};

var callback = 
	{
		success: handleSuccess
	};


function hideElement(elementID)
{
	if( document.getElementById(elementID) )
	{
		div = document.getElementById(elementID);
		if( div.style.display == "block" )
			div.style.display = "none";
	}
}

function hideAllElements(arrayOfElements)
{
	for(var i = 0; i < arrayOfElements.length; i++)
	{
		hideElement('categoryArticles_' + arrayOfElements[i]);
	}
}

function showElement(elementID)
{
	if( document.getElementById(elementID) )
	{
		div = document.getElementById(elementID);
		if( div.style.display == "none" )
			div.style.display = "block";
	}
}

function toggleArea(id)
{
	if( document.getElementById(id).style.display == "none" ) {
		document.getElementById(id).style.display = "";
	}
	else {
		document.getElementById(id).style.display = "none";
	}
}

function toggleTableRow(id)
{
	if( document.getElementById(id).style.display == "none" ) {
		document.getElementById(id).style.display = "";
	}
	else {
		document.getElementById(id).style.display = "none";
	}
}

function toggleCopiesTableRow(id)
{
	toggleTableRow(id);

	document.getElementById("article_id_nl").value = 0;

}

function loadForm()
{
	var request = YAHOO.util.Connect.asyncRequest('POST', '/common/classes/publication_order/ajaxForm.php', callback);
}

function goToContactForm()
{
	var articlesDOM = document.getElementsByName('articles');
	var articles = new Array();	
	
	for(var i = 0; i < articlesDOM.length; i++)
	{
		if (articlesDOM[i].value > "0")
		{
			articles[i] = {
				"articleID" : articlesDOM[i].id,
				"orderValue" : articlesDOM[i].value
									 };
		}
	}
	
	var postData = 'action=contactForm&jsonData=' + YAHOO.lang.JSON.stringify(articles);
	
	var request = YAHOO.util.Connect.asyncRequest('POST', '/common/classes/publication_order/ajaxForm.php', callback, postData);
	
}

function goToPreview()
{
	var fields = ['name', 'address', 'city', 'province', 'postalCode', 'email', 'orgName', 'phone', 'fax'];
												
	var contactInformation = new Array();
	var doSubmit = true;
	
	for (var i = 0; i < fields.length; i++ )
	{
		contactInformation[i] = new Array(2);
		contactInformation[i][0] = fields[i];
		contactInformation[i][1] = document.getElementById(fields[i]).value;
	}
		
	if (doSubmit == true)
	{
		var postData = 'action=preview&jsonData=' + YAHOO.lang.JSON.stringify(contactInformation);
		
		var request = YAHOO.util.Connect.asyncRequest('POST', '/common/classes/publication_order/ajaxForm.php', callback, postData);
	}
}

function submitOrder()
{
	var postData = 'action=printView';
	
	var request = YAHOO.util.Connect.asyncRequest('POST', '/common/classes/publication_order/ajaxForm.php', callback, postData);
}

function loadView(viewName)
{
	var postData = 'action=' + viewName + '&edit=true';
	
	var request = YAHOO.util.Connect.asyncRequest('POST', '/common/classes/publication_order/ajaxForm.php', callback, postData);
}