function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie(name,value,expires,path,domain,secure) {
     document.cookie = name + "=" +escape(value) +
         ( (expires) ? ";expires=" + expires.toGMTString() : "") +
         ( (path) ? ";path=" + path : "") + 
         ( (domain) ? ";domain=" + domain : "") +
         ( (secure) ? ";secure" : "");
 }

qstr = location.search; 
qstr = qstr.substring(qstr.indexOf("?")+1).toUpperCase(); 

pattern = /\s*&\s*/;  // standard regular expression
pairs = qstr.split (pattern);

target_param = "SOURCEID"
result = "";
for (co=0; co<pairs.length; co++) {
     if (pairs[co].indexOf(target_param) == 0){
         result = pairs[co].substring(pairs[co].indexOf("=")+1)
         Interger_Check = /\d{20}/; 
         if (result.length == 20 && result.search(Interger_Check) != -1){
             var expdate = new Date ();
             expdate.setTime (expdate.getTime() + (30 * 24 * 60 * 60 * 1000)); // 2 weeks from now 
             SetCookie ("SourceID", result, expdate, '/');
         }
     }
}

