/**
 * @author sutapa
 */
function addMessage(reply_id){
	
	if(document.getElementById("forumForm").style.display == "block") {
		document.getElementById("forumForm").style.display = "none";
	} else {
			
	 	document.getElementById("forumForm").style.display = "block";
    }
	 
	  if(reply_id != 0){
	 	document.getElementById("reply_id").value = reply_id;
	 } else {
	 	document.getElementById("reply_id").value = 0;
	 }
	
							 

}

	
	var upload_number = 1;
	function addFileInput() {
		document.getElementById('img_file').value = upload_number;
		alert(upload_number);
		if (upload_number > 4) { // assuming 1 file input is in the html
			alert('maximum of 5 uploads allowed');
		}
		else {
			
			var d = document.createElement("div");
			var l = document.createElement("a");
			var file = document.createElement("input");
			file.setAttribute("type", "file");
			file.setAttribute("name", "attfile" + upload_number);
			file.setAttribute("id", "attfile" + upload_number);
			file.setAttribute("style", "height:20px; border-bottom:1px #CCCCCC solid; border-left:none; border-right:none; border-top:none; padding-left:5px;margin-left:25px;");
			l.setAttribute("href", "javascript:removeFileInput('f" + upload_number + "');");
			l.setAttribute("style", "text-decoration:none; color:#666666; font-size:11px; font-family:Geneva, Arial, Helvetica, sans-serif; font-weight:bold; padding-left:8px");
			l.appendChild(document.createTextNode("[remove]"));
			d.setAttribute("id", "f" + upload_number);
			d.appendChild(file);
			d.appendChild(l);
			document.getElementById("moreUploads").appendChild(d);
			upload_number++;
			
		}
	}

	function removeFileInput(i) { 
		var elm = document.getElementById(i); 
		document.getElementById("moreUploads").removeChild(elm); 
		upload_number--;
	}
	
	function ValidateSubmit(){
		
		var nameVal = document.formGallery.name.value;
		var strAlert = new String();
		if(nameVal.length == 0){
			alert("Insert Your Name.");
			return false;	
		}
		var sContVal = document.formGallery.attachment.value;
		if(sContVal.length == 0){
			alert("upload Image File.");
			return false;	
		}
		var attachVal = new Array();
	
		for(j=1; j<upload_number; j++){
				attachFile = "attfile"+j;
				imageVal = document.getElementById(attachFile).value;
				var checkimg = imageVal.toLowerCase();
				if (!checkimg.match(/(\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG|\.jpeg|\.JPEG)$/))
				{
					alert('Your image must have one of the following file extension types: .jpg, .gif, or .png. Please try again.');
				return false;
				}
				else
				{
				return true;
				}
			}
		
		if (sContVal.length != 0 || upload_number>1 ) {
			var gfile = sContVal.toLowerCase();
        	var str = new String();
        	str = gfile;
			var finddot=str.lastIndexOf('.',str.length);
        	var contain=new String();
        	var contain=str.substring(finddot+1,str.length);
			var arr = new Array('jpeg','jpg','gif','png','pjpeg','pjpg'); //add file extensions here
            for(i = 0; i <= arr.length-1; i++)
	        {
	            if(arr[i] == contain)
	            var res="yes";
	        }
			if((res != "yes") || (sContVal == "") || (nameVal == "") )
        	{
				alert('Your image must have one of the following file extension types: .jpg, .gif, or .png. Please try again.');
	            return false;
        	}  else {
            	 return true;
            }
			
		}
		
		
	}

