function checkMoveCursor(source, target, maxLength) {
  var noSpace = source.value;
  source.value = noSpace.replace( /\s/g, '' );
  
  if (source.value.length == maxLength) {
    target.focus();
  }
}

function getChkBoxValue(chkbox)
{
	for (i=0;i<chkbox.length;i++) 
	{ 
		if (chkbox[i].selected) {return chkbox[i].value; }
	}
}

function empty(x) { 
    if (x.length > 0) {
		return false; 
    }
    return true;    
}
function strip(x) {
    if (x.length < 1) { 
		return x;
    } 
    return x.replace(/^\s+|\s+$/g,'');
}

function validatePhone(phone) {
	var filter1 = /^[1-9]\d{2}-\d{3}-\d{4}$/;
	var filter2 = /^[1-9]\d{2} \d{3} \d{4}$/;
	if (!filter1.test(strip(phone)) && !filter2.test(strip(phone))) {
		return false;
	}
	return true;
}



function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function isValidDate(input){
	var validformat=/^\d{1,2}\/\d{1,2}\/\d{4}$/ 
	var returnval=false
	if (validformat.test(input.value)){
		var monthfield=input.value.split("/")[0]
		var dayfield=input.value.split("/")[1]
		var yearfield=input.value.split("/")[2]
		var dayobj = new Date(yearfield, monthfield-1, dayfield)
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			returnval==false
		else
			returnval=true
	}
	return returnval
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

// ---------------------------------------------------------------------------------
// Create XML request.
// -----------------------------------------------------------------------------------
function CreateXMLHTTP() {
  var http;
  try {
    http = new XMLHttpRequest();  /* e.g. Firefox */
  } catch(e) {
    try {
      http = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
    } catch (e) {
      try {
        http = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
      } catch (e) {
        http = false;
      }
    }
  }
  return http;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function showCookieUserPanel() 
{
	  document.getElementById("userName").innerHTML = getCookie('userName');
	  document.getElementById("pwd").value = getCookie('anglerPwd') ;
	  //alert(document.cookie);
}

function logout() {
	createCookie('userName',"",-1);
	createCookie('pwd',"",-1);
}

function ToggleContent(d) {
	if (document.getElementById(d).style.display == 'none')
	{ ShowContent(d); }
	else
	{ HideContent(d); }
}

function HideContent(d) {
document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
document.getElementById(d).style.display = "block";
}

function shareLinkFB(title, anchor) {
	var shareURL = '';
	//clean up share URL # sign if available
	if (location.href.indexOf("#") > -1)
	{
		shareURL = location.href.substring(0, location.href.indexOf("#"));
	} else
	{
		shareURL = location.href;
	}

	// clean up share URL existing anchor param if available
	if (shareURL.indexOf("&anchor=") > -1)
	{
		shareURL = shareURL.substring(0, shareURL.indexOf("&anchor="));
	}

	if (anchor!= '')
	{
		if (shareURL.indexOf("?") > -1)
		{
			shareURL = shareURL + '&anchor=' + anchor;
		}else
		{
			shareURL = shareURL + '?z9=1&anchor=' + anchor;
		}
	}	
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(shareURL)+'&t='+encodeURIComponent(title),'fbshare','toolbar=0,status=0,width=626,height=436');
}





function shareLinkTwitter(title, anchor) {
var shareURL = '';
//clean up share URL # sign if available
if (location.href.indexOf("#") > -1)
{
	shareURL = location.href.substring(0, location.href.indexOf("#"));
} else
{
	shareURL = location.href;
}

// clean up share URL existing anchor param if available
if (shareURL.indexOf("&anchor=") > -1)
{
	shareURL = shareURL.substring(0, shareURL.indexOf("&anchor="));
}

if (anchor!= '')
{
	if (shareURL.indexOf("?") > -1)
	{
		shareURL = shareURL + '&anchor=' + anchor;
	}else
	{
		shareURL = shareURL + '?z9=1&anchor=' + anchor;
	}
}
window.open('http://twitter.com/home?status=' + encodeURIComponent(title) + ' ' + encodeURIComponent(shareURL), 'twittershare','toolbar=0,status=0,width=626,height=436')
}

