String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


function UserCorrectStr(str)
{

   if (str == '')
    return true;
 
   var pattern = /^[0-9]*([0-9]+,)*[0-9]+$/;
   return pattern.test(str.trim()/*split(' ').join('')*/);
			
}


function EmailValidate(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(address);
}


function GetBookmarks(uid) {
$.ajax( {
type: "POST",
dataType: 'JSON',
async: true,
url: "ajax/posting_list_method.php",
data: "method=count_bookmarks&uid="+uid,
success: function(answer)
         {  
            data = eval('('+ answer +')');
												if (data.status==true)
												{
													   if (data.result == 0)
 																$('#bookmarks_count').hide();
																else 
																{
																	  $('#bookmarks_count').show();
   																$('#bookmarks_count').empty().html(data.result);
																}
																							
												}
         }
	  });
			return false;
};

/*------------*/

function GetUserMessages() {
$.ajax( {
type: "POST",
dataType: 'JSON',
async: true,
url: "ajax/user_messages.php",
success: function(answer)
         { 	
												data = eval('('+ answer +')');
												if (data.status==true)
												{     
																
																if (data.result == 0)
																{
 																$("#my_messages").stop();
																	$('#new_messages_count').hide();
																	$('#myb2b_messages_count').hide();
																}
																else 
																{  
																			if (MessageCount != null)
																			{ 
 																			  if ( (data.total > MessageCount) && (data.page == 'user_messages.php'))
	     																{
																									location.href="user_messages.php";
																						}
																			}

                   
                   MessageCount	= data.total;
																			
																			$('#new_messages_count').show();
   																$('#new_messages_count').empty().html("<br>"+data.result);
   																$('#myb2b_messages_count').show().empty().html(data.result);
																			$("#my_messages").cyclicFade({
			                                                repeat: 0,
                                                			params: [{fadeout:100, stayout:100, opout:0, fadein:100, stayin:100, opin:1}
																																																											]
																																																});

																}
																							
												}
         }
	  });
			return false;
};

/*------------*/

function GetUserFunc() {
$.ajax( {
type: "POST",
dataType: 'JSON',
async: true,
url: "ajax/user_func.php",
success: function(answer)
         { 	
												data = eval('('+ answer +')');
												if (data.status==true)
												{     
																if (data.match_count != 0)
																{  
   														  $('#match_count').empty().html("("+data.match_count+")");
                   $('#myb2b_match_group').show();
																			$('#myb2b_match').empty().html(data.match_count);
																}
																else
																{
																	  $('#myb2b_match_group').hide();
																			$('#match_count').empty();
																}
																
												}
         }
	  });
			return false;
};

/*------------*/

function UserPostingsInfo() {
$.ajax( {
type: "POST",
dataType: 'JSON',
async: true,
url: "ajax/user_postings_info.php",
success: function(answer)
         { 	
												data = eval('('+ answer +')');
												if (data.status==true)
												{     
																if (data.p_enable + data.p_disable != 0)
																{  
																			str = '<font color="green">'+data.p_enable+'</font>'+' / '+'<font color="red">'+data.p_disable+'</font>';
																			$('#myposting_count').empty().html("("+str+")");
																}
																else
																{
																			$('#myposting_count').empty();
																}
																
												}
         }
	  });
			return false;
};

/*------------*/

function UserDataInfo() {
$.ajax( {
type: "POST",
dataType: 'JSON',
async: true,
url: "ajax/user_data_info.php",
success: function(answer)
         { 	
												data = eval('('+ answer +')');
												if (data.status==true)
												{     
																if (data.favorite_count != 0)
																		$('#favorite_count').empty().html(data.favorite_count);
																else
																		$('#favorite_count').empty();
																		
																$('#warning_lastupdate').empty().html(data.warning_lastupdate);
												}
         }
	  });
			return false;
};

/*------------*/

function ImagePreview(e) {

       e.nyroModalManual({
																											
                              bgColor: null,
																														minWidth: 370,
																														minHeight: 250,
                              resizable: true,
                              autoSizable: true,
                              padding: 20,
                              regexImg: "[^\.]\.(aspx|jpg|jpeg|png|tiff|gif|bmp)\s*$"
																											}
																								);
}


function UserInfo(e) {

       e.nyroModalManual({

																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
                              autoSizable: true

																											}
								                 );
}


function AdmUserInfo(e) {

       e.nyroModalManual({

/*																														bgColor: null,*/
																														minWidth: 470,
																														modal: false,
																														type: 'iframe',
																														width: 1000,
																														minHeight: 900,
                              autoSizable: false

																											}
								                 );
}



function ModelMissing(e) {

       e.nyroModalManual({

																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
                              autoSizable: true,
																														closeButton: null,
																														cssOpt: {
																															  
																														}

																											}
								                 );
}


function SendMessage(e) {

       e.nyroModalManual({
																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
 																													closeButton: null,
                              autoSizable: true


																											}
								                 );
}


function ShowMessage(e) {

       e.nyroModalManual({

																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
																														closeButton: null,
                              autoSizable: true

																											}
								                 );
}

/*-----*/

function ChangePassword(e) {

       e.nyroModalManual({
																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
 																													closeButton: null,
                              autoSizable: true
																											}
								                 );
}


function UserComments(e) {

       e.nyroModalManual({
																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
 																													closeButton: null,
                              autoSizable: true,
																														modal: false  


																											}
								                 );
}

/*-----*/


function TradersFilter(e) {

       e.nyroModalManual({
																														bgColor: null,
																														modal: true,
																														minWidth: 100,
																														minHeight: 80,
 																													closeButton: null,
                              autoSizable: true
																											}
								                 );
}



function PostingsPeriod(e) {

       e.nyroModalManual({
																														bgColor: null,
																														modal: true,
																														minWidth: 100,
																														minHeight: 80,
 																													closeButton: null,
                              autoSizable: true
																											}
								                 );
}


function UserRating(e) {

       e.nyroModalManual({

																														bgColor: null,
																														minWidth: 100,
																														minHeight: 100,
																														closeButton: null,
                              autoSizable: true

																											}
								                 );
}


function AdvSearch(e) {

       e.nyroModalManual({
																														bgColor: null,
																														modal: true,
																														minWidth: 100,
																														minHeight: 180,
 																													closeButton: null,
                              autoSizable: true,
																														resizable: true
																											}
								                 );
}

/*-----*/

function UserProductCategoryFunc(dtext)
{
   	$("#DivProductCategory").empty().html(data.body);
 	  $('a[id^=EditProductCategory]').unbind('click');
    $('a[id^=EditProductCategory]').click(function(e) 
				{
					  e.preventDefault(); 
       ModelMissing($(this));
     		return false;
				}
				);
				
				$('a[id^=DeleteProductCategory]').unbind('click');
    $('a[id^=DeleteProductCategory]').click(function(e) 
				{
							if (confirm(dtext) == false)
							 return false;

       $.ajax( {
       type: "POST",
       dataType: 'JSON',
       url: "ajax/user_product_category.php",
       data: "ups_id="+$(this).attr("ups")+"&method=delete",
       success: function(answer)
       { 
          data = eval('('+ answer +')');
										if (data.status == true)	
										{  
										 		UserProductCategoryFunc(dtext);
										}
										else {
													     alert(data.errorlist);
													  }
       }        
       });	
     		return false;
				});
				
}