// cookie for low/high bandwidth versions
function createCookie(c_name,value,expiredays,path) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie = c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+ "; path=/" +path+ "/";
}

// popup windows 
var newWin = null; 
function popUp(strURL, strType, strHeight, strWidth) { 
 if (newWin != null && !newWin.closed) 
   newWin.close(); 
 var strOptions=""; 
 if (strType=="console") 
   strOptions="resizable,height="+ 
     strHeight+",width="+strWidth; 
 if (strType=="fixed") 
   strOptions="status,height="+ 
     strHeight+",width="+strWidth; 
 if (strType=="fixedscroll") 
   strOptions="status,scrollbars,height="+ 
     strHeight+",width="+strWidth; 
 if (strType=="elastic") 
   strOptions="toolbar,menubar,scrollbars,"+ 
     "resizable,location,height="+ 
     strHeight+",width="+strWidth;
 if (strType=="elasticmenu") 
   strOptions="menubar,scrollbars,"+ 
     "resizable,height="+ 
     strHeight+",width="+strWidth; 
 newWin = window.open(strURL, 'newWin', strOptions); 
 newWin.focus(); 
}

// bookmark function
function AddBookmarkLink (title, url)
{
	if (window.sidebar) 
	{
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, '');
	}
	else
		if (window.external)
		{
			// IE Favourite
			window.external.AddFavorite (url, title);
		}
		else 
			if (window.opera && window.print)
			{
				// Opera hotlist
				return true;
			}	
}

//email friend
function EmailLink(){
var sPath = window.location.pathname;
var sPage = sPath.substr(sPath.lastIndexOf('/') + 1);
window.location = "mailto:"+"?subject=Anglo American" + "&body=" + "I thought this link might interest you: http://www.angloamerican.co.uk"+sPath;
}

// toggle div function
function toggleDiv(_id){
 _oDivStyle=document.getElementById(_id).style;
(_oDivStyle.display=='block')?_oDivStyle.display='none':_oDivStyle.display='block';
} 

function $( id ){
 return document.getElementById( id );
}

function toggleDivArrow( o, id ){
 if( $( id ) ){
  if( $( id ).style.display == 'none' ){
   o.className = '';
  }else{
   o.className = 'active';
  }
 }
}

function toggleDivBorder( id, o, tag ){
 var oDivStyle = document.getElementById( id ).style;
 var node = o;
 var found = false;
 for( var i = 0 ; i < 10 ; i++ ){
  node = node.parentNode;
  if( node.tagName.toString().toLowerCase() == tag ){
   found = true;
   break;
  }
 }
 if( oDivStyle.display == 'block' ){
  oDivStyle.display = 'none';
  if( found ){
   node.className = 'off';
  }
 }else{
  oDivStyle.display = 'block';
  if( found ){
   node.className = 'on';
  }
 }
}

// random image
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = '/aa/images/css/bg_placeholder_investors.jpg'
theImages[1] = '/aa/images/css/bg_placeholder_investors2.jpg'

// do not edit anything below this line
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

// online form validation function
function checkForm(form){
    intro = 'Please provide the following information:\n\n';
    msg = '';
    regex = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    if(form.txtCompanyName.value==''){msg+='Company name\n';}
    if(form.txtAddress.value==''){msg+='Address\n';}
    if(form.txtTelephone.value==''){msg+='Telephone number\n';}
	if(form.txtMainContact.value==''){msg+='Main contact name\n';}
    if(form.txtEmail.value==''){msg+='E-mail address\n';}
    if(form.txtProduct.value==''){msg+='Product supplied\n';}
    if(form.txtQuery.value==''){msg+='Query\n';}
    if(msg==''){return true}
    else if (msg!= ''){alert(intro + '\n' + msg);return false;}
}

 function maxlength(element, maxvalue)
     {
     var q = eval("document.form."+element+".value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. Please abbreviate "+
       "your text by at least "+r+" characters";
     if (q > maxvalue) alert(msg);
     }
	 
