function textCounter (field, countfield, maxlimit)
  {

      if (field.value.length > maxlimit)

      field.value = field.value.substring(0, maxlimit);

      else

      countfield.value = maxlimit - field.value.length;

  }

  function newWindow (mypage,myname,w,h,features)
  {
      if(screen.width)

      {

          var winl = (screen.width-w)/2;
          var wint = (screen.height-h)/2;

      }

      else

      {

          winl = 0;wint =0;

      }

      if (winl < 0) winl = 0;
      if (wint < 0) wint = 0;

      var settings = 'height=' + h + ',';
      settings += 'width=' + w + ',';
      settings += 'top=' + wint + ',';
      settings += 'left=' + winl + ',';
      settings += features;
      settings += ' scrollbars=yes ';

      win = window.open(mypage,myname,settings);

      win.window.focus();

  }

function checkemail (emailStr) 
{
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) 
{
alert("Sorry, email is incorrect");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Sorry, email is incorrect");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Sorry, email is incorrect");
return false;
   }
}

if (user.match(userPat)==null) 
{
alert("Sorry, email is incorrect");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Sorry, email is incorrect");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Sorry, email is incorrect");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Sorry, email is incorrect");
return false;
}

if (len<2) {
alert("Sorry, email is incorrect");
return false;
}

return true;
}

$("#b_loc").livequery("click",function()
{
	update_tabs('b_loc','cat_loc_ul');
	document.getElementById('locations_outer').style.display = "block";
	document.getElementById('categories_outer').style.display = "none";
	document.getElementById('categories').style.display = "none";
});

$("#b_cat").livequery("click",function()
{
	
	update_tabs('b_cat','cat_loc_ul');
	document.getElementById('locations_outer').style.display = "none";
	document.getElementById('categories_outer').style.display = "block";
	document.getElementById('categories').style.display = "block";	
});



 function stopSubmit() 
 {
	 	
  return false;
  }

/* function submit_small_seach()
{
	
	var cat = document.getElementById('category_one');
	var kw = $('#keyword').val();
	
	
	if(cat == 'companies')
	{
	
	}
	if(cat == 'products')
	{
		
		$('#search_product').click();
		$('#search_keyword').val(kw);
		
	}
	if(cat == 'leads')
	{
		
	}
	
} */

function submit_comp_form()
{
	
	var keyword = document.getElementById('keyword').value;
	
	keyword = keyword.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	if(keyword == '' || keyword.length < 2)
	{
		//keyword = "all";
//		overlib(overlib_html, CENTERPOPUP, FGCOLOR, '#FFFFFF', BGCOLOR, '#A6A6A6',FGBACKGROUND ,tp_dir+'/images/ma_spacer.gif', CAPCOLOR, '#FFFFFF', CAPTIONSIZE, '2', CLOSECOLOR, '#FFFFFF', SHADOW, SHADOWOPACITY, 60, HAUTO, VAUTO, EXCLUSIVE, STICKY, CAPTION, '<div id=overlib_header>Keyword Length</div>', CLOSECLICK, WIDTH, 350, HEIGHT, 80, BORDER, 2, SHADOWX, 5, SHADOWY, 5, CLOSETEXT, '<img src='+tp_dir+'/images/close_icon.gif style=border:none;/>');
                overlib(overlib_html, CENTERPOPUP, BORDER,1, BGCOLOR,"#333333", CLOSECLICK, STICKY, CAPTION, '<div id=overlib_header>Keyword Length</div>', WIDTH, 490, HEIGHT, 80);
		return false;
	}
	
	keyword =  keyword.replace(/[^a-zA-Z 0-9]+/g,'');
	keyword = keyword.replace(/ /g,"-");
	var country = document.getElementById('country').value;
	
	loc = 1;
	var category = document.getElementById('category').value;
	var loc = document.getElementById('loc').value;
	
	var index = loc.indexOf('_');
	if(index > -1)
	{
		var loc_level = 2;
		loc = loc.substring(0,index);
	}
	else
		var loc_level = 4;	
	
	//loc = loc.replace("_","");
	if(category == '')
		category = 0;
	
	if(keyword == '')
		keyword = 'all';
	
	var root_path = document.getElementById('root_path').value;	
	
	// previous search form action
	//document.getElementById('search_frm').action = root_path+"-"+keyword+"-"+category+"-"+loc+"-"+loc_level+"-1.html";
	
	document.getElementById('search_frm').action = root_path+"search.php?m=companies&keyword="+keyword+"&cat="+category+"&loc_id="+loc+"&loc_level="+loc_level+"&page=0";
	
	
	
	
	document.getElementById('search_frm').submit();
}

function submit_prod_form(module)
{
	
	var keyword = document.getElementById('keyword').value;

	keyword = keyword.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	if(keyword == '' || keyword.length < 2)
	{
		//keyword = "all";
//		overlib(overlib_html, CENTERPOPUP, FGCOLOR, '#FFFFFF', BGCOLOR, '#A6A6A6',FGBACKGROUND ,tp_dir+'/images/ma_spacer.gif', CAPCOLOR, '#FFFFFF', CAPTIONSIZE, '2', CLOSECOLOR, '#FFFFFF', SHADOW, SHADOWOPACITY, 60, HAUTO, VAUTO, EXCLUSIVE, STICKY, CAPTION, '<div id=overlib_header>Keyword Length</div>', CLOSECLICK, WIDTH, 350, HEIGHT, 80, BORDER, 2, SHADOWX, 5, SHADOWY, 5, CLOSETEXT, '<img src='+tp_dir+'/images/close_icon.gif style=border:none;/>');
                overlib(overlib_html, CENTERPOPUP, BORDER,1, BGCOLOR,"#333333", CLOSECLICK, STICKY, CAPTION, '<div id=overlib_header>Keyword Length</div>', WIDTH, 490, HEIGHT, 80);
                return false;
	}
	
	keyword =  keyword.replace(/[^a-zA-Z 0-9]+/g,'');
	keyword = keyword.replace(/ /g,"-");
	var category = document.getElementById('category').value;

	
	
	if(category == '')
		category = 0;
	
	if(keyword == '')
		keyword = 'all';
		
	//typeof prev_goto_val != 'undefined'	
		
	if(typeof module == 'undefined' || module == '')
		module = 'products';
		
	
	var root_path = document.getElementById('root_path').value;

	//document.getElementById('search_frm').action = root_path+"-"+keyword+"-"+category+"-1.html";
	document.getElementById('search_frm').action = root_path+"search.php?m="+module+"&keyword="+keyword+"&cat="+category+"&page=0";
	document.getElementById('search_frm').submit();
}


function wh_output()
{

	/*var new_text = '<a onclick=wh_output()  href=javascript:void(0)> Wholesalers ('+count+') <img border=0 src="'+this_domain+'/_directory/common/images/filter_cross_hover.gif"></a>';
	document.getElementById('trader_type_outer').innerHTML = new_text;*/

	if(document.getElementById('only_wholersaler').style.display == 'none')
	{
		document.getElementById('trader_type_outer').style.display = 'none';
		document.getElementById('only_wholersaler').style.display = 'block';
	}
	else
	{
		document.getElementById('trader_type_outer').style.display = 'block';
		document.getElementById('only_wholersaler').style.display = 'none';
	}
}



function newWindow (mypage,myname,w,h,features)
{
  if(screen.width)
  {
	  var winl = (screen.width-w)/2;
	  var wint = (screen.height-h)/2;
  }
  else
  {
	  winl = 0;wint =0;
  }
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;

  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  settings += ' scrollbars=yes ';

  win = window.open(mypage,myname,settings);
  win.window.focus();
}


function tbl_bg(obj)
{
	document.getElementById('contact_info').style.background= '#FEFEFE';
	document.getElementById('lead_info').style.background = '#FEFEFE';
	
	if(document.getElementById('members'))	
		document.getElementById('members').style.background= '#FEFEFE';

	if(document.getElementById(obj))
		document.getElementById(obj).style.background = '#F1FBFF';
}


function toggleCategories(container)
{

	var categories = document.getElementById(container).style.display;
	var hidelink = "hidelink_"+container;

	if(categories == 'none')
	{
		document.getElementById(container).style.display = 'block';
		document.getElementById(hidelink).innerHTML = " <img border=0 src="+this_domain+"/_directory/common/images/leads/minus.jpg>&nbsp;&nbsp;Hide&nbsp;";
		
		if(document.getElementById('prod_h2'))
			document.getElementById('prod_h2').style.display = 'block';
		
	}
	else
	//if(categories == 'block')
	{
		//document.write("this domain : "+this_domain+"/_directory/common/images/leads/plus.jpg");
		document.getElementById(container).style.display = 'none';
		document.getElementById(hidelink).innerHTML = " <img border=0 src="+this_domain+"/_directory/common/images/leads/plus.jpg>&nbsp;&nbsp;Show&nbsp;";	
		if(document.getElementById('prod_h2'))
			document.getElementById('prod_h2').style.display = 'none';		
	}
}



function show_more()
{
	//alert(document.getElementById('max_val').value);	
	var show_hide = document.getElementById('show_hide_county').innerHTML;
	var max_val = document.getElementById('max_val').value;
	var i;
	if(show_hide.indexOf("More") > 0)
	{
		
		
		for(i=7;  i<max_val+1;  i++)
		{
			//alert(i);	
			if(document.getElementById(i))
				document.getElementById(i).style.display = 'block';
		}
		document.getElementById('show_hide_county').innerHTML = '- Hide';
	}
	else
	{
		
		
		for(i=7;  i<max_val+1;  i++)
		{
			//alert(i);	
			if(document.getElementById(i))
				document.getElementById(i).style.display = 'none';
		}
		document.getElementById('show_hide_county').innerHTML = '+ More';

	}
	
}

function show_hide_container(container, imgelement)
{
	if(document.getElementById(imgelement) && document.getElementById(imgelement).src == this_domain + '/_directory/common/images/down.gif')
	{
		document.getElementById(container).style.height = 'auto';
		document.getElementById(container).style.overflow = 'auto';
		document.getElementById(imgelement).src = this_domain + '/_directory/common/images/up.gif';
	}
	else if(document.getElementById(imgelement) && document.getElementById(imgelement).src == this_domain + '/_directory/common/images/up.gif')
	{
		document.getElementById(container).style.height = '24px';
		document.getElementById(container).style.overflow = 'hidden';
		document.getElementById(imgelement).src = this_domain + '/_directory/common/images/down.gif';
	}
}

function load_all_leads(url_path,kw)
{
	kw = kw.replace("_","-");
	
	var l_link = url_path+"/wl-"+kw+"/leads.html";
	//alert(l_link);
	document.getElementById('leads_type_outer').innerHTML = '<a href="'+l_link+'">All <img border=0 src="'+this_domain+'/_directory/common/images/filter_cross_hover.gif"></a>';
}

function load_page(form_action)
{
	var goto_page = document.getElementById('GoToPg').value;
	var form_name = "goto_form";
	var flag = 1;
	if(goto_page != '' || document.getElementById('GoToPg_bottom').value != '')
	{
		if(goto_page == '')
		{
			var goto_page_bottom = document.getElementById('GoToPg_bottom').value;
			if(isNaN(goto_page_bottom))
				flag = 0;
			if(document.getElementById('old_goto_val'))
				var prev_goto_val = document.getElementById('old_goto_val').value;
		}
		else
		{
			if(isNaN(goto_page))
				flag = 0;
		}
		
		if(flag == 1)
		{
		
			if(goto_page == '' && prev_goto_val == '')
			{
				var goto_page = document.getElementById('GoToPg_bottom').value;
			}
		
			if(typeof prev_goto_val != 'undefined' && prev_goto_val != '')	
			{
				var goto_page = prev_goto_val;
			}
		
			if(document.getElementById('GoToPg_bottom').value != '')
			{
				var goto_page = document.getElementById('GoToPg_bottom').value;
				form_name = "goto_form_bottom";
			}
			if((form_action.indexOf("module=companies&body=comp_search&") > -1) || (form_action.indexOf("module=products&body=search&") > -1) || (form_action.indexOf("module=leads&body=search&") > -1) || (form_action.indexOf("module=wholesaleoffers&body=search&") > -1))
			{
				if(goto_page < 1)
					goto_page = 1;
				document.getElementById(form_name).action = form_action+goto_page;
			}
			else	
			if(form_action.indexOf(".html") < 0)
			{
				//alert("form action : "+form_action);
				//alert("goto page : "+goto_page);	
				if(goto_page < 1)
					goto_page = 1;
				document.getElementById(form_name).action = form_action+goto_page+".html";
			}
	
			document.getElementById(form_name).submit();
		}
	}
}

/*ADDED BY FAHAD FARRUKH FOR ADD FAVOURITES SECTION START*/
function add_fav(fav_id, fav_type, container_id)
{
	ajax_page = this_domain+"/_directory/ajax/add_favourites.php?fav_id="+fav_id+"&fav_type="+fav_type;
	$.get(ajax_page,{},function(ajax_response){
		document.getElementById(container_id).innerHTML = ajax_response; 
	});
}
/*ADDED BY FAHAD FARRUKH FOR ADD FAVOURITES SECTION END*/

function ajaxget(url, post_ajax_function)
{
	//alert(2);
	//containerid = containerid.toString();
	var page_request = false;
	try
    {
    // Firefox, Opera 8.0+, Safari
   		 page_request = new XMLHttpRequest();
    }
  	catch (e)
    {
    // Internet Explorer
    	try
      	{
      		page_request = new ActiveXObject("Msxml2.XMLHTTP");
      	}
    	catch (e)
      	{
      		try
        	{
        		page_request = new ActiveXObject("Microsoft.XMLHTTP");
        	}
      		catch (e)
        	{
        		alert("Your browser does not support AJAX!");
        		return false;
        	}
      	}
    }
		
	page_request.onreadystatechange = function()
	{
		//alert(3);
		if (page_request.readyState == 4 && page_request.status == 200 )
		{
			//alert(4);
			post_ajax_function(page_request.responseText);
		}
	}
	if (typeof bustcachevar == 'undefined')
    	{
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();	
	}	
	
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null);
	
}

function swap_div(src_div,des_div)
{
	document.getElementById(src_div).style.display="none";
	document.getElementById(des_div).style.display="block";
}

function swap_classes(src_div,des_div)
{
	document.getElementById(src_div).className = "selected";
	document.getElementById(des_div).className = "";
}

function disableKeyPress(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}

function show_ajax_record(page_value,inner_div)
{
	//if(ajax_page_url.indexOf("/products/") > -1)
		$(".prod_sub").css({"visibility":"hidden"});
	total_link = Math.ceil($("#total_count").val()/$("#total_per_page").val());
	if(page_value > total_link || page_value <= 0 || page_value == "")
		return false;
	url = ajax_page_url;
	table_offset = $("#td_all_data").offset();
	table_height = $("#td_all_data").height() - 75;
	table_width = $("#td_all_data").width();
	div_p = table_height - 30;
	inner_div_style = "";
	if(typeof inner_div !== "undefined")
		inner_div_style = "position:absolute;top:100px;";
	wait_image = "<div align='center' class='page_loading_img' style='width:"+table_width+"px;height:"+table_height+"px;'>";
	wait_image += "<div style='"+inner_div_style+"'><img style='margin-left:-100px;' src='" + this_domain + "/_directory/common/images/loading_slider.gif' border='0' /></div>";
	wait_image += "</div>";
	$("#td_all_data").prepend(wait_image);
	$("html, body").animate({scrollTop: table_offset.top}, 1000);
	get_query = "";
	for(var get_var in ajax_page_func_array)
		get_query += "&" + get_var + "=" + ajax_page_func_array[get_var];
	
	url += "?is_ajax=1&page="+page_value + get_query;
	$.get(url, {}
	,function(str)
	{
		//if(ajax_page_url.indexOf("/products/") > -1)
			$(".prod_sub").css({"visibility":"visible"});
		if(typeof ajax_page_from === "undefined")
			$("#td_all_data").html(str);
		else
		{
			str_data = str.split("@----@");
			$("#div_top_pagination").html(str_data[0]);
			$("#td_all_data").html(str_data[1]);
			$("#div_bottom_pagination").html(str_data[2]);
		}
	});
	return false;
}

// Social Buttons
function soc_btns_change_pos()
{
	// set transprency
	$("#social_buttons").show();
	var browser_width = $(window).width();
	if(browser_width > 1150)
	{
		$("#social_buttons").css('opacity','1');
		$("#social_buttons").hover(function()
		{ 
			$("#social_buttons").css('opacity','1');
		},function(){$("#social_buttons").css('opacity','1');});
	}
	else
	{
		$("#social_buttons").css('opacity','0.7');
		$("#social_buttons").hover(function()
		{ 
			$("#social_buttons").css('opacity','1');
		},function(){$("#social_buttons").css('opacity','0.7');});
	}
	
	//Set Verticale Position
	var browser_height = $(window).height() - 350;
	$("#social_buttons").css('top',browser_height);
	return false;
}
$(document).ready(function(){
	soc_btns_change_pos();
	$(window).resize(function(){
		soc_btns_change_pos();
	});
});

// End - Social Buttons
