
// Beginning of Popup window code -->
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
// End of Popup window code -->

function printpage() {
window.print();  
}

function hidetoggle (id)
{
    if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
	return false;
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// AJAX Function to make a post of form data to the specified URL
var http_request = false;
function makePOSTRequest(url, parameters) {
//alert(url);
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById('myspan').innerHTML = result;            
	 } else {
		alert('There was a problem with the request.\nError: '+http_request.status+'\n'+http_request.responseText);
	 }
  }
}
   
// Simple functions to have default text in the textarea of Send teaching to a friend Message
function BroadcastMSGclearText() {
 if (document.SendTeachingtoFriend.YourMessage.value == "I'm sending you this teaching because I thought you might enjoy listening to it.") {
  document.SendTeachingtoFriend.YourMessage.value = "";
 } else {
  document.SendTeachingtoFriend.YourMessage.select();
 }
}
 
function BroadcastMSGcheckText() {
 if (document.SendTeachingtoFriend.YourMessage.value == "") {
  document.SendTeachingtoFriend.YourMessage.value = "I'm sending you this teaching because I thought you might enjoy listening to it.";
 }
}

// This function takes the values from the form and Posts to the POSTRequest Function
function BroadcastGet(obj) {
  var poststr = "YourName=" + encodeURI( document.getElementById("YourName").value ) +
				"&YourEmail=" + encodeURI( document.getElementById("YourEmail").value ) +
				"&FriendsName=" + encodeURI( document.getElementById("FriendsName").value ) +
				"&FriendsEmail=" + encodeURI( document.getElementById("FriendsEmail").value ) +
				"&YourMessage=" + encodeURI( document.getElementById("YourMessage").value ) +
				"&BroadcastID=" + encodeURI( document.getElementById("BroadcastID").value ) +
				"&SendForm=" + encodeURI( document.getElementById("SendForm").value );
  makePOSTRequest('teachingtofriend.asp', poststr);
}
   
// This function is for "Send this teaching to a Friend" - It generates a nice layout of the form with the unique ID
function SendBroadcastToFriend(vBroadcastID) {

var vBroadcastForm = '';
   vBroadcastForm += "<span name=\"myspan\" id=\"myspan\"><form action=\"javascript:BroadcastGet(document.getElementById('SendTeachingtoFriend'));\" name=\"SendTeachingtoFriend\" id=\"SendTeachingtoFriend\" style=\"text-align:center;\">";
   vBroadcastForm += "<div style=\"width:325px;\">";
   vBroadcastForm += "    <div class=\"formColLabel\">Your Name:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"YourName\" type=\"text\" id=\"YourName\" size=\"25\" /></div>";
   vBroadcastForm += "    <div class=\"formColLabel\">Your E-mail:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"YourEmail\" type=\"text\" id=\"YourEmail\" size=\"25\" /></div>";
   vBroadcastForm += "    <div class=\"formColLabel\">Friend's Name:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"FriendsName\" type=\"text\" id=\"FriendsName\" size=\"25\" /></div>";
   vBroadcastForm += "    <div class=\"formColLabel\">Friend's E-mail:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"FriendsEmail\" type=\"text\" id=\"FriendsEmail\" size=\"25\" /></div>";
   vBroadcastForm += "    <div style=\"width:125px;height:95px;font-weight:bold;padding: 6px 0px;text-align:left;float:left;\">Message:</div> <div style=\"width:200px;height:95px;padding: 6px 0px;text-align:left;float:left;clear:right;\"><textarea class=\"frm_fields\" id=\"YourMessage\" name=\"YourMessage\" cols=\"25\" style=\"height:95px;\" onfocus=\"javascript: BroadcastMSGclearText();\" onblur=\"javascript: BroadcastMSGcheckText();\">I'm sending you this teaching because I thought you might enjoy listening to it.</textarea></div>";
   vBroadcastForm += "    <div class=\"formColLabel\"><input type=\"hidden\" name=\"BroadcastID\" id=\"BroadcastID\" value=\""+vBroadcastID+"\" /></div> <div class=\"formColField\"><input class=\"frm_button\" name=\"Submit\" type=\"submit\" onclick=\"MM_validateForm('YourName','','R','YourEmail','','RisEmail','FriendsName','','R','FriendsEmail','','RisEmail');return document.MM_returnValue\" value=\"Send Teaching\" /></div>";
   vBroadcastForm += "</div>";
   vBroadcastForm += "<input name=\"SendForm\" type=\"hidden\" id=\"SendForm\" value=\"SendTeachingtoFriend\"></form></span>";
   
   return vBroadcastForm;
}

function BroadcastOptions(BroadcastID, BroadcastTapeNum, BroadcastTapeNumTrim, BroadcastFileName) {
	var returnValue = '';
	
	if (BroadcastFileName != 0) {
		returnValue += "<a href=\"http://www.connectionradio.org/images/flash/player.asp?id="+BroadcastID+"\" title=\"Listen\" onclick=\"NewWindow(this.href,'broadcastPlayer','610','230');return false;\"><img src=\"images/web_ui/icon_listen16.png\" alt=\"Listen\" width=\"20\" height=\"20\" border=\"0\" align=\"absmiddle\" style=\"padding: 6px;\" /></a><a href=\"http://www.connectionradio.org/images/flash/player.asp?id="+BroadcastID+"\" title=\"Listen\" onclick=\"NewWindow(this.href,'broadcastPlayer','610','230');return false;\">Listen</a> "
		returnValue += "<a href=\"http://audio.calvaryabq.org/connection/"+BroadcastFileName+".mp3\" title=\"Download\"><img src=\"images/web_ui/icon_download16.png\" alt=\"Download\" width=\"20\" height=\"20\" border=\"0\" align=\"absmiddle\" style=\"padding: 6px;\" /></a><a href=\"http://audio.calvaryabq.org/connection/"+BroadcastFileName+".mp3\" title=\"Download\">Download</a> "
	}
	if (BroadcastTapeNum != 0) {
		returnValue += "<a href=\"https://calvaryabq.org/Merchant2/merchant.mvc?Screen=PROD&Store_Code=CALVARY&Product_Code="+BroadcastTapeNumTrim+"\" target=\"_blank\" title=\"Buy\"><img src=\"images/web_ui/icon_shoppingcart16.png\" alt=\"Buy\" width=\"20\" height=\"20\" border=\"0\" align=\"absmiddle\" style=\"padding: 6px;\" /></a><a href=\"https://calvaryabq.org/Merchant2/merchant.mvc?Screen=PROD&Store_Code=CALVARY&Product_Code="+BroadcastTapeNumTrim+"\" target=\"_blank\" title=\"Buy\">Buy</a> "
	}
	returnValue += "<a href=\"javascript:void(0);\" onclick=\"return overlib(''+SendBroadcastToFriend("+BroadcastID+"), STICKY, CAPTION,'Send Teaching to friend \\'"+BroadcastTapeNum+"\\'', CENTER, CLOSECLICK, WIDTH, 400, RELY, 200, RELX, document.body.scrollWidth/2-200);\"><img src=\"images/web_ui/icon_email.png\" alt=\"Send to Friend\" width=\"20\" height=\"20\" border=\"0\" align=\"absmiddle\" style=\"padding: 6px;\" /></a><a href=\"javascript:void(0);\" onclick=\"return overlib(''+SendBroadcastToFriend("+BroadcastID+"), STICKY, CAPTION,'Send Teaching to friend \\'"+BroadcastTapeNum+"\\'', CENTER, CLOSECLICK, WIDTH, 400, RELY, 300, RELX, document.body.scrollWidth/2-200);\">Send</a>"
	
	return returnValue;
}

function DevoMSGclearText() {
 if (document.SendDevotoFriend.YourMessage.value == "I'm sending you this DevoMail because I thought you might enjoy reading it.") {
  document.SendDevotoFriend.YourMessage.value = "";
 } else {
  document.SendDevotoFriend.YourMessage.select();
 }
}
 
function DevoMSGcheckText() {
 if (document.SendDevotoFriend.YourMessage.value == "") {
  document.SendDevotoFriend.YourMessage.value = "I'm sending you this DevoMail because I thought you might enjoy reading it.";
 }
}

// This function takes the values from the form and Posts to the POSTRequest Function
function DevoGet(obj) {
  var poststr = "YourName=" + encodeURI( document.getElementById("YourName").value ) +
				"&YourEmail=" + encodeURI( document.getElementById("YourEmail").value ) +
				"&FriendsName=" + encodeURI( document.getElementById("FriendsName").value ) +
				"&FriendsEmail=" + encodeURI( document.getElementById("FriendsEmail").value ) +
				"&YourMessage=" + encodeURI( document.getElementById("YourMessage").value ) +
				"&DevoID=" + encodeURI( document.getElementById("DevoID").value ) +
				"&SendForm=" + encodeURI( document.getElementById("SendForm").value );
  makePOSTRequest('devomail_sendAJ.asp', poststr);
}
   
// This function is for "Send this Devo to a Friend" - It generates a nice layout of the form with the unique ID
function SendDevoToFriend(vDevoID) {

var vDevoForm = '';
   vDevoForm += "<span name=\"myspan\" id=\"myspan\"><form action=\"javascript:DevoGet(document.getElementById('SendDevotoFriend'));\" name=\"SendDevotoFriend\" id=\"SendDevotoFriend\" style=\"text-align:center;\">";
   vDevoForm += "<div style=\"width:325px;\">";
   vDevoForm += "    <div class=\"formColLabel\">Your Name:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"YourName\" type=\"text\" id=\"YourName\" size=\"25\" /></div>";
   vDevoForm += "    <div class=\"formColLabel\">Your E-mail:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"YourEmail\" type=\"text\" id=\"YourEmail\" size=\"25\" /></div>";
   vDevoForm += "    <div class=\"formColLabel\">Friend's Name:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"FriendsName\" type=\"text\" id=\"FriendsName\" size=\"25\" /></div>";
   vDevoForm += "    <div class=\"formColLabel\">Friend's E-mail:</div> <div class=\"formColField\"><input class=\"frm_fields\" name=\"FriendsEmail\" type=\"text\" id=\"FriendsEmail\" size=\"25\" /></div>";
   vDevoForm += "    <div style=\"width:125px;height:95px;font-weight:bold;padding: 6px 0px;text-align:left;float:left;\">Message:</div> <div style=\"width:200px;height:95px;padding: 6px 0px;text-align:left;float:left;clear:right;\"><textarea class=\"frm_fields\" id=\"YourMessage\" name=\"YourMessage\" cols=\"25\" style=\"height:95px;\" onfocus=\"javascript: DevoMSGclearText();\" onblur=\"javascript: DevoMSGcheckText();\">I'm sending you this DevoMail because I thought you might enjoy reading it.</textarea></div>";
   vDevoForm += "    <div class=\"formColLabel\"><input type=\"hidden\" name=\"DevoID\" id=\"DevoID\" value=\""+vDevoID+"\" /></div> <div class=\"formColField\"><input class=\"frm_button\" name=\"Submit\" type=\"submit\" onclick=\"MM_validateForm('YourName','','R','YourEmail','','RisEmail','FriendsName','','R','FriendsEmail','','RisEmail');return document.MM_returnValue\" value=\"Send DevoMail\" /></div>";
   vDevoForm += "</div>";
   vDevoForm += "<input name=\"SendForm\" type=\"hidden\" id=\"SendForm\" value=\"SendDevotoFriend\"></form></span>";
   
   return vDevoForm;
}

function matchHeight() {
	document.getElementById('nav').style.height = document.getElementById('main').offsetHeight+"px";
}
window.onload=function(){
	 if(document.getElementById){
		  matchHeight();
	 }
}

