// Global Scripts



// Alert Popup
function popupMsg(msg) { //v1.0
  alert(msg);
}

// Force checkbox selection

function check_it(obj)
{
if (obj.id == 'chk1' && obj.checked) {
document.getElementById('chk2').checked = false;
}
else if (obj.id == 'chk2' && obj.checked) {
document.getElementById('chk1').checked = false;
}

}


// Show-hide layers

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 showHideLayers() { //v6.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// Image Swap
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 swapImage() { //v3.0
  var i,j=0,x,a=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];}
}

// Open Browser Window
function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Set Text Of Field
function setText(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}


// Confirm Box
function confirm_entry()
{
input_box=confirm("This feature is available to Community Members Only\rWould you like to go to the Members page?.");
if (input_box==true)

{ 
// Output when OK is clicked
window.location="http://www.christianhills.org/members"; 
}

else
{
// Output when Cancel is clicked
window.location="#"
}

}

// HOME PAGE THUMB NAVIGATION - LINKABLE
function ChangeColor(tableRow, highLight)
    {
    if (highLight)
    {
      tableRow.style.backgroundColor = '#DFEEEE';
	  tableRow.style.cursor='help';
    }
    else
    {
      tableRow.style.backgroundColor = '';
	  this.style.cursor='auto';
    }
  }

  function DoNav(theUrl)
  {
  document.location.href = theUrl;
  }



//*********************************
//   CD Order Validation Functions
//*********************************
function isEmpty(s) {
   if (s==null || s=='') {
          return true;
   }else{
          return false;
   }
}
function isEmail(strValue) {
   regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/
  
   if (isEmpty(strValue)) {
       return false;
	   }
	   return regexp.test(strValue);
}
function cdorderForm() {
		// Check the document for required fields
		if(isEmpty(document.forms[0].name.value)){
		   alert("Please fill in your Name");
		   document.forms[0].name.focus();
		   return false;
		}
		if(!isEmail(document.forms[0].email.value)){
		   alert("Please fill in your email address correctly");
		   document.forms[0].email.focus();
		   return false;
		}
		
		//Check state of checkbox if checked then validate fields
		if(document.forms[0].chk2.checked) {
			if(isEmpty(document.forms[0].address.value)){
		   	alert("Please fill in your Address");
		   	document.forms[0].address.focus();
		  	return false;
		  	 }  
			if(isEmpty(document.forms[0].city.value)){
		   	alert("Please fill in your City");
		   	document.forms[0].city.focus();
		   	return false;
		  	 }  
			if(isEmpty(document.forms[0].state.value)){
		   	alert("Please fill in your State");
		   	document.forms[0].state.focus();
		    return false;
		  	 }  
			 if(isEmpty(document.forms[0].zip.value)){
		   	alert("Please fill in your Zip Code");
		   	document.forms[0].zip.focus();
		   	return false;
		  	 }  
		 }
			document.forms[0].submit();
		}
			

//*****************************
//   Email Validation Functions
//*****************************

function contactForm() {

		if(isEmpty(document.forms[0].txtFullName.value)){
		   alert("Please fill in your name");
		   document.forms[0].txtFullName.focus();
		   return false;
		}
	
		if(!isEmail(document.forms[0].txtEmail.value)){
		   alert("Please fill in your email address correctly");
		   document.forms[0].txtEmail.focus();
		   return false;
		}
		
		if(isEmpty(document.forms[0].txtMessage.value)){
		   alert("Please type a message");
		   document.forms[0].txtMessage.focus();
		   return false;
		}
			document.forms[0].submit();
		}
		
		
//*****************************
//   Email Validation Functions
//*****************************

function prForm() {

		if(isEmpty(document.forms[0].txtFullName.value)){
		   alert("Please fill in your name");
		   document.forms[0].txtFullName.focus();
		   return false;
		}
		
		if(isEmpty(document.forms[0].prayFor.value)){
		   alert("Please provide at least a First Name to pray for.");
		   document.forms[0].prayFor.focus();
		   return false;
		}
	
		if(isEmpty(document.forms[0].txtMessage.value)){
		   alert("Please provide the request");
		   document.forms[0].txtMessage.focus();
		   return false;
		}
			document.forms[0].submit();
		}
			
//********************
//  End of Functions 
//********************




//******************************************
//   Resource Submition Validation Functions
//******************************************

function rg() {

		if(isEmpty(document.forms[0].title.value)){
		   alert("Please priovide a TITLE");
		   document.forms[0].title.focus();
		   return false;
		}
		
		if(isEmpty(document.forms[0].descript.value)){
		   alert("Please include a short DESCRIPTION");
		   document.forms[0].descript.focus();
		   return false;
		}
	
		if(isEmpty(document.forms[0].topics.value)){
		   alert("Please include at least one TOPIC");
		   document.forms[0].topics.focus();
		   return false;
		}
			document.forms[0].submit();
		}
			
//********************
//  End of Functions 
//********************



