 function cutSpaces(s)
{
        var s1, x;
        x = s1 = "";
        l = s.length;
        for(i = 0; i < l; i++)
                if((x = s.charAt(i))!= " ")
                        s1+=x;
        return s1;
}
function isfilled(field)
{
	if(cutSpaces(field.value)=="" )
		{return false;}	
	else
		{return true; }
}	
/*
function isfilled(field)
{
	if(field.value.length < 1 )
		{return false;}	
	else
		{return true; }
}
*/
function iscombo(field)
{
	if(field.value< 1 )
		{return false;}	
	else
		{return true; }
}	
function isemail(field)
{
	if( (field.value.indexOf("@") == -1 ) || (field.value.indexOf(".") == -1 )  )
		{return false;}	
	else
		{return true; }
}	

function test(f)
{
	
	for(var i=0; i<f.elements.length; i++)
	{
			var element=f.elements[i];
			if(element.className.indexOf("mandatory") != -1)   //-1 means index found 
			{
					if(!isfilled(element))
					{
						alert ("Please enter "+element.title);
						element.focus();
						return false;
					}
			}
			if(element.className.indexOf("selectcombo") != -1)   //-1 means index found 
			{
					if(!iscombo(element))
					{
						alert ("Please select "+element.name);
						element.focus();
						return false;
					}
			}
			if(element.className.indexOf("mandatoryemailrequired")!= -1)			
			{
					if(!isemail(element))
					{
						alert ("Please enter valid email address");
						element.focus();
						return false;
					}
			}
	}
	return true;
}

function bkmark()
{
  var bkm=document.getElementById("bookmark");
    if(!bkm) return false;
    bkm.onclick=function(){
		     bookmarksite('MMV Autobodies Ltd.- Car & Commercial Vehicles','http://mmvautobodies.co.uk/');
			 return false;
	}

}

function bookmarksite(title, url)
{
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

function prepareform()
{
	if(!document.getElementById("EnquiryForm")) return ;
	var id=document.getElementById("EnquiryForm");
	id.onsubmit=function(){
		return test(this);
	}
}
function myform()
{

	if(!document.getElementById("myform")) return ;
	var id=document.getElementById("myform");
	id.onsubmit=function(){
		return test(this);
	}
}

function callbackform()
{
	if(!document.getElementById("recovery")) return ;
	var id=document.getElementById("recovery");
	id.onsubmit=function(){
		return callback_validate(this);
	}
}
function callback_validate(f)
{
	for(var i=0; i<f.elements.length; i++)
	{
			var element=f.elements[i];
			if(element.className.indexOf("required_field") != -1)   //-1 means index found 
			{
					if(!isfilled(element))
					{
						alert ("Please enter your "+element.name);
						element.focus();
						return false;
					}
			}
	}
	return true;
}

function emailafriendform()
{		
	if(!document.getElementById("frmTellFriend")) return;
	var id=document.getElementById("frmTellFriend");
	id.onsubmit=function(){
		return email_validateform(this);
	}
}

function email_validateform(f)
{
	for(var i=0; i<f.elements.length; i++)
	{
		var element=f.elements[i];
		if(element.className.indexOf("required_field") != -1)   //-1 means index found 
		{
			if(!isfilled(element))
			{
				alert ("Please enter your friends name");
				element.focus();
				return false;
			}
		}
		if(element.className.indexOf("required_emailfield")!= -1)			
		{
			if(!isemail(element))
			{
				alert ("Please enter valid email address");
				element.focus();
				return false;
			}
		}
		if(element.className.indexOf("sender") != -1)   //-1 means index found 
		{
			if(!isfilled(element))
			{
				alert ("Please enter your name");
				element.focus();
				return false;
			}
		}
	}
	return true;
}

function addLoadEvent(func)
{
 	var oldonload=window.onload;
	if(typeof window.onload!= 'function')
	{
		window.onload=func	;
	}
	else
	{	
		window.onload= function(){
			oldonload();
			func();
		}	
	}
}

function emailform()
{
	var mailadd=document.getElementById("emailafriend");
	if(mailadd)
	{
		mailadd.onclick=function(){
			mailme();
		}
	}
}

function mailme()
{
	window.location ='mailto:?subject=&body=';
}

function playflash()
{
    var fplay=document.getElementById("flashcontent");
    if(!fplay){ return; }
    var fo = new FlashObject("images/logo-scroll.swf", "flashmovie", "760", "34", "7", "high" );    
    fo.write(fplay);
}
function display_map()
{
	var map=document.getElementById("map1");
	if(!map) {return;}
	map.onclick=function(){
		window.open('images/mmv-map_large.gif','imgopen','menubar=no,width=500, height=295,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=5,left=20', false);
	}
}


addLoadEvent(emailafriendform); 
addLoadEvent(prepareform);
addLoadEvent(callbackform);
addLoadEvent(bkmark);
addLoadEvent(playflash);
addLoadEvent(display_map);
addLoadEvent(myform);
