
function isfilled(field)
{
	if(field.value.length < 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 your "+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('Barnsley Dearne Community Partnership','http://concepts.sitesinprogress.co.uk/bdcp/new/');
			 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 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 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 display_map()
{
	var map=document.getElementById("map");
	if(!map) {return;}
	map.onclick=function(){
		window.open('images/map.jpg','imgopen','menubar=no,width=500, height=310,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=5,left=20', false);
	}
}
addLoadEvent(display_map);
addLoadEvent(emailafriendform); 
addLoadEvent(prepareform);
addLoadEvent(bkmark);
addLoadEvent(callbackform);

/*********************drop down menu for MoreInfo 19th june*/
addLoadEvent(service);
function service()
{
	var vid=document.getElementById("p");
	vid.onmouseover=function(){
		service_hideshow();
	}
}
function service_hideshow()
{
	var x=document.getElementById("mynav");
	if(x.style.display =='none')
    {
		x.style.display ='block';
	}
    else	
	{
    	x.style.display ='none';
    }
}
addLoadEvent(service_out1); 
function service_out1()
{
	var id=document.getElementById("p1");
	id.onmouseover=function(){
	    check();
    }
	var id3=document.getElementById("leftcol1");
	id3.onmouseout=function(){
	    check();
    }
	var id4=document.getElementById("p2");
	id4.onmouseover=function(){
	    check();
    }
}
function check()
{
	var id2=document.getElementById("mynav");
	if(id2)
    {
		id2.style.display ='none';
    }
}
/*---------------for surestart drop down---------------- */
addLoadEvent(service2);
function service2()
{
	var vid=document.getElementById("p4");
	vid.onmouseover=function(){
		service_hideshow2();
	}
}
function service_hideshow2()
{
	var x=document.getElementById("surestart");
	if(x.style.display =='none')
    {
		x.style.display ='block';
	}
    else	
	{
    	x.style.display ='none';
    }

}
addLoadEvent(service_out2); 
function service_out2()
{
	var id=document.getElementById("p3");
	id.onmouseover=function(){
	    check2();
    }
	var id13=document.getElementById("surestart");
	id13.onmouseleave=function(){
	    check2();
    }
	var id4=document.getElementById("p5");
	id4.onmouseover=function(){
	    check2();
    }
}
function check2()
{
	var id2=document.getElementById("surestart");
	if(id2)
    {
		id2.style.display ='none';
    }
}
/*---------------for History drop down---------------- */
addLoadEvent(service3);
function service3()
{
	var vid=document.getElementById("p7");
	vid.onmouseover=function(){
		service_hideshow3();
	}
}
function service_hideshow3()
{
	var x=document.getElementById("history");
	if(x.style.display =='none')
    {
		x.style.display ='block';
	}
    else	
	{
    	x.style.display ='none';
    }

}
addLoadEvent(service_out3); 
function service_out3()
{
	var id=document.getElementById("p6");
	id.onmouseover=function(){
	    check3();
    }
	var id3=document.getElementById("history");
	id3.onmouseleave=function(){
	    check3();
    }

	var id4=document.getElementById("p8");
	id4.onmouseover=function(){
	    check3();
    }
}
function check3()
{
	var id2=document.getElementById("history");
	if(id2)
    {
		id2.style.display ='none';
    }
}
/*---------------for child care drop down---------------- */
addLoadEvent(service4);
function service4()
{
	var vid=document.getElementById("p10");
	vid.onmouseover=function(){
		service_hideshow4();
	}
}
function service_hideshow4()
{
	var x=document.getElementById("childcare");
	if(x.style.display =='none')
    {
		x.style.display ='block';
	}
    else	
	{
    	x.style.display ='none';
    }

}
addLoadEvent(service_out4); 
function service_out4()
{
	var id=document.getElementById("p9");
	id.onmouseover=function(){
	    check4();
    }
	
	var id3=document.getElementById("childcare");
	id3.onmouseleave=function(){
	    check4();
    }

	var id4=document.getElementById("p11");
	id4.onmouseover=function(){
	    check4();
    }
}
function check4()
{
	var id2=document.getElementById("childcare");
	if(id2)
    {
		id2.style.display ='none';
    }
}
/*---------------for Terradrop down---------------- */
addLoadEvent(service5);
function service5()
{
	var vid=document.getElementById("p13");
	vid.onmouseover=function(){
		service_hideshow5();
	}
}
function service_hideshow5()
{
	var x=document.getElementById("terra");
	if(x.style.display =='none')
    {
		x.style.display ='block';
	}
    else	
	{
    	x.style.display ='none';
    }

}
addLoadEvent(service_out5); 
function service_out5()
{
	var id=document.getElementById("p12");
	id.onmouseover=function(){
	    check5();
    }
	
	var id3=document.getElementById("terra");
	id3.onmouseleave=function(){
	    check5();
    }
	/*var idt4=document.getElementById("p29");
	idt4.onmouseover=function(){
	    check5();
    }*/
}
function check5()
{
	var id2=document.getElementById("terra");
	if(id2)
    {
		id2.style.display ='none';
    }
}
