// FUNCTION FOR NO RIGHT CLICK

/*
var message="UNABLE TO ACCESS"; 
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

//END OF NO RIGHT CLICK
*/




//FUNCTIONS USED FOR DATA SORTING 
function sortorder(a,b){
return a - b;
}

function orderbyrank(thearray,theparent,menuitemarray){
var temparray= new Array();
for(var j in thearray){
temparray[thearray[j]] = menuitemarray[thearray[j]].rank;
}
temparray.sort(sortorder);

var outputarray=new Array();
for(var j in temparray){
for(var k in menuitemarray){
if((menuitemarray[k].parent==theparent)&&(menuitemarray[k].rank==temparray[j])){
outputarray[outputarray.length] = k;
}

}
}
return(outputarray);
}

function getsortedsiblings(thearray,theparent,menuitemarray){
var temparray = new Array();
for(var i in thearray){
if(thearray[i].parent==theparent){
temparray[temparray.length]=i;
}
}
return orderbyrank(temparray,theparent,menuitemarray);
}

// END OF DATA SORTING FUNCTIONS


//FUNCTIONS FOR TOP MENU MOUSE ACTIONS
var topmenulastclassname = null;

function topmenumouseover(obj){
topmenulastclassname = obj.className;
if(obj.className=='topmenucellcurrent'){
obj.className = topmenulastclassname;
}
else
{
obj.className = 'topmenucellover';
}
obj.style.cursor = 'hand';
}

function topmenumouseout(obj){
obj.className = topmenulastclassname;
}
//END OF FUNCTIONS FOR TOP MENU CONTROL


// START OF SIDE MENU FUNCTIONS

// FUNCTION FOR CREATING SIDE MENU OBJECTS (SERVICES & PRODUCTS & ATTRIBUTES MENUS) USES HIERACHY CATS
// REMAINS HERE FOR USE BY SERVICES MENU IF REQUIRED
function menuoptionobject(id,label,parent,rank,menu){
this.id=id;
this.label=label;
this.parent=parent;
this.rank=rank;
this.menu=menu;
}

//NEW WAY USING CSS CLASSES
function buildsidemenu(menuname){
//mods for determing array to use within function so only ie 'services' sent as argument instead of 'services_menuitemarray'  
//THESE MODS MAKE THIS FUNCTION DIFFERENT FROM THAT CURRENTLY USED IN VS & LABELMATRIX 
menuitemarray = eval(menuname+"_menuitemarray;");

//get all whose parents are zero
var basearray = new Array();
basearray = getsortedsiblings(menuitemarray,0,menuitemarray);

sidemenuarray = new Array();

//start of main loop
for(var i in basearray){
sidemenuarray[sidemenuarray.length] = menuitemarray[basearray[i]].label.toUpperCase()+";"+basearray[i]+";sidemenucelldefault_1";

var base2array = getsortedsiblings(menuitemarray,menuitemarray[basearray[i]].id,menuitemarray);
if(base2array.length){
for(var j in base2array){
sidemenuarray[sidemenuarray.length] = menuitemarray[base2array[j]].label+";"+base2array[j]+";sidemenucelldefault_2";

var base3array = getsortedsiblings(menuitemarray,menuitemarray[base2array[j]].id,menuitemarray);
if(base3array.length){
for(var k in base3array){
sidemenuarray[sidemenuarray.length] = menuitemarray[base3array[k]].label+";"+base3array[k]+";sidemenucelldefault_3";

var base4array = getsortedsiblings(menuitemarray,menuitemarray[base3array[k]].id,menuitemarray);
if(base4array.length){
for(var m in base4array){
sidemenuarray[sidemenuarray.length] = menuitemarray[base4array[m]].label+";"+base4array[m]+";sidemenucelldefault_4";
}
}

}
}
}
}

}

}








//NEW WAY USING CLASSES
// FUNCTION TO DISPLAY THE SIDE MENU CREATED IN BUILDSIDEMENU
function putsidemenu(menuname){
document.writeln('<table width=100% border=0 cellpadding=2 cellspacing=2>');
for(var i in sidemenuarray){
document.writeln('<tr id='+menuname+'_menuitem_'+sidemenuarray[i].split(";")[1]+'  onclick="">');
//document.writeln('<tr>');
//document.writeln('<div class="sidemenucellbgdefault_1" style="background-color: #ff0000; filter:alpha(opacity=20)">');
document.writeln('<td id='+menuname+'_menucell_'+sidemenuarray[i].split(";")[1]+' class="'+sidemenuarray[i].split(";")[2]+'"  onmouseover="sidemenumouseover(this)" onmouseout="sidemenumouseout(this)" onclick="sidemenumouseclick(this)">');
document.writeln(sidemenuarray[i].split(";")[0]);
document.writeln('</td>');
//document.writeln('</div>');
document.writeln('</tr>');
}
document.writeln('</table>');
}



//FUNCTIONS FOR SIDE MENU ACTIONS
var sidemenulastclassname = null;


function sidemenusetcurrent(obj){
//alert(obj.id);
thecurrent = obj.id.split("_")[2];
thearray = eval(obj.id.split("_")[0]+'_menuitemarray;');
thearray = traceancestors(thearray,thecurrent);
if(cpc){
for(v in thearray){
//alert(thearray[v])
eval(obj.id.split("_")[0]+'_menucell_'+thearray[v]+'.className="sidemenucellcurrent_1";');
//obj.className = "sidemenucellcurrent_1";
}
}


//alert("kak");


}



/*
function traceancestry(obj,thearray){
//alert(obj.parent);
while(obj.parent){
obj = thearray[obj.parent];
//alert(obj.parent);
}
return obj.id;
}
*/

//**********************MODIFIED IN BARCODE
function traceancestors(thearray,tracevalue){
temparray = new Array();
while(thearray[tracevalue].parent!=-1){
theparent=thearray[tracevalue].id;
temparray[temparray.length]=thearray[theparent].id;
tracevalue=thearray[theparent].parent;
}//end while
return temparray;
} 





function sidemenumouseover(obj){
obj.style.cursor = 'hand';
sidemenulastclassname = obj.className;

if((cpc)&&(obj.id.split("_")[2]==cpc)){
obj.className = sidemenulastclassname;
}
else
{
obj.className = "sidemenucellover_1";
}
}

function sidemenumouseout(obj){
obj.className = sidemenulastclassname;
}

function sidemenumouseclick(obj){
theredirect = false;
for(var i in redirectarray){
if((redirectarray[i].split(",")[0]==pagename) && (redirectarray[i].split(",")[1]==obj.id.split("_")[2])){
theredirect = redirectarray[i].split(",")[2];
}
}

if(theredirect){
window.location.href = theredirect;
}
else
{
window.location.href = obj.id.split("_")[0]+".php?cpc="+obj.id.split("_")[2]+"&mode="+mode;
}
}
//END OF SIDE MENU MOUSE ACTIONS


// END OF SIDE MENUS FUNCTIONS



//FUNCTIONS FOR MAKE MENU (TREADSAFE STYLE) MOUSEOVERS
// FUNCTIONS FOR MAKE MENU MOUSE ACTIONS
var makemenulastdimcolor = null;
var makemenulastbordercolor = null;
function makemenumouseover(obj){
makemenulastdimcolor = obj.style.backgroundColor;
makemenulastbordercolor = obj.style.borderColor;
obj.style.borderColor = makemenumouseoverbordercolor;
obj.style.backgroundColor = makemenumouseoverbackgroundcolor;
}

function makemenumouseout(obj){
obj.style.borderColor = makemenulastbordercolor;
obj.style.backgroundColor = makemenulastdimcolor;
}
// END OF MAKE ENU MOUSE ACTIONS FUNCTIONS





// FAQ MOUSEOVER FUNCTIONS require id setting of question and answer cells in calling page
//javascript function to display a faq answer on mouseover 
function showfaqa(obj){
eval("faqa_"+obj.id.split('_')[1]+".style.display=''");
}

//javascript function to hide a faq answer on mouseout 
function hidefaqa(obj){
eval("faqa_"+obj.id.split('_')[1]+".style.display='none'");
}






