// JavaScript Document

function cms_contentEditorPop(contentName, contentPage)
{
	var popurl = '/cms/admin/contentEditorPop.php?name='+contentName+'&page='+contentPage;
	
	window.open(popurl ,'cms_contentEditorPop','width=900,height=600,toolbar=no,menubar=no') 
}

function cms_contentEditorPopById(contentID)
{
	var popurl = '/cms/admin/contentEditorPop.php?id='+contentID;
	
	window.open(popurl ,'cms_contentEditorPop','width=900,height=600,toolbar=no,menubar=no') 
}

function setAction(theForm, theValue)
{
	theForm.submitactionfield.value = theValue;
	return true;
}

function forceNumericInput(el, allowDot, allowMinus, event) {
   var allowed = false;
   var key = String.fromCharCode(event.charCode || event.keyCode);
	var charCode = (event.which) ? event.which : event.keyCode;
	
	
   if (((charCode == 8) || (charCode == 37) || (charCode == 38) || (charCode == 39) || (charCode == 40) || (charCode == 46) ))  
   	allowed = true;
	
   switch(key) {
      case '-': if(allowMinus === true) {
         allowed = true;
         // wait until the element has been updated to see if the minus is in the right spot
         setTimeout(function (el) {
            return function () {
               removeNonstartingMinus(el); }; }
         (el), 250);
         }
      break;
      case '.': if(allowDot === true) {
         allowed = true;
         if(el.value.indexOf(".") > - 1) {
            // don't allow more than one dot
            allowed = false;
            }
         }
      break;
      default : 	
	  		if (key >= '0' && key <= '9') {
         		allowed = true;
         	}
			if(el.name == "answer_text1_362")
			{
				if (key >= 'A' && key <= 'Z') 
				{
					allowed = true;
				}
				if (key >= 'a' && key <= 'z') 
				{
					allowed = true;
				}
   			}
      }
   return allowed;
   }
function removeNonstartingMinus(el) {
   var s = el.value, i = s.lastIndexOf("-");
   // if "-" exists then it better be the 1st character
   if(i > 0) {
      el.value = s.substring(0, i) + s.substring(i + 1);
      }
   }

function popupSurvey(finished)
{
	if (finished)
		var thewin = window.open("/the-sleep-survey/survey-pages/?user=finished", "surveywindow","resizable=1,location=0,status=0,scrollbars=1,width=750,height=500");
	else
		var thewin = window.open("/the-sleep-survey/survey-pages/", "surveywindow","resizable=1,location=0,status=0,scrollbars=1,width=750,height=500");
	
	
	thewin.focus();
}	

function hideshow(whattoshow, toshow)
{
	
	if (toshow)
		$("#"+whattoshow).show();
	else
		$("#"+whattoshow).hide();
}


