function JQajax(div , path , method , values)
{
	if(values == '_blank')
	{
		return true;
	} else {
		$.ajax({
			url: path,
			beforeSend: function()
			{
				width = $('#' + div).width();
				height = $('#' + div).height();
				$('#ajax_loading').css('width' , width + 'px');
				$('#ajax_loading').css('height' , height + 'px');
				$('#ajax_loading').show();
				document.location = '#' + path;
				$('#rssLink').attr('href' , '/rss' + path.replace('ajax/' , ''));
				$('html, body').animate({
					scrollTop: $("#main_div").offset().top
				}, 500);
				$('#cursor_div').css('display' , 'block');
			},
			success: function(data)
			{
				$('#ajax_loading').hide();
				$('#' + div).html('<div id="ajax_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
				$('#cursor_div').css('display' , 'none');
			},
		});
		return false;
	}
}

function JQajaX(key , page)
{
	$.ajax({
		url: '/ajax/search/' + encodeURIComponent(key) + '/page/' + page + '/index.cgi',
		beforeSend: function()
		{
			width = $('#main_div').width();
			height = $('#main_div').height();
			$('#ajax_loading').css('width' , width + 'px');
			$('#ajax_loading').css('height' , height + 'px');
			$('#ajax_loading').show();
			document.location = '#' + '/ajax/search/' + encodeURIComponent(key) + '/page/' + page + '/index.cgi';
			$('html, body').animate({
				scrollTop: $("#main_div").offset().top
			}, 500);
			$('#cursor_div').css('display' , 'block');
		},
		success: function(data)
		{
			$('#ajax_loading').hide();
			$('#main_div').html('<div id="ajax_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
			$('#cursor_div').css('display' , 'none');
		},
	});
	
	return false;
}

function reloadBasket()
{
	$.ajax({
		url: '/ajax/basket/index.cgi',
		beforeSend: function()
		{
			width = $('#basket_div').width();
			height = $('#basket_div').height();
			$('#basket_loading').css('width' , width + 'px');
			$('#basket_loading').css('height' , height + 'px');
			$('#basket_loading').show();
			$('#cursor_div').css('display' , 'block');
		},
		success: function(data)
		{
			$('#basket_loading').hide();
			$('#basket_div').html('<div id="basket_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
			$('#cursor_div').css('display' , 'none');
		},
	});
}

function calendar(time)
{
	$.ajax({
		url: '/ajax/calendar/' + time + '/index.cgi',
		beforeSend: function()
		{
			width = $('#calendar_div').width();
			height = $('#calendar_div').height();
			$('#calendar_loading').css('width' , width + 'px');
			$('#calendar_loading').css('height' , height + 'px');
			$('#calendar_loading').show();
			$('#cursor_div').css('display' , 'block');
		},
		success: function(data)
		{
			$('#calendar_loading').hide();
			$('#calendar_div').html('<div id="calendar_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
			$('#cursor_div').css('display' , 'none');
		},
	});
}

function check_card_form(vendor)
{
	var my_form = document.card_form;
	var ostan_id = my_form.id_ostan.value;
	var shahr_id = my_form.id_shahr.value;
	var PIDS = my_form.PIDS.value;
	var PIDS = PIDS.split('^^');
	var params = '';
	for(i = 0 ; i < PIDS.length - 1 ; i++)
	{
		var field = 'num_' + PIDS[i];
		var gholi = document.getElementsByName(field);
		var thisdata = gholi[0].value;
		params = params + '&' + field + '=' + thisdata;
	}

	if(shahr_id && ostan_id)
	{
		$.ajax({
			url: '/ajax/card/' + vendor + '/step/index.cgi',
			type: 'POST',
			data: 'id_ostan=' + ostan_id + '&id_shahr=' + shahr_id + params,
			beforeSend: function()
			{
				width = $('#main_div').width();
				height = $('#main_div').height();
				$('#ajax_loading').css('width' , width + 'px');
				$('#ajax_loading').css('height' , height + 'px');
				$('#ajax_loading').show();
				document.location = '#/ajax/card/' + vendor + '/step/index.cgi';
				$('#cursor_div').css('display' , 'block');
			},
			success: function(data)
			{
				$('#ajax_loading').hide();
				$('#main_div').html('<div id="ajax_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
				$('#cursor_div').css('display' , 'none');
			},
		});
	} else {
		alert('شهر یا استان انتخاب نشده است.');
	}
	
	return false;
}

function check_card_step_form(vendor)
{
	var my_form = document.card_step_form;

	var ostan_id = my_form.id_ostan.value;
	var shahr_id = my_form.id_shahr.value;
	var imc_activated = my_form.imc_activated.value;
	var name = my_form.name.value;
	var last_name = my_form.last_name.value;
	var phone = my_form.phone.value;
	var cell = my_form.cell.value;
	var email = my_form.email.value;
	var zip = my_form.zip.value;
	var address = my_form.address.value;
	var comment = my_form.comment.value;
	if(my_form.send_type)
	{
		var sendlength = my_form.send_type.length;
		for (i = 0 ; i < sendlength ; i++)
		{
			if(my_form.send_type[i].checked)
				var sendtype = my_form.send_type[i].value
		}
	}
	
	var PIDS = my_form.PIDS.value;
	var PIDS = PIDS.split('^^');
	var params = '';
	for(i = 0 ; i < PIDS.length - 1 ; i++)
	{
		var field = 'num_' + PIDS[i];
		var gholi = document.getElementsByName(field);
		var thisdata = gholi[0].value;
		params = params + '&' + field + '=' + thisdata;
	}
	
	if(ostan_id && shahr_id && name && last_name && (phone || cell) && address)
	{
		$.ajax({
			url: '/ajax/card/' + vendor + '/finish/index.cgi',
			type: 'POST',
			data: 'id_ostan=' + ostan_id + '&id_shahr=' + shahr_id + '&name=' + name + '&last_name=' + last_name + '&phone=' + phone + '&cell=' + cell + '&email=' + email + '&zip=' + zip + '&address=' + address + '&comment=' + comment + '&send_type=' + sendtype + '&imc_activated=' + imc_activated + params,
			beforeSend: function()
			{
				width = $('#main_div').width();
				height = $('#main_div').height();
				$('#ajax_loading').css('width' , width + 'px');
				$('#ajax_loading').css('height' , height + 'px');
				$('#ajax_loading').show();
				document.location = '#/ajax/card/' + vendor + '/finish/index.cgi';
				$('#cursor_div').css('display' , 'block');
			},
			success: function(data)
			{
				$('#ajax_loading').hide();
				$('#main_div').html('<div id="ajax_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
				$('#cursor_div').css('display' , 'none');
			},
		});
	} else {
		alert('لطفا اطلاعاتتان را کامل وارد نمایید.');
	}
	return false;
}

function searchMe()
{
	var search_key = document.search_form.key.value;
	if(search_key.length > 0)
		$.ajax({
			url: '/ajax/search/' + encodeURIComponent(search_key) + '/index.cgi',
			beforeSend: function()
			{
				width = $('#main_div').width();
				height = $('#main_div').height();
				$('#ajax_loading').css('width' , width + 'px');
				$('#ajax_loading').css('height' , height + 'px');
				$('#ajax_loading').show();
				document.location = '#/ajax/search/' + encodeURIComponent(search_key) + '/index.cgi';
				$('#rssLink').attr('href' , '/rss/search/' + encodeURIComponent(search_key) + '/index.cgi');
				$('html, body').animate({
					scrollTop: $("#main_div").offset().top
				}, 500);
				$('#cursor_div').css('display' , 'block');
			},
			success: function(data)
			{
				$('#ajax_loading').hide();
				$('#main_div').html('<div id="ajax_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
				$('#cursor_div').css('display' , 'none');
			},
		});
	else
		alert('لطفا کلمه ای را جهت جستجو وارد نمایید');
	return false;	
}

function traceMe()
{
	var trace_key = document.trace_form.key.value;
	if(trace_key.length == 26)
		$.ajax({
			url: '/ajax/trace/' + trace_key.replace('/' , '+') + '/index.cgi',
			beforeSend: function()
			{
				width = $('#main_div').width();
				height = $('#main_div').height();
				$('#ajax_loading').css('width' , width + 'px');
				$('#ajax_loading').css('height' , height + 'px');
				$('#ajax_loading').show();
				document.location = '#/ajax/trace/' + trace_key.replace('/' , '+') + '/index.cgi';
				$('html, body').animate({
					scrollTop: $("#main_div").offset().top
				}, 500);
				$('#cursor_div').css('display' , 'block');
			},
			success: function(data)
			{
				$('#ajax_loading').hide();
				$('#main_div').html('<div id="ajax_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
				$('#cursor_div').css('display' , 'none');
			},
		});
	else
		alert('لطفا شناسه سفارش را کامل وارد نمایید');
	return false;	
}

function vote(pid)
{
	var my_form = document.vote_form;
	var votelength = my_form.ask.length;
	for (i = 0 ; i < votelength ; i++)
	{
		if(my_form.ask[i].checked)
			var ask = my_form.ask[i].value
	}
	
	$.ajax({
		url: '/ajax/vote/' + pid + '/' + ask + '/index.cgi',
		beforeSend: function()
		{
			width = $('#vote_div').width();
			height = $('#vote_div').height();
			$('#vote_loading').css('width' , width + 'px');
			$('#vote_loading').css('height' , height + 'px');
			$('#vote_loading').show();
			$('#cursor_div').css('display' , 'block');
		},
		success: function(data)
		{
			$('#vote_loading').hide();
			$('#vote_div').html('<div id="vote_loading" style="z-index: 9999; display: none; position: absolute"></div>' + data);
			$('#cursor_div').css('display' , 'none');
		},
	});
	return false;
}

function checkS(e)
{
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        posx = e.clientX;
        posy = e.clientY;
    }

	posx += 20;
	document.getElementById('cursor_div').style.left = posx + 'px';
	document.getElementById('cursor_div').style.top = posy + 'px';
}


function Online_users()
{
	var today = new Date();	
	$.ajax({
		url: '/ajax/online/'+today.getTime()+'/index.cgi',
		success: function(data)
		{	
			$('#online_user_div').html(data);		
		},
	});
}
