// Copyright (c) 1999-2006 Cyber-dynamics International Inc. All Rights Reserved.  info@cyber-dynamics.com

function bookM(){if (document.all){var uRL=self.location.href,txt=self.document.title;window.external.AddFavorite(uRL,txt);}else{alert("Please click OK then press CTRL-D");}}
function homeP(){if (document.all){document.all[0].style.behavior='url(#default#homepage)';document.all[0].setHomePage(self.location.href);}else{alert("Please click OK then View/Options or Parameters and set Current Page as Home Page");}}
function printP(){if (parseInt(navigator.appVersion)>=4){window.print();}else{alert("This action is not supported by your browser\nPlease select File/Print");}}
function addEmail() {var s="<a href='mailto:EnterAddress?subject=Please visit " + self.location.href 
+ "&amp;body=This page is useful: " + document.title + " at " + self.location.href + 
"' onmouseover=\"sw('2','i2');\" onmouseout=\"sw('3','i2')\">"  
+ "<img src='http://www.caycompass.com/images/i_emailp.gif' width='16' height='16'name='i2' id='i2' border='0' " 
+ "alt='Email details of this page to a colleague, friend, or yourself' /></a>";
document.write(s); 
}
function addEmail2() {var s="<a href='mailto:EnterAddress?subject=Please visit " + self.location.href 
+ "&amp;body=This page is useful: " + document.title + " at " + self.location.href + 
"' onmouseover=\"sw('12','i12');\" onmouseout=\"sw('13','i12')\">"  
+ "<img src='http://www.caycompass.com/images/i_emailp.gif' width='16' height='16'name='i12' id='i12' border='0' " 
+ "alt='Email details of this page to a colleague, friend, or yourself' /></a>";
document.write(s); 
}
function addEmail3() {var s="<a href='mailto:EnterAddress?subject=Please visit " + self.location.href 
+ "&amp;body=This page is useful: " + document.title + " at " + self.location.href + 
"' class=\"rhn\"><img src='http://www.caycompass.com/images/news_emailfriend_icon2.gif' width='29' height='21' border='0' alt='Email This Article' /></a>"  ;
document.write(s); 
}
function addEmail4() {var s="<a href='mailto:EnterAddress?subject=Please visit " + self.location.href 
+ "&amp;body=This page is useful: " + document.title + " at " + self.location.href + 
"' class=\"rhn\">Email This Article</a>"  ;
document.write(s); 
}
// left menu:
function addEmail5() {var s="<a href='mailto:EnterAddress?subject=Please visit " + self.location.href 
+ "&amp;body=This page is useful: " + document.title + " at " + self.location.href + 
"' class=\"menulnk\">Email This Page</a>"  ;
document.write(s); 
}

var  supp;
function popUp(url,pLeft,pTop,pWidth,pHeight) { if (pWidth<10){pWidth=400;} if (pHeight<10){pHeight=200;} 
var str='left='+pLeft+',top='+pTop +',width='+pWidth+',height='+pHeight+',resizable=no,scrollbars=yes';
if (supp) {if (supp.open) {supp.close();}} url=url; supp=window.open(url,"popper",str); 
if (!supp.opener){supp.opener = self;} if (supp.focus != null) {supp.focus();} return false;}
	
function checkForm(oForm){var err = "",f;if (oForm) {f=oForm} else {if (document.inquiry){f=document.inquiry;}else{if(document.admanager){f=document.admanager;}}}
var i,s,fE=f.elements,iFound=0;
	for(i=0;i<fE.length;i++){ 
		if  (!((fE[i].name.substr(0,1) == '_') || (fE[i].name.substr(1,1) == '_'))) {
			if  ( ((fE[i].value.indexOf('>') > -1) || (fE[i].value.indexOf('<') > -1)) || (fE[i].value.indexOf('|') > -1) ) {
				alert('Please do not use special characters such as  < > or |\nNote to spammers: you cannot use this form for spamming');iFound = 1;fE[i].focus();break;
		}	}
		if (iFound == 0) {
			var aEmails = new Array(); aEmails = fE[i].value.split("@");if (aEmails.length > 4) {
				alert('Too many @ signs. Please use a + instead if necessary.\nNote to spammers: you cannot use this form for spamming');
				iFound = 1;fE[i].focus();break;	
		}	} 
		if (iFound == 0) {
			var aHTTP = new Array(); aHTTP = fE[i].value.split(/http\:\/\//);if (aHTTP.length > 4) {
				alert('Too many URLs. Please amend.\nNote to spammers: you cannot use this form for spamming or posting links.');
				iFound = 1;fE[i].focus();break;	
	}	}	} 
if(iFound==0){
	iFields = new Array;iFields = f._required.value.split(",");
	for (var i=0;i<iFields.length;i++){if(iFields[i].length>1){
		if(iFields[i].indexOf("Email")>-1){if(badEmail(f[iFields[i]].value)) {err+=", "+iFields[i];}}
		else if (f[iFields[i]].type=='checkbox'){if (f[iFields[i]].checked==false){err+=", "+iFields[i];}}
		else if (f[iFields[i]].type!='checkbox'){ if (badField(f[iFields[i]].value,2)){err+=", "+iFields[i];}}}}
	if(err){alert("Please check the following entries and then submit this form:\n"+err.substr(2));return false;}else{
	if ((f.i_antiSpamDevice) && (cdAntiSpamCheck(f) == 0)) {
		alert('Please confirm the security code.');
		f.i_antiSpamCheck.focus();
	} else {	
		f.title.value=document.title;
		f.submit();
	}}}
	return false;
}

function cdSwapAntiSpam(sImage,sSRC1,sSRC2) {
	if (document.getElementById){
		var img = document.getElementById(sImage);
		if(img.src.indexOf(sSRC1)>-1) {
				document.getElementById(sImage).src=sSRC2;				
			}else {
				document.getElementById(sImage).src=sSRC1;
}	}	}	

function cdAntiSpamCheck(sFormID){
	var i=0,j=0,k=4,s = sFormID.i_antiSpamCheck.value;
	if (s.length==5) {
		for (j=0;j<4;j++){i = i + (k * s.charAt(j));k--;}
		if ((i%11) == s.charAt(4)) {
			return(1);
	}	}
		return(0);
}

function bookmarkForm(sURL, sCaption) {if (window.external) {window.external.AddFavorite(sURL,sCaption);} else{alert('Sorry, your browser does not support dynamic bookmarks. Please print the page or make a note of the reference number.');}}
function clickClear(oMe,sVal) {if (oMe.value==sVal){oMe.value='';}}
function sStatus(sStr) {window.status=sStr;document.returnValue=true;}
function badEmail(str){if (isBlank(str)||(str.indexOf("@")==-1)||(str.indexOf(".")==-1)||(str.length<6)){return true}else{return false}}	 
function badField(str,minlength){if(isBlank(str)||(str.length<minlength)){return true}else{return false}}	 
function isBlank(str){if(str.length==0){return true};for(i=0;i<=str.length-1;i++){if(str.charAt(i)!=" "){return false}}return true;}
function insertTicker() {
	var s = '<iframe height="20" marginwidth="0" width="560" scrolling="no" src="CFPCCnewsticker.shtml" frameborder="0" marginheight="0"><\/iframe><\/div>';
	if ((document.getElementById) && (document.body.innerHTML)) {document.write("<div class='ticko'>" + s);} else {document.write("<div class='tickh'>" + s);}	
}

// FOLLOWING ROWS USED BY SEARCH THE ARCHIVES //

function miniSearch(s) {
	var fm = document.srchFm;
	if (s == 'web') {
		fm.q.value = fm.SearchTerm.value;
//		fm.SearchTerm.value = '';
		fm.where.value = '';
		fm.action = "http://www.google.com/search";
		fm.method = "get";
		fm.target = "_blank";
	} else {
		fm.action = "http://www.caycompass.com/cgi-bin/CFPnewsSearch.cgi";
		fm.where.value = 'news';
		fm.method = "post";
		fm.q.value='';
	}
	fm.submit();
}


function startSearch() {
	if (badField(document.search.SearchTerm.value,2)) {
		alert('Invalid search word/s');
	}else{		
		if ((checkStartDate())&&(checkEndDate())) {
				document.search.submit();	
}	}	}
function checkStartDate() {
	var dF = document.search;
//	if (! dF.FixStart.checked) {
//		return(1);
//	}else{	
		var sSD = getSQLdate(dF.StartYear.options[dF.StartYear.selectedIndex].text,dF.StartMonth.options[dF.StartMonth.selectedIndex].text,dF.StartDay.options[dF.StartDay.selectedIndex].text);
		if (sSD=='') {
			alert('Invalid start date');
			return(0);
		} else {
			if (dF.FixEnd.checked) {
				var sED = getSQLdate(dF.EndYear.options[dF.EndYear.selectedIndex].text,dF.EndMonth.options[dF.EndMonth.selectedIndex].text,dF.EndDay.options[dF.EndDay.selectedIndex].text);
				if (sED=='') {
					alert('Invalid end date');
					return(0);
				} else { 
					if (sED < sSD) {
						alert('The start date should not be after the end date');
						return(0);
	}	}	}	}	// }
	return(1);
}	
function checkEndDate() {
	var dF = document.search;
	if (! dF.FixEnd.checked) {
		return(1);
	}else{	
		var sED = getSQLdate(dF.EndYear.options[dF.EndYear.selectedIndex].text,dF.EndMonth.options[dF.EndMonth.selectedIndex].text,dF.EndDay.options[dF.EndDay.selectedIndex].text);
		if (sED=='') {
			alert('Invalid end date');
			return(0);
		} else {
			// if (dF.FixStart.checked) {
				var sSD = getSQLdate(dF.StartYear.options[dF.StartYear.selectedIndex].text,dF.StartMonth.options[dF.StartMonth.selectedIndex].text,dF.StartDay.options[dF.StartDay.selectedIndex].text);
				if (sSD=='') {
					alert('Invalid start date');
					return(0);
				} else {
					if (sED < sSD) {
						alert('The start date should not be after the end date');
						return(0);
	}	}	}	}	// }
	return(1);
}		
function getSQLdate(sY,sM,sD) {
	var sMthName = new Array ('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	for (var i=1;i<13;i++){if (sMthName[i]==sM) {sM=i;break;}}
	if ((checkDate(sY,sM,sD)==0)){return('');} else {			
		return(sY +'-'+ formatI(sM,2) +'-'+ formatI(sD,2));		
}	}
function checkDate(sY,sM,sD){
	sY=sY*1;sM=sM*1;sD=sD*1;
	if (sY<1900){sY=(sY*1)+1900;} 	
	if ( (isNaN(sY))||(isNaN(sM))||(isNaN(sD))||(sM<1)||(sM>12)||(sD<1)||(sD>31)
		||(((sM==4)||(sM==6)||(sM==9)||(sM==11))&&(sD>30))
		||((sM==2)&&(sD>28)&&(!(((Math.round(sY/4)*4)==sY)||((d[2]==2000)))))
		||((sM==2)&&(sD>29))
		||(sY<=1900)
		){return(0);}else{return(1);};
}
function get(i) {
	document.search.Start.value = i;
	startSearch();
}
function formatI(i,ilen){i='00000000'+i;return(i.substr(i.length-ilen));}
// END OF ROWS USED BY SEARCH THE ARCHIVES //

function autoFitInFrame(id){
 if (!window.opera && !document.mimeType && document.all && document.getElementById){ parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";}
 else if(document.getElementById) { parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"}	
}

function cdFixFlash(){
 if ((document.getElementsByTagName)&&(document.getElementsByTagName("object"))){
  oObjects=new Array();
  oObjects=document.getElementsByTagName("object");
  for (var i=0;i<oObjects.length;i++) {oObjects[i].outerHTML=oObjects[i].outerHTML;}
}}

