/* Copyright (c) 2007 Affno (Pvt) Ltd, . All rights reserved.

 This software is the confidential and proprietary information of        
 Affno  ("Confidential Information").  You shall not disclose such 
 Confidential Information and shall use it only in accordance with
 the terms of the license agreement you entered into with Affno.

Module Name		: MOBWEB1
File Name		: menu.js
Description		: Mobitel hover menu and other goodies
Created By		: Bjorn de Lima
Created Date	: 12-April-2007 (hover menu originally for ODLWEB1)
Modified By		: 
Modified Date	: Er..start of the project :(
Version			: 1.00.000
Modified By		: bjorn
Modified Date	: 18/09/2007
Version			: 1.10.000 (Added mobitel sidemenu)

*/

onerror = handle;

function handle(){
	 return true;
	}

var currentMenu = null;
var menuHideTimer = null;
var showTime = 300; // ms

function showMenu(str,obj){	
if (str!=currentMenu){
	//$E('.selectMenu').style.visibility = 'none';
	hideMenu_New();
	resetTimer();
	var off = 16;
	var pos = Array();
	pos = findPos(obj);
	obj2 = document.getElementById(str);
	obj2.style.display = "block";
	
	//var inv = new Fx.Style(str, 'opacity').set(0); 
	var fx = new Fx.Styles(str,{duration:300,transition: Fx.Transitions.linear} ); 
	fx.start({
			// 'opacity' : [0,1]
			 'padding-top' : [5,0]
			 });
	
	
	obj2.style.left = parseInt(pos[0]-5)+"px";
	obj2.style.top = parseInt(pos[1]+off)+"px";
	currentMenu = str;
	}
	else{
		resetTimer();
		}
}

function showIt(obj){
	//alert('s');
	obj.style.display = 'block';
	}
	
function hideMenu_New(){	

	if (currentMenu){
	obj = document.getElementById(currentMenu);
	obj.style.display = "none";
	currentMenu="";
	// do we want to be really fancy ??
	//if ($E('.selectMenu')){
	//$E('.selectMenu').style.display = 'block';
	//}
	//var inv = new Fx.Style(currentMenu, 'padding-top').set(0); 
	
}
	
	}	

function startTimer(){
	menuHideTimer = setTimeout("hideMenu_New()", showTime);
	}
	
function resetTimer(){
	if (menuHideTimer){
		clearTimeout(menuHideTimer);
	}
	menuHideTimer = null;	
	}

function getCurrentPage(url){
	if (url){
	str = url+"";
	arr = str.split('/');
	url = arr[arr.length-1];
	if (url){
	return url;
	}
	}
	else{
		return url;
		}
}

function sideMenu(){
	mainobjs = Array();
	mainobjs = "";
	cursubobj = curobj = false;
	if($('sidemenu')){
		var menuitems = $('sidemenu').getChildren();
		var url = getCurrentPage(location.href);
		j = menuitems.length
		for (i=0;i<j;i++){
		menuitems[i].setStyle('display','block');	
			if (menuitems[i].hasClass('subitem') ){
				subobj = menuitems[i];
				}
			if ( url == getCurrentPage(menuitems[i].getFirst().href) ){
				if (menuitems[i].hasClass('subsubitem')){ 
				cursubobj = menuitems[i];
				curobj = subobj;
				}
				if (menuitems[i].hasClass('subitem')){
				cursubobj = menuitems[i];
				curobj = menuitems[i];
				}
			}
		}
		
	//	alert(curobj);
		if (cursubobj){
			curobj.addClass('blue');
			cursubobj.addClass('green');
			//	curobj.setStyle('margin-top','10px');
			cursubobj.setStyle('display','block');
			
		if (curobj.getNext()){
		node = curobj.getNext();
		while (!node.hasClass('subitem')){				
				node.setStyle('display','block');
				node = node.getNext();
				}
			//node.setStyle('padding-top','10px');
			
			}
		}
		
	}
}


// JavaScript Document
window.addEvent('domready', function(){
  init();
  //phonieslideshow();
 
});

function init(){
if ($('phonie')){  phonie();  }

if ($('a1')) { 
current = Cookie.get('userSelect');
current2 = Cookie.get('userSelect2');
if (!current){
	current=0;
	current2=0;
 	}

$('userSelect').selectedIndex = current;
num = parseInt(current)+1;
$('a'+num).style.display ="block";
$('a'+num).selectedIndex = current2;
}
else{
	Cookie.remove('userSelect');
	Cookie.remove('userSelect2');
	}


if ($("userSelect")){
$$("#userSelect").addEvent('change', function(){
quick(this);
});
quick($('userSelect'));
}

$$(".subsubitem a").addEvent('click', function(){
if (this.href.contains('#')){ 
	$('sidemenu').getChildren().removeClass('green');
	this.getParent().addClass('green');
	
	}
});


$$(".boxclear").addEvent('focus', function(){
if ((this.value=='Mobile No') || (this.value=='Password') || (this.value=='DD') || (this.value=='YYYY') || (this.value=='First name') || (this.value=='Last name') || (this.value=='City')){ 
this.value="";
this.style.color = "#222222";
}
});

if ($('sidemenu')){
	sideMenu();
	}
}



function findPos(obj) {  // http://www.quirksmode.org/js/findpos.html#
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}



function quick(obj){
arr = $$(".hideselects select");
for(i=0;i<arr.length;i++){
	arr[i].style.display="none";
	}
$('a'+parseInt(obj.selectedIndex+1)).style.display = "block";
}

	

function openPopup(obj){
	window.open('s','popup');
	}
	
function openPopupWindow(params){
	window.open(params);
	}	
	
function quickNavi(obj){
	for (i=0;i<obj.childNodes.length;i++){
		if(obj.childNodes[i].id){
			if(obj.childNodes[i].style.display == 'block'){
				Cookie.remove('userSelect');
				Cookie.set('userSelect',$('userSelect').selectedIndex,{path: '/'});
				Cookie.set('userSelect2',obj.childNodes[i].selectedIndex,{path: '/'});
				document.location = obj.childNodes[i].value;
				}
			}
		}
	
	}	
	
	
function flashWrite(file,width,height){
		document.write("<object type='application/x-shockwave-flash' width='"+width+"' height='"+height+"' data='"+file+"'>	<param name='movie' value='"+file+"' /><param name='quality' value='high' /><param name='wmode' value='opaque' /><embed src='"+file+"' quality='high'   wmode='opaque'></embed></object>");	
	}
