/* orders.js functions called inside orderupdates.cfm & related html forms */

/* for starter 1000-word site: check to see the total number of words doesn't exceed 1000 in the 6 topic areas*/
/* changed to 1600 word limit 9/21/00 cmk */
function wordcount(form) {
	var num1 = 0;
	for (var i=0; i<form.text1.value.length; i++) {
      if (form.text1.value.substring(i,i+1) ==" " | form.text1.value.substring(i,i+1) == "\r") {
		num1 = num1 + 1;
	  }
	}
	if (form.text1.value.length>0) {	
		num1 = num1+1;
	}
	var num2 = 0;
	for (var i=0; i<form.text2.value.length; i++) {
      if (form.text2.value.substring(i,i+1) ==" " | form.text2.value.substring(i,i+1) == "\r") {
		num2 = num2 + 1;
	  }
	}
	if (form.text2.value.length>0) {	
		num2 = num2+1;
	}
	var num3 = 0;
	for (var i=0; i<form.text3.value.length; i++) {
      if (form.text3.value.substring(i,i+1) ==" " | form.text3.value.substring(i,i+1) == "\r") {
		num3 = num3 + 1;
	  }
	}
	if (form.text3.value.length>0) {	
		num3 = num3+1;
	}
	var num4 = 0;
	for (var i=0; i<form.text4.value.length; i++) {
      if (form.text4.value.substring(i,i+1) ==" " | form.text4.value.substring(i,i+1) == "\r") {
		num4 = num4 + 1;
	  }
	}
	if (form.text4.value.length>0) {	
		num4 = num4+1;
	}
	var num5 = 0;
	for (var i=0; i<form.text5.value.length; i++) {
      if (form.text5.value.substring(i,i+1) ==" " | form.text5.value.substring(i,i+1) == "\r") {
		num5 = num5 + 1;
	  }
	}
	if (form.text5.value.length>0) {
		num5 = num5+1;
	}
	var num6 = 0;
	for (var i=0; i<form.text6.value.length; i++) {
      if (form.text6.value.substring(i,i+1) ==" " | form.text6.value.substring(i,i+1) == "\r") {
		num6 = num6 + 1;
	  }
	}
	if (form.text6.value.length>0) {
		num6 = num6+1;	
	}	
	var allwords = num1 + num2 + num3 + num4 + num5 + num6;		
	var msg = "There are " + allwords + " words in your text. Only 1600 are allowed. Remove some text.";
	if (allwords>1600) {
		alert(msg);
		return false;
	}
	return true;
}	

/* for starter 300-word site: check to see the total number of words doesn't exceed 300 */
function wordcountdescrip(form) {
	var num = 0;
	for (var i=0; i<form.webdescription.value.length; i++) {
      if (form.webdescription.value.substring(i,i+1) ==" " | form.webdescription.value.substring(i,i+1) == "\r") {
		num = num + 1;
	  }
	}
	if (form.webdescription.value.length>0) {
		num = num+1;	
	}	

	var msg = "There are " + num + " words in your text. Only 250 are allowed. Remove some text."
	if (num>300) {
		alert(msg);
		return false;
	}
	return true;
}	

/* for lam & other textarea fields */
function charcount(fld,mxchars,fldenglish) {
	if (fld.value.length > mxchars) {
		var msg = "There are " + fld.value.length + " characters in the " + fldenglish + " text entry area.\r" 
		msg = msg + "Only " + mxchars + " are allowed. Remove some text."
		alert(msg);
		return false;
	}
	return true;
}

/* validation onsubmit of lam entry (not lam0)  */
function allcharcounts(form) {
	if (form.productid.value=='LAM1A') { 
		var mxchars = 200; 
		if (form.description.value.indexOf('http') != -1 || form.description.value.indexOf('<a href') != -1) {
			alert("urls are not allowed in the Summary Description of Practice field.\r");
			return false;
		}
	}
	else { var mxchars = 1600; }
	
	//var mxchars = 800;
	if (form.description.value.length > mxchars) {
		var msg = "There are " + form.description.value.length + " characters in the Summary Description of Practice text entry area.\r" 
		msg = msg + "Only " + mxchars + " are allowed. Remove some text."
		alert(msg);
		return false;
	}
	if (form.productid.value !='LAM1A') {
		if (form.profbkgd.value.length > mxchars) {
			var msg = "There are " + form.profbkgd.value.length + " characters in the Professional Background text entry area.\r" 
			msg = msg + "Only " + mxchars + " are allowed. Remove some text."
			alert(msg);
			return false;
		}
		if (form.mdnexperience.value.length > mxchars) {
			var msg = "There are " + form.mdnexperience.value.length + " characters in the Mediation Experience text entry area.\r" 
			msg = msg + "Only " + mxchars + " are allowed. Remove some text."
			alert(msg);
			return false;
		}
		if (form.approach.value.length > mxchars) {
			var msg = "There are " + form.approach.value.length + " characters in the Approach text entry area.\r" 
			msg = msg + "Only " + mxchars + " are allowed. Remove some text."
			alert(msg);
			return false;
		}
		if (form.fees.value.length > mxchars) {
			var msg = "There are " + form.fees.value.length + " characters in the Fees text entry area.\r" 
			msg = msg + "Only " + mxchars + " are allowed. Remove some text."
			alert(msg);
			return false;
		}
		if (form.otherinfo.value.length > mxchars) {
			var msg = "There are " + form.otherinfo.value.length + " characters in the Other Information text entry area.\r" 
			msg = msg + "Only " + mxchars + " are allowed. Remove some text."
			alert(msg);
			return false;
		}				
	}
}

	  
/* for uploading photos in starter or mpd site */			                     
function PopItUp(jcamefrom,jclientid,jproductid,jphoto,jtopicpage) {
	var str = 'uplimage.cfm?camefrom=' + jcamefrom + '&clientid=' + jclientid + '&productid=' + jproductid +'&topicpage=' + jtopicpage;
	if (jphoto != 0) {
		str = str + '&photofilename=' + jphoto;
	}
	wintips = open(str,'upload','width=315,height=215,scrollbars=No,location=No,left=10,top=10,menubar=No,alwaysRaised=Yes,resizable=yes,toolbar=No');                  
	if (document.layers) { /* navigator.userAgent only in Netscape */
		agent = navigator.userAgent;
		if ((agent.indexOf('Mozilla') != -1) && ((agent.indexOf('Spoofer') == -1) && (agent.indexOf('compatible') == -1))) {
			wintips.focus();
	}
	}
}

function PopClose()     {
	str="uplimage.cfm";
	wintips = open(str,'upload','width=315,height=215,scrollbars=Yes,location=No,left=10,top=10,menubar=no,alwaysRaised=Yes,resizable=no,toolbar=No');                  
	wintips.close();
}
  
function oktodelete(first,last,clientid) {
	var msg = 'Are you sure you want to delete ' + first + ' ' + last + '?';
	if (confirm(msg)) 
		location="cldelete.cfm?clientid=" + clientid;
}

function Poktodelete(clistid,clientid,productid) {
	var msg = 'Are you sure you want to delete this product?';
	if (confirm(msg)) 
		location="clproddelete.cfm?clistid=" + clistid + "&clientid=" + clientid + "&productid=" + productid;
}

function isrequired(obj,retvalb){
 if (retvalb) {
   retvalb=false
   /* check for the presense of any character besides a blank */

   for (var i=0; i<obj.value.length; i++) {
      if (obj.value.substring(i,i+1) !=" ") {
		retvalb=true
		break
	}
   }   

   if (!retvalb) {
      alert("This field may not be left empty")
   }
 }
 return retvalb
}

/* first character of last name must be A-Za-z */
function isvalidlastname(ln)	{
	var retval = true;
	if (ln.value.length==0)	{
		retval = false;
		alert("This field may not be left empty");
	} else {
		//var firstchar = ln.charAt(0);
		var firstchar = ln.value.substring(0,1);
		if (firstchar.toLowerCase()< "a" || firstchar.toLowerCase()>"z") {
			retval = false;
			alert("This field must be composed of letters");
		}
	}
	return retval
}

/* nochars: check for the existence of a non int character within a string */
function nochars(strval) {
	var retval=true
	for (var i=0; i<strval.length;i++) {
		if (strval.substring(i,i+1) < "0" || strval.substring(i,i+1) > "9") {
			retval=false
			break
		}
	}
	return retval
}

/* isdate - validate date format (mm/dd/yyyy) */

function isdate(obj,retval) {
 var month, day, year
 if (retval) {
  retval=false
  if (obj.value!=""){
	/* check formatting of string */
	if (obj.value.length != 10 || obj.value.substring(2,3)!="/" || obj.value.substring(5,6)!="/") {
	}
	else {
		/* Month must be between 1 and 12 */ 
		month=obj.value.substring(0,2);
		//month = parseInt(month);
		if (nochars(month) && month > 0 && month <= 12) {
			day=obj.value.substring(3,5)
			if (nochars(day)) {
				/* 30 days hath september, april, june, and november... */
				if (((month!=9 && month !=4 && month!=6 && month !=11 && month !=2) && (day>=1 && day<=31)) ||
				     (month==9 || month==4 || month==6 || month==11  && (day>=1 && day<=30)) ||
				     (month==2 && day>=1 && day<=28)) {
					year=obj.value.substring(6,10);
					/* limit year to range 1900 - 2100 */
					if (nochars(year) && parseInt(year) >= 1900 && parseInt(year)<=2100) {
						retval=true;
					}
				}
			
			}
		}
	}
		
	if (!isrequired(obj,true) || !retval) {
		alert("Month: " + month + "    Day: " + day + "    Year: " + year);
		//alert("Nochars: " + nochars(month) + "   Parse: " + parseInt(month));
		alert("Invalid date: You must enter a date in the format mm/dd/yyyy");
		retval=false;
	}

   }
   else {
   		alert("No date: You must enter a date in the format mm/dd/yyyy");
		retval=false;
   }
 }
 return retval
}

function isboth(istart,istop,retval) {
 retval = isdate(istart,retval);
 if (retval) {
 	retval = isdate(istop,retval);
 }
 return retval
 }

 function testavailability(str) {
       	window.open('urltest.cfm?xurl='+escape(str),'availability','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=390,height=250');
	return true;
}

function PopAnyUp(str,wname) {
	wintips = open(str,wname,'toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=yes,resizable=yes,width=500,height=420');
	agent = navigator.userAgent;
	if ((agent.indexOf('Mozilla') != -1) && ((agent.indexOf('Spoofer') == -1) && (agent.indexOf('compatible') == -1))) {
		wintips.focus();
	}
}



/* help popup, if you are looking for the pop-up function that controls Dynamic Site help system, please see cssscriptdict.js found in the orders directory */


function getdef(Help)
{
	path = "viewglossary.cfm?Help=" + escape(Help);
	window.open (path, "GlossaryWindow", 'resizable=yes,width=500,height=500,scrollbars=yes');
}	

