﻿$jq.namespace('MatchCore.UI.Search');
$jq(document).ready(function(){ 
  $jq("#txtHandle").keypress(function (e) {
    if (e.which == 13) {
      location.href = "/usearch/usearchdl.aspx?lid=226&handle=" + escape($jq(this).val());
      return false;
    }
  });
  
  $jq("#txtKeyword").keypress(function (e) {
    if (e.which == 13) {
      location.href = "/kwsearch/kwsearch.aspx?lid=108&KW=" + escape($jq(this).val());
      return false;
    }
  });
  $jq("#txtMatchWords").keypress(function (e) {
    if (e.which == 13) {
      location.href = "/mwsearch/mwsearch.aspx?EXEC=go&TAG=" + escape($jq(this).val());
      return false;
    }
  });
  
  $jq('.cssGoButton').click(function () {
    var url = $jq('.cssSavedSearchList :selected').val();
    location.href = url;
    return false;
  });
  
  
})


function alphaNumericCheck(){
  
	var regex=/[^0-9a-zA-Z]/;
	if(regex.test(document.formName.zip.value)){
		alert("Please enter a valid ZIP code.");
		document.formName.action = "";
		document.formName.target = "";
		return false;
	} else {
		document.formName.action = "http://cityguides.msn.com";
		document.formName.target = "_new";
		document.formName.submit();
		return true;
	}
	return isNotAlpha;
}


function UsernameSearchSubmit()
{
  location.href='/usearch/usearchdl.aspx?lid=226&handle=' + escape(document.getElementById('txtHandle').value);
}
function KeywordSearchSubmit()
{
  location.href='/kwsearch/kwsearch.aspx?lid=108&KW=' + escape(document.getElementById('txtKeyword').value);
}
function MatchWordsSearchSubmit()
{
  location.href='/mwsearch/mwsearch.aspx?EXEC=go&TAG=' + escape(document.getElementById('txtMatchWords').value);
}

MatchCore.UI.Search.Pager = function() {
    var _container;
    var _pageSize = 0;
    var _currentPage = 1;
    var _totalPages = 0;
    var _elmCollection = new Array();

    var wireUpControls = function() {
        $jq("li", _container).each(function() {
            elmCollection.push(this);
        });
        totalPages = collection.length / pageSize;
        $jq(".nextPage").bind("click", showNextPage);
    }
    var hidePages = function() {
        $jq(collection).each(function() {
            $jq(this).hide();
        });
    }
    var showNextPage = function() {
        hidePages();
        if (currentPage >= totalPages) {
            currentPage = 0;
        }
        var startIndex = currentPage * pageSize;
        var endIndex = startIndex + pageSize;
        currentPage++;
        for (startIndex; startIndex <= endIndex; startIndex++) {
            $jq(collection[startIndex]).show();
        }
    }
    return {
        init: function(opts) {
            _container = opts.container;
            _pageSize = opts.pageSize;
            wireUpControls();
            showNextPage();
        }
    }

}
