$(document).ready(function(){
	
});

//get traffic for sale
function get_sale_traffic(type,page) {
	var type = (type)	?	type	:	1;

	$.post(url, { sale_traffic_type: type, Page:page } , function(data) {
		$("#source").html(data);	
	});

}

function close_window() {
	tb_remove();
	document.location.reload();
}

function explode( delimiter, string ) {  
	// http://kevin.vanzonneveld.net  
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
	// +   improved by: kenneth  
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
	// *     example 1: explode(' ', 'Kevin van Zonneveld');  
	// *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}  

	var emptyArray = { 0: '' };  

	if ( arguments.length != 2  
	|| typeof arguments[0] == 'undefined'  
	|| typeof arguments[1] == 'undefined' )  
	{  
	return null;  
	}  

	if ( delimiter === ''  
	|| delimiter === null )  
	{  
	return false;  
	}  

	if ( typeof delimiter == 'function'  
	|| typeof delimiter == 'object'  
	|| typeof string == 'function'  
	|| typeof string == 'object' )  
	{  
	return emptyArray;  
	}  

	if ( delimiter === true ) {  
	delimiter = '1';  
	}  

	return string.toString().split ( delimiter.toString() );  
}  


function checkvalue (el_id, v_min, v_max) {

	var old_val = document.getElementById(el_id).value;
	if (isNaN(document.getElementById(el_id).value) || (document.getElementById(el_id).value == '')){
		document.getElementById(el_id).value = '';
		alert('Значение поля должно быть численным.','',1,'');
		document.getElementById(el_id).value = 1;
		return false;
	}
	else{
		if ((v_min != -1) && (v_max != -1))
		if ((document.getElementById(el_id).value < v_min) ||  (document.getElementById(el_id).value > v_max)){
			document.getElementById(el_id).value = '';
			alert('Значение поля должно лежать в диапазоне от '+v_min+' до '+v_max+'.','',1,'');	
			document.getElementById(el_id).value = 1;
			return false;
		}
	}
	return true;
}


function slideToggle(element) {
	var element = (element) ? element : "gdomain";
	 $("#"+element).slideToggle("slow");
}


function getAccounts(billing_id) {
	
	var billing_id = (billing_id)	?	billing_id	:	0;

	$.post(url, { billing_id: billing_id } , function(data) {
		$("#user_id").html(data);	
	});
}


function getPeriods(period) {

	var period = (period)	?	period	:	0;

	$.post(url, { period : period } , function(data) {
		$("#periods").html(data);	
	});

}

function getDays(month_id,name,dname) {

	var month_id = (month_id)	?	month_id	:	0;

	$('#period').val(6);

	d=$('#'+dname).val(); 

	if( dname == 'SD')
		$.post(url, { month_id: month_id, dname: dname, 'SD' : d } , function(data) {
			$(name).html(data);	
		});
	else
		$.post(url, { month_id: month_id, dname: dname, 'ED' : d } , function(data) {
			$(name).html(data);	
		});
}

function getAccountsComment(cbilling_id) {

	var cbilling_id = (cbilling_id)	?	cbilling_id	:	0;

	$.post(url, { cbilling_id: cbilling_id } , function(data) {
		$("#account_comment").html(data);
	});
}


function getAccountsInfo(abilling_id) {

	var abilling_id = (abilling_id)	?	abilling_id	:	0;

	$.post(url, { abilling_id: abilling_id } , function(data) {
		$("#account_info").html(data);	
	});

}
