﻿// JavaScript Document
function flashingText(div, class1, class2)
{
	if(document.getElementById(div).className == class1)
	{
		document.getElementById(div).className=class2;
	}
	else
	{
		document.getElementById(div).className=class1;
	}
}

// Preload Over and Down state images
Image1= new Image(10,12);
Image1.src = "../images/alexButtonBgDown.gif";
Image2= new Image(10,12);
Image2.src = "../images/alexButtonBgOn.gif";

function press(ID)
{
	document.getElementById(ID).style.backgroundImage='url(../images/alexButtonBgDown.gif)';
	document.getElementById(ID).style.backgroundPosition='top';
}
function release(ID)
{
	document.getElementById(ID).style.backgroundPosition='bottom';
	document.getElementById(ID).style.backgroundImage='url(../images/alexButtonBg.gif)';
}
function over(ID)
{
	document.getElementById(ID).style.backgroundPosition='bottom';
	document.getElementById(ID).style.backgroundImage='url(../images/alexButtonBgOn.gif)';
}
	function linkify(URL,target, config)
{
	if(target != '')
	{
		// Open in a new window
		window.open(URL, target, config);
	}
	else
	{
		location.href=URL;
	}
}

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.id; 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 == '');
}

function doSubmit(formName, page)
{
	switch(page)
	{
		case 'index':
			// Ask Page
			MM_validateForm('formquestion','','R','formname','','R','formemail1','','RisEmail'); 
			break;
		case 'taf':
			// Tell-A-Friend
			MM_validateForm('Your First Name','','R','Your Email','','RisEmail','Friends Name','','R','Friends Email','','RisEmail');
			break;
	}
	
	if(document.MM_returnValue != true)
	{
		return document.MM_returnValue;
	}
	else
	{
		switch(page)
		{
			case 'index':
				// Ask Page
				document.forms[formName].submit();
				break;
			case 'taf':
				// Tell-A-Friend
				document.forms[formName].elements['ajax'].value = 'true';
				submitForm(document.forms[formName]);
				break;
		}
	}
}

// Close all <div class="close">
function classChange()
{
	for (i=0;i<document.getElementsByTagName("div").length; i++) 
	{
		if (document.getElementsByTagName("div").item(i).className == "close")
		{
			document.getElementsByTagName("div").item(i).style.display = "none";
		}
	}
}

/* Collapsable/Expandable Div Display Box */
function showDiv(ID, closeAll)
{
	/*
	Author:
		Another Tool by SBC 2005-12-05
	Usage:
		showDiv(ID)
	Purpose:
		Allows a "hidden" div to be placed in a HTML document and displayed when appropritate with
		the use of JavaScript event handlers: onClick, onMouseover and etc.
	Directions:
		Use the <div> statement below to establish your display box.
		
			<div id="Unique_ID_Name_Goes_Here" style="display:none;">
			
		If you want the display box visible when the page loads, change display:none to display:block.
		You can call this function using any JavaScript event handler method.  Below are some examples.
		
		Hyperlink:
			<a href="#" onclick="showDiv('Unique_ID_Name_Goes_Her'); return false">Display or Close Display Box</a>
			
		Input button:
			<input type="button" onclick="showDisplay('Unique_ID_Name_Goes_Her'); return false" value="Display or Close Display Box">
	*/
	// Should all open divs be closed?
	// If there is no div, don't throw a JavaScript error
	if(!document.getElementById(ID)){ alert('The ID `' + ID + '` does not exist on this page.'); return false; }
	
	// Evaluate the current visibility status of the display box.
	if(document.getElementById(ID).style.display == 'none')
	{
		if(closeAll == true){ classChange(); }		
		// The display box is not visible, so we want to display the box
		document.getElementById(ID).style.display='block';
	}
	else
	{
		if(closeAll == true){ classChange(); }				
		// The display box is visible, so we want to hide the display box
		document.getElementById(ID).style.display='none';
	}
}

function up_or_down(ID)
{
	if(up == true)
	{
		document.getElementById(ID).src = 'images/Collapse-Up.jpg';
		up = false;
	}
	else
	{		
		document.getElementById(ID).src = 'images/Collapse-Down.jpg';	
		up = true;
	}
}

function hideMessage()
{
	// Hide system messages on Admin page.
	document.getElementById('message').style.display='none';
	clearInterval(intervalID);
}

function addSecurityCode(formName, fieldName, ID)
{
	securityCode = document.forms[formName].elements[fieldName];

	// Does the field have data in it?
	if(securityCode.value.length != 0)
	{
		secruityLock = "?vbt=" + securityCode.value;
	}
	else
	{
		secruityLock = '';
	}
	
	// Return data to page
	document.getElementById(ID).innerHTML= secruityLock;
}

function forceDownloadAlert()
{
	if(document.forms['form1'].elements['forceDownload'].checked == true)
	{
		alert('By checking this box you will have to upload the config.ask.php file manually.');
	}
}

function setImage(newValue, img, formName, fieldName)
{
	if(newValue != '')
	{ 
		document.getElementById(img).src= newValue; 
		document.forms[formName].elements[fieldName].value= newValue; 
	}
}

function setFile(newValue, formName, fieldName)
{
	if(newValue != '')
	{ 
		document.forms[formName].elements[fieldName].value= newValue; 
	}
}

function submitForm(f)
{
	if(window.XMLHttpRequest){
	var xmlReq = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
	var xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
	}
	var formData = '', elem = '';
	for(var s=0; s<f.elements.length; s++){
	elem = f.elements[s];
	if(formData != ''){
	formData += '&';
	}
	formData += elem.name+"="+elem.value;
	}
	xmlReq.onreadystatechange = function(){
	if(xmlReq.readyState == 4){
	document.getElementById('taf').innerHTML = xmlReq.responseText;
	}
	}
	xmlReq.open(f.method, f.action, true);
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlReq.send(formData);
	return false;
}

function setFlashCode(formName, targetFieldName, filePath, swfWidth, swfHeight)
{
	// Look for existing content
	if(document.forms[formName].elements[targetFieldName].value != '')
	{
		overwrite = confirm("This Custom HTML field already contains data.\nAre you sure you want to overwrite the current data?\n\nIf you would like to overwrite the current data press `Ok`\n\nOR\n\nIf you want to keep the current data press `Cancel`.");
	}
	else{ overwrite = true; }
	
	if(overwrite == true)
	{
		output  = '<script type="text/javascript">\n';
		
		output += "AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0','width','"+ swfWidth +"','height','"+ swfHeight +"','src','" + filePath.substr(0, (filePath.length-4)) + "','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','" + filePath.substr(0, (filePath.length-4)) + "' ); //end AC code";
		output += '</script>\n';
		output += '<noscript>\n';
		output += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="' + swfHeight + '" width="' + swfWidth + '">\n';
		output += '<param name="movie" value="' + filePath + '">\n';
		output += '<param name="quality" value="high">\n';
		output += '<embed src="' + filePath + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" height="' + swfHeight + '" width="' + swfWidth + '">';
		output += '</object>\n';
		output += '</noscript>';
	
		// Set new HTML
		document.forms[formName].elements[targetFieldName].value=output;
	}
}

function setImageCode(formName, targetFieldName, filePath, imgWidth, imgHeight, imgBorder, imgTitle, imgAlign)
{
	// Look for existing content
	if(document.forms[formName].elements[targetFieldName].value != '')
	{
		overwrite = confirm("This Custom HTML field already contains data.\nAre you sure you want to overwrite the current data?\n\nIf you would like to overwrite the current data press `Ok`\n\nOR\n\nIf you want to keep the current data press `Cancel`.");
	}
	else{ overwrite = true; }
	
	if(overwrite == true)
	{
		// check for empty attributes and do not include them
		if(imgWidth == '')  { newWidth = "";   } else { newWidth   = ' width="' + imgWidth + '"'; }
		if(imgHeight == '') { newHeight = "";  } else { newHeight = ' height="' + imgHeight + '"'; }
		if(imgTitle == '')  { newTitle = "";   } else { newTitle   = ' title="' + imgTitle + '"'; }
		if(imgBorder == '') { newBorder = "";  } else { newBorder  = ' border="' + imgBorder + '"'; }
		if(imgAlign == '')  { newAlign = "";   } else { newAlign   = ' align="' + imgAlign + '"'; }		
		
		output = '<img src="' + filePath + '"' + newHeight + newWidth + newTitle + newBorder + newAlign + '>';

		// Set new HTML
		document.forms[formName].elements[targetFieldName].value=output;			
	}
}

function setInputValue(formName, fieldName, newValue)
{
	document.forms[formName].elements[fieldName].value= newValue;
}

function campaign(type)
{
	field     = new Array();
	field[0]  = "_common['teleseminar_call_duration']";
	field[1]  = "_common['teleseminar_date']";
	field[2]  = "_common['teleseminar_time']";
	field[3]  = "_common['teleseminar_phone_number']";
	field[4]  = "_common['teleseminar_pass_code']";
	field[5]  = "scrapbookEight";
	field[6]  = "_thanks['notes']";
	field[7]  = "_thanks['is_paid']";
	field[8]  = "_thanks['pay_url']";
	field[9]  = "_replay['is_paid']";
	field[10] = "_replay['pay_url']";
	field[11] = "scrapbookFive";
	field[12] = "_replay['image']";
	field[13] = "scrapbookSix";
	field[14] = "_replay['transcript']";
	field[15] = "_replay['one_click']";
	field[16] = "_replay_audio[1]";
	field[17] = "_replay_audio[2]";
	field[18] = "_replay_audio[3]";
	field[19] = "_replay_audio[4]";
	field[20] = "_replay_audio[5]";
	field[21] = "_replay_audio[6]";
	field[22] = "_replay_download[1]";
	field[23] = "_replay_download[2]";
	field[24] = "_replay_download[3]";
	field[25] = "_replay_download[4]";
	field[26] = "_replay_download[5]";
	field[27] = "_replay_download[6]";
	field[28] = "_replay['taf_subject']";
	field[29] = "_replay['taf_email']";
	
	for(i=0; i<=(field.length-1); i++)
	{
		if(type == 'ask'){ document.forms['form1'].elements[field[i]].disabled = true; document.getElementById('rcYes').disabled = true; document.getElementById('rcNo').disabled = true; }
		else             { document.forms['form1'].elements[field[i]].disabled = false; document.getElementById('rcYes').disabled = false; document.getElementById('rcNo').disabled = false; }
	}
	
	if(type == 'ask'){ document.getElementById('disableReplay').style.display = "none"; document.getElementById('replayAlert').style.display = "block"; }
	else             { document.getElementById('disableReplay').style.display = "block"; document.getElementById('replayAlert').style.display = "none"; }
}

var base64		= {
 charmap		: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 encode			: function(str) {
  var ret		= "";
  var c, i, acc		= 0;
  var div		= 1;
  for(i=0,c=0;i<str.length;i++,c++) {
   acc			= acc*256 + str.charCodeAt(i);
   div			= div*4;
   ret			= ret + base64.charmap.charAt(parseInt(acc/div));
   acc			= acc % div;
   if(div==64) ret	= ret + base64.charmap.charAt(parseInt(acc)), acc = 0, div = 1,c++;
   if(c>=75) c=-1, ret	= ret + "\n";
  } if(i%3) {
   ret			= ret + base64.charmap.charAt(parseInt(acc*((i%3==1)?16:4)));
   ret			= ret + ((i%3)==1?"==":"=");
  } return ret;
 },
 decode			: function(str) {
  var ret		= "";
  var i, acc		= 0;
  var div		= 1;
  for(i=0;i<str.length;i++) {
   if(str.charAt(i)=="=" || str.charAt(i)=='\n') break;
   acc			= acc*64 + base64.charmap.indexOf(str.charAt(i));
   div			= (div==1?64:div/4);
   if(div!=64) {
    ret			= ret + String.fromCharCode(parseInt(acc/div));
    acc			= acc % div;
   }
  } return ret;
 }
}

var closeAll = false; // true|false



function bookMark(pageURL, pageTitle) 
{ 
	if (window.external) { window.external.AddFavorite(pageURL,pageTitle) } 
	else { alert("Sorry! Your browser doesn't support this function."); } 
} 

function myCookie(name, value, expiry, path, domain)
{
	document.cookie= name + "=" + value + "; expires=" + expiry + "; " + " path=" + path + "; domain=" + domain + ";";
}