

function SetCookie (name, value) 
   {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   //var path = (argc > 3) ? argv[3] : null;
   var path="/";
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
   }

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}                                

            
function toggle(id)
{
    if (document.getElementById('content'+id).style.display == 'none') 
	{
      document.getElementById('content'+id).style.display = 'block';
      document.getElementById('handle'+id).innerHTML = 'Hide';
    } 
    else 
	{
      document.getElementById('content'+id).style.display = 'none';
      document.getElementById('handle'+id).innerHTML = 'Read more';
    }
}

function SetFocus(sCtrlID,e)
{
  if (e.keyCode == 13)
  {
    e.cancel = true;
    document.getElementById(sCtrlID).focus();
    return false;
  } 
   return true;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail() {

	var fld=document.download.Email;
	var color='#FFFFE1';
    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 = color;
        error = "You didn't enter an email address";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = color;
        error = "Enter a valid email address";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = color;
        error = "The email address contains illegal characters";
    } else {
        fld.style.background = 'white';
    }
    if (error!="") 
	{
		mydiv = document.getElementById("emailmessage");
		mydiv.innerHTML=error;
		//mydiv.style.visibility = "block";
		fld.focus(); 
		return false;
	}
	else 
	{
	return true;
	}
}

function OnKeyDown(sForm,e)
{
  if (e.keyCode == 13)
  {  

	if (sForm != "download")
	{
		e.cancel = true;
		document.forms[sForm].submit();
		return false;  
	}
	if (validateEmail())
	{
		e.cancel = true;
		document.forms[sForm].submit();
	}
    return false;
  } 
  return true;

}			


if (document.referrer.indexOf("xlinesoft.com") == -1 &&  document.cookie.indexOf("referrer") == -1) {
 // this referrer is from off site
  var expdate = new Date (); 
  expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
  SetCookie("referrer", document.URL + '+' + document.referrer, expdate, '', 'www.xlinesoft.com');
}

