function toggleLayer(theLayer){
	var lay=document.getElementById(theLayer);

	if(lay.style.visibility=='visible'){
		lay.style.visibility='hidden';
	}
	else{
		lay.style.visibility='visible';
	}
}

function toggle(obj) {
	// Moz. or IE
	var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
	// hide or show
	if(sibling.style.display=='' || sibling.style.display=='block') {
		sibling.style.display='none';
		obj.firstChild.firstChild.data='';
	}
	else {
		sibling.style.display='block';
		obj.firstChild.firstChild.data='';
	}
}
//


function initCollapse() {

	var oDT=document.getElementById('version').getElementsByTagName('dt');
	for (var i=0; i < oDT.length; i++) {
		oDT[i].onclick=function() {toggle(this)};
		var oSpan=document.createElement('span');
		var sign=document.createTextNode('+');
		oSpan.appendChild(sign);
		oDT[i].insertBefore(oSpan, oDT[i].firstChild);
		oSpan.style.fontFamily='arial';
		oSpan.style.paddingRight='2px';
		oDT[i].style.cursor='pointer';
		toggle(oDT[i]);
	}
	oDT=null;
}
function validateNewsletter(){
	var root=document.newsletter;
	var name=root.name;
	var email=root.email;
	var subscribtion=root.subscribtion;

	if(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;

	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = email.value.match(pattern);
	if(!flag2){
		alert("Please enter a valid email address");
		email.focus();
		return false;
	}

	var xmlhttp=false;
	var STATUS = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if(subscribtion[0].checked==true){
		sub="yes";
	}
	else{
		sub="no";
	}
	var url = "/newsletter/suscribeUnsus.php";
	var params="name="+name.value+"&email="+email.value+"&subscribtion="+sub;
	xmlhttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");

	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			resp=xmlhttp.responseText;
			//			alert(resp);
			//			if(resp==1){
			//				alert('The guestbook was signed successfully.');
			//				clearGuestbook();
			//			}
			//			else if(resp==-1){
			//				alert('An error occured while submitting the form. Please try again later.')
			//			}
			//			else{
			alert(resp);
			toggleLayer('newsletterLayer');
			//			}
		}
	}
	xmlhttp.send(params);

}

function checkContactform(){
	var root=document.contactForm;


	var name=root.name;
	var company=root.company;
	var phone=root.phone;
	var fax=root.fax;
	var email=root.email;
	var subject=root.subject;
	var message=root.message;

	if(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(phone.value==""){
		alert('Please enter your home phone number.');
		phone.focus();
		return false;
	}
	if(isNaN(phone.value)){
		alert('The phone number should only contain digits.');
		phone.select();
		return false;
	}
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	if(subject.value==""){
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}
	if(message.value==""){
		alert('Please enter your message.');
		message.focus();
		return false;
	}


}

function clearContactForm(){
	var root=document.contact;

	var name=root.name;
	var email=root.email;
	var subject=root.subject;
	var message=root.message;

	name.value="";
	email.value="";
	subject.value="";
	message.value="";

	return false;
}

function clearGuestbook(){
	var root=document.add_signature;

	var name=root.name;
	var email=root.email;
	var message=root.comment;
	var vcode=root.vcode;

	name.value="";
	email.value="";
	message.value="";
	vcode.value="";

	return false;
}
function showHideGuestbook(){
	var theLayer=document.getElementById('guestbookForm');

	if(theLayer.style.visibility=='hidden'){
		theLayer.style.visibility='visible';
	}
	else{
		theLayer.style.visibility='hidden';
	}
}
function showHidePrayer(){
	var theLayer=document.getElementById('prayerForm');

	if(theLayer.style.visibility=='hidden'){
		theLayer.style.visibility='visible';
	}
	else{
		theLayer.style.visibility='hidden';
	}
}

function toggleNewsletter(){
	var theLayer=document.getElementById('newsletterLayer');

	if(theLayer.style.visibility=='hidden'){
		theLayer.style.visibility='visible';
	}
	else{
		theLayer.style.visibility='hidden';
	}
}

function popImageNew(imageURL,imageTitle){
	//alert(imageURL);
	defaultWidth  = 480;
	defaultHeight = 530;
	//alert(imageURL);
	var optNN='scrollbars=1,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100,resizable=1';
	var optIE='scrollbars=1,width=150,height=100,left=100,top=100,resizable=1';

	var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=1,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100,resizable=1';
		var optIE='scrollbars=1,width=150,height=100,left=100,top=100,resizable=1,resizable=1';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
			writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if (isIE){');
			writeln('window.resizeTo(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src="'+imageURL+'" style="display:block"></body></html>');
			close();
		}
}
function popImage(imageURL,imageTitle){
	//alert(imageURL);
	defaultWidth  = 480;
	defaultHeight = 530;
	//alert(imageURL);
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
	var optIE='scrollbars=no,width=150,height=100,left=100,top=100';

	var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
		var optIE='scrollbars=no,width=150,height=100,left=100,top=100';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
			writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if (isIE){');
			writeln('window.resizeTo(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src="'+imageURL+'" style="display:block"></body></html>');
			close();
		}
}
function popImageForAlbum(imageURL,imageTitle,comment){
	//alert(imageURL);
	defaultWidth  = 480;
	defaultHeight = 530;
	//alert(imageURL);
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
	var optIE='scrollbars=no,width=150,height=100,left=100,top=100';

	var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
		var optIE='scrollbars=yes,width=150,height=100,left=100,top=100';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
			writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if (isIE){');
			writeln('window.resizeTo(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height)+100;');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height+100;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src="'+imageURL+'" style="display:block"><br><span style="font-family: arial;font-size:11px;color:#000000;padding:0px 10px 10px 10px">'+comment+'</span></body></html>');
			close();
		}
}

/*
function validateTellAFriend(e){
var root = document.tell_a_friend;
var name = root.name.value;
if (name==''){
alert('Please fill up your name');
root.name.focus();
return false;
}
var email = root.email.value;
if (email==''){
alert('Please fill up your email');
root.email.focus();
return false;
}
var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
flag=email.match(pattern);
if(!flag){
alert('Please insert a valid email address.');
root.email.select();
return false;
}
var count=0;
for(var i=0;i<e;i++){
var f_name= eval('root.f_name'+i+'.value');
var f_email= eval('root.f_email'+i+'.value');
if(f_name==''&&f_email==''){
count++;
}
if(f_name==''&&f_email!=''){
alert('Please fill up your friends name');
eval('root.f_name'+i+'.focus()');
return false;
}
if(f_name!=''&&f_email==''){
alert('Please fill up your friends email');
eval('root.f_email'+i+'.focus()');
return false;
}
var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
if(f_name!=''){
flag=f_email.match(pattern);
if(!flag){
alert('Please insert a valid email address.');
eval('root.f_email'+i+'.select()');
return false;
}
}
}
if(count==e){
alert('Please provide at least one friend email');
root.f_name0.focus();
return false;
}
var vcode = root.vcode.value;
if (vcode==''){
alert('Please provide the visual code.');
root.vcode.focus();
return false;
}
return true;
}*/
function validateGuestbook(){

	var root=document.add_signature;

	var name=root.name;
	var email=root.email;
	var comment=root.comment;

	if(name.value==''){
		alert('Please enter your name.');
		name.focus();
		return false;
	}
	if(email.value==''){
		alert('Please enter your email address.');
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	if(comment.value==''){
		alert('Please enter your message.');
		comment.focus();
		return false;
	}


	var xmlhttp=false;
	var STATUS = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	var seed1=root.seed1.value;
	var seed2=root.seed2.value;
	var vcode=root.vcode.value;
	var url = "/guestbook/sign.php";
	var params="name="+name.value+"&email="+email.value+"&comment="+comment.value+"&seed1="+seed1+"&seed2="+seed2+"&vcode="+vcode;
	xmlhttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");

	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			resp=xmlhttp.responseText;
			if(resp==1){
				alert('The guestbook was signed successfully.');
				clearGuestbook();
			}
			else if(resp==-1){
				alert('An error occured while submitting the form. Please try again later.')
			}
			else{
				alert(resp);
			}
		}
	}
	xmlhttp.send(params);

}
function validateContact(){
	var root = document.contact;

	if(root.name.value==''){
		alert('Please enter your name.');
		root.name.focus();
		return false;
	}
	if(root.email.value==''){
		alert('Please enter your email address.');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	if(root.subject.value==''){
		alert('Please enter a subject.');
		root.subject.focus();
		return false;
	}
	if(root.message.value==''){
		alert('Please enter a message.');
		root.message.focus();
		return false;
	}

	var xmlhttp=false;
	var STATUS = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	var url = "/contact/send.php";
	var params ="";
	params="name="+root.name.value+"&email="+root.email.value+"&subject="+root.subject.value+"&message="+root.message.value;
	xmlhttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");

	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			resp=xmlhttp.responseText;
			if(resp==1){
				alert('The contact form has been submitted successfully.');
				clearContactForm();
			}
			else if(resp==-1){
				alert('An error occured while submitting the form. Please try again later.')
			}
		}
	}
	xmlhttp.send(params);
}


function validateTellAFriend(e){
	var root = document.tell_a_friend;
	var name = root.name.value;
	var message = root.message;
	if (name==''){
		alert('Please fill up your name');
		root.name.focus();
		return false;
	}
	var email = root.email.value;
	if (email==''){
		alert('Please fill up your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	var count=0;
	for(var i=0;i<e;i++){
		var f_name= eval('root.f_name'+i+'.value');
		var f_email= eval('root.f_email'+i+'.value');
		if(f_name==''&&f_email==''){
			count++;
		}
		if(f_name==''&&f_email!=''){
			alert('Please fill up your friends name');
			eval('root.f_name'+i+'.focus()');
			return false;
		}
		if(f_name!=''&&f_email==''){
			alert('Please fill up your friends email');
			eval('root.f_email'+i+'.focus()');
			return false;
		}
		var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if(f_name!=''){
			flag=f_email.match(pattern);
			if(!flag){
				alert('Please insert a valid email address.');
				eval('root.f_email'+i+'.select()');
				return false;
			}
		}
	}
	if(count==e){
		alert('Please provide at least one friend email');
		root.f_name0.focus();
		return false;
	}
	var vcode = root.vcode.value;
	if (vcode==''){
		alert('Please provide the visual code.');
		root.vcode.focus();
		return false;
	}


	var xmlhttp=false;
	var STATUS = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	var seed1=root.seed1.value;
	var seed2=root.seed2.value;
	var vcode=root.vcode.value;
	var url = "/tell_a_friend/do_tell.php";
	var params="name="+name+"&email="+email+"&message="+message.value+"&seed1="+seed1+"&seed2="+seed2+"&vcode="+vcode;
	for(var j=0;j<e;j++){
		var f_name= eval('root.f_name'+j+'.value');
		var f_email= eval('root.f_email'+j+'.value');
		params+="&f_name"+j+"="+f_name+"&f_email"+j+"="+f_email;
	}
	xmlhttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");

	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			resp=xmlhttp.responseText;
			if(resp==1){
				alert('Your friends were notified successfully.');
				toggleLayer('tell_a_friend');
			}
			else if(resp==-1){
				alert('An error occured while submitting the form. Please try again later.')
				toggleLayer('tell_a_friend');
			}
			else{
				alert(resp);
				toggleLayer('tell_a_friend');
			}
		}
	}
	xmlhttp.send(params);
}
