//code lib
//dries samyn 02/2001
//razorfish.com

function mElement(elementName) {//V2.0 	- improved for better DOM support, 

	if (document.layers) {
		if (mElement.arguments.length == 1) {
			var cEl = eval("document.layers['" + elementName + "']");
		} else if (mElement.arguments[1] == 'DoC') {
			var cEl = eval("document.layers['" + elementName + "'].document");
		} else if (mElement.arguments[1] == 'iMageZ') {//support for images - weird spelling so no conflicts with objects, should have done with 'DoC' as well
			var cEl = eval("document.images['" + elementName + + "']");
		} else if (mElement.arguments.length > 1 && mElement.arguments[1] != 'DoC' && mElement.arguments[1] != 'iMageZ') {
			var cEl = "document.layers['" + mElement.arguments[1] + "']";//start the string
			for (var i=2;i<mElement.arguments.length;i++) {//leave the first argument, because that's the one you're after, the second because you used that one to start the string
				if ( (mElement.arguments[i] != 'DoC') && (mElement.arguments[i] != 'iMageZ') ) {
					//alert(mElement.arguments[i]);
					cEl = cEl + ".document.layers['" + mElement.arguments[i] + "']";//get the next layer
				}
			}
			if (mElement.arguments[mElement.arguments.length-1] == 'iMageZ')  {
				cEl = cEl + ".document.images['" + elementName + "']";//in case you need the images in the layer rather than the layer or doc
			} else {
				cEl = cEl + ".document.layers['" + mElement.arguments[0] + "']";//add first element (the one you're after)
				if (mElement.arguments[mElement.arguments.length-1] == 'DoC') {
				cEl = cEl + ".document";//in case you need the document in the layer rather than the layer itself
				}
			} 
			cEl = eval(cEl);//wrap up and make string into an object
		} else {
			var cEl = eval("document.layers['" + mElement.arguments[1] + "'].document." + elementName);
		}
	} else if (document.all) {
		var cEl = eval('document.all.' + elementName);
	} else {
		var cEl = document.getElementById(elementName);
	}
	return cEl;
}

//write 'content'-string in Layer:
function writeDiv(divName,content) {
	if(document.layers) {
		mElement(divName,'DoC').open();
		mElement(divName,'DoC').write(content);
		mElement(divName,'DoC').close();
	} else {
		mElement(divName).innerHTML = content;
	}
}

//make a div visible, and/or position it:
function makeVis(posX,posY,divName) {
	if(document.layers) {
		if (posX != null) mElement(divName).left = posX;
		if (posY != null) mElement(divName).top = posY;		
		mElement(divName).visibility = 'show';
	} else {
		if (posX != null) mElement(divName).style.left = posX;
		if (posY != null )mElement(divName).style.top = posY;
		mElement(divName).style.visibility = 'visible';
	}
}

//make it invisible:
function makeInVis(divName) {
	if(document.layers) {
		mElement(divName).visibility = 'hide';
	} else {
		mElement(divName).style.visibility = 'hidden';
	}
}

/* Mouse rollover for image swapping within layers.
 ARGUMENTS:
  layRef: layer name
  imgRef: image name
  srcRef: source reference
*/
function rollOver(layRef,imgRef,srcRef) {
	mElement(imgRef,layRef,'iMageZ').src = srcRef;
}

//popup window for the copyright link (footer)
function copyrightWindow() {
	window.open('http://www.vodafone.com/legal/copyright_popup.htm#copyright','Legal','width=670,height=440,scrollbars=yes,titlebar=no,screenx=0,screeny=0,resizable=no');
}

//popup window for the sponsorship page (about section)
function sponsorshipWindow() {
	window.open('sponsorship_popup.htm','Sponsorship','width=756,height=385,titlebar=no,screenx=0,screeny=0,resizable=no');
}

//popup window for the structure page (about section)
function structureWindow() {
	window.open('structure_popup.htm','Sponsorship','width=761,height=512,titlebar=no,screenx=0,screeny=0,resizable=no');
}

//popup window for the privacy policy
function ppolicyWindow() {
	window.open('http://www.vodafone.com/legal/ppolicy_popup.htm','PrivacyPolicy','width=670,height=440,scrollbars=yes,titlebar=no,screenx=0,screeny=0,resizable=no');
}

//popup window for the PDA demo
function pdaWindow() {
	window.open('http://www.vodafone.com/pocketpc/default.php','PDA','width=270,height=330,scrollbars=yes,titlebar=no,screenx=0,screeny=0,resizable=no');
}


//Get the arguments for a querystring passed in a url
function getArgs() {
	var args = new Object();
	var query = location.search.substring(1); 
	var pairs = query.split("&"); 
	
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('='); 
		if (pos == -1) continue; 
		var argname = pairs[i].substring(0,pos); 
		
		var value = pairs[i].substring(pos+1); 
		args[argname] = unescape(value); 
	}
	return args; // Return the Object
}

//carousel for the media homepage and whole about section
	myPix = new Array("../img/carousel/1.gif","../img/carousel/2.gif","../img/carousel/3.gif")
	imgCt = myPix.length 

function choosePic() {
	randomNum = Math.floor((Math.random() * imgCt))
	mElement('myPicture','divInfo','iMageZ').src = myPix[randomNum];
}

//popup window for the worldwide operations chart popup
function worldwideOperWindow(sPath) {
	window.open(sPath,'worldoper','width=785,height=520,scrollbars=yes,titlebar=no,screenx=0,screeny=0,resizable=yes');
}

// prints a page (pc only) 
function printPage() {
	if (isPC) javascript:window.print();
}
/*Resize Code for NS.*/
if (isNS4) {
	window.captureEvents(Event.RESIZE);
	window.onresize = handleResize
    var lastWidth=window.innerWidth;
    var lastHeight=window.innerHeight;
}
function handleResize() {
    if (isNS4) {
        var myW = window.innerWidth;
        var myH = window.innerHeight;
        if ((lastWidth != myW) && (lastHeight != myH)){
            lastWidth=myW;
            lastHeight=myH;
            document.location.reload();
        }
    }
}
function validateEmail(oFormName,oTxtName,oFromName) {
	var oForm = eval ('document.'+oFormName);
	var oTxtElement = eval('document.'+oFormName+'.'+oTxtName);
	var oFromElement = eval('document.'+oFormName+'.'+oFromName);
	// make sure body of email has txt
	if ((oTxtElement.value=="") || (oTxtElement.value==null)) {
		alert('Error! You must enter text into the text box before you press SEND.');
		return;
	}
	// put default from field value
	if ((oFromElement.value=="") || (oFromElement.value==null)) {
		oFromElement.value = "webmaster@vodafone.com";
	}		
	else {
		oForm.submit();
	}
}