function navOver(imgName)
{
	var theImage = document.getElementById(imgName);
	
	if(theImage.src.indexOf("_off.gif") != -1)
	{
		theImage.src = theImage.src.replace("_off.gif","_on.gif");
	}
	
	else
	{
		theImage.src = theImage.src.replace("_on.gif","_off.gif");
	}
}

function openEmailAFriend(pageRef)
{
	newwin = window.open("/emailafriend.php?pageRef="+ pageRef + "","terms","width=470,height=346,scrollbars=no");
}

function dealerDetails(dId)
{
	newwin = window.open("/dealer-details.php?dId="+ dId + "","terms","width=445,height=546,scrollbars=no");
}

function tnc()
{
	newwin = window.open("/tnc.php","terms","width=485,height=546,scrollbars=yes");
}

function validateSellerEnquiry(theForm)
{	
	valid = true;
	message = "Please complete the following fields before proceeding:\n\n";
	
	if(theForm.elements["buyerName"].value == "")
	{
		
		message += "Your name\n";
		valid = false;
	}

	if(theForm.elements["buyerEmail"].value == "")
	{
		
		message += "Your email address\n";
		valid = false
	}	
		
	if(theForm.elements["buyerEmail"].value != "")	
	{	
		var supEmail = theForm.elements["email"].value;
		var emLen = supEmail.length;
		var posAt = supEmail.indexOf('@')
		var posDot = supEmail.lastIndexOf('.')
		if((emLen < 7) || (posAt < 1) || (posDot <= (posAt + 1)) || (posDot >= (emLen - 1)))
		{
			message += "Valid email address\n";
			valid = false;
		}
	}	
	
	if(theForm.elements["buyerPhoneNumber"].value == "")
	{
		message += "Your phone/mobile number\n";
		valid = false
	}
	
	
	if(theForm.elements["ddlPreferredToBeContacted"].value == "")
	{
		message += "Preferred method of contact\n";
		valid = false
	}
	
	
	if(theForm.elements["buyerEnquiry"].value == "")
	{
		message += "Your enquiry\n";
		valid = false
	}
	
	if(valid)
	{			
		return true;
	}
	else
	{		
		alert(message);
		return false;
	}		
}

function callSiFR()
{
	if(typeof sIFR == 'function')
	{	
	
		sIFR.replaceElement('h2.price', named({sFlashSrc: '/flash/sifr2.swf',sColor: '#d60000' ,sLinkColor:"#999999",sHoverColor:"333333",sBgColor: '#ffffff',sFlashVars: 'textalign=right', sWmode:'transparent'}));				
		sIFR.replaceElement('h2', named({sFlashSrc: '/flash/sifr2.swf',sColor: '#000000' ,sLinkColor:"#999999",sHoverColor:"333333",sBgColor: '#ffffff', sWmode:'transparent'}));				
		sIFR.replaceElement('h3.price', named({sFlashSrc: '/flash/myriadpro.swf',sColor: '#d60000' ,sLinkColor:"#999999",sHoverColor:"333333",sBgColor: '#ffffff', sFlashVars: 'textalign=right', sWmode:'transparent'}));		
		sIFR.replaceElement('h3', named({sFlashSrc: '/flash/myriadpro.swf',sColor: '#000000' ,sLinkColor:"#999999",sHoverColor:"333333",sBgColor: '#ffffff', sWmode:'transparent'}));		
		
		sIFR.replaceElement('h4.data', named({sFlashSrc: '/flash/sifr2.swf',sColor: '#000000' ,sLinkColor:"#999999",sHoverColor:"333333",sBgColor: '#ffffff', sWmode:'transparent'}));		
		sIFR.replaceElement('h4', named({sFlashSrc: '/flash/sifr2.swf',sColor: '#959595' ,sLinkColor:"#999999",sHoverColor:"333333",sBgColor: '#ffffff', sWmode:'transparent'}));		
		sIFR.replaceElement('h5.data', named({sFlashSrc: '/flash/myriadpro.swf',sColor: '#000000' ,sLinkColor:"#ccccc0",sHoverColor:"dae53d",sBgColor: '#ffffff', sWmode:'transparent'}));		
		sIFR.replaceElement('h5', named({sFlashSrc: '/flash/myriadpro.swf',sColor: '#ffffff' ,sLinkColor:"#ffffff",sHoverColor:"eeeeee",sBgColor: '#ffffff', sWmode:'transparent'}));		
	}
}		


function changeBorder(theElement)
{		
	theElement.style.backgroundColor = "#f4fffe";											
}
function resetBorder(theElement)
{		
	theElement.style.backgroundColor = "#ffffff";									
}	

function changeSmallMap(image)
{	
	document.getElementById("smallMap").src = image;
}

function resetSmallMap()
{
	document.getElementById("smallMap").src = "images/map.gif";
}

/* START NAVIGATION */
var menuOffDelay = 50;
onMenus = new Array();

function showMenu(whichMenu)
{	alert(whichMenu);

	onMenus.push(whichMenu);
	var dropmenuobj = document.getElementById(whichMenu);
	dropmenuobj.style.display = "block";
} 


function hideMenu(whichMenu)
{
	for(i=0;i<onMenus.length;i++)
	{
		if(onMenus[i] == whichMenu)
		{
			onMenus[i] = null;
			break;
		}
	}
	setTimeout("removeMenuNow('" + whichMenu + "');",menuOffDelay);
}

function removeMenuNow(whichMenu)
{
	var shouldBeVisible = false;
	for(i=0;i<onMenus.length;i++)
	{
		if(onMenus[i] == whichMenu)
		{
			shouldBeVisible = true;
			break;
		}
	}
	if(!shouldBeVisible)
	{
		var dropmenuobj = document.getElementById(whichMenu)
		dropmenuobj.style.display="none";
	}
}

function getHeight()
{
	
	if (window.innerHeight && window.scrollMaxY) 
	{
		var height = window.innerHeight + window.scrollMaxY;		
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		var height = document.body.scrollHeight;
	} 
	else 
	{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		var height = document.body.offsetHeight;
  	}
	
	var width = document.documentElement.clientWidth;
	
	if(document.getElementById('overlay') != null)
	{
		document.getElementById('overlay').style.height = height + 'px';
		document.getElementById('overlay').style.width = width + 'px';
	}
	if(document.getElementById('overlay2') != null)
	{
		document.getElementById('overlay2').style.height = height + 'px';
		document.getElementById('overlay2').style.width = width + 'px';
	}
	if(navigator.userAgent.indexOf("Mac") != -1)
	{
		if(document.getElementById('overlay') != null)
		{
			document.getElementById("overlay").style.backgroundColor = "transparent";
		}
		if(document.getElementById('overlay2') != null)
		{
			document.getElementById("overlay2").style.backgroundColor = "transparent";
		}
	} 
}	
	

function mathRound(value) 
{
  result=Math.floor(value)+"." ;
  n = result.length;
  var cents=100*(value-Math.floor(value))+0.5;
  result += Math.floor(cents/10);
  result += Math.floor(cents%10);
  return(result)
}

function Cal() 
{
	var valid = true;
	var Year;
    var Interest;
	var Carprice;
	var Downpayment;	
	
	var Carprice = document.getElementById('Carprice').value;
	var Downpayment = document.getElementById('Downpayment').value;
	var Interest = document.getElementById('Interest').value;    
	var Month = document.getElementById('periods').value;
	
	if((Carprice == '') || (Carprice == 'e.g. 50000'))
	{
		valid = false;
		document.getElementById('Carprice').style.backgroundColor = "#ffaeae";
	}
	
	if((Downpayment == '') || (Downpayment == 'e.g. 5000'))
	{
		valid = false;
		document.getElementById('Downpayment').style.backgroundColor = "#ffaeae";
	}	
	
	if(Interest == '')
	{
		valid = false;
		document.getElementById('Interest').style.backgroundColor = "#ffaeae";
	}	
	
	if(Month == '')
	{
		valid = false;
		document.getElementById('periods').style.backgroundColor = "#ffaeae";
	}
	
	if(valid)
	{
		document.getElementById('basicCalcResult').style.display = "block";
		document.getElementById('basicCalcResult').value = 'Monthly repayments: RM' + mathRound((((Carprice-Downpayment) * (1 + (Interest/100*(Month/12)))) / Month)) ;
		// document.getElementById('basicCalcDis').innerHTML = 'This monthly repayment indicates the average loan repayment. As repayments will differ over the duration of the loan, use our <a href="#">advance calculator</a> to see the specific monthly repayments over the loan duration.'; 
		document.getElementById('basicCalcDis').innerHTML = 'Note that the monthly repayment is indicative only.'; 
		
	}
	
	return false;
}

function ctw(id)
{	
	var theId = document.getElementById(id);
	theId.style.backgroundColor = '#ffffff';
}
 