var dc		= document;
var dca		= document.all;
var dcb		= document.body;
var isDOM	= dc.getElementById ? 1 : 0;
var isIE		= dca ? 1 : 0;
var isNS4	= navigator.appName == 'Netscape' && !isDOM ? 1 : 0;
var isIE4	= isIE&&!isDOM ? 1 : 0;
var isOp		= window.opera ? 1 : 0;
var isDyn	= isDOM || isIE || isNS4;
var ie		= /MSIE/.test(navigator.userAgent);
var moz 	= !ie && navigator.product == "Gecko";

// Constants 
var MOT	= "menuOut";	
var MOV	= "menuOver";
var NE	= "none";

document.write("<SCRIPT LANGUAGE='JavaScript' TYPE='text/JavaScript' SRC='/WL.nsf/3/GrlFunc/$file/GrlFunc.js'></SCRIPT>");

// General function for access to the element
function gEBId(aID){
	var rv = null;
	
	if( isDOM ){
// alert("gEBId: " + aID );
		rv = dc.getElementById(aID);
	} else if( isNS4 ){
		rv = dc.layers[aID];
	} else if( isIE4 ){
		rv = dc.all[aID];
	}
	return rv;
}

var tar;

function closemenu() {
	Menu1.className = MOT;
	Menu2.className = MOT;
	Menu3.className = MOT;
	Menu4.className = MOT;
	Menu5.className = MOT;
	Menu6.className = MOT;
	Menu7.className = MOT;
	SubMenu1.style.display = NE;
	SubMenu2.style.display = NE;
	SubMenu3.style.display = NE;
	SubMenu4.style.display = NE;
	SubMenu5.style.display = NE;
	SubMenu6.style.display = NE;
	SubMenu7.style.display = NE;
}

function subMenuOpen(e) {
if( tar )tar.value = tar.value + " subMenuOpen: " + e.id + "\n";

// alert("subMenuOpen: " + e.id);
// alert("window.status: " + window.status + " || " + e.childNodes[1].textContent);
// if( !isIE ) 
// window.status = e.childNodes[1].textContent;// gEBId(e.id).blur();
// alert("window.status: " + window.status);
// if( !isIE ) window.status = e.childNodes[1].textContent;// gEBId(e.id).blur();
// if( !isIE ) window.status = e.childNodes[1].textContent;// gEBId(e.id).blur();
// if( !isIE ) window.status = e.childNodes[1].textContent;// gEBId(e.id).blur();

	e.className = MOV;
	eval( "Sub" + e.id + ".style.display='inline'");
}

// var sMO = subMenuOpen;

function subMenuOpenE(e) {
	e.className = MOV + "E";
	eval("Sub" + e.id + ".style.display='inline'");
}

function subMenuClose(e) {
if( tar ) tar.value = tar.value + " subMenuClose: " + e.id + "\n";
// if( !isIE ) window.status = "Done";// gEBId(e.id).blur();
	e.className = MOT;
	eval("Sub" + e.id + ".style.display='none'");
}

function sMClm(	e	// event
) {
// alert("sMClm:" + e);
// if( e.id.style.display != 'none' ?? moz ) eval( e.id + ".style.display='none'" );

//	e.className = MOT;
//	eval("Sub" + e.id + ".style.display='none'");
}

// Add Event Listeners for mouse out for SUbMenu Item
function aELSI(){
tar	= gEBId( "TAR" );
	// Sub Munu Item 
	var si = gEBId( "Sub" + "Menu1" );
//	alert( "Add Event Listeners si" + si );
	if( !si ){ return; }
//	alert( "Add Event Listeners " );
//alert( "tar :" + tar );
// if( !isIE )	si.addEventListener( "mouseout", sMClm, false );
}

function ssMC( e ) {
	var obj = document.getElementById( e );
	obj.className = MOT;
	eval( e + ".style.display='none'");
}

//var sMC = subMenuClose;
function subMenuCloseE(e) {
	e.className = MOT +"E";
	eval("Sub" + e.id + ".style.display='none'");
}

function subMenuOver(e) {
	e.className = "sub" + MOV;
}
//var sMV = subMenuOver;

function subMenuOut(e) {
	e.className = "sub" + MOT;
}
//var sMT = subMenuOut;

//-----------------מחירון


function openTaarifonWindow(){

	var tUL = '/tarifp1/Tarifp1.html';
	// taarifon Window Properties
	var tWP = 'width=' + screen.width + ',height=400,toolbar=no,status=yes,scrollbars=yes';
	
	var taarifon = window.open( tUL, 'taarifon', tWP );
}


//-----------TABLE SORT
function setDataType(	cValue
){
	// This function converts dates and numbers for proper array 
	// sorting when in the sort function
	var isDate = new Date(cValue);
	if( isDate == "NaN" ){
		if( isNaN(cValue) ){
			// The value is a string, make all characters in string upper 
			// case to assure proper a-z sort
			cValue = cValue.toUpperCase();
			return cValue;
		} else {
			// Value is a number, to prevent string sorting of a number, 
			// add an additional digit that is the + to the length of the 
			// number when it is a string.
			return (String.fromCharCode(48 + cValue.length) + cValue);
		}
	} else {
		// Value to sort is a date, remove all of the punctuation and return the string number
		// bug - strng and not numerical sort... (1 - 10 - 11...)
		var mD = new String();
		mD = isDate.getFullYear() + " " ;
		mD += isDate.getMonth() + " ";
		mD += isDate.getDate() + " ";
		mD += isDate.getHours() + " ";
		mD += isDate.getMinutes() + " ";
		mD += isDate.getSeconds();
		//myDate = String.fromCharCode(48 + myDate.length) + myDate;
		return mD ;
	}
}

function sortTable(	col, 
						tableToSort
){
	window.status  ='Sorting.....';
	var iCurCell   = col + tableToSort.cols;
	var totalRows  = tableToSort.rows.length;
	var bSort      = 0;
	var colArray   = new Array();
   	var oldIndex   = new Array();
	var indexArray = new Array();
	var bArray     = new Array();
	var newRow, newCell;
	var i, c, j;		// Counters

	// ** Populate the array colArray with contents of the column selected
	for( i = 1; i < tableToSort.rows.length; i++){
		colArray[i - 1] = setDataType(tableToSort.cells(iCurCell).innerText);
		iCurCell = iCurCell + tableToSort.cols;
	}
	// ** Copy array for comparison after sort
	for( i = 0; i < colArray.length; i++ ){
		bArray[i] = colArray[i];
	}
	// ** Sort the column items
	colArray.sort();
	for( i = 0; i < colArray.length; i++ ){ 		// Loop through the new sorted array
		indexArray[i] = i + 1;
		for( j = 0; j < bArray.length; j++) { 		// Loop through the old array
			// When the item in the old and new match, place the current row number 
	        // in the proper position in the new order array so rows can be moved...
	        // make sure current row number is not already in the new order array
			if( colArray[i] == bArray[j] ){
				for( c = 0; c < i; c++ ){
					if( oldIndex[c] == (j+1) ){
						bSort = 1;
					}
				}
				if( !bSort ){
					oldIndex[i] = (j+1);
				}
				bSort = 0;
			}
		}
	}
	// ** Sorting complete, add new rows to base of table....
	for( i = 0; i < oldIndex.length; i++ ){
		newRow = tableToSort.insertRow();
		newRow.className = "viewtd";
		
		for( c = 0; c < tableToSort.cols; c++ ){
			newCell = newRow.insertCell();
			newCell.innerHTML = tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
		}
	}
  	//Move new rows to top of table....
	for( i = 1; i < totalRows; i++ ){
		tableToSort.moveRow( (tableToSort.rows.length -1), 1 );
	}
  	//Delete the older rows from the bottom of the table....
	for( i = 1; i < totalRows; i++ ){
		tableToSort.deleteRow();
   	}
	window.status ='Finished sorting.';
}
