var countryCode = "";
var CountryName = '';
var Currency = '';

if (document.cookie && document.cookie.indexOf('Country')>-1){

	countryCode = readCookie('Country');

	if(! countryCode.indexOf('none'))countryCode='';

	if(countryCode != '')
		document.write("<SCRIPT LANGUAGE='JavaScript' SRC='/oag/resources/js/"+countryCode + ".js'><\/SCRIPT>");
}

function setCountry (fieldName) {
var expires = new Date();
expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000) * 365 );

var c_str = "Country="+fieldName+ ";expires="+expires.toGMTString() ;
c_str+="; path=/; domain=.oag.com;";

document.cookie= c_str;
}


function displayEditions(editionData) {


// if any variables not set do not do table
if(editionData == '' || countryCode =='' ) return ;
//loop through editions and check there is a valid price, if not - return






var containsMonthlyBilling = false ;

var OAGRegion = itemList.getOAGRegion();





//Start table

var entryList = new items();
entryList.setOAGRegion(OAGRegion);

//break into records on #, then break into fields on ~
var versionArray=editionData.split('#');

for (i=0;i<versionArray.length;i++){

	var editionArray=versionArray[i].split('~');
	versionDesc=editionArray[0];
	versionId=editionArray[1];
	show=editionArray[2];
	showBuy=editionArray[3];
	group=editionArray[4];
	prod=editionArray[5];


	if(itemList.findItem(versionId) != null){
		
		var editionItem = new item();
editionItem = itemList.findItem(versionId);
editionItem.setEdition(versionDesc);

if(showBuy == 'N'){
	editionItem.setShowBuyButton(false);
}
else{
	editionItem.setShowBuyButton(true);
}

var orderUrl = "https://safe.oag.com/cart/OAGAddItemToShoppingCart.do?regionCode=" + OAGRegion + "&subscriptionDefId=" + versionId + "&country=" + countryCode;

editionItem.setUrl(orderUrl);


	if(show == 'Y'){
		//alert('' + editionItem.toString());
		entryList.add(editionItem);
	}

}
	
}//end loop		

	createPricingTable(entryList) ; 
	//entryList.clear();
	


}

function createPricingTable(entries){

//startPricingTable();

var containsMonthlyBilling = false ; 

var lst = new Array();

lst = entries.getItemsList(); 

for(i=0;i<lst.length;i++){
	
	var tmpitem = lst[i]; 
	
	if(tmpitem.getPriceType() == 0) {
		containsMonthlyBilling = true  ; 
	}
	
}


 addPricingTableHeader(containsMonthlyBilling);

	for(i=0;i<lst.length;i++){
		
		var monthlyItem = lst[i] ; 
		
		var annualItem = entries.findEdition(monthlyItem.getEdition() , monthlyItem.getId());
		
		if(annualItem != null){
			entries.remove(entries.findItemIndex(annualItem.getId));
		}
		
		if(monthlyItem.getShowBuyButton()) {
			addpricing(monthlyItem,annualItem) ; 
		}

	}

endPricingTable(containsMonthlyBilling);	
	
	lst.clear();
	
}


function addPricingTableHeader(containsMonthlyBilling){

	document.write('<table width="313" border="0" align="center" cellpadding="0" cellspacing="0" summary="Header detailing editions and price" bgcolor="#e6eef7">');
	document.write('<tr><td width="10"><IMG SRC="'+img_bhl+'" WIDTH="10" HEIGHT="23" BORDER="0" ></td>');
	document.write('<td nowrap="nowrap" width="153" background="'+img_bhm+'" class="whiteboldstandard">Edition</td>');


	if(containsMonthlyBilling){
		document.write('<td nowrap="nowrap" width="77" background="'+img_bhm+'" class="whiteboldstandard">Monthly*</td>');
		document.write('<td nowrap="nowrap" background="'+img_bhm+'" class="whiteboldstandard" align="left">Annual</td>');
	}
	else{
		document.write('<td nowrap="nowrap" background="'+img_bhm+'" class="whiteboldstandard">Price</td>');
	}

	document.write('<td width="10"><IMG SRC="'+img_bhr+'" WIDTH="10" HEIGHT="23" BORDER="0" ></td>');
	document.write('</tr><tr height="10"><td></td></tr></table>');

}


function addpricing(monthlyItem,annualItem){



document.write('<table width="313" cellpadding="0" cellspacing="0" border="0" bgcolor="#e6eef7"><tr>');
document.write('<td class="blacksmall" width="165">');
document.write('<span style="padding-left:5px">' + monthlyItem.getEdition() + '</span>') ; 
document.write('</td>');		

document.write('<td');

if(annualItem != null) document.write(' width="65" ');

document.write(' align="left">');
addBuyButton(monthlyItem);
document.write('</td>');
		
document.write('<td width=10><IMG SRC="'+xspacer+'" WIDTH="10" BORDER="0" height="25"></td>');
		
			if(annualItem != null){
				document.write('<td align="left" width="65"">');
				addBuyButton(annualItem);
				document.write('</td>');
			}
			else{
				document.write('<td align="left" width="65"><IMG SRC="'+xspacer+'" WIDTH="20" BORDER="0" ></td>'); 
			}
			
document.write('<td width=10><IMG SRC="'+xspacer+'" WIDTH="10" BORDER="0" height="25"></td>');
document.write('</tr><tr height="10"><td colspan="5"><IMG SRC="'+xspacer+'" height="10" BORDER="0" ></td></tr></table>');


}


function addBuyButton(item){

document.write('<table width="65" border="0" cellpadding="0" cellspacing="0" summary="buy button"><tr>');
		document.write('<td width="5" height="25"><IMG SRC="'+img_li+'" WIDTH="5" HEIGHT="25" BORDER="0" ></td>');
		document.write('<td width="55" align="center" nowrap="nowrap" background="'+img_mi+'">');
		document.write('<a title="Buy" class="blacklink" href="' + item.getUrl() + '">'+getCurrencySymbol(item.getCurrency())  + item.getPrice()+'</a>');
		document.write('<td width="5" height="25"><IMG SRC="'+img_ri+'" WIDTH="5" HEIGHT="25" BORDER="0" ></td>');
		document.write('</tr></table>');

}





function endPricingTable(containsMonthlyBilling){


//document.write('</td></tr>');
if(containsMonthlyBilling){

document.write('<table width="313" bgcolor="#E6EEF7"><tr><td   align="center" style="font-size: 55%;padding-bottom:5px;color:grey;">* Payable by credit card only for a minimum period of twelve months</td></tr></table>');
}
//document.write('</td></tr></table>');
}



function startPricingTable(){

document.write('<table width="313" border="1" cellpadding="0" cellspacing="0" summary="Product Editions pricing table"><tr><td>');

document.write('<table width="313" border="1" cellpadding="0" cellspacing="0" summary="Product Editions pricing table"><tr><td>');
document.write('<table width="313" border="0" align="center" cellpadding="0" cellspacing="0" summary="Header detailing editions and price">');
document.write('<tr><td width="10"><IMG SRC="'+img_bhl+'" WIDTH="10" HEIGHT="23" BORDER="0" ></td>');
document.write('<td nowrap="nowrap" width="125" background="'+img_bhm+'" class="whiteboldstandard"> Edition</td>');
document.write('<td nowrap="nowrap" width="168" background="'+img_bhm+'" class="whiteboldstandard">Price</td>');
document.write('<td width="10"><IMG SRC="'+img_bhr+'" WIDTH="10" HEIGHT="23" BORDER="0" ></td>');
document.write('</tr></table>');
document.write('</td></tr><tr>');
document.write('<td><img src="'+xspacer+'" width="14" height="3" alt=""></td>');
document.write('</tr><tr>');
document.write('<td bgcolor="#E6EEF7"><img src="'+xspacer+'" width="14" height="5" alt=""></td>');
document.write('</tr><tr><td bgcolor="#E6EEF7" class="blackbody">');
}


function IsValidObject(objToTest) {

	if (objToTest == null) return false;

	if(objToTest == "undefined") return false ; 

	if( objToTest == 'undefined') return false ; 
	
	return true;
}

function showTable(TableId,hideTableId){

	if(document.all){ 
	 document.all[TableId].style.display="";
	 document.all[hideTableId].style.display="none";
	}
	else if (document.getElementById)
	{
		document.getElementById(TableId).style.display="";
		document.getElementById(hideTableId).style.display="none";
	}
	
}