// JavaScript Document
if(typeof HTMLElement!="undefined" && !
HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
{
switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}
}
HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}
HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
{
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)
}
}
function addEvent() {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById("theValue").value -1)+ 2;
  if(num>6)
  {
  alert("Maximum six files can be added here.");
  }
  else
  {
  
  numi.value = num;
  var divIdName = "my"+num+"Div";
  var newdiv = document.createElement('div');
  newdiv.setAttribute("id",divIdName);
  
  newdiv.innerHTML = "<div class='clear' >&nbsp;</div><div class='bodyfont'><input type='file' name='AttachFile"+num+"' id='AttachFile"+num+"'/></div>";
  //newdiv.innerHTML = "Element Number " + num + " has been added! <a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\">Remove the element &quot;"+divIdName+"&quot;</a>";
  ni.appendChild(newdiv);
  }
}
function numericalCheckWithDecimal (obj)
	{
		var checkOK ="0123456789.";
		var checkStr = obj.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}
		if (!allValid)
		{
			
			obj.focus();
			return false;
		}
	}
	function numericalCheckWithoutDecimal (obj)
	{
		var checkOK ="0123456789";
		var checkStr = obj.value;
		var allValid = true;
		
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
			
				if (ch == checkOK.charAt(j))
					break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}
		if (!allValid)
		{
			
			obj.focus();
			return false;
		}
	}
function addInput()
{
	var x = document.getElementById("myDiv");
	//alert(x.innerHTML);
	//x.innerHTML += ;
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
  if(num>6)
  {
  alert("Maximum six files can be added here.");
  }
  else
  {
	  numi.value = num;
	 // alert(document.getElementById("myDiv"));
	document.getElementById("myDiv").insertAdjacentHTML('beforeEnd','<input type=\"file\" name=\"ModuleImage[]\" /><br>');
  }
	
}

function removeElement(divNum) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}





function removeEcourse(ecourseId)
	{
		if(ecourseId!=0)
		{
			if(confirm("Do you sure to delete this ecourse"))
			{
				window.location.href='ecourse_action.php?action=delete_Ecourse&delId='+ecourseId
			}
		}
	}
