var num = 1;
var numAstract = 0;
var numHeading = 0;
var numSection = 0;
var numContent = 0;
var numSubSection = 0;
var numSubHeading = 0;
var numSubContent = 0;
var tab =new Array();
tab.push(0); 

function setVars(val) {
	
	 num = val;
	 numAstract = val;
	 numHeading = val;
	 numSection = val;
	 numContent = val;
	 numSubHeading = val;
	 numSubContent = val;
	 /*
	 num = 1000;
	 numAstract = 1000;
	 numHeading = 1000;
	 numSection = 1000;
	 numContent = 1000;
	 numSubHeading = 1000;
	 numSubContent = 1000;
	 */
	 //alert ("set veriables " + "val=" + val);
}
 
function addAuthor() {
	var ni = document.getElementById('author'); 
	num++; 
	tab.push(num); 
	//alert(tab);
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	//newdiv.innerHTML = "File: <input type='text' id='myfile[]' name='myfile[]'> <a 				href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove</a>";
	
	//newdiv.innerHTML  = "<br><fieldset><legend>  Author " +num+ " Information ( <a href=\"javascript:;\" onclick=\"removeAuthor(\'"+num+"\')\">Remove</a> ) </legend><br><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='23%'>Author and affiliation</td><td width='77%'><input type='text' name='author[]' id='author" +num+ "' SIZE='60' /></td></tr><tr><td>Author mailing address</td><td><input type='text' name='mail[]' id='mail[]' SIZE='60' /></td></tr><tr><td>Author email</td><td><input type='text' name='email[]' id='email[]' SIZE='60' /></td></tr></table><br><input type='checkbox' name='isCorres" +num+ "' id='isCorres" +num+ "' /> Check if corresponding author</fieldset>";

//newdiv.innerHTML = "<br><table border='0' cellspacing='0' cellpadding='0' width='680'>  <tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td><img src='images/h.gif' width='680' height='7' /></td> <td><img src='images/hd.gif' width='7' height='7' /></td>    </tr> <tr> <td background='images/g.gif'>&nbsp;</td> <td  ><span class='style11 style22'>Author " +num+ " Information </span> ( <a href=\"javascript:;\" class='style1' onclick=\"removeAuthor(\'"+num+"\')\">Remove</a> )</span><table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFF0F0'> <tr> <td width='32%' align='right' class='style1'><span class='style3'>Name and affiliation</span> &nbsp; </td><td width=68%'><input type='text' name='author[]' id='author" +num+ "' SIZE='60' /></td> </tr> <tr> <td align='right' class='style1'><span class='style3'>Mailing address</span> &nbsp; </td><td><input type='text' name='mail[]' id='mail[] size='60' /></td> </tr> <tr><td align='right' class='style1'><span class='style3'>Email</span> &nbsp;</td> <td><input type='text' name='email[]' id='email[]' size='60' /></td> </tr> </table></td> <td background='images/d.gif'>&nbsp;</td> </tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td> <td><img src='images/bd.gif' width='7' height='7' /></td> </tr></table>  ";

 	newdiv.innerHTML =  "  <br><table border='0' cellspacing='0' cellpadding='0' width='680'>  <tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td><img src='images/h.gif' width='680' height='7' /></td> <td><img src='images/hd.gif' width='7' height='7' /></td>    </tr> <tr> <td background='images/g.gif'>&nbsp;</td> <td  ><span class='style11 style22'>Author " +num+ " Information </span> ( <a href=\"javascript:;\" class='style1' onclick=\"removeAuthor(\'"+num+"\')\">Remove</a> )</span><table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFF0F0'> <tr><td align='right' class='style1'><span class='style3'>First Name </span> &nbsp;</td>   <td><input type='text' name='fname[]' id='fname" +num+ "' SIZE='65' /></td></tr> <tr><td align='right' class='style1'><span class='style3'>Last Name </span> &nbsp;</td><td><input type='text' name='lname[]' id='lname" +num+ "' SIZE='65' /></td></tr><tr> <td width='32%' align='right' class='style1'><span class='style3'>Affiliation</span> &nbsp; </td><td width='68%'><input type='text' name='author[]' id='author" +num+ "' SIZE='60' /></td> </tr>  <tr> <td align='right' class='style1'><span class='style3'>Mailing address</span> &nbsp; </td><td><input type='text' name='mail[]' id='mail" + num+ "' size='60' /></td> </tr> <tr><td align='right' class='style1'><span class='style3'>Email</span> &nbsp;</td> <td><input type='text' name='email[]' id='email" +num+ "' size='60' /></td> </tr> </table></td> <td background='images/d.gif'>&nbsp;</td> </tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td> <td><img src='images/bd.gif' width='7' height='7' /></td> </tr></table>    ";

	ni.appendChild(newdiv);
	 //alert(ni.innerHTML);

	 
}

function unset(array, valueOrIndex){
	var output=[];
	for(var i in array){
		if (i!=valueOrIndex)
			output[i]=array[i];
	}
	return output;
}

function removeAuthor(num){
	//updateDivNames(num);
	var divNum = "my"+num+"Div";
	var d = document.getElementById('author');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
	// updateDivNames(num);
	for(i=0; i< tab.length; i++) {
		if(tab[i] == num) {
			tab = unset(tab, i);
		}
	}
	//alert(tab);
		
	
}
function updateDivNames(numStart){
	
	for (i=numStart; i<=num; i++){
	 	//alert(i);
		var oldDivNum = "my"+ i +"Div";
		var olddiv = document.getElementById(oldDivNum);
		var newDivIdName = "my"+ i+1 +"Div";
		olddiv.setAttribute("id","77");
		/*
		var ni = document.getElementById('author'); 
		num++; 
		var newDivIdName = "my"+num+"Div";
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id",divIdName);
		*/
		
	}
	
	var divNum = "my"+num+"Div";
	var d = document.getElementById('author');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
	
}

function validate (){
	validateTitleError = validateTitle();
	validateAuthorseError = validateAuthors();
	validateSectionError = validateSection();
	
	var errorsMessage = validateTitleError + "\n " + validateAuthorseError + " \n" + validateSectionError;
	var error  =  validateTitleError + validateAuthorseError + validateSectionError;
	
	if (error != "") {
		alert("Some items are empty : " + errorsMessage);
	}
	//var error  =  validateTitle()  + validateAuthors() + validateSection ();
	
	if (error != "") return false;
	else return true;
	/*
	for (i=1; i<=num; i++){
		var authorId ="author" + i;
		var author = document.getElementById(authorId).value;
		if(author == "")  alert ( " Author " + i + " is empty" );
		//alert ("d = " + d);
	}
*/	 
	
  //var ni = document.getElementById('myfile');
// alert("Submitting"); 
// return false;
 
}

function validateTitle (){
	var errorsMessage = "";
	var titleid ="title" ;
	var title = document.getElementById(titleid).value;
	if(title == "")  {  
		errorsMessage = errorsMessage +  " \n - Title";		
	}
	return errorsMessage;
}


function validateAuthors (){
	var errorsMessage = "";
	//alert("validateAuthorNames"); 

		
			

	for(j=0; j< tab.length; j++) {
		i = tab[j];
		if(i == null) continue;
		var fnameid ="fname" + i;
		//alert (j + " " + fnameid);
		var fname = document.getElementById(fnameid).value;
		if(fname == "")  {
			if(i==0) 
				errorsMessage = errorsMessage +  " \n - Author first name";	
			else 
				errorsMessage = errorsMessage +  " \n - Author " + i + " first name";		
		}
		
		var lnameid ="lname" + i;
		var lname = document.getElementById(lnameid).value;
		if(lname == "")  {
			if(i==0) 
				errorsMessage = errorsMessage +  " \n - Author last name";	
			else 
				errorsMessage = errorsMessage +  " \n - Author " + i + " last name";		
		}
		
		var affid ="author" + i;
		var affi = document.getElementById(affid).value;
		if(affi == "")  {
			if(i==0) 
				errorsMessage = errorsMessage +  " \n - Author affiliation";	
			else 
				errorsMessage = errorsMessage +  " \n - Author " + i + " affiliation";		
		}
		var mailid ="mail" + i;
		var mail = document.getElementById(mailid).value;
		if(mail == "")  {
			if(i==0) 
				errorsMessage = errorsMessage +  " \n - Author mailing address";	
			else 
				errorsMessage = errorsMessage +  " \n - Author " + i + " mailing address";
		}
		
		var emailid ="email" + i;
		var email = document.getElementById(emailid).value;
		if(email == "")  {
			if(i==0) 
				errorsMessage = errorsMessage +  " \n - Author email address";	
			else 
				errorsMessage = errorsMessage +  " \n - Author " + i + " email address";		
		}
		
	}
	return errorsMessage;
	 
}

function validateSection (){
	var errorsMessage = "";
	//alert("validateAuthorNames"); 
 
	var heading0Id ="heading0" ;
	var heading0 = document.getElementById(heading0Id).value;
	if(heading0 == "")  {
		errorsMessage = errorsMessage +  " \n - Heading of the first section";		
	 
	}
	/*
	var contentId ="content0" ;
	var content0 = document.getElementById(contentId).value;
	if(content0 == "")  {
		errorsMessage = errorsMessage +  " \n - Content of the first section";		
	 
	}
	*/
	return errorsMessage;
	 
}
 
function addAbstract() { 
	numAstract++; 
	if(numAstract >1 ) return;
 
    var ni = document.getElementById('abstract'); 
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id","AddedAbstract");
	newdiv.innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='680' bgcolor='#FFF0F0'><tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td><img src='images/h.gif' width='680' height='7' /></td><td><img src='images/hd.gif' width='7' height='7' /></td> </tr> <tr> <td background='images/g.gif'>&nbsp;</td> <td  ><span class='style7'>Abstract</span> ( <a href='javascript:;' class='style1' onclick='removeAbstract()'>Remove</a> )<br /> <textarea name='abstract' cols='85' id='abstract'></textarea></td><td background='images/d.gif'>&nbsp;</td></tr> <tr><td><img src='images/bg.gif' width='7' height='7' /></td><td><img src='images/b.gif' width='680' height='7' /></td> <td><img src='images/bd.gif' width='7' height='7' /></td></tr></table> ";
	 
	ni.appendChild(newdiv);
	var d = document.getElementById('abstract');
 	var olddiv = document.getElementById('addAbstract');
 	d.removeChild(olddiv);
	 
}

function removeAbstract( ){
	//updateDivNames(num);
	 //alert("yes");
	//var divNum = "my"+num+"Div";
 	var d = document.getElementById('abstract');
 	var olddiv = document.getElementById('AddedAbstract');
 	d.removeChild(olddiv);
	
	var ni = document.getElementById('abstract'); 
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id","addAbstract");
	newdiv.innerHTML = "<a href='javascript:;' onclick='addAbstract();'>Add Abstract</a><br>";
	ni.appendChild(newdiv);
 	numAstract--; 
	
}


function addSection() {  // alert( "adding to " );

	numSection++;
	numHeading++;
	numContent++;
	dispNumSection = numSection+1;
//	 alert( "adding to section" + numSection);
    var ni = document.getElementById("sections"); 
	var newdiv = document.createElement('div');
	var divName = "section"+numSection;
	newdiv.setAttribute("id",divName);
	
	
	var fck = new FCKeditor("content" +numContent);
	fck.BasePath = "./fck/";  
	fck.Config["CustomConfigurationsPath"] = "../myconfig.js"  ;
	
	newdiv.innerHTML = " <br><table width='680' border='0' cellpadding='0' cellspacing='0'> <tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td><img src='images/h.gif' width='680' height='7' /></td> <td><img src='images/hd.gif' width='7' height='7' /></td>  </tr> <tr> <td background='images/g.gif'> </td> <td  >	 <table width='100%' border='0' cellpadding='0' cellspacing='2' bgcolor='#EBEBD6'> <tr><td><span class='style29'>&nbsp; Section " + dispNumSection +  " Heading</span> ( <a href=\"javascript:;\" class='style1' onclick=\"removeSection(\'"+divName+"\')\">Remove</a> )<br>  <input name='heading" +numHeading+ "' type='text' id='heading" +numHeading+ "' size='80' /></td> </tr><tr> <td><span class='style29'>&nbsp; Section " + dispNumSection + " Content </span>   <br>      " +  fck.CreateHtml()   +   "  <br> <span class='style17'>&gt;&gt;&gt;&gt;</span ><a href='javascript:;' onclick='addSubSection(\""+divName+"\", "+numSection+");'>Add a Sub-section to this section</a></td> </tr> </table> </td> <td background='images/d.gif'>&nbsp;</td></tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td>   <td><img src='images/bd.gif' width='7' height='7' /></td> </tr></table>";
	ni.appendChild(newdiv); 
	
	//newdiv.innerHTML = "<br><table width='100%' border='0' cellpadding='0' cellspacing='2' bgcolor='#EFEFEF'><tr><td><strong>Heading</strong> ( <a href=\"javascript:;\" onclick=\"removeSection(\'"+divName+"\')\">Remove</a> )<br><input name='heading" +numHeading+ "' type='text' id='heading" +numHeading+ "' size='100' /></td></tr><tr><td><strong>Content</strong><a href='javascript:;' onclick='insertion(\"content" +numContent+ "\");'>Add image</a><br><textarea name='content" +numContent+ "' cols='100' rows='15' id='content" +numContent+ "'></textarea> </td></tr> </table><br><a href='javascript:;' onclick='addSubSection(\""+divName+"\", "+numSection+");'>Add Subbb-section</a><br>";
	//Section " +numSection+ " Heading
	
	
	/*
	newdiv.innerHTML  = "  <br><table width='680' border='0' cellpadding='0' cellspacing='0'> <tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td><img src='images/h.gif' width='680' height='7' /></td> <td><img src='images/hd.gif' width='7' height='7' /></td>  </tr> <tr> <td background='images/g.gif'> </td> <td  >	 <table width='100%' border='0' cellpadding='0' cellspacing='2' bgcolor='#FFF0F0'> <tr><td><span class='style7'>Section " + dispNumSection +  " Heading</span> ( <a href=\"javascript:;\" class='style1' onclick=\"removeSection(\'"+divName+"\')\">Remove</a> )<br>  <input name='heading" +numHeading+ "' type='text' id='heading" +numHeading+ "' size='80' /></td> </tr><tr> <td><span class='style7'>Section " + dispNumSection + " Content </span>   <br>       <table width='231' border='0' cellspacing='0' cellpadding='0'>  <tr>  <td width='115'>  <span class='style17'>&gt;&gt;</span >   <a href='javascript:;' class='style1' onclick='insertion(\"content" +numContent+ "\");'  onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"  >Add image</a>        						  </td> <td width='21'>  <a href='javascript:;'  onclick= 'formatting(\"content" +numContent+ "\", \"b\");'><img src='../images/bold.gif' alt='bold' width='21' height='20' border='0' /></a></td>  <td width='21'><a href='javascript:;'  onclick= 'formatting(\"content" +numContent+ "\", \"i\");'><img src='../images/italic.gif' alt='italik' width='21' height='20' border='0' /></a></td>  <td width='24'><a href='javascript:;'  onclick= 'formatting(\"content" +numContent+ "\", \"u\");'><img src='../images/underline.gif' alt='underline' width='21' height='20' border='0' /></a></td> 					   <td width='36'><a href='javascript:;'  onclick= 'formatting(\"content" +numContent+ "\", \"ul\");'><img src='../images/insertunorderedlist.gif' alt='list' width='21' height='20' border='0' /></a><a href='javascript:;' class='style1'   onMouseover=\"ddrivetip('<br><strong>Note for Lists </strong> : First, separate each item of the list by a new line, then, select  the entire list and click on the button.', 300)\";  onMouseout=\"hideddrivetip()\"  ><sup>?</sup></a>     </td>     <td width='21'><a href='javascript:;'  onclick= 'formatting(\"content" +numContent+ "\", \"sub\");'><img src='../images/footnote.gif' alt='footnote' width='21' height='20' border='0' /></a></td>      </tr>  </table>          <br> <textarea name='content" +numContent+ "' cols='85' rows='12' id='content" +numContent+ "'></textarea> <br> <span class='style17'>&gt;&gt;&gt;&gt;</span ><a href='javascript:;' onclick='addSubSection(\""+divName+"\", "+numSection+");'>Add a Sub-section to this section</a></td> </tr> </table> </td> <td background='images/d.gif'>&nbsp;</td></tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td>   <td><img src='images/bd.gif' width='7' height='7' /></td> </tr></table> ";
	/*
	newdiv.innerHTML  = " <br><table width='680' border='0' cellpadding='0' cellspacing='0'> <tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td><img src='images/h.gif' width='680' height='7' /></td> <td><img src='images/hd.gif' width='7' height='7' /></td>  </tr> <tr> <td background='images/g.gif'> </td> <td  >	 <table width='100%' border='0' cellpadding='0' cellspacing='2' bgcolor='#FFF0F0'> <tr><td><span class='style7'>Section " + dispNumSection +  " Heading</span> ( <a href=\"javascript:;\" class='style1' onclick=\"removeSection(\'"+divName+"\')\">Remove</a> )<br>  <input name='heading" +numHeading+ "' type='text' id='heading" +numHeading+ "' size='80' /></td> </tr><tr> <td><span class='style7'>Section " + dispNumSection + " Content </span>   <br><span class='style17'>&gt;&gt;</span > <a href='javascript:;' class='style1' onclick='insertion(\"content" +numContent+ "\");'        onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"       >Add image</a><br> <textarea name='content" +numContent+ "' cols='85' rows='12' id='content" +numContent+ "'></textarea> <br> <span class='style17'>&gt;&gt;&gt;&gt;</span ><a href='javascript:;' onclick='addSubSection(\""+divName+"\", "+numSection+");'>Add a Sub-section to this section</a></td> </tr> </table> </td> <td background='images/d.gif'>&nbsp;</td></tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td>   <td><img src='images/bd.gif' width='7' height='7' /></td> </tr></table> ";
	 */
 	
}



function removeSection( sectionDiv ){ 
//alert (sectionDiv);
 	var d = document.getElementById('sections');
 	 var olddiv = document.getElementById(sectionDiv);
 	d.removeChild(olddiv); 
}



function addSubSection(sectionDiv, number) {    
	//alert( "adding to sectionDiv=" + sectionDiv + " numer = " + number + " numSection=" + numSection);
	/*
	var div = document.getElementById(sectionDiv);
	var fck = new FCKeditor("myFCKeditor");
	fck.BasePath = "./fck/";

	div.innerHTML = fck.CreateHtml();


	alert( "innerHTML=" + innerHTML );
			*/
			
	numSubSection++;
	numSubHeading++;
	numSubContent++;
	var subHeadingName="subHeading" + number + "-" + numSubHeading;
	var subContentName="subContent" + number + "-" + numSubContent;
	// alert( subHeadingName);
    var ni = document.getElementById(sectionDiv); 
	var newdiv = document.createElement('div'); 
	var divName = "subSection" + number + "-" + numSubSection;
	newdiv.setAttribute("id",divName);
	 
	var fck = new FCKeditor(subContentName);
	fck.BasePath = "./fck/";  
	fck.Config["CustomConfigurationsPath"] = "../myconfig.js"  ;
	
	newdiv.innerHTML = "<table width='99%' border='0' cellpadding='0' cellspacing='2' ><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td bgcolor='#E4E4C9'><span class='style29'>  &nbsp; Heading</span>   ( <a href=\"javascript:;\" onclick=\"removeSubSection(\'"+sectionDiv+"\', \'"+divName+"\')\">Remove</a> )<br><input name='" +subHeadingName+ "' type='text' id='" +subHeadingName+ "' size='80' /></td> </tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp; </td><td bgcolor='#E4E4C9'><span class='style29'>  &nbsp; Content</span>&nbsp; <br>    " + fck.CreateHtml() + "   </td></tr> </table> <br>";
	
	
 	ni.appendChild(newdiv);  //alert (ni.innerHTML);
	
	
	
	/////////fck
	
	// <textarea name='" +subContentName+ "' cols='80' rows='15' id='" +subContentName+ "'></textarea> 
	
	/*
	 	newdiv.innerHTML =	"  <table width='90%' border='0' cellpadding='0' cellspacing='2' ><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td bgcolor='#FFE6E6'><span class='style7'>Heading</span> ( <a href=\"javascript:;\" onclick=\"removeSubSection(\'"+sectionDiv+"\', \'"+divName+"\')\">Remove</a> )<br><input name='" +subHeadingName+ "' type='text' id='" +subHeadingName+ "' size='80' /></td> </tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp; </td><td bgcolor='#FFE6E6'><span class='style7'>Content </span>&nbsp;  <br>    <table width='231' border='0' cellspacing='0' cellpadding='0'>  <tr>  <td width='115'>  <span class='style17'>&gt;&gt;</span >   <a href='javascript:;' class='style1' onclick='insertion(\"" +subContentName+ "\");'  onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"  >Add image</a>        						  </td> <td width='21'>  <a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"b\");'><img src='../images/bold.gif' alt='bold' width='21' height='20' border='0' /></a></td>  <td width='21'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"i\");'><img src='../images/italic.gif' alt='italik' width='21' height='20' border='0' /></a></td>  <td width='24'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"u\");'><img src='../images/underline.gif' alt='underline' width='21' height='20' border='0' /></a></td> 					   <td width='36'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"ul\");'><img src='../images/insertunorderedlist.gif' alt='list' width='21' height='20' border='0' /></a><a href='javascript:;' class='style1'   onMouseover=\"ddrivetip('<br><strong>Note for Lists</strong> : First, separate each item of the list by a new line, then, select the entire list and click on the button.', 300)\";  onMouseout=\"hideddrivetip()\"  ><sup>?</sup></a>   </td>            <td width='21'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"sub\");'><img src='../images/footnote.gif' alt='footnote' width='21' height='20' border='0' /></a></td>            </tr>  </table>           <br> <textarea name='" +subContentName+ "' cols='80' rows='15' id='" +subContentName+ "'></textarea> </td></tr> </table> <br> ";
		*/
		//////////
	
	
	
	
	
	
	
	
	//newdiv.innerHTML = "<br><table width='100%' border='0' cellpadding='0' cellspacing='2' ><tr><td>fffffff</td><td bgcolor='#EFCCEF'><strong>Heading</strong> ( <a href=\"javascript:;\" onclick=\"removeSubSection(\'"+sectionDiv+"\', \'"+divName+"\')\">Remove</a> )<br><input name='" +subHeadingName+ "' type='text' id='heading" +numHeading+ "' size='100' /></td></tr><tr><td>fffffff</td><td bgcolor='#EFCCEF'><strong>Content</strong><a href='javascript:;' onclick='insertion(\"content" +numContent+ "\");'>Add image</a><br><textarea name='" +subContentName+ "' cols='100' rows='15' id='content" +numContent+ "'></textarea> </td></tr> </table>";

 	/*
	 	newdiv.innerHTML =	"  <table width='90%' border='0' cellpadding='0' cellspacing='2' ><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td bgcolor='#FFE6E6'><span class='style7'>Heading</span> ( <a href=\"javascript:;\" onclick=\"removeSubSection(\'"+sectionDiv+"\', \'"+divName+"\')\">Remove</a> )<br><input name='" +subHeadingName+ "' type='text' id='" +subHeadingName+ "' size='80' /></td> </tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp; </td><td bgcolor='#FFE6E6'><span class='style7'>Content </span>&nbsp;  <br>    <table width='231' border='0' cellspacing='0' cellpadding='0'>  <tr>  <td width='115'>  <span class='style17'>&gt;&gt;</span >   <a href='javascript:;' class='style1' onclick='insertion(\"" +subContentName+ "\");'  onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"  >Add image</a>        						  </td> <td width='21'>  <a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"b\");'><img src='../images/bold.gif' alt='bold' width='21' height='20' border='0' /></a></td>  <td width='21'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"i\");'><img src='../images/italic.gif' alt='italik' width='21' height='20' border='0' /></a></td>  <td width='24'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"u\");'><img src='../images/underline.gif' alt='underline' width='21' height='20' border='0' /></a></td> 					   <td width='36'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"ul\");'><img src='../images/insertunorderedlist.gif' alt='list' width='21' height='20' border='0' /></a><a href='javascript:;' class='style1'   onMouseover=\"ddrivetip('<br><strong>Note for Lists</strong> : First, separate each item of the list by a new line, then, select the entire list and click on the button.', 300)\";  onMouseout=\"hideddrivetip()\"  ><sup>?</sup></a>   </td>            <td width='21'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"sub\");'><img src='../images/footnote.gif' alt='footnote' width='21' height='20' border='0' /></a></td>            </tr>  </table>           <br> <textarea name='" +subContentName+ "' cols='80' rows='15' id='" +subContentName+ "'></textarea> </td></tr> </table> <br> ";
		*/
		
		
          
						
		/*
		
		 "<a href='javascript:;' onclick='insertion(\"" +subContentName+ "\");'      onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"      >Add image    </a>    " 
		 
		       "<table width='231' border='0' cellspacing='0' cellpadding='0'>  <tr>  <td width='115'>  <span class='style17'>&gt;&gt;</span >   <a href='javascript:;' class='style1' onclick='insertion(\"" +subContentName+ "\");'  onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"  >Add image</a>        						  </td> <td width='21'>  <a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"b\");'><img src='../images/bold.gif' alt='bold' width='21' height='20' border='0' /></a></td>  <td width='21'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"i\");'><img src='../images/italic.gif' alt='italik' width='21' height='20' border='0' /></a></td>  <td width='24'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"u\");'><img src='../images/underline.gif' alt='underline' width='21' height='20' border='0' /></a></td> 					   <td width='33'><a href='javascript:;'  onclick= 'formatting(\"" +subContentName+ "\", \"ul\");'><img src='../images/insertunorderedlist.gif' alt='italik' width='21' height='20' border='0' /></a>  <a href='javascript:;' class='style1'   onMouseover=\"ddrivetip('<br><strong>Note</strong> : First, separate each item of the list by a new line, then, select all the list and click on the button.', 300)\";  onMouseout=\"hideddrivetip()\"  >?</a>     </td>          </tr>  </table>"
	
	*/
	
	/*
	newdiv.innerHTML =	"  <table width='90%' border='0' cellpadding='0' cellspacing='2' ><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td bgcolor='#FFE6E6'><span class='style7'>Heading</span> ( <a href=\"javascript:;\" onclick=\"removeSubSection(\'"+sectionDiv+"\', \'"+divName+"\')\">Remove</a> )<br><input name='" +subHeadingName+ "' type='text' id='" +subHeadingName+ "' size='80' /></td> </tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp; </td><td bgcolor='#FFE6E6'><span class='style7'>Content </span>&nbsp;  <br><span class='style17'>&gt;&gt;</span >     <a href='javascript:;' onclick='insertion(\"" +subContentName+ "\");'      onMouseover=\"ddrivetip(' <br><strong>Note</strong>  : To position an image in your article, first place your cursor where you want the image to show in the text. Then click <i>Add Image</i>. This marks the spot where the image will be inserted. You can browse to get the image itself at the next step in the submission process<br><br> ', 300)\";  onMouseout=\"hideddrivetip()\"      >Add image    </a><br> <textarea name='" +subContentName+ "' cols='80' rows='15' id='" +subContentName+ "'></textarea> </td></tr> </table> <br> ";
	
	*/
	// newdiv.innerHTML = "   <table width='680' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFE6E6'> <tr><td>pppp </td></tr><tr> <td><img src='images/hg.gif' width='7' height='7' /></td><td><img src='images/h.gif' width='680' height='7' /></td> <td><img src='images/hd.gif' width='7' height='7' /></td> </tr> <tr> <td background='images/g.gif'>&nbsp;</td> <td  ><span class='style7'>Heading</span> <br /> <input name='heading0' type='text' id='heading0' size='80' /> <br /> <span class='style7'>Content</span> &nbsp;&nbsp;<a href='javascript:;' class='style1' onclick='insertion(\"content0\");'>Add image</a><br /> <textarea name='content0' cols='85' rows='12' id='content0'></textarea></td> <td background='images/d.gif'>&nbsp;</td></tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td> <td><img src='images/bd.gif' width='7' height='7' /></td></tr></table>      ";
	
	// newdiv.innerHTML ="   <table width='80%' border='0' cellspacing='0' cellpadding='0'><tr><td width='5%'>&nbsp;</td> <td width='95%'><table width='723' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFE6E6'> <tr> <td><img src='images/hg.gif' width='7' height='7' /></td> <td width='680'><img src='images/h.gif' width='680' height='7' /></td> <td width='10'><img src='images/hd.gif' width='7' height='7' /></td> </tr> <tr> <td background='images/g.gif'>&nbsp;</td><td  ><span class='style7'>Heading</span> <br /> <input name='heading02' type='text' id='heading02' size='80' /> <br /> <span class='style7'>Content</span> &nbsp;&nbsp;<a href='javascript:;' class='style1' onclick='insertion(\"content0\");'>Add image</a><br /> <textarea name='textarea' cols='85' rows='12' id='textarea'></textarea></td> <td background='images/d.gif'>&nbsp;</td> </tr> <tr> <td><img src='images/bg.gif' width='7' height='7' /></td> <td><img src='images/b.gif' width='680' height='7' /></td> <td><img src='images/bd.gif' width='7' height='7' /></td> </tr> </table></td> </tr> <tr> <td>&nbsp;</td><td>&nbsp;</td></tr></table>";
	 
	 //<br><a href='javascript:;' onclick='addSubSection(\'"+sectionDiv+"\', 0);'>Add Sub-section</a><br>
	 
}



function removeSubSection( sectionDiv, subSectionDiv ){ 
 	var d = document.getElementById(sectionDiv);
 	 var olddiv = document.getElementById(subSectionDiv);
 	d.removeChild(olddiv); 
}


function insertion1( textareaDiv) {
	// alert('yyy ' + textareaDiv);
}

function insertion( textareaDiv) {
	// alert(textareaDiv);
  //var textareaDiv = "sec";	
  var ni = document.getElementById(textareaDiv); 
  var input =ni;
  var repdeb="<asistImage>";
  var repfin="</asistImage>"; 
  var insText = "";
  insText =prompt (" Add Image \n Image Name and Caption (e.g Figure 2: Decoding  Multiple Knowledge ... )", "");
  if(insText == "" || insText == null) return;
  input.focus();
  /* pour l'Explorer Internet */
  if(typeof document.selection != 'undefined') {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    //var insText = range.text;
//	var insText = "";
    range.text = repdeb + insText + repfin;
    /* Ajustement de la position du curseur */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  /* pour navigateurs plus récents basés sur Gecko*/
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    //var insText = input.value.substring(start, end);
   // var insText = "";
	input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
    /* Ajustement de la position du curseur */
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* pour les autres navigateurs */
  else
  {
    /* requête de la position d'insertion */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Insertion du code de formatage */
    //var insText = prompt("Veuillez entrer le texte à formater:");
	//var insText = "";
    input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
  }
}

function insertion2( textareaDiv) {
	// alert(textareaDiv);
  //var textareaDiv = "sec";	
  var ni = document.getElementById(textareaDiv); 
  var input2 =ni;
  var repdeb="<sup>";
  var repfin="</sup>"; 
  var insText = "";
  insText =prompt (" Add Footnote Number \n Insert just the footnote number here", "");
  if(insText == "" || insText == null) return;
  input2.focus();
  /* pour l'Explorer Internet */
  if(typeof document.selection != 'undefined') {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    //var insText = range.text;
//	var insText = "";
    range.text = repdeb + insText + repfin;
    /* Ajustement de la position du curseur */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  /* pour navigateurs plus récents basés sur Gecko*/
  else if(typeof input2.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    var start = input2.selectionStart;
    var end = input2.selectionEnd;
    //var insText = input.value.substring(start, end);
   // var insText = "";
	input2.value = input2.value.substr(0, start) + repdeb + insText + repfin + input2.value.substr(end);
    /* Ajustement de la position du curseur */
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    input2.selectionStart = pos;
    input2.selectionEnd = pos;
  }
  /* pour les autres navigateurs */
  else
  {
    /* requête de la position d'insertion */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Insertion à la position (0.." + input2.value.length + "):", "0");
    }
    if(pos > input2.value.length) {
      pos = input2.value.length;
    }
    /* Insertion du code de formatage */
    //var insText = prompt("Veuillez entrer le texte à formater:");
	//var insText = "";
    input2.value = input2.value.substr(0, pos) + repdeb + insText + repfin + input2.value.substr(pos);
  }
}

function formatting(textareaID, tag) {
//alert("yes "+ textareaID + " tag " + tag);
  //var textareaDiv = "sec";	
  var ni = document.getElementById(textareaID); 
  var input =ni;
  
  var repdeb="<" + tag + ">";
  var repfin="</" + tag + ">";
  /*  var repdeb="<image>";
  var repfin="</image>";
  */
  
  //var ni = document.getElementById(sectionDiv); 	
//  var input =  form.elements['saisie'];
//  var input = document.forms['formulaire'].elements['saisie'];
  input.focus();
  /* pour l'Explorer Internet */
  if(typeof document.selection != 'undefined') {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    var insText = range.text;
	//var insText = "";
    range.text = repdeb + insText + repfin;
    /* Ajustement de la position du curseur */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  /* pour navigateurs plus récents basés sur Gecko*/
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    //var insText = "";
	input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
    /* Ajustement de la position du curseur */
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* pour les autres navigateurs */
  /*
  else
  {
    // requête de la position d'insertion 
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    // Insertion du code de formatage 
    var insText = prompt("Veuillez entrer le texte à formater:");
	//var insText = "";
    input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
  }
  */
}

