// JavaScript Document

function addMenuHover(){
	/* Main Navigation */
	aryNavItems = document.getElementById('navigationWrapper').getElementsByTagName('div');
	for(increment = 0; increment < aryNavItems.length; increment++){
		if(aryNavItems[increment].className == 'navigationItem'){
			aryNavItems[increment].onmouseover = function(){this.className = 'navigationItemSelected';};
			aryNavItems[increment].onmouseout = function(){this.className = 'navigationItem';};
		}
	}
}

function ssTracking(id) {
	
	if (id.toUpperCase().indexOf('CP') >= 0) {
		window.open('http://www.4pod.com.au/track.php?key=clever&track='+id, 'Tracking', 'width=615, height=700, resizable=yes, scrollbars=Yes, toolbar=no, location=no, menubar=no');
	}else if((id.toUpperCase().indexOf('SMT') >= 0) || (id.toUpperCase().indexOf('MNF') >= 0)){
		var thisID = padNumber(id)
		window.open('MainFreightTrackPage.cfm?consignment=SMT'+thisID, 'Tracking', 'width=615, height=700, resizable=yes, scrollbars=Yes, toolbar=no, location=no, menubar=no');
		//window.open('MainFreightTrackPage.cfm?consignment='+id, 'Tracking', 'width=615, height=700, resizable=yes, scrollbars=Yes, toolbar=no, location=no, menubar=no');
	}else if(id.toUpperCase().indexOf('SSD') >= 0){
		window.open('http://www.tntexpress.com.au/interaction/asps/trackdtl_tntau.asp?'+id, 'Tracking', 'width=755, height=700, resizable=yes, scrollbars=Yes, toolbar=no, location=no, menubar=no');
	}else {
		window.open('Tracking.aspx?consignment='+id, 'Tracking', 'width=615, height=700, resizable=yes, scrollbars=Yes, toolbar=no, location=no, menubar=no');
	}
}

function reduceTextToDigits (strValue) {
		$(strValue).value = strValue.value.replace (/([^0-9])/g, "", strValue);
	}
	
	
function padNumber(id){
	value = id.replace(/([^0-9])/g, "", id)
	value = leadingZeros(value, 6, "0")
	return value;
}

function leadingZeros(num, totalChars, padWith) {
	num = num + "";
	padWith = (padWith) ? padWith : "0";
	if (num.length < totalChars) {
		while (num.length < totalChars) {
			num = padWith + num;
		}
	} else {}

	if (num.length > totalChars) { //if padWith was a multiple character string and num was overpadded
		num = num.substring((num.length - totalChars), totalChars);
	} else {}

	return num;
}

window.onload = addMenuHover;