//################################# Text Counter #####################################//
function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
  		field.value = field.value.substring(0, maxlimit);
   		alert("عفواً ، رسالتك طويلة فضلاً نرجوا الاختصار");
	}
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

//################################# PopUp shadow #####################################//
function updownshadow()
{	if (event.srcElement.className=="popshadow")
	{
		tempobject=event.srcElement
		if (event.type=="mousedown")
		{	tempobject.filters[0].enabled=false
			tempobject.style.left=tempobject.style.top=0
		}
		else
		{	tempobject.filters[0].enabled=true
			tempobject.style.left=tempobject.style.top=-5
		}
	}
}
	
//################################# Highlight menu effect #################################//	

function borderize(what,color,color1)
{	
	what.style.backgroundColor=color1
}

function borderize_on(e)
{
	if (document.all)
		source3=event.srcElement
	else if (document.getElementById)
		source3=e.target
	if (source3.className=="menulines")
		borderize(source3,"black","#F3EACB")
	else
	{
		while(source3.tagName!="TABLE")
		{
			source3=document.getElementById? source3.parentNode : source3.parentElement
			if (source3.className=="menulines")
				borderize(source3,"black","#F3EACB")
		}
	}
}
	
function borderize_off(e)
{
	if (document.all)
		source4=event.srcElement
	else if (document.getElementById)
		source4=e.target
	if (source4.className=="menulines")
		borderize(source4,"##D5EAE9","white")
	else
	{
		while(source4.tagName!="TABLE")
		{
			source4=document.getElementById? source4.parentNode : source4.parentElement
			if (source4.className=="menulines")
				borderize(source4,"##D5EAE9","white")
		}
	}
}

function ShowTable(TCode,TNum)
{
	if (TNum == 1)
		TableLevel1.innerHTML = TCode
	else
		TableLevel2.innerHTML = TCode
}

//################################# 1-Click Easy Drop-Down Menues #################################//	
// Set the target window or frame
// _top opens in the same window
// _blank opens in a new window


var theTarget = "_top";

function goThere()
{
	//if(!document.theForm.theMenu.selectedIndex=="")
	//{
		window.open(document.theForm.theMenu.options[document.theForm.theMenu.selectedIndex].value,theTarget,"");
	//}
}

//################################# textCounter() #################################//
function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
 		field.value = field.value.substring(0, maxlimit);
		alert("عفواً ، رسالتك طويلة فضلاً نرجوا الاختصار");
	}
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}
	
//################################# Functions used for Questions #################################//

function SingleUnCheck(ChkBox)
{
	FirstCheck.checked=false
}

function UnCheck(FirstCheck,SecondCheck,Index)
{
	FirstCheck[Index].checked=false 
	SecondCheck[Index].checked=false
}

//################################# Function used to select all items on UsrClasses select box #################################//
function presubmit(id)
{
  var selObj = document.getElementById(id);
  for (var i=0; i<selObj.options.length; i++) {
   selObj.options[i].selected = true;
  }
}

//################################# Function used for upload files #################################//
function onSubmitUploadForm() {
    var formDOMObj = document.frmSend;
    if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
        alert("فضلاً تأكد من تحديد ملف واحد على الأقل")
    else
		return true;
    return false;
}

//################################# Date funcions #################################//
function Sdate()
{
	var today=new Date()
	today.setDate(today.getDate() +  parseInt(document.AddWithDate.StartDateoff.value))
	document.AddWithDate.StartDate.value = today.getDate() + "/";
	m = today.getMonth() + 1;
	document.AddWithDate.StartDate.value += m + "/";
	document.AddWithDate.StartDate.value += today.getFullYear();
}

function Edate()
{
	var today=new Date()
	today.setDate(today.getDate() +  parseInt(document.AddWithDate.EndDateoff.value))
	document.AddWithDate.EndDate.value = today.getDate() + "/";
	m = today.getMonth() + 1;
	document.AddWithDate.EndDate.value += m + "/";
	document.AddWithDate.EndDate.value += today.getFullYear();
}

//################################# Filling the options.... #################################//
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) 
{
	var i, j;
	var prompt;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) 
		selectCtrl.options[i] = null; 
	prompt = (itemArray != null) ? goodPrompt : badPrompt;
	if (prompt == null) 
		j = 0;
	else 
	{
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}
	if (itemArray != null)
	{
		// add new items
		for (i = 0; i < itemArray.length; i++)
		{
			selectCtrl.options[j] = new Option(itemArray[i][0]);
			if (itemArray[i][1] != null)
				selectCtrl.options[j].value = itemArray[i][1]; 
			j++;
		}
		// select first item (prompt) for sub list
		selectCtrl.options[0].selected = true;
   }
}

