/**
 * @package: Core
 * @subpackage: Common functions
 * @version: v.1.3
 * @author: Mezahir Efendiyev <cengmezo@yahoo.com>
 * @see: http://www.cengmezo.com/kiwi
 */
 
var kiwi_browserIsIE = document.all? true:false;

function j_getElement (id , winObj) {
	if ( winObj ) {
		return winObj.document.getElementById(id);
	} else {
		return document.getElementById(id);
	}
}

// Open new browser window

function j_openNewWindow ( linkURL , windowID, winWidth , winHeigth, winParams ) {
	
	if ( ! winParams ) {
		winParams = 'menubar=0,addressbar=0,toolbar=0,statusbar=0,resizable=1,scrollbars=yes,location=0,DisableSysMenu=0,frameborder=0';
	}
	
	if ( ! windowID ) {
		windowID = parseInt(Math.random()*1000*1000);
	}
	
	var screenSizes = j_screenSizes();
	var temp;
	
	if ( ! winWidth ) {
		winWidth = 0;
	}

	if ( ! winHeigth ) {
		winHeigth = 0;
	}
	
	// Width	
	if ( winWidth <= 0 ) {
		winWidth += screenSizes[0];
	}
	
	if ( ( winWidth > screenSizes[0] ) || ( winWidth < 1 ) ) {
		winWidth = screenSizes[0];
	}
	
	temp = parseInt ( ( screenSizes[0] - winWidth ) / 2 );
	winParams += ',width='+winWidth+',left='+temp;
	
	// Height
	if ( winHeigth <= 0 ) {
		winHeigth += screenSizes[1];
	}
	
	if ( ( winHeigth > screenSizes[1] ) || ( winHeigth < 1 ) )  {
		winHeigth = screenSizes[1];
	}
	
	temp = parseInt ( ( screenSizes[1] - winHeigth ) / 2 );
	winParams += ',height='+winHeigth+',top='+temp;
	
	var newWin = window.open( linkURL , 'kiwiWindow_' + windowID , winParams );
	return newWin;
}

// Get Screen Dimensions

function j_screenSizes () {
	
	var screenW = 640, screenH = 480;
	
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;
	} else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled() ) {
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}
	
	return [screenW , screenH];
}

// Get window sizes
function j_windowSizes () {
	
	var myWidth = 0, myHeight = 0;
	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;
	}
	
	return [ myWidth, myHeight ];
}

// Get tag dimensions

function j_objectSizes ( tagID ) {
	
	var tagWidth = 0 , tagHeight = 0;
	obj = j_getElement (tagID);
	
	if ( obj ) {
		tagWidth  = obj.offsetWidth;
		tagHeight = obj.offsetHeight;
	}
	
	return [ tagWidth , tagHeight ];
}


