/*
	getElementsByClass - algorithm by Dustin Diaz, shortened by Pawel Knapik
*/
function getElementsByClass(s,n,t) {  // class, node, tag
	var c=[], e=(n?n:document).getElementsByTagName(t?t:'*'),r=new RegExp("(^|\\s)"+s+"(\\s|$)");
	for (var i=0,j=e.length;i<j;i++) r.test(e[i].className)?c.push(e[i]):''; return c }
	
/*
	$() based on prototype.js dollar function idea, optimized by Pawel Knapik.
*/
function $(){var r=[],a=arguments;for(var i=0,j=a.length;i<j;i++){(typeof a[i]=='string')?(r.push(document.getElementById(a[i]))):(r.push(a[i]))}
return(r.length==1)?r[0]:r}

/*

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

*/


// By Simon Willison
function addLoadEvent(func) {
   var oldonload = window.onload;
   if (typeof window.onload != 'function') {
      window.onload = func;
   }
   else {
      window.onload = function() {
      oldonload();
      func();
      }
    }
}

function cookiesAllowed() {
   setCookie('checkCookie', 'test', 1);
   if (getCookie('checkCookie')) {
      deleteCookie('checkCookie');
      return true;
   }
   return false;
}

function setCookie(name,value,expires, options) {
   if (options===undefined) { options = {}; }
   if ( expires ) {
      var expires_date = new Date();
      expires_date.setDate(expires_date.getDate() + expires)
   }
   document.cookie = name+'='+escape( value ) +
      ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + 
      ( ( options.path ) ? ';path=' + options.path : '' ) +
      ( ( options.domain ) ? ';domain=' + options.domain : '' ) +
      ( ( options.secure ) ? ';secure' : '' );
}

function getCookie( name ) {
   var start = document.cookie.indexOf( name + "=" );
   var len = start + name.length + 1;
   if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
      return null;
   }
   if ( start == -1 ) return null;
   var end = document.cookie.indexOf( ';', len );
   if ( end == -1 ) end = document.cookie.length;
   return unescape( document.cookie.substring( len, end ) );
}

function deleteCookie( name, path, domain ) {
   if ( getCookie( name ) ) document.cookie = name + '=' +
      ( ( path ) ? ';path=' + path : '') +
      ( ( domain ) ? ';domain=' + domain : '' ) +
      ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

/*

USAGE:

// Check if cookies are allowed in this browser.
if cookiesAllowed() { 
  alert('you can set cookies');
} else {
  alert("This browser doesn't allow cookies.");
}
// Create a cookie named myCookie with a value of 'Peanut Butter'
// The cookie will expire in 10 days.
setCookie('myCookie','Peanut Butter', 10);

// Retreive the value of 'myCookie'
var userCookie = getCookie('myCookie');

// Delete 'myCookie'
deleteCookie('myCookie');	




*/


// functions by jonathan gala: www.jongala.com

function isBlank(val) {
	if(val==null){return true;}
	var b = /\S/;
	var match = b.test(val);
	return !match;
}


function checkemail(email) {
	/* This RegExp requires an address of the form xxx@xxx.xxx where xxx is one or more alphanumeric characters.  The last xxx can't have any numbers.  */
	var address= /[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}/;
	var match = address.test(email);
	return match;
}

function checkphone(num) {
	/* This functionjust strips non-digits, and checks to see that there are at least 10 numbers left over */
	x = num.replace(/[\D]*/g,"");
	if (x.length<10) {
		return false;
	} else {
		return true;
	}
}


function msg(s,c) {	c?$('msgbox').innerHTML+= " -- " + s:$('msgbox').innerHTML=s;};


function makePopups() {
	atags = document.getElementsByTagName("A");
	r=new RegExp("(^|\\s)" + "poplink" + "(\\s|$)");
	for (var i=0; i<atags.length ; i++) {
		if(r.test(atags[i].className)) {
			//alert("pop");
			atags[i].onclick = function () {
				window.open(this.href,'_blank','width=570,height=400,scrollbars=yes,resizable=yes');
            	return false;
			}
			atags[i].title += " (Opens in new window) ";
		}
	}
}


function makeExtLinks() {
	var pops = new Array();
	atags = document.getElementsByTagName("A");
	r=new RegExp("(^|\\s)" + "extlink" + "(\\s|$)");
	w=new RegExp("(^|\\s)" + "confirm" + "(\\s|$)");
	warntext=(typeof(warntext)!='undefined')?warntext:"You are now leaving the ValstarSolution.com web site. Links to other sites are provided as a convenience to the visitor. Endo Pharmaceuticals accepts no responsibility for the content of linked sites.";
	for (var i=0; i<atags.length ; i++) {
		if(r.test(atags[i].className)) {
			if(w.test(atags[i].className)) {
				atags[i].onclick = function () {
					if(window.confirm(warntext)) {
						window.open(this.href,'_blank','width=640,height=400,toolbar,location,status,scrollbars,resizable');
						return false;
					} else {
						return false;
					}
				}
			} else {
				atags[i].onclick = function () {
					window.open(this.href,'_blank','width=640,height=400,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes');
					return false;
				}
			}
			atags[i].title += " (Opens in new window) ";
		}
	}
}

function makeDBLinks() {
	var pops = new Array();
	atags = document.getElementsByTagName("A");
	r=new RegExp("(^|\\s)" + "dblink" + "(\\s|$)");
	w=new RegExp("(^|\\s)" + "affirm" + "(\\s|$)");
	warntext2=(typeof(warntext2)!='undefined')?warntext2:"By providing your name, address and other requested information, you are giving Endo Pharmaceuticals and other parties working with us the permission to communicate with you about VALSTAR. We will not sell your name or other personal information to any other party for their marketing use.";
	for (var i=0; i<atags.length ; i++) {
		if(r.test(atags[i].className)) {
			if(w.test(atags[i].className)) {
				atags[i].onclick = function () {
					if(window.confirm(warntext2)) {
						window.open(this.href,'_self','width=640,height=400,toolbar,location,status,scrollbars,resizable');
						return false;
					} else {
						return false;
					}
				}
			} else {
				atags[i].onclick = function () {
					window.open(this.href,'_self','width=640,height=400,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes');
					return false;
				}
			}
			atags[i].title += " (Opens in new window) ";
		}
	}
}

function makeHCPLinks() {
	var pops = new Array();
	atags = document.getElementsByTagName("A");
	r=new RegExp("(^|\\s)" + "hcplink" + "(\\s|$)");
	w=new RegExp("(^|\\s)" + "affirm" + "(\\s|$)");
	warntext3=(typeof(warntext3)!='undefined')?warntext3:"This site contains information for licensed healthcare professionals in the United States.  By entering this Web site you acknowledge that you are a licensed healthcare professional practicing in the United States.";
	for (var i=0; i<atags.length ; i++) {
		if(r.test(atags[i].className)) {
			if(w.test(atags[i].className)) {
				atags[i].onclick = function () {
					if(window.confirm(warntext3)) {
						window.open(this.href,'_self');
						return false;
					} else {
						return false;
					}
				}
			} else {
				atags[i].onclick = function () {
					window.open(this.href,'_self');
					return false;
				}
			}
			
		}
	}
}

addLoadEvent(makePopups); // init popups
addLoadEvent(makeExtLinks); // init popups
addLoadEvent(makeDBLinks); // init popups
addLoadEvent(makeHCPLinks); // init popups