
	function submitSearch(searchId){
		window.location = htmlLink+'?search_key='+document.getElementById(searchId).value;
	}

	function sortItem(order,isByTime){
        var pattern = '';
        if(isByTime==true){
            pattern = 'timeby';
        } else {
            pattern = 'sortby';
        }
		var str = window.location + '';

		var index = str.indexOf('?');

		if(index==-1){//if there's not any param
			str+='?'+pattern+'='+order;
		} else {   //if there's some params
			var index_sort = str.indexOf(pattern);
			
			if(index_sort == -1){  //if pattern not existing
				str+='&'+pattern+'='+order;
			} else {//if existed pattern
				var index_and = str.indexOf('&',index_sort);				;
				if(index_and == -1)
                    index_and = str.length;
				str = str.slice(0, index_sort) + pattern + '='+order + str.slice(index_and, str.length);
			}
		}

		str =  str.replace(/#/g, '');
		window.location = str;
	}

	function edit(object){
		input_id = object.next('span').down().id;
	
		object.hide();
	
		if($(input_id)){
			$(input_id).show();
			$(input_id).focus();
		}
	}
	
	function checkPress(myEvent, object){
		if(myEvent.keyCode == 13)updateData(object);
		if(myEvent.keyCode == 27){
			object.hide();
			span_id = 'span_' + object.id;
			if($(span_id)){
				$(span_id).show();
			}
		}
	}
	
	function updateData(object){
		span_id = 'span_' + object.id;
	
		str_id = object.id.split('_');
		field 	= str_id[0];
		user_id = str_id[1];
		if(isNaN(user_id)){
			user_id = str_id[2];
			field = str_id[0]+'_'+str_id[1];
		}
	
		value   = object.value;
		oldValue = object.title;
	
		object.hide();
		var check = (value!=oldValue);
	
		if($(span_id)){
			$(span_id).show();
			if(check)$(span_id).innerHTML = "<img src='" + ajaxImg + "' />";
		}
	
		if(check){
	
			var url = categoryUpdate;
			var pars = 'id=' + user_id + '&field=' + field + '&value=' + value;
			var target = span_id;
	
			new Ajax.Request(url,
				  {
					method:'get',
					parameters: pars,
	
					onSuccess: function(transport){
						if(transport.responseText!='')value = transport.responseText;
						object.title = value;
						$(span_id).innerHTML = value;
	
					},
					onFailure: function(){
						alert('Something went wrong...')
					}
				  });
		}
	}
	
	function submitenter(myfield,e){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
		
		if (keycode == 13)
		   {
		   myfield.form.submit();
		   return false;
		   }
		else
		   return true;
	}
	
	function validEmail(str){
		var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(str.match(emailRegEx))
			return true;
	
		return false;
	
	}
	
	function validateURL(str){
	 if(str.match(/^(http|https|ftp|udp|telnet)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ||
     str.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i)){
		return true;
	  } else {
		return false;
	  }
	}
	
	function checkForm(formname){
		var count = 0;
		var arr = new Array();
		arr[0] = '';
		arr[1] = '';
	
		strErrEmp = "";
		strErrPw = "";
		strErrEm = "";
		strErr  = "";
	
		valid = true;
		checkChb = false;
        checkChb_Refine = false
		found = false;
        found_refine = false; //flag marks refine-category
		$$('#'+formname+' input, textarea, select').each(function(e){ //tungnt added condition textarea, select tags
			//setStyle({background:'#FFFFFF'}); //conflict prototype & jquery
             e.style.background = '#FFFFFF'; 
			if( (e.title == 'req') || (e.title == 'req-pw') || (e.title == 'req-em') || (e.title == 'req-t') || (e.title == 'req-f') || (e.title == 'req-chb') || (e.title == 'req-w') ||(e.title=='req-chb-refine'))
			{
				if(e.title == 'req-em'){
					if(!validEmail(e.value)){
						valid = false;
						strErrEm += 'Invalid Email !\n';
					}
				}
	
				if(e.title == 'req-pw'){
					arr[count] = e.value;
					count++;
				}
	
				if(e.title == 'req-t'){
					if(e.checked == false){
						valid = false;
						strErrEmp+='You must accept our Terms and Conditions \n ';
					}
				}
				
				if(e.title =='req-w'){
					if(!validateURL(e.value)){
						//e.setStyle({background:'#999999'});
                        e.style.background = '#999999';
						valid = false;
						strErrEmp+='You need to enter a valid url( with http ) \n';
					}
				}
	
				if(e.title == 'req-chb'){
					if(e.checked == true)checkChb = true;
					found = true;
				}
                
                if(e.title == 'req-chb-refine'){
                    if(e.checked == true)checkChb_Refine = true;
                    found_refine = true;
                }
                
				if (e.value.strip().length == 0)
				{
					//setStyle({background:'#999999'})
	                e.style.background = '#999999';
					if(e.title == 'req-f'){strErrEmp+= 'You need to submit your image ! \n';}else{
						strErrEmp+= e.id.substr(4) + ' is empty \n';
					}
					valid = false;
				}
			}
		})
	
		if(arr[0]!=arr[1]){
			valid = false;
			strErrPw+= 'Password confirm do not match !\n';
		}
	
		if((!checkChb && found == true) || (!checkChb_Refine && found_refine == true)){
			strErrEmp+= 'You need to choose atleast one category ! \n';
			valid = false;
		}
	
		strErr = strErrEmp + strErrPw + strErrEm;
		if(strErr != '')
		alert(strErr);
		return valid;
	}

    function ajax_rate(item_id, rating){
        div_name = 'star_'+item_id;

        //$(div_name).innerHTML = ajaxImg;

        var url = itemRating + item_id + '/' + rating;

        var pars = '';
        var target = div_name;
        new Ajax.Request(url,
          {
            method:'get',
            onSuccess: function(transport){

              var response = transport.responseText || "no response text";

              data = response.split("<!");

              if( data[0] == '!!!LOGIN!!!'){
                    //location
              } else {
                    $('rating_bar_'+item_id).setStyle({width:data[0]*15+'px'});
              }

            },
            onFailure: function(){ alert('Something went wrong...') }
          });
    }
	
	function setStatus(item_id, status, calendarId){
	
		//var url = adminApp + item_id + '/' + status;
        var url = adminApp;
        var pars = 'item_id=' + item_id + '&status=' + status;
        e = $(calendarId);
        e_div  = $('div_' + e.id);
        
        e.setStyle({background:'#FFFFFF'});
        
        if(status) {
            active_time = $(calendarId).value;
            if(active_time == '') 
            {
                alert('You must set timer to activate.');
               e.setStyle({background:'#999999'}); 
               return;
            }
           pars = pars + '&active_time=' + $(calendarId).value;
        }
		
		var target = 'admin_approve_' + item_id;
		
		new Ajax.Request(url,
			{
				method:'get',
                parameters:pars,
				onSuccess:function(transport){
					if($(target)){
						$(target).innerHTML = transport.responseText;
                        if(status){
                            e_div.hide();
                        } else {
                            e_div.show(); 
                        }
					}					
				},
				onFailure:function(){ alert('Something went wrong...') }
			});
	}
    
 function setOrderCombobox(_type, span_id) {
        var url = htmlLink + '/slug/renderOrderForAjax/';
        var pars = 'type=' + _type;
        var target = span_id;
        new Ajax.Request(url,
              {
                method:'get',
                parameters: pars,

                onSuccess: function(transport){
                    $(target).innerHTML = transport.responseText;

                },
                onFailure: function(){
                    alert('Something went wrong...')
                }
              });
    }

	function checkAjx(){
	
		var url_check = ajaxCheck;
		var target = 'adminMsg';
		
		new Ajax.Request(url_check,
			{
				method:'get',
				onSuccess:function(transport){
					response = transport.responseText;
					data = response.split("<!");
					
					if(data[0]!='  nothing'){

						str = data[0].split(":");
						
						if(str[0] == '  ok'){
							win1.getContent().innerHTML = str[2];
							win1.show();
						}
					}
				},
				onFailure:function(){  }
			});
    }
	