/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function comparatorpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

function optional(field,thisEvent)
{
	var ele = 13;
	if (field == 'polity_formation') {ele = 13;}
	if (field == 'polity_government') {ele = 14;}
	if (field == 'polity_legalsystem') {ele = 15;}
	if (field == 'polity_legislature') {ele = 16;}
	if (field == 'polity_electoralsystem') {ele = 17;}
	if (field == 'polity_directdemocracy') {ele = 18;}
	if (field == 'polity_partysystem') {ele = 19;}

	var loc = showContainer(thisEvent);
	
	if (loc != "")
	{
		document.getElementById(loc).getElementsByTagName('div')[13].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[14].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[15].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[16].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[17].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[18].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[19].style.display = 'none';
		document.getElementById(loc).getElementsByTagName('div')[ele].style.display = 'block';
	}
	return false;
}

function showContainer(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
		
		var thisContainer = "";
		while(targ.parentNode)
		{
			if((targ.id == "comparea1") || (targ.id == "comparea2") || (targ.id == "comparea3"))
			{
					thisContainer = targ.id;
					break;
			}
			targ = targ.parentNode;
		}
		return thisContainer;
}

function buildCompForm() {
	var finalHTML = "<option value=\"\">Select a country</option>";
	var pathArray = new Array(
                                    '/uk/orc/bin/9780199574971/01student/map/alg/',
                                    '/uk/orc/bin/9780199574971/01student/map/and/',
                                    '/uk/orc/bin/9780199574971/01student/map/ang/',
                                    '/uk/orc/bin/9780199574971/01student/map/arg/',
                                    '/uk/orc/bin/9780199574971/01student/map/ast/',
                                    '/uk/orc/bin/9780199574971/01student/map/aze/',
                                    '/uk/orc/bin/9780199574971/01student/map/blr/',
                                    '/uk/orc/bin/9780199574971/01student/map/bra/',
                                    '/uk/orc/bin/9780199574971/01student/map/btw/',
                                    '/uk/orc/bin/9780199574971/01student/map/bul/',
                                    '/uk/orc/bin/9780199574971/01student/map/cam/',
                                    '/uk/orc/bin/9780199574971/01student/map/can/',
                                    '/uk/orc/bin/9780199574971/01student/map/chl/',
                                    '/uk/orc/bin/9780199574971/01student/map/col/',
                                    '/uk/orc/bin/9780199574971/01student/map/cos/',
                                    '/uk/orc/bin/9780199574971/01student/map/cro/',
                                    '/uk/orc/bin/9780199574971/01student/map/cub/',
                                    '/uk/orc/bin/9780199574971/01student/map/cyp/',
                                    '/uk/orc/bin/9780199574971/01student/map/den/',
                                    '/uk/orc/bin/9780199574971/01student/map/egy/',
                                    '/uk/orc/bin/9780199574971/01student/map/ger/',
                                    '/uk/orc/bin/9780199574971/01student/map/hun/',
                                    '/uk/orc/bin/9780199574971/01student/map/ind/',
                                    '/uk/orc/bin/9780199574971/01student/map/isr/',
                                    '/uk/orc/bin/9780199574971/01student/map/ita/',
                                    '/uk/orc/bin/9780199574971/01student/map/jap/',
                                    '/uk/orc/bin/9780199574971/01student/map/lei/',
                                    '/uk/orc/bin/9780199574971/01student/map/mex/',
                                    '/uk/orc/bin/9780199574971/01student/map/mol/',
                                    '/uk/orc/bin/9780199574971/01student/map/nia/',
                                    '/uk/orc/bin/9780199574971/01student/map/nic/',
                                    '/uk/orc/bin/9780199574971/01student/map/nor/',
                                    '/uk/orc/bin/9780199574971/01student/map/prc/',
                                    '/uk/orc/bin/9780199574971/01student/map/rus/',
                                    '/uk/orc/bin/9780199574971/01student/map/sau/',
                                    '/uk/orc/bin/9780199574971/01student/map/slk/',
                                    '/uk/orc/bin/9780199574971/01student/map/slv/',
                                    '/uk/orc/bin/9780199574971/01student/map/sou/',
                                    '/uk/orc/bin/9780199574971/01student/map/swi/',
                                    '/uk/orc/bin/9780199574971/01student/map/taj/',
                                    '/uk/orc/bin/9780199574971/01student/map/tur/',
                                    '/uk/orc/bin/9780199574971/01student/map/ukd/',
                                    '/uk/orc/bin/9780199574971/01student/map/usa/'
                                );
	var nameArray = new Array(
                                'Algeria',
                                'Andorra',
                                'Angola',
                                'Argentina',
                                'Australia',
                                'Azerbaijan',
                                'Belarus',
                                'Brazil',
                                'Botswana',
                                'Bulgaria',
                                'Cambodia',
                                'Canada',
                                'Chile',
                                'Columbia',
                                'Costa Rica',
                                'Croatia',
                                'Cuba',
                                'Cyprus',
                                'Denmark',
                                'Egypt',
                                'Germany',
                                'Hungary',
                                'India',
                                'Israel',
                                'Italy',
                                'Japan',
                                'Liechtenstein',
                                'Mexico',
                                'Moldova',
                                'Nigeria',
                                'Nicaragua',
                                'Norway',
                                'P.R. China',
                                'Russia',
                                'Saudi Arabia',
                                'Slovakia',
                                'Slovenia',
                                'South Africa',
                                'Switzerland',
                                'Tajikistan',
                                'Turkey',
                                'United Kingdom',
                                'United States of America');
	
	for (var i in pathArray)
	{
		finalHTML += "<option value=\""+pathArray[i]+"?view=usa\">"+nameArray[i]+"</option>";
	}
	return finalHTML;
}

