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 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 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 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 conferencevalidation(formname){
tabrequiredname=new Array("country","date","time","venue","email_booking");
tabrequiredalert=new Array("a country","a date","a time","a venue","an email for bookings");
return formvalidation(formname);
}

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);
}

function conference_urlvalidation(formname){
tabrequiredname=new Array("country","month","link_url");
tabrequiredalert=new Array("a country","a date","the url for bookings");
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="You 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("Invalid email address")
				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("Confirm email address")
				reqtag2.focus()
				return false
				}
			}
		}
	
	return true;
	
	}

}

function onloadbody(){

if (document.getElementById('playmusicid') && window.trackurl){
	document.getElementById('playmusicid').style.display='';
	document.getElementById('playmusicid').innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH=20 HEIGHT=90 id=ml_sound1 > <PARAM NAME=movie VALUE="'+trackurl+'"> <PARAM NAME=loop VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=scale VALUE=noscale> <PARAM NAME=salign VALUE=LT> <PARAM NAME=bgcolor VALUE=#333333> <EMBED src="'+trackurl+'" loop=false quality=high scale=noscale salign=LT bgcolor=#333333  WIDTH=20 HEIGHT=90 id=ml_sound1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" ></EMBED></OBJECT>';
	
	}
	

/*
var startleft=Math.floor(Math.max((document.body.clientWidth-761)/2,0));

if (window.document.getElementById('cms_header')){document.getElementById('cms_header').style.position='absolute';document.getElementById('cms_header').style.left+=startleft;}
if (window.document.getElementById('cms_content_header')){document.getElementById('cms_content_header').style.position='absolute';document.getElementById('cms_content_header').style.left+=startleft;}
if (window.document.getElementById('cms_main_content')){document.getElementById('cms_main_content').style.position='absolute';document.getElementById('cms_main_content').style.left+=startleft;}
if (window.document.getElementById('cms_main_content_left')){alert(document.getElementById('cms_main_content_left').style.left);document.getElementById('cms_main_content_left').style.position='absolute';document.getElementById('cms_main_content_left').style.left+=startleft;alert(document.getElementById('cms_main_content_left').style.left);}
if (window.document.getElementById('cms_main_content_right')){document.getElementById('cms_main_content_right').style.position='absolute';document.getElementById('cms_main_content_right').style.left+=startleft;}
if (window.document.getElementById('cms_main_content_left_right')){document.getElementById('cms_main_content_left_right').style.position='absolute';document.getElementById('cms_main_content_left_right').style.left+=startleft;}
if (window.document.getElementById('cms_left_column')){document.getElementById('cms_left_column').style.position='absolute';document.getElementById('cms_left_column').style.left+=startleft;}

if (window.document.getElementById('cms_right_column')){document.getElementById('cms_right_column').style.position='absolute';document.getElementById('cms_right_column').style.left=startleft + 605;}
*/
}

function itemmenuover(menuitemid){
		
	document.getElementById(menuitemid).style.display='';
	}
	
function itemmenuout(menuitemid){
	document.getElementById(menuitemid).style.display='none';
	
	}
	
function openvideowindow(theURL,winName) { //v2.0
  window.open(theURL,winName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=490,height=540');
}

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://martinlindstrom.com/signup.php?from=brandsense';
	var photoWindow = window.open(link,"BRANDstormNEWSLETTER",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=400,height=610');
}