var D = document;
var nc = ( navigator.userAgent.indexOf("MSIE") == -1 && navigator.userAgent.indexOf("Opera") == -1 ) ? 1 : 0;
var opera = ( navigator.userAgent.indexOf("Opera") != -1 ) ? 1 : 0;

if( nc ) { D.write('<LINK HREF="css/main_nc.css" REL="StyleSheet">'); }

function wopen( url, target, w, h, asize, title, res ) 	{
	if( !url ) {
		event.cancelBubble = true;
		event.returnValue = false;
		return;
	}
	if( !target ) target = '_blank';
	if( !w ) w = 550;
	if( !h ) h = 400
	r = res ? 0 : 1;
	if( asize && !title && !res ) r = 0;

	w = parseInt( w, 10 );
	h = parseInt( h, 10 );
	var aw = screen.availWidth;
	var ah = screen.availHeight;
	if( w > aw ) w = aw;
	if( h > ah ) h = ah;

	var left = Math.round( ( aw - w ) / 2 );
	var top = Math.round( ( ah - h ) / 2 );
	var wd = window.open( url, target, 'channelmode= 0, directories=0, fullscreen=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable='+r+', scrollbars=1, status=0, toolbar=0, top='+top+'px, left='+left+'px' );
}

//#########################################################

function inPopup( obj, w, h ) {
	if( !obj || !obj.href ) return false;
	event.returnValue = false;
	if( !w ) w = 0; w = parseInt( w ); if( !w || isNaN( w ) ) w = 550; 
	if( !h ) h = 0; h = parseInt( h ); if( !h || isNaN( h ) ) h = 350;
	wopen( obj.href, "", w, h );
	return false;
}

function go( url ) {
	if ( url ) { top.location.href = url; }
}

//#########################################################

function winfull( url, target ) {
	if ( !url ) { return false; }
	if ( !target ) { target = '_blank'; }
    var wd = window.open( url, target, 'fullscreen=1, scrollbars=1, toolbar=0' );
}

//#########################################################

function setCookie( name, value, path, domain, expires, secure ) {
	// get expires in days, set time in milliseconds
	var today = new Date(); today.setTime(today.getTime());
	var expires_date = new Date( today.getTime() + ( expires ? expires * 1000 * 60 * 60 * 24 : 0 ) );	
	D.cookie = name + "=" + escape( value ) +
	  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	  ( ( path ) ? ";path=" + path : "" ) + 
	  ( ( domain ) ? ";domain=" + domain : "" ) +
	  ( ( secure ) ? ";secure" : "" );
}

//#########################################################

function getCookie( name ) {
	var cook = D.cookie;
	var pos = cook.indexOf( name + '=' );
	if( pos == -1 ) { return null; } 
	else {
	  var pos2 = cook.indexOf( ';', pos );
	  if( pos2 == -1 ) return unescape( cook.substring( pos + name.length + 1 ) );
	  else return unescape( cook.substring( pos + name.length + 1, pos2 ) );
	}
}

//#########################################################

function check_email( obj ) {
	if( !obj || !obj.value ) return false;
	var CC = /^[._a-z0-9-]+@[._a-z0-9-]+\.[a-z]{2,4}$/i;
	if( !CC.test( obj.value ) ) { return false; }
	return true;
}

//#########################################################

function check_phone( obj ) {
	if( !obj || !obj.value ) return false;
	var CC = /^[+0-9]{7,12}$/i;
	if( !CC.test( obj.value ) ) { return false; }
	return true;
}

//#########################################################

function check_float( obj ) {
	if( !obj || !obj.value ) return false;
	var o = parseFloat( obj.value );
	if( !o || isNaN( o ) || o == 0 ) return false;
	obj.value = o;
	return true;
}

//#########################################################

function check_length( obj, min, max ) {
	if( !obj || !obj.value ) return false;
	min = parseInt( min );
	max = parseInt( max );
	if( min && obj.value.length < min ) return false;
	if( max && obj.value.length > max ) { obj.value = obj.value.substring(0,max); }
	return true;
}

//#########################################################

function wait( mode ) {
	var obj = D.getElementById( "progress_bar" );
	if( obj ) { 
		obj.className = !mode ? "hide" : "show";  
		h = obj.style.height ? parseInt( obj.style.height ) : 50;
		obj.style.top = ( getDocumentHeightCenter() - h ) + "px";
	}
}

//#########################################################

// Vertical scrolling position
function getBodyScrollTop() { return self.pageYOffset || ( D.documentElement && D.documentElement.scrollTop ) || ( D.body && D.body.scrollTop ); }
// Document height with scrolling
function getDocumentHeight() { return ( D.body.scrollHeight > D.body.offsetHeight ) ? D.body.scrollHeight : D.body.offsetHeight; }
// Get window heght
function getClientHeight() { return D.compatMode=='CSS1Compat' && !window.opera ? D.documentElement.clientHeight : D.body.clientHeight; }
// Vertical document center with scrolling
function getDocumentHeightCenter() { return parseInt( getClientHeight() / 2 ) + getBodyScrollTop(); }

//#########################################################
//#########################################################
//#########################################################
//#########################################################

var inputAllData = "Input all needed data!";
function checkCommentForm( frm, msg ) {
	if( !frm ) return false;
	if( !frm.name.value || !frm.comment.value ) {
		alert( msg ? msg : inputAllData );
		return false;
	}
	if( frm.url ) frm.url.value = top.location.href;
	return true;
}

function comment_alerts( msg ) {
	if( !msg ) return false;
	alert( msg );
}

//#########################################################


