﻿// JavaScript Document

var arrInput = new Array(0);

function addInput() {
  arrInput.push(arrInput.length);
  display();
}

function display() {
  document.getElementById('otherField').innerHTML="";
 
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('otherField').innerHTML+=createInput();
   document.getElementById('otherField').innerHTML+=createFile();
  }

}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput() {
  return "<p><input name=\"txtfile[]\" id=\"txtfile[]\" type=\"text\" class=\"Title\" size=\"40\" value=\"File Title\"></p>";
}

function createFile() {
 // return "<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br><br>";
 return "<input name=\"ufile[]\" id=\"ufile[]\" type=\"file\" class=\"input\" size=\"35\" style=\"border:solid 1px #000000\" value=\"File Path\"><br>-----------------------------------------------------------------";
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
  }
  display(); 
}

function TitleAndFile()
{
	
	 var i, TxtFile = document.getElementsByTagName('input');
    for (i = 0; i < TxtFile.length; ++i) {
		  if (TxtFile[i].type.toLowerCase() == 'text') { 
				if(TxtFile[i].value == ''){
					alert('Please enter the title!');
					return false;
					TxtFile[i].focus();
				}
		  }
	}
	
    for (i = 0; i < TxtFile.length; ++i) {
		  if (TxtFile[i].type.toLowerCase() == 'file') { 
				if(TxtFile[i].value == ''){
					alert('Please select the file!');
					return false;
					TxtFile[i].focus();
				}
		  }
	   }		
	
}

function goToUploadFile()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		
		document.Frm_grid.action = "upload.php";
		document.Frm_grid.method = "post";
		document.Frm_grid.submit();
	}
	else
		alert('Please select the category!');
}

function goToViewFile()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		
		location = "viewfile.php?cat="+SelectId;

	}
	else
		alert('Please select the category!');
}

function editCategory(Id)
{
	location = 'editcategory.php?mod='+Id;
}// thie function to edit category.

function checkTitle()
{
	if(Trim(document.Frm_cat.txt_title.value) == ""){
		alert('Please enter the title!');
		document.Frm_cat.txt_title.focus();
		return false;
	}
	else
		return true;
}

function updateCategory(Id)
{
	  if(checkTitle())
	  {
		document.Frm_cat.action = '../action/download.php?mod='+Id;
		document.Frm_cat.method = "post";
		document.Frm_cat.submit();
	 }
}

function saveCategory(Id)
{
	  if(checkTitle())
	  {
		document.Frm_cat.action = '../action/download.php?mod_n='+Id;
		document.Frm_cat.method = "post";
		document.Frm_cat.submit();
	 }
}

function deleteCategory(Id,ChildCount)
{

	if(ChildCount == "0"){
		if(confirm("Are you sure about delete this category?")){
			location = '../action/download.php?mod_d='+Id;
		}
	}
	else
		alert('This category have file,can not delete!');
}


function deleteFile()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		if(confirm("Are you sure about delete this file?")){
			location = '../action/download.php?mod_Fd='+SelectId;
		}
	}
	else
		alert('Please select file!');
}

function checkLoginDown()
{
	//Frm_Forms
	userName = document.getElementById('down_username');
	txtPassword = document.getElementById('down_password');
	
	if(Trim(userName.value) == ""){
		alert('Please enter the username!');
		userName.focus();
		return false;
	}
	else if(Trim(txtPassword.value) == ""){
		alert('Please enter the password!');
		txtPassword.focus();
		return false;
	}
	else
		return true;
}

function checkLoginDownAr()
{
	//Frm_Forms
	userName = document.getElementById('down_username');
	txtPassword = document.getElementById('down_password');
	
	if(Trim(userName.value) == ""){
		alert('!الرجاء إدخال اسم المستخدم');
		userName.focus();
		return false;
	}
	else if(Trim(txtPassword.value) == ""){
		alert('!الرجاء إدخال كلمة السر');
		txtPassword.focus();
		return false;
	}
	else
		return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}