var restricted_words;
$('#txtSearch').css("color","#999999");

function searchUser( page ){
	$('#hidPage').val(page);
	var pmSortBy = $('#hiddSortBy').val();
	var pmSortId = $('#hiddSortId').val();
	
	var optsearch = $('input[name=searchby]:checked').val();
	var p = typeof page == 'undefined' ? 1 : page;
	optsearch == 'undefined' ? '' : optsearch;
	var txtSearch = $('#txtSearch').val();
	if (txtSearch != "Search")
		txtSearch = txtSearch;
	else
		txtSearch = '';
	vData = 'p='+p+'&pmSortBy='+pmSortBy+'&pmSortId='+pmSortId+'&searchby='+optsearch+'&searchvalue='+encodeURIComponent(txtSearch);
	$('#search-results').html( '<span class="warning">Loading....</span>' );
	$.ajax({
		type : "POST",
		url	 : g_site_path+"ajax/filter-user",
		data : vData,
		dataType : 'html',
		success: function(html){
			$('#search-results').html( html );
		}
   });
}
function traceKey( keycode ){
	if ( keycode == 13 ){
		searchUser();
	}
}
function openProfileWindow(){
	d = new dialog({'title':'Add Deadbeat Profile',top:50, ismodel:true, width:725, height:500, onclose:'d.close()'});
	d.show();
	d.sethtml('<span class="warning">Loading...</span>');
	var vData = '';
	$.ajax({
		type : "POST",
		url	 : g_site_path+"ajax/get-profile-add-form",
		data : vData,
		dataType : 'html',
		success: function(html){
			d.sethtml( html );
			setCookInfoToLogin();
			d.resizeDialog();
		}
   });
}
function SaveProfileValues(){
	var first_name = trim( $('#txtFirstName').val() );
	var last_name  = trim( $('#txtLastName').val() );
	var zipcode    = trim( $('#txtZipcode').val() );
	var address    = trim( $('#txtAddress').val() );
	var txtCountry    = trim( $('#profile_choo_country').val() );
	var txtOweAmt    = trim( $('#txtOweAmt').val() );
	var txtAliases    = trim( $('#txtAliases').val() );
	var txtHeight    = trim( $('#txtHeight').val() );
	var txtWeight    = trim( $('#txtWeight').val() );
	var txtOcu    = trim( $('#txtOcu').val() );
	var txtCaseNo    = trim( $('#txtCaseNo').val() );
	var txtOcuLis    = trim( $('#txtOcuLis').val() );
	var txtEColor    = trim( $('#txtEColor').val() );
	var txtHColor    = trim( $('#txtHColor').val() );
	var txtDesc    = trim( $('#txtDesc').val() );
	var flagChech = '0';
	
	clearAllErrorFields( ['error_first_name','error_aliases','error_hcolor','error_ecolor','error_height','error_weight','error_ocu','error_caseno','error_desc','error_occlis','error_oculis','error_last_name','error_address','error_zipcode','error_image','error_county','error_oweamt'] );
	
	clearHighlightFields( ['txtFirstName','txtAliases','txtHeight','txtWeight','txtHColor','txtEColor','txtOcu','txtCaseNo','txtOcuLis','txtDesc','txtLastName','txtOcuLis','txtAddress','filePhoto','txtZipcode','txtOweAmt','profile_choo_country'], 'error_text_field' );
	
	if ( !hasValue(first_name, 'error_first_name', 'txtFirstName', 'Please enter first name' ) ){
		d.resizeDialog();
		//makeHightlightField('txtFirstName', 'error_text_field');
		flagChech = '1';
	}
		
	if ( !hasValue(last_name, 'error_last_name', 'txtLastName', 'Please enter last name' ) ){
		//makeHightlightField('txtLastName', 'error_text_field');
		d.resizeDialog();
		flagChech = '1';
	}	
	
	if ( !hasValue(address, 'error_address', 'txtAddress', 'Please enter last known street address' ) ){
		//makeHightlightField('txtAddress', 'error_text_field');
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( !hasValue(zipcode, 'error_zipcode', 'txtZipcode', 'Please enter last known zipcode in numeric' ) ){
		//makeHightlightField('txtZipcode', 'error_text_field');
		d.resizeDialog();
		flagChech = '1';
	}
	if ( !isZipcode(zipcode) ){
		$('#error_zipcode').html('Please enter last known zipcode in 5 digit');
		//makeHightlightField('txtZipcode', 'error_text_field');
		ge('txtZipcode').focus();
		d.resizeDialog();
		flagChech = '1';
	}	
	
	if(txtCountry == ""){
		$('#profile_choo_country').focus();
		$('#error_county').html('Please enter the country name');
		//makeHightlightField('profile_choo_country', 'error_text_field');
		d.resizeDialog();
		flagChech = '1';		
	}
	
	
	if (!(/(^([0-9])*$)/).test(txtOweAmt) || txtOweAmt == "" ) {		
		$('#error_oweamt').html('<span class="warning">Please enter the amount in numeric</span>');		
		$('#txtOweAmt').select();
		//makeHightlightField('txtOweAmt', 'error_text_field');
		d.resizeDialog();
		flagChech = '1';
	}
	var aPhotoFile = new Array('jpg', 'jpeg');	
	if ( ffCheckFileExtension(aPhotoFile,ge('filePhoto').value) == false){		
		$('#error').html('Please select valid image and special characters ( except - _ ) are not allowed with image name.');		
		//makeHightlightField('filePhoto', 'error_text_field');
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtCountry ) ){
		$('#error_county').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('profile_choo_country', 'error_text_field');
		ge('profile_choo_country').focus();
		d.resizeDialog();
		//return 0;
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( address ) ){
		$('#error_address').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtAddress', 'error_text_field');
		ge('txtAddress').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtDesc ) ){
		$('#error_desc').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtDesc', 'error_text_field');
		ge('txtDesc').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtOcuLis ) ){
		$('#error_occlis').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtOcuLis', 'error_text_field');
		ge('txtOcuLis').focus();
		d.resizeDialog();
		flagChech = '1';
	}	
	
	if ( checkRestrictedWord( txtOcu ) ){
		$('#error_ocu').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtOcu', 'error_text_field');
		ge('txtOcu').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtWeight ) ){
		$('#error_weight').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtWeight', 'error_text_field');
		ge('txtWeight').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtHeight ) ){
		$('#error_height').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtHeight', 'error_text_field');
		ge('txtHeight').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtCaseNo ) ){
		$('#error_caseno').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtCaseNo', 'error_text_field');
		ge('txtCaseNo').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtAliases ) ){
		$('#error_aliases').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtAliases', 'error_text_field');
		ge('txtAliases').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( first_name ) ){
		$('#error_first_name').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtFirstName', 'error_text_field');
		ge('txtFirstName').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	
	if ( checkRestrictedWord( txtEColor ) ){
		$('#error_ecolor').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtEColor', 'error_text_field');
		ge('txtEColor').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( txtHColor ) ){
		$('#error_hcolor').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtHColor', 'error_text_field');
		ge('txtHColor').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	
	if ( checkRestrictedWord( last_name ) ){
		$('#error_last_name').html('We\'ve found that some of the text is offensive. Please avoid offensive word(s)');
		makeHightlightField('txtLastName', 'error_text_field');
		ge('txtLastName').focus();
		d.resizeDialog();
		flagChech = '1';
	}
	if(flagChech == '1')
		return 0;
	
	$('#show_status_form').html('Please wait... Save your profile values')
	ge('frmProfile').submit();
}

function comment(id){
	//alert(id);
	var vData = 'id='+id;
	$.ajax({
		type : "POST",
		url	 : g_site_path+"ajax/comments",
		data : vData,
		dataType : 'html',
		success: function(html){
			//alert(html);
			//d.sethtml( html );
		}
   });
}

function Sort(pmSortId,pmSortBy) {	
	var optsearch = $('input[name=searchby]:checked').val();
	var p = typeof page == 'undefined' ? 1 : page;
	optsearch == 'undefined' ? '' : optsearch;
	var txtSearch = $('#txtSearch').val();
	if (txtSearch != "Search")
		txtSearch = txtSearch;
	else
		txtSearch = '';
	vData = 'p='+p+'&pmSortBy='+pmSortBy+'&pmSortId='+pmSortId+'&searchby='+optsearch+'&searchvalue='+encodeURIComponent(txtSearch);
	$.ajax({
		type : "POST",
		url	 :g_site_path+"ajax/filter-user",
		data : vData,
		dataType: "html",
		success: function(html){			
			$('#search-results').html(html);
		}
   });

}
function clrText() {
	if($('#txtSearch').val() == "Search") {
		$('#txtSearch').val('');
		$('#txtSearch').css("color","#000000");
	}
}
function blrText() {
	if($('#txtSearch').val() == "") {
		$('#txtSearch').css("color","#999999");
		$('#txtSearch').val('Search');
	}
		
}

function flagUpdate(id) {	
	vData = 'pmid='+id;	
	$.ajax({
		type : "POST",
		url	 : g_site_path+"ajax/flag-user",
		data : vData,
		dataType : 'html',
		success: function(html){			
			$('#'+id).html( 'Report abuse updated sucessfully...' );
			$('#'+id).fadeOut("slow");			
		}
	});
	 
}
