/*
	main.js

	(c) 2007 Secure Computing Corporation
*/


function redirectTo(redirect) {
	window.location.href = redirect;
}

function highlight(object) {
	object.style.backgroundColor = "#ffff99";
}

function normal1(object) {
	object.style.backgroundColor = "#ffffff";
}

function normal2(object) {
	object.style.backgroundColor = "#f1f1f1";
}



/*
	Navigation
*/

function naviShow(objectID) {

	if ( (objectID != 'home') && (objectID != 'intelligence') ) {
		var obj = document.getElementById('btn_' + objectID);

		var leftValue 	= findPosX(obj);
		var topValue		= findPosY(obj);
		var heightValue	= obj.offsetHeight;

		document.getElementById('menu_box_' + objectID).style.left = leftValue + 'px';
		document.getElementById('menu_box_' + objectID).style.top = (topValue+heightValue-1) + 'px';
		document.getElementById('menu_box_' + objectID).style.display = "inline";
	}
}


function naviHide(objectID) {
	if ( (objectID != 'home') && (objectID != 'intelligence') ) {
		document.getElementById('menu_box_' + objectID).style.display = "none";
	}
}


function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent) {
		while(1) {
			curleft += obj.offsetLeft;
			if (!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent) {
		while(1) {
			curtop += obj.offsetTop;
			if (!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function set_cookie(name, value, expire_days, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expire_days ){
		expire_msecs = expire_days * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expire_msecs) );

	var cookie_string = name + "=" +escape( value ) +
		( ( expire_days ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	document.cookie = cookie_string;	
}

function initialize_flash(swf_path, name, id, width, height){
	var so = new SWFObject(swf_path, name, width, height, "8", "#ffffff");
	so.addParam("wmode", "transparent");
	so.addParam("quality", "high");
	so.addParam("allowScriptAccess", "sameDomain");
	so.write(id);
}

function initialize_flash_amchart(swf_path, name, id, width, height, settings_file, data_file, path){
	var so = new SWFObject(swf_path, name, width, height, "8", "#ffffff");
	so.addParam("wmode", "transparent");
	so.addParam("quality", "high");
	so.addParam("allowScriptAccess", "sameDomain");
	
	// for amcharts pie
	so.addVariable("settings_file", escape(settings_file));
	so.addVariable("data_file", escape(data_file));
	so.addVariable("preloader_color", "#999999");
	
	if(path){
		so.addVariable("path", path);
	}
	
	so.write(id);
}

// does a redirect to a nice query url if the query is a domain or IP

function query_it(){
	document.getElementById('query_button').blur;
	var query=document.getElementById('short_query').value;
	
	if(
		(query.match(/^[a-z0-9\.]+$/i) != null)			// domain or IP
		&& !document.getElementById('partner_field').value
		&& !document.getElementById('session_field').value
	){
		//redirect to nice URL
		window.location.href = '/query/' + query;
		return(false);		// don't post the form
	}
	
	document.search_box.submit();
}

