// JavaScript Document
var xmlhttp = false;
var objDHTML = (document.getElementById || document.all || document.layers);


if (!xmlhttp && typeof XMLHttpRequest !='undefined') {
	xmlhttp = new XMLHttpRequest();
}

function validateForm() {
	var objform = document.forms.adform;
		
	if (objform.height.value=="") {
		alert("Please enter a height!");
		objform.height.focus();
	}
	else if (objform.width.value=="") {
		alert("Please enter a width!");
		objform.width.focus();
	}
	else if (objform.colour.value=="") {
		alert("Please enter a Colour!");
		objform.colour.focus();
	}
	else {
		ajax_call('GET', 'ad_cost.php', '', 'Calculate_Cost()');
	}
	return false;
}

function getFormObjects() {
	var objform = document.forms.adform;
	var request_str = "";
	var formobj, radio_obj, chkbox_obj, rad_ischecked=false, chkbox_ischecked=false;
	var i, j;

	for (i=0;i<objform.length;i++) {
		formobj = objform.elements[i];
		// Get text elements
		switch (formobj.type) {
			case "text":
			case "textarea":
				request_str += formobj.name + "=" + formobj.value + "&";
			break;
			// Get radio box elements
			case "radio":
				radio_obj = objform[objform[i].name];
				for(j=0; j<radio_obj.length; j++) {
					if(radio_obj[j].checked) {
						if(!rad_ischecked) {
							request_str += formobj.name + "=" + radio_obj[j].value + "&";
							rad_ischecked = true;
						}
						break;
					}
				}
			break;
			// Get checkbox elements
			case "checkbox":
				chkbox_obj = objform[objform[i].name];
			
				for(j=0; j<chkbox_obj.length; j++) {
					if(chkbox_obj[j].checked && !chkbox_ischecked) {
						request_str += formobj.name + "[" + j + "]=" + chkbox_obj[j].value + "&";
					}
					else {
						chkbox_ischecked = true;
					}
				}			   
			break;
			// Get single drop-down elements
			case "select-one":
				for(j=0; j<formobj.options.length; j++) {
					if(formobj.options[j].selected && formobj.options[j] != "") {
						request_str += formobj.name + "=" + formobj.options[j].value + "&";
					}
				}
			break;
			default:
			break;
		}
	}
	//return request_str;
	return request_str;
}

function createRequestObject() {
	if(window.XMLHttpRequest) {
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Could not create new ActiveXObject! Please check your browser settings.");
			}
		}
	}
}

function sendRequest(formmethod, url, formstr, callback_function)
{
	alert("ReadyState: " + xml.readyState);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete')
		{
			if (xmlhttp.status == 200) {
				eval(callback_function);
			} else{
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
		}
	};
	if(formmethod=="POST"){
		xmlhttp.open(formmethod, url, true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
		xmlhttp.setRequestHeader("Content-length", formstr.length);//parameters.length
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(formstr);	
	} else{	
		xmlhttp.open(formmethod, url + '?' + formstr, true);
		xmlhttp.send(null);
	}	
}

	
function ajax_call(formmethod, url, parameters, callback_function)
{
	var formstr = getFormObjects();
	
	createRequestObject();
		
	if (!xmlhttp) {
		alert("Your browser does not support this feature!");
		return false;
	}
		
	sendRequest(formmethod.toUpperCase(), url, formstr, parameters, callback_function);
	
	return false;
}

function getDivObj(divname) {
	var divobj;
	
	if (document.getElementById) {
		divobj = document.getElementById(divname);
	} else if (document.all)  {
		divobj = document.all[divname];
	} else if (document.layers)  {
		divobj = document.layers[divname];
	}
	return divobj;
}

/*function showDiv(divname, option)
{
	divDisplay(divname, option);
	
}*/

function divDisplay(divname, displayOpt)
{
	if (!objDHTML) return;
	var divobj = new getDivObj(divname);
	divobj.style.display = (displayOpt)? (displayOpt=='inline'?'':displayOpt) : (divobj.style.display=='inline'|| divobj.style.display=='') ? 'none' : '';	
}

function ShowMoreText(pagenumber) {
	var page1, page2, page3, page4, page5;
	page1 = "The Advertising Department has been in existence since Nation Publishing was created in 1973. The primary objective of this department is to work with clients and help them find the best ways to promote and sell their products and services using the Nation's wide range of advertising options. </p>";
	page1 += "<p>Through a well trained team of sales professionals. The Nation's advertising department can handle all the needs of advertisers from, rate quotations, booking ads, providing advise on how to maximize advertising spend, overseeing advertising campaigns, as well as developing artwork and copy for ads.</p>";
	page1 += "<p>The advertising department is divided into 5 key areas:<br /><br /><strong>Retail Advertising</strong><br />This section of the advertising team comprises sales executives who work directly with clients. From first contact, they work to develop an intimate knowledge of each client's business and help them get the most of their advertising campaigns with the Nation newspaper and other specialized publications produced by Nation Publishing such as Better Health Magazine etc.";
	page1 += "<p><strong>Classified Advertising</strong><br />";
	page1 += "The classified team is made up of:";
	page1 += "<ul><li>Classified advisors who handle advertising for the traditional classified pages of the newspaper such as, but not limited to family notices, auto guide, real estate, items for sale and vacancies.</li></ul>";
	page2 = "<ul><li>Classified sales executives who work primarily with small commercial business clients.</li></ul>";
	page2 += "<p><strong>Fourth Estate</strong><br />This is the commercial section. Fourth estate comprises writing and public relations experts who work directly with clients to develop press releases, newspaper advertorials and supplements. The team also works closely with our advertising sales executives to create special advertising and editorial sections, which deliver niche market segments for advertisers.";
	page2 += "<p><strong>Clerical Department</strong><br />The clerical team is responsible for providing advertising advice to \"walk-in\" advertising clients and for the processing of all ad bookings. This team ensures that ads appear in the relevant advertising media on time and in the right position. They are also responsible with working with the accounts department to ensure that clients are billed accurately and receive receipts and invoices for their advertising as required. </p>";
	page2 += "<strong>Art Department</strong><br />This group of talented artists design ads for internal and external clients.";
	page2 += "<p>To ensure that you gain maximum benefit from your advertising with the Nation, <a href='contact_us.html'>contact</a> our lead advertising team.</p> ";
	page3 = "<table border=0 cellpadding=0 cellspacing=0 width='452' valign='top'><tr><td colspan='4'>&nbsp;</td></tr><tr><td width='35'>&nbsp;</td><td width='85' valign='top'><img src='ad_images/w_field_1.jpg' width='85' height='100' style='border: 1px #333333 solid;'></td><td width='15'>&nbsp;</td><td><span class='bodytext-whitebghdr'>Wilfred Field</span><br />Advertising Manager/ Director<br />Tel: 246-430-5510<br />Email: <a href='mailto:wilfredfield@nationnews.com'>wilfredfield@nationnews.com</a></td></tr>";
	page3 += "<tr class='textdiv'><td colspan='4' height='40'>&nbsp;</td></tr><tr><td width='35'>&nbsp;</td><td width='85' valign='top'><img src='ad_images/p_jones_1.jpg' width='85' height='100' style='border: 1px #333333 solid;'></td><td width='15'>&nbsp;</td><td valign='top'><span class='bodytext-whitebghdr'>Paulette Jones</span><br />Assistant Advertising Manager<br />Tel: 246-430-5412<br />Email: <a href='mailto:paulettejones@nationnews.com'>paulettejones@nationnews.com</a><br /></td></tr></table>";
	page4 = "<table border=0 cellpadding=0 cellspacing=0 width='452' valign='top'><tr><td colspan='4'>&nbsp;</td></tr></tr><tr class='textdiv'><td width='35'>&nbsp;</td><td width='85' valign='top'><img src='ad_images/t_marshall_1.jpg' width='85' height='100' style='border: 1px #333333 solid;'></td><td width='15'>&nbsp;</td><td><span class='bodytext-whitebghdr'>Trevor Marshall</span><br />Advertising Administration Manager<br />Tel: 246-430-5512<br />Email: <a href='mailto:trevormarshall@nationnews.com'>trevormarshall@nationnews.com</a></td></tr>";
	page4 += "<tr class='textdiv'><td colspan='4' height='40'>&nbsp;</td></tr><tr><td width='35'>&nbsp;</td><td width='85' valign='top'><img src='ad_images/v_hope_1.jpg' width='85' height='100' style='border: 1px #333333 solid;'></td><td width='15'>&nbsp;</td><td valign='top'><span class='bodytext-whitebghdr'>Valerie Hope</span><br />Marketing Executive<br />Tel: 246-430-5589<br />Email: <a href='mailto:valeriehope@nationnews.com'>valeriehope@nationnews.com</a></td></tr></table>";

	var obj = document.getElementById('textdiv');
	switch(pagenumber) {
		case 1:
			obj.innerHTML = page1;
			document.getElementById('arrow').innerHTML = "<a href='javascript: void(0)' onclick='ShowMoreText(2);return false;'>Page 2&nbsp;<span class='arrow'>&raquo;</span></a>";
		break;
		case 2:
			obj.innerHTML = page2;
			document.getElementById('arrow').innerHTML = "<a href='javascript: void(0)' onclick='ShowMoreText(1);return false;'><span class='arrow'>&laquo;</span>&nbsp;Page 1</a>";				
		break;
		case 3:
			obj.innerHTML = page3;
			document.getElementById('arrow').innerHTML = "<a href='javascript: void(0)' onclick='ShowMoreText(4);return false;'>Page 2&nbsp;<span class='arrow'>&raquo;</span></a>";
		break;
		default:
			obj.innerHTML = page4;
			document.getElementById('arrow').innerHTML = "<a href='javascript: void(0)' onclick='ShowMoreText(3);return false;'><span class='arrow'>&laquo;</span>&nbsp;Page 1</a></a>";
		break;
	}
}