/********************************/
/***  Filename:	cm_scripts.js	*/
/***  		                    */
/********************************/

// Change Subscription Type to 1Shoppingcart.com			   
function setHTML (option) {
    var newsLetterHTML          = '237380'; 
    var	newsLetterText          = '237383'; 
    var webSubscribeHTML        = '237393';  // Option 2 	
    var webSubscribeReportsHTML	= '237390';  // Option 1
    var webSubscribeText	    = '237396';  // Option 2
    var webSubscribeReportsText	= '237392';  // Option 1 
	
	// Set Web Autoresponder
    if (option == 1) {          // Reports
       document.form1.ar[0].value = (document.form1.html.checked) ?  webSubscribeReportsHTML : webSubscribeReportsText;
    } 
	else if (option == 2) {	     // No Reports
       document.form1.ar[0].value = (document.form1.html.checked) ?  webSubscribeHTML : webSubscribeText;
	}
	
	// Set Newsletter Subscriber
    document.form1.ar[1].value = (document.form1.html.checked) ? newsLetterHTML : newsLetterText;	
	return (true);
}

// Check for a Valid Email Address
function validateEmailAddress (email) {
    var regexString = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$";
    var regex       = new RegExp(regexString, "i");
    var results     = regex.exec( email );
    if( results == null ) { return ""; }  // bad address return ""
    else { return results[0]; }	          // good address return address
}


// Popup a Specific Sized Window
function popWindow (url, name, w, h) {
	if (name == null) { name = url; }
    var popWin = window.open(url, name, "status,resizable,width="+w+",height="+h+"");
    popWin.focus();
}

// Show Window Message
function popContentWindow (name, content, w, h) {
	var popContent = window.open('/', name, "status,resizable,left=200,top=200,width="+w+",height="+h+"");
	popContent.document.write('<HTML>\n<HEAD>\n');
	popContent.document.write('<TITLE>Pop Up Message</TITLE>\n');
	popContent.document.write('<link href="/common/cm_styles.css" rel="stylesheet" type="text/css">\n');
	popContent.document.write('</HEAD>\n');
	popContent.document.write('<BODY">\n');
								 
	popContent.document.write('<table>\n');
   	popContent.document.write('<tr><td width=5>&nbsp;</td><td class="style49">'+content+'</td><td width=5>&nbsp;</td></tr>\n');	
   	popContent.document.write('<tr><td width=5>&nbsp;</td>\n');
	popContent.document.write('<td align="right"><br><br><a href="javascript:window.close();"><span class="style63">CLOSE WINDOW</span></a></td>');
	popContent.document.write('<td width=5>&nbsp;</td></tr>\n');	
	popContent.document.write('</table>\n');

	popContent.document.write('</BODY>\n');
	popContent.document.write('</HTML>\n');
	popContent.document.close();
	popContent.focus();
}


	
// Article Page Setup
function setupArticle () {
    var text = document.getElementById("article_text").innerHTML;
    var nl   = text.split("\n", 1);
    var title = nl[0].replace(/^<pre>/i,'').replace(/^\s+/,'').replace(/\s+$/g,''); 
    var newText = text.replace(title,'');
  																
    //document.title = "Better Conversations eZine - " +title;
    document.getElementById("article_title").innerHTML = title;
    document.getElementById("article_text").innerHTML = newText;
}

// Get Article Title
function getArticleTitle () {
    return ( document.getElementById("article_title").innerHTML );
}
// Get Article Text
function getArticleText () {
    return ( document.getElementById("article_text").innerHTML );
}
// Get Article Copyright
function getArticleCopyright () {
    return ( document.getElementById("article_copyright").innerHTML );
}

// Get Parent Page Information
function getParentTitle () {
    return ( window.parent.opener.document.getElementById("article_title").innerHTML );
}
function getParentText () {
    return ( window.parent.opener.document.getElementById("article_text").innerHTML );
}
function getParentCopyright () {
    return ( window.parent.opener.document.getElementById("article_copyright").innerHTML );
}

// Email and Print Articles			   
function emailArticle () {
	articleWindow = window.open('/php/article_email.php','emailArticle','left=100,top=100,width=500,height=340');
	articleWindow.focus();
}

function printArticle () {
    var title = getArticleTitle ();
	var text  = getArticleText  ();
	var copyright = getArticleCopyright ();
	
	articleWindow = window.open('/','printArticle','resizable,scrollbars,left=100,top=100,width=750,height=800');
	articleWindow.document.write('<HTML>\n<HEAD>\n');
	articleWindow.document.write('<TITLE>'+title+'</TITLE>\n');
	articleWindow.document.write('<link href="/common/cm_styles.css" rel="stylesheet" type="text/css">\n');
	articleWindow.document.write('</HEAD>\n');
	articleWindow.document.write('<BODY onload="window.print()">\n');
								 
   	articleWindow.document.write('<br>\n<table class="articleMargin" align="center">\n');
	articleWindow.document.write('<tr><td class="style27">'+title+'</td></tr>'); 
    articleWindow.document.write('</table>\n');
	
	articleWindow.document.write('<table>\n');
   	articleWindow.document.write('<tr><td>'+text+'</td></tr>');	
	articleWindow.document.write('</table>\n');
	
	articleWindow.document.write('<table class="articleMargin">\n');
	articleWindow.document.write('<tr><td class="articleContent">'+copyright+'</td></tr>\n');
	articleWindow.document.write('</table>\n');

	articleWindow.document.write('</BODY>\n');
	articleWindow.document.write('</HTML>\n');
	articleWindow.document.close();
}
	
