var filesCount=1;
function addRowClone(tblId)
{
	if ( filesCount >= 10 ) return(alert('Maximum files reached'));
	var tblBody = document.getElementById(tblId).tBodies[0];
	newNode = tblBody.rows[0].cloneNode(true);
	var e = newNode.getElementsByTagName('span');
	e[0].style.display = 'inline';
	var f = newNode.getElementsByTagName('input');
	var first=document.getElementById('firstfile');
	f[0].value = '';
	f[0].id='';
	f[0].name='file_name[]';
	f[1].value = '';
	f[1].id='';
	f[1].name='file[]';
	//e[0].style.display = 'none';
	filesCount++;
	tblBody.appendChild(newNode);
}
function removeCloneRow(node) {
	 document.getElementById('atrForm').removeChild(node);
}
function removeCloneRow2(node) {
	 document.getElementById('atrForm2').removeChild(node);
}
function exec_ajax(file, method)
{
     $.ajax({
        type: method,
        url: file,
        data: null,
        cache: false,
        success: function(html){
        	eval(html);
        }
     });
}

var promotion = 1;
//var max_promotions = 2;
var tout;

function switch_promotions(direction, clicked)
{
	if ( clicked ) { clearTimeout(tout); } 
	if ( direction == 'up' ) promotion = promotion+1;
	else promotion = promotion-1;
	 
	if ( promotion > max_promotions ) promotion = 1;
	else if ( promotion == 0 ) promotion = max_promotions;
	
	$.ajax({
		type: "GET",
		url: "/main/promotion/"+promotion,
		data: null,
		cache: false,
		success: function(html){
			$("#psz").html(html);
		}
	});
}

function loop_promotions() {
	switch_promotions('up');
	tout = setTimeout("loop_promotions('up', false)", 5000);
}





var new_products = 1;
//var max_new_products = 2;
var tout_new;

function switch_new_products(direction, clicked)
{
	if ( clicked ) { clearTimeout(tout_new); } 
	if ( direction == 'up' ) new_products = new_products+1;
	else new_products = new_products-1;
	 
	if ( new_products > max_new_products ) new_products = 1;
	else if ( new_products == 0 ) new_products = max_new_products;
	
	$.ajax({
		type: "GET",
		url: "/main/new_products/"+new_products,
		data: null,
		cache: false,
		success: function(html){
			$("#psz_new").html(html);
		}
	});
}

function loop_new_products() {
	switch_new_products('up');
	tout_new = setTimeout("loop_new_products('up', false)", 5000);
}




var special_products = 1;
//var max_special_products = 3;
var tout_special;

function switch_special_products(direction, clicked)
{
	if ( clicked ) { clearTimeout(tout_special); } 
	if ( direction == 'up' ) special_products = special_products+1;
	else special_products = special_products-1;
	
	if ( special_products > max_special_products ) special_products = 1;
	else if ( special_products == 0 ) special_products = max_special_products;
	
	$.ajax({
		type: "GET",
		url: "/main/special_products/"+special_products,
		data: null,
		cache: false,
		success: function(html){
		$("#psz_special").html(html);
	}
	});
}

function loop_special_products() {
	switch_special_products('up');
	tout_special = setTimeout("loop_special_products('up', false)", 5000);
}





function remove_block(id) {
	$(".bl"+id).fadeOut();
}


function user_type_other(sel){
	$.ajax({
		
        type: "GET",
        url: '/main/user_type_other/'+sel,
        cache: false,
        success: function(html){
        $("#user_type_other").html(html);
        }
     });
}




function approve_user(id) {
	$.ajax({
		type: "GET",
		url: "/admin/users/approve_user/"+id,
		data: null,
		cache: false,
		success: function(html){
			remove_block(id);
		}
	});
}

function decline_user(id) {
	$.ajax({
		type: "GET",
		url: "/admin/users/decline_user/"+id,
		data: null,
		cache: false,
		success: function(html){
		remove_block(id);
	}
	});
}

function setVisible(obj){
    obj = document.getElementById(obj);
    obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
    
    if (obj.style.visibility == 'hidden')
    	$(".overlay_div").remove();
}

function switchOverlay()
{	
	div = "<div class='overlay_div'></div>";
	$("body").append(div);
	$(".overlay_div").fadeIn();
}
