
// JavaScript Document
function AllowNoDups()
{
   var cookie_ls = document.cookie;
   if (cookie_ls.indexOf(document.location) > -1) 
   {
      alert("You've already submitted your answers. Thank you for your interest!  ");
      return false;
   }
   else
   	{
      document.cookie = window.location.href + " from " + document.referrer + "; path=/; expires=Thu, 23-Aug-2012 00:00:01 GMT;";
      return true;
   };
   };

function cnt(w,x){
var y=w.value;
var r = 0;
a=y.replace('\n',' ');
a=a.split(' ');
for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
x.value=r;
}

function onlyNumbers(object){
  object.value = object.value.replace(/[\D\.\,]+/gi,"");
}

function onlyDecimals(object){
    object.value = object.value.replace(/^\./gi,"");
    object.value = object.value.replace(/[^\d\.]/gi,"");
    object.value = object.value.replace(/\.{2,}/gi,".");
  if(object.value.indexOf('.') > -1 && object.value.lastIndexOf('.') > object.value.indexOf('.'))
    object.value = object.value.substring(0,object.value.lastIndexOf('.')); 
}

function findObj(n){
 var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
 x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
 }else{x=document.getElementById(n)}return x;
}

function all_findObj(n, d) { //v3.0
  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); return x;
}

function displayLayers() { //v3.0
  var i,p,v,obj,args=displayLayers.arguments;
  var fun=(document.getElementById) ? "findObj" : "all_findObj";
  for (i=0; i<(args.length-2); i+=3)
  {
   if ((obj=eval(fun+"(args[i])"))!=null) 
 { 
  v=args[i+2];
     if (obj.style) 
  { 
   obj=obj.style; 
   v=(v=='show')?'':(v='hide')?'none':v;
   obj.display='block';
  }
     obj.display=v; obj.zIndex=1 
 }
  }
    
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

function submit_toggle(show_div) {

	displayLayers('submitButton','','hide');
	displayLayers('pleasewait','','show');


}

function SpellCheckText(txtfld) {

	var oSpell= new JavaScriptSpellCheck();
	oSpell.spellCheckWindow('story');

}

function sizeWin(URL, w, h) {	theWIn = window.open(URL,"PopDialog","toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + w + ",height=" + h + ",screenX=25,screenY=25,top=25,left=25");
			if (window.focus) {theWIn.focus();}
}

function formatPhone (field) {
    field.value = trim(field.value);

    var ov = field.value;
    var v = "";
    var x = -1;

    // is this phone number 'escaped' by a leading plus?
    if (0 < ov.length && '+' != ov.charAt(0)) { // format it
        // count number of digits
        var n = 0;
        if ('1' == ov.charAt(0)) {  // skip it
            ov = ov.substring(1, ov.length);
        }

        for (i = 0; i < ov.length; i++) {
            var ch = ov.charAt(i);

            // build up formatted number
            if (ch >= '0' && ch <= '9') {
                if (n == 0) v += "(";
                else if (n == 3) v += ") ";
                else if (n == 6) v += "-";
                v += ch;
                n++;
            }
            // check for extension type section;
            // are spaces, dots, dashes and parentheses the only valid non-digits in a phone number?
            if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')') {
                x = i;
                break;
            }
        }
        // add the extension
        if (x >= 0) v += " " + ov.substring(x, ov.length);

        // if we recognize the number, then format it
        if (n == 10 && v.length <= 40) field.value = v;
    }
    return true;
}
