function loadjscssfile(filename, filetype) {
	if (filetype=="js") {
		var fileref=document.createElement("script");
		fileref.setAttribute("type","text/javascript");
		fileref.setAttribute("src", filename);
	}
	else if (filetype=="css") {
		var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);
	}
	if (typeof fileref!="undefined") {
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

function initialize() {
	loadjscssfile("prototype.js", "js");
	loadjscssfile("scriptaculous.js", "js");
	loadjscssfile("chat.js", "js");
	loadjscssfile("AutoComplete.js", "js");
}

function style() {
	loadjscssfile("chat.css", "css");
}


function loadPage(pid,myParent) {
	var ahrefref=document.createElement("a");
	ahrefref.setAttribute("id","commentlink"+pid);
	ahrefref.setAttribute("class","commentlink");
	ahrefref.setAttribute("href","");
	ahrefref.setAttribute("onclick","ctoggle('content"+pid+"','commentlink"+pid+"');return false;");
	ahrefref.setAttribute("title","Click to see comments");
	ahrefref.setAttribute("alt","Click to see comments");
	ahrefref.innerHTML = "0 Comments";
	
	var bigdivref=document.createElement("div");
	bigdivref.setAttribute("id","content"+pid);
	bigdivref.setAttribute("class","content");
	bigdivref.setAttribute("name","content");
	bigdivref.setAttribute("style","display:none;");
	
	var showHideWrap=document.createElement("div");
  showHideWrap.setAttribute("class","formlinkwrap");
	//showHide.setAttribute("onclick","ctoggle('formWrap"+pid+"','sh"+pid+"');return false;");
	
	var showHide=document.createElement("a");
	showHide.setAttribute("id","sh"+pid);
  showHide.setAttribute("class","formlink");
	showHide.setAttribute("href","");
	showHide.setAttribute("onclick","ctoggle('formWrap"+pid+"','sh"+pid+"');return false;");
	//showHide.setAttribute("title","test");
	//showHide.setAttribute("alt","test");
	showHide.innerHTML = "Show Comment Form";
	var scrolldivref=document.createElement("div");
	scrolldivref.setAttribute("id","scroll"+pid);
	scrolldivref.setAttribute("class","scroll");
	var formdivref=document.createElement("span");
	
	var formWrap=document.createElement("div");
	formWrap.setAttribute("id","formWrap"+pid);
	formWrap.setAttribute("style","display:none;");
	
  var tbl = document.createElement("table");
  tbl.setAttribute("border", "0");
  tbl.setAttribute("id","tbl"+pid);
  tbl.setAttribute("class","tbl");
  tbl.setAttribute("align", "center");
  tbl.setAttribute("cellspacing","0");
  var tblBody = document.createElement("tbody");
		
	// Create SUBMIT BUTTON
		var subButton=document.createElement('input');
		subButton.setAttribute("type", "button");
		subButton.setAttribute("value", "Post");
		var strOnClick = "sendMessage("+pid+");";
		subButton.setAttribute("onclick", strOnClick);
		subButton.setAttribute("align", "center");
		
	// Create info box
	  var myInfo=document.createElement('span');
	  myInfo.setAttribute("id","myInfo"+pid);
	  myInfo.setAttribute("class","myInfo");
	  myInfo.setAttribute("name","thetop"+pid);
		
	// Create adbox
	  var myadbox=document.createElement('div');
	  var cellImg = document.createElement('img');
	  cellImg.setAttribute("src","logo_tiny_white_bg.png");
	  cellImg.setAttribute("style","float:right;margin:1px;margin-left:5px;border:0px;");
	  cellImg.setAttribute("title","Created & Developed by Designs by Chace")
	  var lnkReg = document.createElement('a');
	  lnkReg.setAttribute("href","register.html");
	  lnkReg.setAttribute("mce_href","register.html");
	  lnkReg.setAttribute("class","lbOn");
	  var dbcReg = document.createElement('a');
	  dbcReg.setAttribute("href","http://www.designsbychace.com");
	  dbcReg.setAttribute("class","imgOff");
    var txtReg = document.createTextNode("Sign up for a free account!");
    lnkReg.appendChild(txtReg);
    myadbox.setAttribute("id","adbox"+pid);
	  myadbox.setAttribute("class","adbox");
	  dbcReg.appendChild(cellImg);
    myadbox.appendChild(dbcReg);
    myadbox.appendChild(lnkReg);

	// USERNAME
    var row1 = document.createElement("tr");
    var cell1 = document.createElement("td");
    var cell2 = document.createElement("td");
    var textUser = document.createElement('input');
		var mycheck = document.createElement('span');
		mycheck.setAttribute("id", "mycheck1"+pid);
		mycheck.setAttribute("style", "");
		mycheck.setAttribute("class", "woicon");
		textUser.setAttribute("name", "string");
		textUser.setAttribute("type", "text");
    textUser.setAttribute("id", "userName"+pid);
		textUser.setAttribute("maxlength", "20");
    textUser.setAttribute("size", "68");
    textUser.setAttribute("value", "Guest");
		textUser.setAttribute("onBlur", "checkUsername("+pid+");loseMyFocus('userName"+pid+"')");
		textUser.setAttribute("onFocus", "getMyFocus('userName"+pid+"')");
		textUser.setAttribute("style", "margin-right:3px;");
		
	// EMAIL
		var row2 = document.createElement("tr");
    var cell11 = document.createElement("td");
    var cellText22 = document.createTextNode("");
    var cell22 = document.createElement("td");
		var mycheck2 = document.createElement('span');
		mycheck2.setAttribute("id", "mycheck2"+pid);
		mycheck2.setAttribute("style", "");
    var pwdDiv = document.createElement('div');
    pwdDiv.setAttribute("id", "acDiv"+pid);
		pwdDiv.setAttribute("style", "width:437px;display:inline;");
		var row3 = document.createElement("tr");
    var cell3 = document.createElement("td");
    var cellText2 = document.createTextNode("Email:");
    var cell4 = document.createElement("td");
    var textEmail = document.createElement('input');
		textEmail.setAttribute("type", "text");
    textEmail.setAttribute("id", "email"+pid);
		textEmail.setAttribute("maxlength", "50");
    textEmail.setAttribute("size", "68");
		textEmail.setAttribute("onBlur", "");
		textEmail.setAttribute("onFocus", "this.value='';");
		textEmail.setAttribute("value", "Email...");
		textEmail.setAttribute("onFocus", "getMyFocus('email"+pid+"')");
		textEmail.setAttribute("onBlur", "loseMyFocus('email"+pid+"')");
		
	// WEBSITE
		var row4 = document.createElement("tr");
		var cell5 = document.createElement("td");
    var cellText3 = document.createTextNode("Website:");
    var cell6 = document.createElement("td");
    var textWebsite = document.createElement('input');
		textWebsite.setAttribute("type", "text");
    textWebsite.setAttribute("id", "website"+pid);
		textWebsite.setAttribute("maxlength", "100");
    textWebsite.setAttribute("size", "68");
		textWebsite.setAttribute("onBlur", "");
		textWebsite.setAttribute("value", "http://");
		textWebsite.setAttribute("onFocus", "getMyFocus('website"+pid+"')");
		textWebsite.setAttribute("onBlur", "loseMyFocus('website"+pid+"')");
	
	// COMMENTS
		var row5 = document.createElement("tr");
		var cell7 = document.createElement("td");
    var cellText4 = document.createTextNode("Comments:");
    var cell8 = document.createElement("td");
    var textComments = document.createElement('textarea');
		//textComments.setAttribute("cols", "55");
    //textComments.setAttribute("rows", "5");
		textComments.setAttribute("maxlength", "25000");
    textComments.setAttribute("id", "messageBox"+pid);
    textComments.setAttribute("value", "Write something . . .");
		textComments.setAttribute("onKeyDown", "handleKey(event);");
		textComments.setAttribute("onFocus", "getMyFocus('messageBox"+pid+"')");
		textComments.setAttribute("onBlur", "loseMyFocus('messageBox"+pid+"')");
		
    //cell1.appendChild(cellText1);
		//cell1.setAttribute("class", "desc");
		//cell1.setAttribute("align", "right");
		//cell2.appendChild(mycheck);
		cell2.appendChild(textUser);
		cell11.appendChild(cellText22);
		cell11.setAttribute("class", "desc");
		cell11.setAttribute("align", "right");
		cell22.appendChild(pwdDiv);
		cell22.appendChild(mycheck2);
		//cell3.appendChild(cellText2);
		//cell3.setAttribute("class", "desc");
		//cell3.setAttribute("align", "right");
		cell4.appendChild(textEmail);
		//cell5.appendChild(cellText3);
		//cell5.setAttribute("class", "desc");
		//cell5.setAttribute("align", "right");
		cell6.appendChild(textWebsite);
		//cell7.appendChild(cellText4);
		//cell7.setAttribute("class", "desc");
		//cell7.setAttribute("align", "right");
		cell8.appendChild(textComments);
		cell8.innerHTML += "<br />";
	  cell8.appendChild(subButton);
	  cell8.appendChild(myInfo);
		//cell8.innerHTML += "<br />";
		
    //row1.appendChild(cell1);
		row1.appendChild(cell2);
		//row2.appendChild(cell11);
		row2.appendChild(cell22);
		//row3.appendChild(cell3);
		row3.appendChild(cell4);
		//row4.appendChild(cell5);
		row4.appendChild(cell6);
		//row5.appendChild(cell7);
		row5.appendChild(cell8);
    tblBody.appendChild(row1);
		tblBody.appendChild(row2);
		tblBody.appendChild(row3);
		tblBody.appendChild(row4);
		tblBody.appendChild(row5);
		
        // put the <tbody> in the <table>
  tbl.appendChild(tblBody);
  formWrap.appendChild(tbl);
  showHideWrap.appendChild(showHide);
  bigdivref.appendChild(showHideWrap);
	bigdivref.appendChild(formWrap);
	bigdivref.appendChild(scrolldivref);
	bigdivref.appendChild(myadbox);
	//bigdivref.appendChild(formdivref);
	
	document.getElementById(myParent).appendChild(ahrefref);
	document.getElementById(myParent).appendChild(bigdivref);
	//document.getElementsByTagName("body")[0].appendChild(tbl);
}

function doitupcuz(id,myParent) {
  loadPage(id,myParent);
  var AC = new AutoComplete('userName','acDiv',id);
  AC.clearField = false;
  var load = new init(id,id);
}
//initialize();

//style();
