function Simple_ajaxcall( process, div, method, form )
{
	myFormData = '';
	if( !method )
	{
		method = 'get';
	}
	
	if( !form )
	{
		form = false;
	}
	else if( !$(form) )
	{
		form = false;
		method = 'get';
	}
	else
	{
		myFormData = $(form).serialize(true);
	}
	
	Hide_Popups();
	if( process.include('step=') )
	{
		$('form_loading').style.display = 'block';
	}

	if( !process ) return false;
	if( !div ) div = 'false_div';
	
	// alert('ajax fv.: ' + process);
	ajaxRequest = new Ajax.Request(
		process,
		{
			method: method,
			parameters: myFormData,
			onComplete: function(request) 
			{ 
				var myMesArr = request.responseText.split("##");
				if( $('form_loading') )
				{
					$('form_loading').style.display = 'none';
				}
				
				// alert( 'test:: ' + request.responseText);
				if( myMesArr[0] == 'ok' )
				{
					if( div != 'false_div' && $(div) )
					{
						$(div).innerHTML = myMesArr[1];
					}
					else
					{
						var index = 1;
						if( !$(myMesArr[index]) && $('resp') && !myMesArr[index].include('jscode') )
						{
							// alert('false place :: ' + myMesArr[index++]);
							$('resp').innerHTML = myMesArr[index++];
							$('resp').style.display='';
							position_layer('resp', 1, 0, -200);
						}
						
						if( myMesArr[index].include('jscode') )
						{
							code = myMesArr[index].split('jscode');
							// alert(myMesArr[index]);
							if( code[1].include('js#') )
							{
								codes = code[1].split('js#');
								// alert(codes.length);
								for( var k=0; k<codes.length; k++ )
								{
									eval( codes[k] );
								}
							}
							else
							{
								eval( code[1] );
							}
							index++;
						}
						
						while( true )
						{
							if( $(myMesArr[index]) )
							{
								$(myMesArr[index++]).innerHTML = myMesArr[index++];
							}
							else
							{
								break;
							}
						}
						
						if( myMesArr[index].include('jscode') )
						{
							code = myMesArr[index].split('jscode')
							if( code[1].include('js#') )
							{
								codes = code[1].split('js#');
								// alert(codes.length);
								for( var k=0; k<codes.length; k++ )
								{
									eval( codes[k] );
								}
							}
							else
							{
								eval( code[1] );
							}
							index++;
						}
					}					
				}
				else { alert(request.responseText);return false; }
				
			}
		}
	) 
}

function JQS_ajaxcall( process, div, method, form ) 
{
    var pre = '#';
    if( !process ) return false;
    if( !div ) div = 'false_div';
    
	myFormData = '';
	if( !method )
	{
		method = 'GET';
	}
	
	if( !form )
	{
		form = false;
	}
	else if( !jQuery(pre+form) )
	{
		form = false;
		method = 'GET';
	}
	else
	{
		myFormData = jQuery(pre+form).serialize(true);
	}
    
    jQuery.ajax({
        url: process,
        // global: false,
        type: method,
        data: myFormData,
        dataType: "html",
        async:false,
        success: function( msg )
        {
            JQProc_ajaxcall( msg, div );
        }
    });
}

function JQProc_ajaxcall( msg, div )
{
    var pre = '#';
    if( !div ) div = 'false_div';
    var myMesArr = msg.split("##");
    // alert(myMesArr[0]);
    
    if( myMesArr[0] == 'ok' )
    {
        if( div != 'false_div' && jQuery(pre+div) )
        {
            jQuery(pre+div).innerHTML = myMesArr[1];
        }
        else
        {
            var index = 1;
            if( !document.getElementById(myMesArr[index]) && document.getElementById('resp') && !/jscode/.test(myMesArr[index]) )
            {
                jQuery(pre+'resp').html( myMesArr[index++] );
                jQuery(pre+'resp').show();
            }
            
            var start = 0;
            while( index > start )
            {
                start = index;
                if( /jscode/.test(myMesArr[index]) )
                {
                    code = myMesArr[index].split('jscode');
                    if( /js#/.test(code[1]) )
                    {
                        codes = code[1].split('js#');
                        for( var k=0; k<codes.length; k++ )
                        {
                            if( /notcode/.test(codes[k]) )
                            {
                                codes[k] = codes[k].substr(7);
                                continue;
                            }
                            eval( codes[k] );
                        }
                    }
                    else
                    {
                        eval( code[1] );
                    }
                    index++;
                }
                
                while( true )
                {
                    if( myMesArr[index] && document.getElementById(myMesArr[index]) )
                    {
                        jQuery(pre+myMesArr[index]).show();
                        jQuery(pre+myMesArr[index++]).html( myMesArr[index++] );
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }					
    }
    else { alert(msg);return false; }
}

function position_layer(div, type, korx, kory )
{
	if( !type ) type = 1;
	if( !korx ) korx = 0;
	if( !kory ) kory = 0;
	
  var dim = document.viewport.getDimensions();
  var myLayer = $(div);
  AktTop = document.viewport.getScrollOffsets().top;
  mywidth = myLayer.getWidth();
  myheight = myLayer.getHeight();
  // myheight += (myheight<50 ? plusheight : 0);
	
	// alert( dim.width + ' - ' + AktTop + ' :: ' + mywidth + ' - ' + myheight );
  
  newLeft = parseInt( (dim.width-mywidth)/2 );
	if(myheight > dim.height)newtop = AktTop + 10;
  else newtop = AktTop + parseInt( (dim.height-myheight)/2 );
	if(newLeft < 10)newLeft = 10;
	if(newtop < 10)newtop = 10;

	if( type == 1 )
	{
		myLayer.setStyle({ left : newLeft + korx + "px", top : newtop + kory + "px" });
	}
	else if( type == 2 )
	{
		myLayer.setStyle({ left : newLeft + korx + "px" });
	}
	else if( type == 3 )
	{
		myLayer.setStyle({ top : newtop + kory + "px" });
	}
  // alert(myLayer.style.left + ' - ' + myLayer.style.top);
  // myLayer.style.left = newLeft + "px";
  // myLayer.style.top = newtop + "px";
}

var captcha_here_ID = 'captcha_here';
var captcha_plus_ID = 'captcha_plus';
function Init_Captcha( num )
{
	if( !num )num = '';
	
	var spamsource_ID = 'spamsource' + num;
	captcha_here_ID = 'captcha_here' + num;
	captcha_plus_ID = 'captcha_plus' + num;
	
	jQuery('#' + spamsource_ID).html( '<div class="ctextarea" style="background:none; height:auto;">'+
		'<div id="' + captcha_here_ID + '" style="float:left; width:140px; height:45px; font-size:10px !important;"></div>'+	
		'<div style="float:left;" id="' + captcha_plus_ID + '"><a href="javascript:loadCaptcha_ajax( \''+captcha_here_ID+'\', \''+captcha_plus_ID+'\' ) "><img src="captcha_files/refresh.png" border="0" alt="(New)" /></a></div>'+
	'</div>');
	loadCaptcha_ajax( captcha_here_ID, captcha_plus_ID );
}

function loadCaptcha_ajax( captcha_here_ID, captcha_plus_ID ) 
{
	jQuery("#" + captcha_plus_ID).css("display","none");
	jQuery("#" + captcha_here_ID).html('Loading code...<br />Please wait...');
	jQuery.get("captcha_files/captcha_table.php", { },
		function(data)
		{	
			jQuery("#" + captcha_here_ID).html(data);
			jQuery("#" + captcha_plus_ID).html('<a href="javascript:loadCaptcha_ajax( \''+captcha_here_ID+'\', \''+captcha_plus_ID+'\' )"><img src="captcha_files/refresh.png" border="0" alt="(New)" /></a>');
			jQuery("#" + captcha_plus_ID).css("display","block");
		}
	);
}

function Simple_Show_Layer( div )
{
	Hide_Popups();
	if( !div )div = 'popup_message';

	if( $(div) )$(div).appear();
}

function Hide_Popups()
{
	var index = '';
	for( var i=1; i<4; i++ )
	{
		if( i==1 )index = '';
		else index = i;
		
		if( $('popup' + index) )
		{
			$('popup' + index).setStyle({ display: 'none' });
		}
	}
}

function Positioned_Show_Layer( div )
{
	Get_Top_Position( item );
	
	if( !div )div = 'popup_message';

	if( $(div) )$(div).appear();
}

function Set_InvoiceData( show )
{
	if( !show )show=false;
	
	var invoiceShow = $('invoice_address').value;
	if( show )
	{
		$('movedown').hide();
		$('moveup').show();
		$('invoice_address').value='1';
		// new Effect.Move('scroll_box', { x: 0, y: moveShow }); 
	}
	else
	{
		$('movedown').show();
		$('moveup').hide();
		$('invoice_address').value='0';
		// new Effect.Move('scroll_box', { x: 0, y: moveHide }); 
	}
	
	// if( invoiceShow && $('invoice_address').value )
	// {
		// show = true;
	// }
	Show_InvoiceData( show );
	
	return false;
}

function Show_InvoiceData( show )
{
	var top = $('scroll_box').style.top;
	if( !top )
	{
		top = 0;
	}
	else 
	{
		top = parseInt( top );
	}
	
	var move = 195;
	if( top < 0 )
	{
		move = 195;
	}
	else if( !show && $('invoice_address').value )
	{
		move = 0;
	}
	
	if( show )
	{
		move = top - 195;
		if( top < 0 )
		{
			move = 0;
		}
	}
	
	
	
	new Effect.Move('scroll_box', { x: 0, y: move }); 
}

function show_dangerous( item )
{
	var top = Get_Top_Position( item );
	leftSide = Get_Left_Size();
	
	$('popup').setStyle({ top : top - 600 + "px", left : leftSide + 402 + "px", display: 'block' });
}

function show_partner( item )
{
	var top = Get_Top_Position( item );
	leftSide = Get_Left_Size();
	
	$('popup2').setStyle({ top : top - 460 + "px", left : leftSide + 360 + "px" });
}

function Get_Left_Size()
{
	var dim = document.viewport.getDimensions();
	var viewportWidth = dim.width;
	if(/MSIE (8|7|6|5|4)/.test(navigator.userAgent))
	{
		viewportWidth = document.body.offsetWidth;
	}
	
	var leftSide = parseInt((viewportWidth-960)/2);
	
	if( leftSide < 0 ) leftSide = 0;
	
	return leftSide;
	
}

function Get_Top_Position( item )
{
	var pos = Position.cumulativeOffset(item);
	// alert(pos[1]);
	return pos[1];
	
}
