

	

function getMouseXY(e) 
{
	if (IE) 
	{ 		
	posX = event.clientX + document.body.scrollLeft
	posY = event.clientY + document.body.scrollTop
	} 
	else 
	{ 
	posX = e.pageX
	posY = e.pageY
	}  
	
	if (posX < 0){posX = 0}
	if (posY < 0){posY = 0} 				
	
	
	
	if(showTtp)
	{				
			currTtp.style.left=(posX)+"px";
			currTtp.style.top=(posY+22)+"px";
	}
	
	
	return true
}

function getWH()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
}








function commonFunctionsAfterLoad()
{
	getWH();
	
//	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	
	
	createToolTip();	
	//FOR HEADER MENU
	//tabdropdown.init("glowmenu", "auto");
		
	
}



function afterResized()
{
	getWH();

	
}




//=================================================================For tooltip============================>

function createToolTip()
{
	currTtp=document.createElement('div');
	currTtp.id='asd';
	mttp_div=currTtp;	
		
	mttp_div.style.position='absolute';
	mttp_div.style.fontFamily='Verdana, Arial, Helvetica, sans-serif';
	mttp_div.style.fontSize='10px';
	mttp_div.style.color='#FFFFFF';	
	mttp_div.style.zIndex='999999';
	mttp_div.style.border='1px dotted #666666';
	mttp_div.style.backgroundColor='#999999';
	mttp_div.style.padding='5px';
	document.body.appendChild(mttp_div);
	mttp_div.style.display="none";
}



function showToolTip(str)
{		
	showTtp=true;	
	str=str.replace('%nl%','<br/>');
	
	currTtp.innerHTML=str;		
	ttpfadeIn(currTtp.id,400);
}

function hideToolTip()
{
	showTtp=false;
	ttpfadeOut(currTtp.id,100);	
}



function ttpfadeOut(thisId,speed) 
{
 
	var obj = document.getElementById(thisId);
    //obj.style.zoom = 1; //needed for IE
    speed = speed/20;
    var i = 100;
    var intervalId = setInterval(function() {
		if(showTtp)	clearInterval(intervalId);										  
										  
        if(i>=0) 
		{
			obj.style.opacity = (i / 100);
			obj.style.MozOpacity = (i / 100);
			obj.styleKhtmlOpacity = (i / 100);
			obj.style.filter = "alpha(opacity=" + i + ")";			
			
			//document.getElementById('info').innerHTML=i;
            i -= 5;						
        } 
		else 
		{
            setTimeout(function() {obj.style.display = "none";}, speed);
            clearInterval(intervalId);			
            return false;
        }
    }, speed);
}

function ttpfadeIn(thisId,speed) 
{	

    var obj = document.getElementById(thisId);
    obj.style.display = "block";
    //obj.style.zoom = 1; //needed for IE
    obj.style.opacity = 0;
    obj.style.filter = "alpha(opacity = 0)";
    speed = speed/20;
    var i = 0;
    var intervalId = setInterval(function() 
	{
        if(i <= 100) 
		{
			obj.style.opacity = (i / 100);
			obj.style.MozOpacity = (i / 100);
			obj.styleKhtmlOpacity = (i / 100);
			obj.style.filter = "alpha(opacity=" + i + ")";
			//document.getElementById('info').innerHTML=i;
            i += 5;
        } 
		else {
			//setTimeout(function() {obj.style.display = "block";}, speed);
            clearInterval(intervalId);						
            return false;
        }
    }, speed);
}


//=================================================================For tooltip============================|











//======================================================Absolute Positioning of div======================>

function setDivToPosition(div_id,allign_x,allign_y,xfactor,yfactor)
{
	var mydiv=document.getElementById(div_id);
	
	
	mydiv.style.display='block';
	
	mydiv.style.position='absolute';
	divWidth=mydiv.offsetWidth;
	divHeight=mydiv.offsetHeight;
	
	
	
	if(allign_x=='left')mydiv.style.left=xfactor+'px';
	else if(allign_x=='right')mydiv.style.left=(myWidth-xfactor-divWidth)+'px';
	else if(allign_x=='middle')mydiv.style.left=((myWidth-divWidth)/2+xfactor)+'px';
	
	if(allign_y=='top')mydiv.style.top=yfactor+'px';
	else if(allign_y=='bottom')mydiv.style.top=(myHeight-yfactor-divHeight)+'px';
	else if(allign_y=='middle')mydiv.style.top=((myHeight-divHeight)/2-yfactor)+'px';
	
	
	
	//alert((myHeight-divHeight)/2-yfactor);
}

//======================================================Absolute Positioning of div======================|



function setDivSize(divid, ww, hh)
{

	obj=document.getElementById(divid);
	
	if(ww!='*')obj.style.width=ww+'px';
	if(hh!='*')obj.style.height=hh+'px';
	
}





//======================================================Fadein Fadeout Div================================>
function fadeOut(thisId,speed) 
{
 
	var obj = document.getElementById(thisId);
	
    //obj.style.zoom = 1; //needed for IE
    speed = speed/20;
    var i = 100;
    var intervalId = setInterval(function() {												  
										  
        if(i>=0) 
		{
			obj.style.opacity = (i / 100);
			obj.style.MozOpacity = (i / 100);
			obj.styleKhtmlOpacity = (i / 100);
			obj.style.filter = "alpha(opacity=" + i + ")";			
			
			//document.getElementById('info').innerHTML=i;
            i -= 5;						
        } 
		else 
		{
            setTimeout(function() {obj.style.display = "none";}, speed);
            clearInterval(intervalId);			
            return false;
        }
    }, speed);
}

function fadeIn(thisId,speed) 
{	

    var obj = document.getElementById(thisId);
    obj.style.display = "block";
    //obj.style.zoom = 1; //needed for IE
    obj.style.opacity = 0;
    obj.style.filter = "alpha(opacity = 0)";
    speed = speed/20;
    var i = 0;
    var intervalId = setInterval(function() 
	{
        if(i <= 100) 
		{
			obj.style.opacity = (i / 100);
			obj.style.MozOpacity = (i / 100);
			obj.styleKhtmlOpacity = (i / 100);
			obj.style.filter = "alpha(opacity=" + i + ")";
			//document.getElementById('info').innerHTML=i;
            i += 5;
        } 
		else {
			//setTimeout(function() {obj.style.display = "block";}, speed);
            clearInterval(intervalId);						
            return false;
        }
    }, speed);
}

//======================================================Fadein Fadeout Div================================|



function clearBox(val,obj){if(obj.value==val){obj.select();}else chkBlank(val,obj);}
function chkBlank(val,obj){if(obj.value=='')obj.value=val;}
function mkPasswordField(val,obj){obj.type='password';}
function onstartSelect(divid){document.getElementById(divid).select();}



function createLoader(container,str)
{		
	currLdr=document.createElement('div');
	currLdr.id='pageloader';	
		
	currLdr.style.position='absolute';
	currLdr.align='center';
	currLdr.style.fontFamily='Verdana, Arial, Helvetica, sans-serif';
	currLdr.style.fontSize='11px';
	currLdr.style.fontWeight='bold';
	currLdr.style.color='#999999';	
	currLdr.style.zIndex='999999';
	currLdr.style.border='1px solid #999999';
	currLdr.style.backgroundColor='#666666';
	currLdr.style.padding='5px';
	document.getElementById(container).appendChild(currLdr);
	
	
	currLdr.innerHTML='<strong>'+str+'</strong>';
	currLdr.style.width=currLdr.offsetWidth+'px';
	currLdr.innerHTML=str;
	/*currLdr.style.display="none";*/
	setDivToPosition('pageloader','middle','middle',0,0);
	showLoader();
}

function showLoader()
{
	str=currLdr.innerHTML;
	strlen=str.length;
	view_str='';
	curpos=0;
	var ldrintervalId = setInterval(function() 
	{
		curpos++;
		
		if(curpos>=strlen){curpos=0;view_str='';}
		pre_str=str.slice(0,curpos);
		post_str=str.slice(curpos+1,strlen);
		view_str=pre_str+'<font color="#CCCCCC">'+str.charAt(curpos)+'</font>'+post_str+'<br/><span style="font-size:8px;color:#333333;">PLEASE BE PATIENT WHILE LOADING</span>';
		
		currLdr.innerHTML=view_str;
	},100);
}


function loadPage(loadtoid,pageName,getVar)
{
	
	document.getElementById(loadtoid).innerHTML='<img src="site/user/images/loader/ldr.gif">';
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		try
		  {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		catch (e)
		  {
			  alert("Your browser does not support AJAX!");
			  return false;
		  }
		}
	  }
	  xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		  {
			//alert(xmlHttp.responseText);
			document.getElementById(loadtoid).innerHTML=xmlHttp.responseText;
		  }
		}
	
	  xmlHttp.open("GET","site/user/php/pbox/"+pageName+".php?"+getVar,true);
	  xmlHttp.send(null);
	  
}





function submitForm(loadtoid,pageName,getVar,redirect)
{
	
	if(loadtoid!='')document.getElementById(loadtoid).innerHTML='<img src="'+base_url+'/site/user/images/loader/ldr.gif" alt="Loading..."><br/>'+document.getElementById(loadtoid).innerHTML;
	
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		try
		  {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		catch (e)
		  {
			  alert("Your browser does not support AJAX!");
			  return false;
		  }
		}
	  }
	  xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		  {
			//alert(xmlHttp.responseText);
			if(loadtoid!='')document.getElementById(loadtoid).innerHTML=xmlHttp.responseText;
			if(redirect!='')location=redirect;
		  }
		}
	
	  xmlHttp.open("GET",base_url+"/site/user/php/pbox/"+pageName+".php?"+getVar,true);
	  xmlHttp.send(null);
}







function number_format (number, decimals, dec_point, thousands_sep){
	if (isNaN(number) || number=='') number = 0;

	var decimals 		= decimals != undefined ? decimals : 2,
		dec_point		= dec_point != undefined ? dec_point : '.',
		thousands_sep	= thousands_sep != undefined ? thousands_sep : ' ',
		negative		= number<0;

	if (negative) number *= -1;

	var left 	= parseInt(number, 10),
		right	= Math.round(parseFloat(number.toString().replace(/^\d+./, '0.')) * Math.pow(10, decimals));

	left  = left.toString().split('').reverse().join('')
			.match(/\d{3}|\d{1,2}/g)
			.join(thousands_sep)
			.split('').reverse().join('');

	right = (right / Math.pow(10,decimals)).toString().replace(/^\d+./, '').toString();

	if (right.length < decimals) for (var iRight=right.length; iRight < decimals; iRight++) right += '0';

	return (negative?'-':'')+left+dec_point+right;
}
