function showInfo(i_title, msg){
	$('info_pic').src = '/public/img/ajax-load.gif';
	$('inf_title').innerHTML = i_title;
	$('inf_content').innerHTML = msg;
	$('informer').style.display = 'block';
}

function hideInfo(){
	$('info_pic').src = '/public/img/ok.gif';
	new Effect.Fade('informer', {duration:1.5});
}

function codeSet(value){
	$('code_search').value = value;
}

function HideDropDown(){
	new Effect.Fade('dd_list', {duration:0.5});
}

function HideZoom(id){
//	var items = $$.('.zoom');
	alert(id);
}

function Hide(id_name){
	new Effect.SlideUp(id_name, {duration:0.3});
}

function Show(id_name){
	new Effect.SlideDown(id_name, {duration:0.3});
}

function sh(id_name){
	if($(id_name).style.display == 'none') Show(id_name);
	else Hide(id_name);
}

function CheckLogin(value){
	$('reg_login').className  = 'loa';
	if(value == '') return false;
	var get_srt = 'check_login='+value;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/auth.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	var val = originalRequest.responseText;
		    	if(val == 'no'){
		    		$('reg_login').className  = 'valid';
		    	}else {
		    		$('reg_login').className  = 'novalid';
		    	}
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function GetDropDown(value){
	$('code_search').className  = 'seatext2 loa';
	var get_srt = 'code_search='+value;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/search.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	var val = originalRequest.responseText;
		    	if(val != '0'){
		    		$('dd_list').innerHTML = val;
		    		$('dd_list').style.display = 'block';
		    	}else {
		    		$('dd_list').style.display = 'none';
		    	}
		    	$('code_search').className  = 'seatext2';
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function getSubItems(grpid){
	if(grpid == '-1') return false;
	$('nameitem_div').innerHTML = '<img src="/public/img/ajax-load.gif"/>';
	var get_srt = 'grp_id='+grpid;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/search.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	var val = originalRequest.responseText;
		    	$('nameitem_div').innerHTML = val;
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...');
		     }
		  }
	  );
}

function SetFavorites(tid){
	showInfo('Администрирование','Редактирование отображения товара для показа на главной странице сайта');
	var res = 'no';
	res = ($('check'+tid).checked == true) ? 'yes' : 'no';
	var get_str = 'mp_value='+res+'&tid='+tid;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/favorite.php',
		  { method:'get',
		    parameters: get_str,
		    onSuccess: function(){
		    	hideInfo();
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function getIncommingTable(pid){
	var get_srt = 'incomming_id='+pid;
	$('incomming_table').innerHTML = '<img src="/public/img/loading2.gif"/>';
	new Ajax.Request('http://'+document.location.host+'/public/ajax/incomming.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	var val = originalRequest.responseText;
		   		$('incomming_table').innerHTML = val;
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );	
}

function GetIncomming(pid,value){
	if(value == '') Hide('a_dropdown');
	var get_srt = 'code_search='+value+'&pid='+pid;
//	alert(get_srt);
	new Ajax.Request('http://'+document.location.host+'/public/ajax/incomming.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
		    	var val = originalRequest.responseText;
		    	if(val != '0'){
		    		$('a_dropdown').innerHTML = val;
		    		Show('a_dropdown');
		    	}else {
		    		Hide('a_dropdown');
		    	}
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function DeleteIncomming(pid,tid){
	var get_srt = 'del_pid='+pid+'&del_tid='+tid;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/incomming.php',
		  { method:'get',
		    parameters: get_srt,
		    onSuccess: function(originalRequest){
				new Effect.Puff('inbox_'+tid);
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
		    }
		  }
	  );
}

function AddToIncomming(pid,tid){
	var get_str = 'add_pid='+pid+'&add_tid='+tid;
	new Ajax.Request('http://'+document.location.host+'/public/ajax/incomming.php',
		  { method:'get',
		    parameters: get_str,
		    onSuccess: function(){
		    	getIncommingTable(pid);
		    },
		    onFailure: function(){ 
		    	alert('Something went wrong...'); 
				getIncommingTable(pid);
		    }
		  }
	  );
}

function ShowMessage(title, msg){
	win = new Window({
		className: "alphacube", 
//		hideEffect: Effect.SwitchOff, 
		title: title, 
		width:300, 
		height:150, 
		destroyOnClose: true, 
		recenterAuto:false
	});
	win.getContent().update(msg);
	win.showCenter();
}



function ltrim(inp) {
	var ptrn = /\s*((\S+\s*)*)/;
	return inp.replace(ptrn, "$1");
}

function rtrim(inp) {
	var ptrn = /((\s*\S+)*)\s*/;
	return inp.replace(ptrn, "$1");
}

function trim(inp) {
	return ltrim(rtrim(inp));
}

function validateEMail(addr){
	var reg = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
	return true;
}

function validatePhone(phone){
	var reg = /^(\+[0-9\(\)\s\-\,\.]+)$/;
	return true;
}
