var url = document.getElementById('siteurl').value;
/*
$(function()
{
  Date.format = 'yyyy-mm-dd';
	$('.date-pick').datePicker({startDate:'1996-01-01'});
});*/

//this function removes unwanted characters on typing
function removeSpecialChars(id)
{ 
	var field = document.getElementById(id);
	var maintainplus = '';
	var numval = field.value;
	if ( numval.charAt(0)=='+' ){ var maintainplus = '';}
	curphonevar = numval.replace(/[\\!\"£@$%^&*+={};:'()#~,¦\/<>?|`¬\]\[]/g,'');
	field.value = maintainplus + curphonevar;
	var maintainplus = '';
	field.focus;
}


//this function removes unwanted characters on typing
function removeSpecialChars2(id)
{ 
	var field = document.getElementById(id);
	var maintainplus = '';
	var numval = field.value;
	if ( numval.charAt(0)=='+' ){ var maintainplus = '';}
	curphonevar = numval.replace(/[\\!\"£^{}()#~,¦\/<>?|`¬\]\[]/g,'');
	field.value = maintainplus + curphonevar;
	var maintainplus = '';
	field.focus;
}



function removeSpecialChars3(id)
{ 
	var field = document.getElementById(id);
	var maintainplus = '';
	var numval = field.value;
	if ( numval.charAt(0)=='+' ){ var maintainplus = '';}
	curphonevar = numval.replace(/[a-zA-Z\\!\"£@$%^&*+={};:'()#~,¦\/<>?|`¬\]\[]/g,'');
	field.value = maintainplus + curphonevar;
	var maintainplus = '';
	field.focus;
}



//TRIM FUNCTION

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


//=======================================================

function search_validation()
{
	var key = document.getElementById('search_key').value;
	//var cat = document.getElementById('category_id').value;
	//if(trim(key) == '' && trim(cat) == '')
	if(trim(key) == '' || trim(key) == 'Name your product here...')
	{
		alert('Please enter the Search Key');
		return false;
	}
	return true;
}


function highlight(id)
{
	document.getElementById(id).style.background = '#e7eff3';
	document.getElementById(id).style.border= '1px solid #b4dff3';
}

function remove_highlight(id)
{
	document.getElementById(id).style.background = 'none';
	document.getElementById(id).style.border= '1px solid white';
}

//=======================================================

function product_refine(id)
{
	$.get(url+"products/products_list_ajax/" + id, function(data){
			$('#refined_products').html(data);
		});
}

function checkAvailability(username, div)
{
	$.get(url+"users/check_username_availability/" + username, function(data){
			$('#' + div).html(data);
		});
}

function checkAvailabilityEdit(username, div, userid)
{
	$.get(url+"users/check_username_availability_edit/" + username + '/user_id:'+userid, function(data){
			$('#' + div).html(data);
		});
}
