function openwin(cms_url,winname){
eval(winname+"=window.open('"+cms_url+"','"+winname+"');")
if (!winname){alert("Sorry, pop-up windows are disable. ");}
eval(winname+".focus();")
}

function displaydiv(divid){
var tag=document.getElementById(divid)
tag.style.display='';
x=Math.floor((document.body.clientWidth-tag.offsetWidth)/2+document.body.scrollLeft);
y=Math.floor((document.body.clientHeight-tag.offsetHeight)/2+document.body.scrollTop);
	//alert('x='+x+'  y='+y+'  clientwidth='+document.body.clientWidth+'  offsetwidth='+tag.offsetWidth+'  clientHeight='+document.body.clientHeight+'  offsetHeight='+tag.offsetHeight)	

	if (x+ tag.offsetWidth >document.body.scrollLeft +document.body.clientWidth - 160){
		x=document.body.scrollLeft +document.body.clientWidth-tag.offsetWidth-1-160
		}
	if (y+ tag.offsetHeight >document.body.scrollTop +document.body.clientHeight-270){
		y=document.body.scrollTop +document.body.clientHeight-tag.offsetHeight-1-270
		}
tag.style.position='absolute';
tag.style.left=x;
tag.style.top=y;



}

function validationpage(valtype){


if (valtype=='create'){
	eval("var inlist=listcheckname.search(/,"+document.forms.mainform.pagename.value+",/)");
	if (inlist>=0){
		alert('The name already exists. Creation impossible.')
		return false;
		}
	
	}

var error=0;
messagealert='';
if (!document.forms.mainform.pagename.value){
	messagealert+="the page name\n"
	document.forms.mainform.pagename.focus()
	error=1;
	}
	else{
	if (valtype!='create' && window.oldpagename && document.forms.mainform.pagename.value!=oldpagename){
		if (!confirm("The page's name has changed.\nYou may wish to create a new page.\nAre you sure you want to replace the page's name?")){return false;}
		}
	}
	
if (error==1){
	messagealert="You need to enter :\n"+messagealert;
	alert(messagealert);
	return false;
	}
	else{
	return true;
	
	}

}

function bookingvalidation(formname){
tabrequiredname=new Array("lastname","firstname","company","email","email2","phone");
tabrequiredalert=new Array("your last name","your first name","the company name","an email address","the email confirmation","a phone number");
return formvalidation(formname);
}

function validationcontent(valtype){
document.forms.editcontentform.contenttext.value=document.forms.editcontentform.contenttext.value.replace(/<form/gi,"<cmsform")
document.forms.editcontentform.contenttext.value=document.forms.editcontentform.contenttext.value.replace(/<\/form/gi,"</cmsform")
document.forms.editcontentform.contenttext.value=document.forms.editcontentform.contenttext.value.replace(/</gi,"&lt;")
if (document.forms.editcontentform.contentname.value.search(/cms_/)==0){
	alert("WARNING\nA content name starting with the 'cms_'prefix is a default content and cannot be created or updated.\nSave the content under another name and modify the attached pages accordingly.");
	return false;
	}

var error=0;
messagealert='';
if (!document.forms.editcontentform.contentname.value){
	messagealert+="the content name\n"
	document.forms.editcontentform.contentname.focus()
	error=1;
	}
	else if (valtype=='create'){
	eval("var inlist=listcheckname.search(/,"+document.forms.editcontentform.contentname.value+",/)");
	if (inlist>=0){
		alert('The name already exists. Creation impossible.')
		return false;
		}
	}
	else{
	
	if (valtype!='create' && window.oldcontentname && document.forms.editcontentform.contentname.value!=oldcontentname){
		if (!confirm("The content's name has changed.\nYou may wish to create a new content.\nAre you sure you want to replace the content's name?")){return false;}
		}
	}

if (document.forms.editcontentform.contenttext.value.search(/(<\?)|(&lt;\?)/)!=-1 && document.forms.editcontentform.contentname.value.substr(document.forms.editcontentform.contentname.value.length-4,4).toLowerCase()!=".php"){
	alert("The content contains the code '<?' which could indicate some php code and therefore it will be saved as a file.\n Please rename the content with a .php extension \nor make sure the is no '<?' in the text.");
	document.forms.editcontentform.contentname.focus();
	return false;
	}
	
if (document.forms.editcontentform.contentname.value.substr(document.forms.editcontentform.contentname.value.length-4,4).toLowerCase()==".php" && !checkcontentname()){
	alert("The content name is not a correct file name. Please rename the content.");
	document.forms.editcontentform.contentname.focus();
	return false;
	}
	

if (document.forms.editcontentform.contenttype.selectedIndex==0){
	messagealert+="the content type\n"
	document.forms.editcontentform.title.focus()
	error=1;
	}

if (error==1){
	messagealert="You need to enter :\n"+messagealert;
	alert(messagealert);
	return false;
	}
	else{
	
	if (window.editorisused && editorisused){document.forms.editcontentform.contenttext.value=oEdit1.getHTMLBody();}

	return true;
	
	}

}

function validationarchive(valtype){
document.forms.editcontentform.contenttext.value=document.forms.editcontentform.contenttext.value.replace(/<form/gi,"<cmsform")
document.forms.editcontentform.contenttext.value=document.forms.editcontentform.contenttext.value.replace(/<\/form/gi,"</cmsform")
document.forms.editcontentform.contenttext.value=document.forms.editcontentform.contenttext.value.replace(/</gi,"&lt;")
if (document.forms.editcontentform.contentname.value.search(/cms_/)==0){
	alert("WARNING\nA content name starting with the 'cms_'prefix is a default content and cannot be created or updated.\nSave the content under another name and modify the attached pages accordingly.");
	return false;
	}

var error=0;
messagealert='';
if (!document.forms.editcontentform.contentname.value){
	messagealert+="the content address\n"
	document.forms.editcontentform.contentname.focus()
	error=1;
	}
	else if (valtype=='create'){
	eval("var inlist=listcheckname.search(/,"+document.forms.editcontentform.contentname.value+",/)");
	if (inlist>=0){
		alert('The address already exists. Creation impossible.')
		return false;
		}
	}
	else{
	
	if (valtype!='create' && window.oldcontentname && document.forms.editcontentform.contentname.value!=oldcontentname){
		if (!confirm("WARNING: The archive's address has changed. \nThe links that are currently using this address will be lost. \nYou may wish to create a new archive.\nAre you sure you want to replace the archive's address?")){return false;}
		}
	}

if (document.forms.editcontentform.contenttext.value.search(/(<\?)|(&lt;\?)/)!=-1 && document.forms.editcontentform.contentname.value.substr(document.forms.editcontentform.contentname.value.length-4,4).toLowerCase()!=".php"){
	alert("The archive contains the code '<?' which could indicate some php code and therefore it will be saved as a file.\n Please rename the archive with a .php extension \nor make sure the is no '<?' in the text.");
	document.forms.editcontentform.contentname.focus();
	return false;
	}
	
if (document.forms.editcontentform.contentname.value.substr(document.forms.editcontentform.contentname.value.length-4,4).toLowerCase()==".php" && !checkcontentname()){
	alert("The archive address is not a correct file name. Please change the archvive's address.");
	document.forms.editcontentform.contentname.focus();
	return false;
	}
	

if (document.forms.editcontentform.contentclass.selectedIndex==0){
	messagealert+="the archive class\n"
	document.forms.editcontentform.title.focus()
	error=1;
	}

if (error==1){
	messagealert="You need to enter :\n"+messagealert;
	alert(messagealert);
	return false;
	}
	else{
	
	if (window.editorisused && editorisused){document.forms.editcontentform.contenttext.value=oEdit1.getHTMLBody();}

	return true;
	
	}

}

function valcontentdelete(){

if (document.forms.editcontentform.contentname.value.search(/cms_/)==0){
	alert("WARNING\nA content name starting with the 'cms_'prefix is a default content and cannot be deleted.");
	return false;
	}

if (confirm('Are you sure you want to delete this content?\n\nWARNING: some pages could be affected')){return true;}else{return false;}
}

function checkpagename(){
var tag=document.getElementById('pagenameid');
if (tag.value.search(/\s/)!=-1){
	if (confirm("The Page's name is used in URLs and cannot accept spaces.\nDo you want to replace the spaces with underscores?")){
		tag.value=tag.value.replace(/\s/g,"_");
		while (tag.value.search(/__/)!=-1){
			tag.value=tag.value.replace(/__/g,"_");
			}
		}
		else{
		tag.value='';
		return false;
		}
	}

if (tag.value.search(/\W/)!=-1){
	alert("The page's name will be stripped of some special characters.")
	tag.value=tag.value.replace(/\W/g,"");
	}
return true;
}

function checkcontentname(){
var tag=document.forms.editcontentform.contentname;
if (tag.value.search(/\s/)!=-1){
	if (confirm("The content's name is used in URLs and cannot accept spaces.\nDo you want to replace the spaces with underscores?")){
		tag.value=tag.value.replace(/\s/g,"_");
		while (tag.value.search(/__/)!=-1){
			tag.value=tag.value.replace(/__/g,"_");
			}
		}
		else{
		tag.value='';
		return false;
		}
	}
var tag2=tag.value.replace(/\./g,"__dot__")
if (tag2.search(/\W/)!=-1){
	alert("The content's name will be stripped of some special characters.")
	tag2=tag2.replace(/\W/g,"");
	tag.value=tag2.replace(/__dot__/g,".");
	}
return true;
}


function validEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}




function whitepapervalidation(formname){
tabrequiredname=new Array("lastname","firstname","company","amazon_nb","email","email2");
tabrequiredalert=new Array("your last name","your first name","the company name","the Amazon order phone number","an email address","the email confirmation");
return formvalidation(formname);
}



tabrequiredname=new Array;
tabrequiredalert=new Array;

function formvalidation(formname){

var error=0;
messagealert='';
if (!window.tabrequiredname){return true;}

for (var i=0;i<tabrequiredname.length;i++){
	eval("var confirmexist=window.document."+formname+"."+tabrequiredname[i])
	if (!confirmexist){continue;}
	eval("var reqtag=document."+formname+"."+tabrequiredname[i])
	if (!reqtag.value){
		messagealert+=tabrequiredalert[i]+"\n"
		if (!error){reqtag.focus();}
		error=1;
		}
	}
	
if (error==1){
	messagealert="Ooops - I know you're busy, but you haven't completed the form.\n\nYou need to enter :\n"+messagealert;
	alert(messagealert);
	return false;
	}
	else{
	for (var i=0;i<tabrequiredname.length;i++){
		if (tabrequiredname[i].search(/email/)==-1){continue;}
		eval("var reqtag=document."+formname+"."+tabrequiredname[i])
		if (!validEmail(reqtag.value))
			{
				alert("Ooops - your email address is not valid")
				reqtag.focus()
				return false
			}
		eval("var confirmexist=window.document."+formname+"."+tabrequiredname[i]+"2")
		if (confirmexist){
			eval("var reqtag2=document."+formname+"."+tabrequiredname[i]+"2")
			if (reqtag2.value!=reqtag.value)
				{
				alert("Ooops - I think you're typing too fast. \nYour two email addresses don't match.")
				reqtag2.focus()
				return false
				}
			}
		}
	
	return true;
	
	}

}

function onloadbody(){
	
	MM_preloadImages('/images/custom/topmenu_healing_over.png','/images/custom/topmenu_greathealer_over.png','/images/custom/topmenu_givinglife_over.png','/images/custom/topmenu_breastfeeding_over.png','/images/custom/topmenu_conscious_over.png','/images/custom/topmenu_thewomb_over.png','/images/custom/topmenu_alternatives_over.png','/images/custom/topmenu_thejourney_over.png','/images/custom/menu_visit_over.png','/images/custom/menu_seevideos_over.png','/images/custom/menu_foundation_over.png','/images/custom/menu_online_over.png','/images/custom/menu_inviteus_over.png','/images/custom/menu_speaking_over.png','/images/custom/menu_tellus_over.png','/images/custom/button_wisdom_over.png','/images/custom/button_learn_over.png','/images/custom/icon_blog_over.png','/images/custom/icon_video_blog_over.png','/images/custom/icon_youtube_over.png','/images/custom/icon_rss_over.png','/images/custom/icon_twitter_over.png','/images/custom/button_join_over.png','/images/custom/tiptopmenu_aboutus_over.png','/images/custom/tiptopmenu_contactus_over.png','/images/custom/tiptopmenu_photogallery_ove.png','/images/custom/tiptopmenu_press_over.png','/images/custom/tiptopmenu_endorsements_ove.png','/images/custom/tiptopmenu_store_over.png','/images/custom/tiptopmenu_search_over.png','/images/custom/home_moreinfo_over.png','/images/custom/home_buynow_over.png','/images/custom/button_sub_join_the_club_ov.png','/images/custom/sub_topmenu_aboutus_over.png','/images/custom/sub_topmenu_contactus_over.png','/images/custom/sub_topmenu_photogallery_ov.png','/images/custom/sub_topmenu_press_over.png','/images/custom/sub_topmenu_shop_over.png','/images/custom/sub_topmenu_search_over.png','/images/custom/sub_topmenu_endorsements_ov.png','/images/custom/button_tell_a_friend_over.png')

}

function itemmenuover(menuitemid){
		
	document.getElementById(menuitemid).style.display='';
	}
	
function itemmenuout(menuitemid){
	document.getElementById(menuitemid).style.display='none';
	
	}
	
function openvideowindow(theURL,winName) { //v2.0
  videowindow=window.open(theURL,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=490,height=540');
videowindow.focus();
}

function openlinkwindow(theURL,winName) { //v2.0
  linkwin=window.open(theURL,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=437,height=400');
}

function popupSignupPage() {
	link = 'http://www.thenewparenting.com/signup.php?from=thenewparenting';
	var photoWindow = window.open(link,"NPC",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=400,height=320');
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function photo_open(link, width, height) {
	var photoWindow = window.open(link,"New Parenting Club: Gallery",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+width+',height='+height);
}
function Search() {
	keywordsearch = document.formSearch.keywords.value;
	if((keywordsearch != 'Keywords....') && (keywordsearch != '') && (keywordsearch != 'Try Again')) {
		top.location.href = 'index.php?id=search&submit=submit&keyword=' + keywordsearch; 
	} else {
		document.formSearch.keywords.value = "Try Again";
	}
}


function submitIt(subsForm) {
 if (!validEmail(document.subsForm.email.value))
  {
   alert("Ooops - your email address is not valid")
   document.subsForm.email.focus()
   document.subsForm.email.select()
   return false
  }
 if (document.subsForm.email2.value!=document.subsForm.email.value)
  {
  alert("Ooops - I think you're typing too fast. \nYour two email addresses don't match.")
  document.subsForm.email.focus()
  document.subsForm.email.select()
  return false
  }
 var pref = "";
 var reqfields = new Array();
 
  for(i=0; i < reqfields.length;i++)
   {
    tempfield = "document.subsForm."+pref+reqfields<i>+".value";
    tempid = "document.subsForm."+pref+reqfields<i>+".id";
    tempval = eval(tempfield);
    tempid = eval(tempid);
    
    if(tempval=="")
     {
      alert("Please provide a "+tempid+".");
      return false;
     }
  }
 return true
}


function validateform(){
var error=0;
messagealert="";
if (!document.getElementById("name").value){
 messagealert+="Your name\n"
 document.getElementById("name").focus()
 error=1;
 }
 
if (!validEmail(document.getElementById("email").value)){
 messagealert+="A correct email address\n"
 document.getElementById("email").focus()
 error=1;
 }
if (!document.getElementById("message").value){
 messagealert+="A message\n"
 document.getElementById("message").focus()
 error=1;
 }
if (error==1){
 messagealert="You need to enter :\n"+messagealert;
 alert(messagealert);
 return false;
 }
 else{
 return true;
 }
}
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setContent(element_name) {
	if (document.getElementById) {
		if (self.pageYOffset) // all except Explorer
		{
			var x = self.pageXOffset;
			var y = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
		{
			var x = document.documentElement.scrollLeft;
			var y = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			var x = document.body.scrollLeft;
			var y = document.body.scrollTop;
		}
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentElement = document.getElementById(element_name);
			var contentHeight = contentElement.offsetHeight;
			if (y>0) {
				contentElement.style.top = Math.round(y) + "px";
			} else {
				contentElement.style.top = '150px';
			}
		}
	}
}
function email_friend() {
	setContent("emailfriendid");
//	document.getElementById("emailfriendid").style.left = Math.round((document.documentElement.clientWidth/2)-(document.getElementById("emailfriendid").style.width/2)-100)+"px";
	document.getElementById("emailfriendid").style.display = "block";
}
function email_friend_validation() {
	if (document.form_email_friend.friend_email.value=='') {
		alert('Please type your friend\'s email address into the "Friend\'s Email" field');
		return false;
	} else if (document.form_email_friend.your_name.value=='') {
		alert('Please type your name into the "Your Name" field');
		return false;
	} else {
		return true;
	}
}
function social_media(encoded_url,digg_count,tweets) {
	document.write('<div class="socialp"><div class="tweetp_cnt">'+tweets+'</div><div class="socialp_img"><a href="http://twitter.com/home?status='+encoded_url+'" target="_blank" title="Send this link to your Twitter followers"><img src="/images/social_panel/retweet_black.gif"></a></div>');
	document.write('<div class="diggp_cnt">'+digg_count+'</div><div class="socialp_img"><a href="http://digg.com/submit?url='+encoded_url+'" target="_blank" title="Recommend this link on Digg"><img src="/images/social_panel/digg_black.gif"></a></div>');
	document.write('<div class="socialp_img"><a href="http://www.facebook.com/sharer.php?u='+encoded_url+'" target="_blank" title="Post this link to your facebook wall"><img src="/images/social_panel/facebook_black.gif" border=0></a></div>');
	document.write('<div class="socialp_img"><a href="http://www.stumbleupon.com/submit?url='+encoded_url+'" target="_blank" title="recommend this link on StumbleUpon"><img src="/images/social_panel/stumble_black.gif" border=0></a></div>');
	document.write('<div class="socialp_img"><a href="http://delicious.com/save?url='+encoded_url+'" target="_blank" title="Bookmark this link on delicious"><img src="/images/social_panel/delicious_black.gif" border=0></a></div>');
	document.write('<div class="socialp_img"><a href="http://www.thenewparentingclub.com/index.php/cmsid__rss" target="_blank" title="New Parenting Club news via RSS"><img src="/images/social_panel/rss_black.gif" border=0></a></div>');
	document.write('<div class="socialp_img"><a href="http://www.thenewparentingclub.com/vodcast.xml" target="_blank" title="Vodcast (video podcast) of latest New Parenting Club video presentations"><img src="/images/social_panel/video_black.gif" border=0></a></div>');
	document.write('<div class="socialp_img"><a href="JavaScript:email_friend()" title="Recommend this link to a friend"><img src="/images/social_panel/friend_black.gif" border=0></a></div></div>');
}

function social_media_old(encoded_url,digg_count,tweets) {
	document.write('<div align=center><div class="socialm"><div class="tweet_cnt">'+tweets+'</div><div class="tweet"><a href="http://twitter.com/home?status='+encoded_url+'" target="_blank" title="Send this link to your Twitter followers">retweet</a></div>');
	document.write('<div class="digg"><a href="http://digg.com/submit?url='+encoded_url+'" target="_blank" title="Recommend this link on Digg">'+digg_count+' Diggs</a></div>');
	document.write('<div class="social_img"><a href="http://www.facebook.com/sharer.php?u='+encoded_url+'" target="_blank" title="Post this link to your facebook wall"><img src="/images/facebook.gif" width=59 height=19 border=0></a></div>');
	document.write('<div class="social_img"><a href="http://www.stumbleupon.com/submit?url='+encoded_url+'" target="_blank" title="recommend this link on StumbleUpon"><img src="/images/stumble.gif" width=63 height=19 border=0></a></div>');
	document.write('<div class="social_img"><a href="http://delicious.com/save?url='+encoded_url+'" target="_blank" title="Bookmark this link on delicious"><img src="/images/delicious.gif" width=57 height=19 border=0></a></div>');
	document.write('<div class="social_img"><a href="http://www.thenewparenting.com/index.php/cmsid__rss" target="_blank" title="New Parenting Club news via RSS"><img src="/images/common/rss.gif" width=31 height=19 border=0></a></div>');
	document.write('<div class="social_img"><a href="http://www.thenewparenting.com/vodcast.xml" target="_blank" title="Vodcast (video podcast) of latest New Parenting Club video presentations"><img src="/images/common/vodcast.gif" width=36 height=19 border=0></a></div>');
	document.write('<div class="social_img"><a href="JavaScript:email_friend()" title="Recommend this link to a friend"><img src="/images/common/letter.gif" width=21 height=19 border=0></a></div></div></div>');
}
