//-----------------------------------------------------------------------------
//
// MDS Common functions v1.0.0
//																   2007-09-05
//
//-----------------------------------------------------------------------------
var global_is_opera = ( navigator.userAgent.indexOf('Opera')!=-1 );
//-----------------------------------------------------------------------------
// get browser inner width
//-----------------------------------------------------------------------------
function getBrowserWidth() {  
	if ( window.innerWidth ) {
		return window.innerWidth;
	} else if ( document.documentElement
		&& document.documentElement.clientWidth != 0 ) {
		return document.documentElement.clientWidth;
	} else if ( document.body ) {
		return document.body.clientWidth;
	}
	return 0;  
}
//-----------------------------------------------------------------------------
// get browser inner height
//-----------------------------------------------------------------------------
function getBrowserHeight() {  
	if ( window.innerHeight ) {
		return window.innerHeight;
	} else if ( document.documentElement
		&& document.documentElement.clientHeight != 0 ) {
		return document.documentElement.clientHeight;
	} else if ( document.body ) {
		return document.body.clientHeight;
	}
	return 0;  
}
//-----------------------------------------------------------------------------
// get scroll width
//-----------------------------------------------------------------------------
function getScrollWidth() {  
	var value = 0;
	if( document.all && !global_is_opera){
		value = parseInt(document.documentElement.scrollLeft);
	} else {
		value = parseInt(self.pageXOffset);
	}
	return value;
}
//-----------------------------------------------------------------------------
// get scroll height
//-----------------------------------------------------------------------------
function getScrollHeight() {  
	var value = 0;
	if( document.all && !global_is_opera){
		value = parseInt(document.documentElement.scrollTop);
	} else {
		value = parseInt(self.pageYOffset);
	}
	return value;
}

//-----------------------------------------------------------------------------
// get mouse x
//-----------------------------------------------------------------------------
function getMouseX(e){
	if(window.opera){
		return e.clientX;
	} else if(document.all) {
		return document.body.scrollLeft+event.clientX;
	} else if(document.layers||document.getElementById) {
		return e.pageX;
	}
	return;
}
//-----------------------------------------------------------------------------
// get mouse y
//-----------------------------------------------------------------------------
function getMouseY(e){
	if(window.opera){
		return e.clientY
	} else if(document.all) { 
		return document.body.scrollTop+event.clientY
	} else if(document.layers||document.getElementById){
		return e.pageY
	}
}
//-----------------------------------------------------------------------------
// get page size
//-----------------------------------------------------------------------------
function getPageSize(){
    
    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){    
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

//-----------------------------------------------------------------------------
// aliase : get element by id
//-----------------------------------------------------------------------------
function $(tagId) {
	return document.getElementById(tagId);
}
//-----------------------------------------------------------------------------
// Create HTTP Request
//-----------------------------------------------------------------------------
function createXMLHttpRequest(cbFunc) {
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}
//-----------------------------------------------------------------------------
// Create Random String
//-----------------------------------------------------------------------------
function RandomString() {
	this.str = '';
	this.randam_char_array	= new Array(
		'a','b','c','d','e','f','g','h','i','j'
		,'k','l','m','n','o','p','q','r','s','t'
		,'u','v','w','x','y','z'
		,'A','B','C','D','E','F','G','H','I','J'
		,'K','L','M','N','O','P','Q','R','S','T'
		,'U','V','W','X','Y','Z'
		,'0','1','2','3','4','5','6','7','8','9'
	);
	this.get = function(strlen) {
		var str = '';
		for( i=0; i<8; i++ ){
			var rand = Math.floor( Math.random() * this.randam_char_array.length );
			str += this.randam_char_array[rand];
		}
		this.str=str;
		return str;
	}
	this.set = function(obj,strlen) {
		this.get(strlen);
		obj.value = this.str;
	}
}
//-----------------------------------------------------------------------------
// Common functions : Paging
//-----------------------------------------------------------------------------
function common_next_page(){
	var next_page = document.sform.pn.value;
	if( NaN != parseInt(next_page) ){
		next_page = parseInt(next_page);
	}
	next_page++;
	document.sform.pn.value = String(next_page);
	document.sform.submit();
}
function common_prev_page(){
	var prev_page = document.sform.pn.value;
	if( NaN != parseInt(prev_page) ){
		prev_page = parseInt(prev_page);
	}
	prev_page--;
	document.sform.pn.value = String(prev_page);
	document.sform.submit();
}

function int2hexString( number ) {
	var charArray	= new Array(
		'0','1','2','3','4','5','6','7','8','9',
		'a','b','c','d','e','f'
	);
	var n16=0;              
	var result ="";
	while (number > 0) {
		n16		= number % 16;
		number	= ( number - n16 ) / 16;
		result = charArray[n16] + result;
	}
	if( result.length == 0 ) {
		result	= '00';
	}else if( result.length == 1 ) {
		result	= '0' + result;
	}
	return result;
}