//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function OpenWindow(page,name,width,height) {
     x = (1024 - width)/2;
     y = (768 - height)/2;
     if (screen) {
         y = Math.floor((screen.availHeight - height)/2);
         x = Math.floor((screen.availWidth - width)/2) - 10;
     }
	 myWindow = window.open(page, name, 'width=' + width + ',height=' + height + ',top='+ y +',left='+ x +',screenX=' + x + ',screenY=' + y + ',toolbar=no,menubar=0,location=no,scrollbars=yes,resizable=no');
	 myWindow.focus();
  }
  

function checkMaxLength() {
	tmp = this.value;
	tmp2 = tmp.split(" ");
	flag = 0;
	var j = 0;
	for (var i = 0; i < tmp2.length; i++)
	{
		if (tmp2[i].length > 26) {
			crtmp = escape(tmp2[i]);
			if(crtmp.indexOf("%0D%0A") > 1) {
				crcheck = crtmp.split("%0D0A");
				for (j = 0; j < crcheck.length; j++)
				{
				if(crcheck[j].length > 26) {
					tmp2[i] = Left(tmp2[i],26);	
					flag = 1;	  
				 	}
				}
			 }
			else if(crtmp.indexOf("%0A") > 1) {
				crcheck = crtmp.split("%0A");
				for (j = 0; j < crcheck.length; j++)
				{
				if(crcheck[j].length > 26) {
					tmp2[i] = Left(tmp2[i],26);	
					flag = 1;	  
					}
				}

			}
			else if(crtmp.indexOf("%0D") > 1) {
				crcheck = crtmp.split("%0D");
				for (j = 0; j < crcheck.length; j++)
				{
				if(crcheck[j].length > 26) {
					tmp2[i] = Left(tmp2[i],26);	
					flag = 1;	  
					}
				}
			}
			else {
				tmp2[i] = Left(tmp2[i],26);	
				flag = 1;	
			}
		}
	}
	
	if (flag == 1) {
		tmp3 = tmp2.join(" ");
		this.value = tmp3;
		alert('You have used too many characters in a row without a space, which may cause your text to be removed at printing in order to fit. Please cut down the number of letters in a row or use a different word.');
		this.focus();
		return;
	}
	
	tmp = escape(this.value);
	
	if (tmp.indexOf("%0D%0A") > -1) {
		tmp2 = tmp.split("%0D%0A");
		if (tmp2.length > 3) {
			tmp3 = tmp2[0] + "%0D%0A" + tmp2[1] + "%0D%0A" + tmp2[2] + "%0D%0A";
			for (var x = 3; x < tmp2.length; x++)
   			{
			   tmp3 = tmp3 + tmp2[x];
			}
			this.value = unescape(tmp3);
		}
	}
	else if (tmp.indexOf("%0D") > -1) {
		tmp2 = tmp.split("%0D");
		if (tmp2.length > 3) {
			tmp3 = tmp2[0] + "%0D" + tmp2[1] + "%0D" + tmp2[2] + "%0D";
			for (var x = 3; x < tmp2.length; x++)
   			{
		   	tmp3 = tmp3 + tmp2[x];
			}
			this.value = unescape(tmp3);
		}
	}
	else if (tmp.indexOf("%0A") > -1) {
	tmp2 = tmp.split("%0A");
	if (tmp2.length > 3) {
		tmp3 = tmp2[0] + "%0A" + tmp2[1] + "%0A" + tmp2[2] + "%0A";
		for (var x = 3; x < tmp2.length; x++)
   		  {
		  	tmp3 = tmp3 + tmp2[x];
		  }
			this.value = unescape(tmp3);
		}
	}
		
	
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	var remainingLength = maxLength - currentLength;
	if (currentLength > maxLength) {
		this.value = this.value.substring(0, maxLength);
		this.relatedElement.className = 'toomuch';
	}
	else {
		this.relatedElement.className = '';
		this.relatedElement.firstChild.nodeValue = remainingLength;
	}
	// not innerHTML
}


function Right(str, n){
	if (n <= 0) {
		return "";
	}
	else if (n > String(str).length) {
		return str;
	}
	else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}


function Left(str, n){
    if (n <= 0) {
        return "";
	}
    else if (n > String(str).length) {
        return str;
	}
    else {
        return String(str).substring(0,n);
	}
}
	
	
function replace(string,text,by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
	newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function firsttime() {
alert('*** IMPORTANT: FIRST TIME USERS ***\n\n*  You are limited to 350 characters (about 60-80 words) and a maximum of 10 lines per page (including blank lines). In addition, you are limited to three hard returns per page. Putting in more than the allowable amount of text or returns may cause you to lose part of your story. To ensure the accuracy of your story, check it in \'Preview\' before adding to cart.\n\n*  To go from page to page, use the arrows or the images at the top of the screen. DO NOT use the \'Back\' button on your browser, or you may lose part of your story.\n\n*  If you need to take a break from writing, press \'Save Draft for Later\' to save your story. When you are ready to go back to writing, go to \'My Saved Drafts\' under Bookstore, and press \'Edit\'.\n\n*  When you\'re finished writing and are ready to buy the book, press \'Add to Cart\'');
}
 
