
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 validateNewsletter(){
	var root=document.newsletter;

	var name=root.name;
	var email=root.email;


	if(name.value==''){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(email.value==''){
		alert('Please enter your email address.');
		email.focus();
		return false;
	}

}

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;
	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;
	}
}

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.contactus;

	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(confirm('Are you sure you want to clear this form?')){
		name.value="";
		company.value="";
		fax.value="";
		phone.value="";
		email.value="";
		subject.value="";
		message.value="";

		return false;
	}

	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 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=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);');
			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 toggleLayer(theLayer){
	var layer=document.getElementById(theLayer);
	arrayOfLayers = ['saintOfTheDay','bibleOfTheDay'];

	var numOfEntries=arrayOfLayers.length;
	for (i=0;i<numOfEntries;i++) {
		var xElement=arrayOfLayers[i];
		if(xElement!=theLayer){
			theElement = eval(document.getElementById(arrayOfLayers[i]));
			theElement.style.visibility='hidden';
		}
	}

	if(layer.style.visibility=='hidden'){
		layer.style.visibility='visible';
	}
	else{
		layer.style.visibility='hidden';
	}

}
function copy_clip(meintext){

	var browserName=navigator.appName;
	if (browserName=="Microsoft Internet Explorer")
	{

		if (window.clipboardData)
		{
			// the IE-way
			window.clipboardData.setData("Text", meintext);

			// Probabely not the best way to detect netscape/mozilla.
			// I am unsure from what version this is supported
		}
		else if (window.netscape)
		{

			// This is importent but it's not noted anywhere
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

			// create interface to the clipboard
			var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
			if (!clip) return;

			// create a transferable
			var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
			if (!trans) return;

			// specify the data we wish to handle. Plaintext in this case.
			trans.addDataFlavor('text/unicode');

			// To get the data from the transferable we need two new objects
			var str = new Object();
			var len = new Object();

			var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

			var copytext=meintext;

			str.data=copytext;

			trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

			var clipid=Components.interfaces.nsIClipboard;

			if (!clip) return false;

			clip.setData(trans,null,clipid.kGlobalClipboard);

		}
		alert("Following info was copied to your clipboard:\n\n" + meintext);
		return false;
	}
	else
	{
		alert('This option can only be used on Internet Explorer.')
	}
}
function toggleBirthdayDeath(theLayer,otherLayer,lang){
	var a=theLayer;
	var b=otherLayer;
	var theLayer=document.getElementById(theLayer);
	var otherLayer=document.getElementById(otherLayer);

	var theImage=eval(document.getElementById('birthdayImg'));
	var otherImage=eval(document.getElementById('deathImg'));

	otherLayer.style.visibility='hidden';
	theLayer.style.visibility='visible';

	if(a=='birthday'){
		theImage.src='/images/'+lang+'/botd_on.gif';
		otherImage.src='/images/'+lang+'/dotd_off.gif';
	}
	else{
		theImage.src='/images/'+lang+'/botd_off.gif';
		otherImage.src='/images/'+lang+'/dotd_on.gif';
	}

}
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;
	}

}
function validateContact(){
	var root = document.contactus;

	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;
	}
	return true;
}


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 rotateBirthday(imageString,num){
	var img=document.getElementById('bImage');
	var interval=5000;
	var imageArray=new Array();
	var imageArray=imageString.split('?%?');
	var len=imageArray.length;
	if(num>=len){
		num=0;
	}
	img.src="/birthday/images/thumb/"+imageArray[num];
	num++;
		setTimeout("rotateBirthday('"+imageString+"',"+num+");",interval);
}

function rotateDeath(imageString,num){
	var img=document.getElementById('dImage');
	var interval=5000;
	var imageArray=new Array();
	var imageArray=imageString.split('?%?');
	var len=imageArray.length;
	if(num>=len){
		num=0;
	}
	img.src="/birthday/images/thumb/"+imageArray[num];
	num++;
		setTimeout("rotateDeath('"+imageString+"',"+num+");",interval);
}
function reloadLinksHP(){
	var catId=document.getElementById('cat_name').value;

	location.href='/links/index.php?cat='+catId;
	return true;
}
//////////////////////////////////
///////////////
if(document.images){

var botd_on=new Image();
var botd_off=new Image();
var dotd_on=new Image();
var dotd_off=new Image();
}
/////////////////////////

function swapIMG(num,lang){
var fd;

if(lang=='ar'){
fd="ar";
}
else{
fd="en";
}
//alert(num);
botd_on.src="../images/"+fd+"/"+"botd_on.gif";
botd_off.src="../images/"+fd+"/"+"botd_off.gif";
dotd_on.src="../images/"+fd+"/"+"dotd_on.gif";
dotd_off.src="../images/"+fd+"/"+"dotd_off.gif";
//alert(botd_on.src);
if(document.images){

	if(num=='1'){
		document.images["birthday"].src=botd_on.src;
		document.images["death"].src=dotd_off.src;
		var state = document.getElementById('birthdaydiv').style.visibility;
        if(state == "hidden"){
                document.getElementById('birthdaydiv').style.visibility="visible";
                document.getElementById('deathdiv').style.visibility='hidden';
	  }
	}
	if(num=='2'){
		document.images["birthday"].src=botd_off.src;
		document.images["death"].src=dotd_on.src;
		 var state1 = document.getElementById('deathdiv').style.visibility;
        if(state1 == "hidden"){
                document.getElementById('birthdaydiv').style.visibility="hidden";
                document.getElementById('deathdiv').style.visibility='visible';
	 }
  }
}
}

