var isIE=document.all?true:false;

function checkchars(entered,alertbox) {
var max=255;
with (entered)
	{
if (value.length > max) {
if (alertbox!="") {alert(alertbox);} return false;}
	    else {return true;}
}
} //- Fin With


function checked(entered, alertbox)
{
	with (entered)
	{
	  if (!checked)
	  {if (alertbox!="") {alert(alertbox);} return false;}
	    else {return true;}
	}
} 


function excludestringvalidation(entered, toexclude, alertbox)
{  
with (entered)
	{
	index_string=value.indexOf(toexclude);
	if (index_string>-1)
		{if (alertbox) {alert(alertbox);} return false;}
		else {return true;}
	}
}

function excludespecialcharacters(entered, alertbox)
{  
  return excludestringvalidation(entered, '"', alertbox)
 }
 
function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
	  if (value==null || value=="")
	  {
	  	if (alertbox!="") 
	  	{
	  		alert(alertbox);
	  	}
	  	return false;
	  }
	  else 
	  {
	  	return true;
	  }
	}
} 


function lengthvalidation(entered, maxLength, alertbox){
    if (entered.value.length > maxLength){
        alert(alertbox);
        return false;
    }
    return true;
}

function minlengthvalidation(entered, minLength, alertbox){
    if (entered.value.length < minLength){
        alert(alertbox);
        return false;
    }
    return true;
}

function emailvalidation(entered, alertbox)
{
with (entered)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function digitvalidation(entered, min, max, alertbox, datatype)
{// Explained at www.echoecho.com/jsforms.htm
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
  {smalldatatype=datatype.toLowerCase();
   if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
  }
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function obfuscate(email,t){
	output = "";
	for (i=0;(i<email.length);i++){ output += "&#" + email.charCodeAt(i) + ";"; }
	if(t==0){ return('<a HREF="mailto:' + output + '">' + output + '</a>'); }
	else{ return(output); }
}


function changeColor(item_name, bgcolor, show) {
		td_obj = eval('document.getElementById("td_' + item_name + '")');
		a_obj = eval('document.getElementById("a_' + item_name + '").style');
		td_obj.bgColor = bgcolor;
		if(show) a_color = "#ff6600";
				else a_color = "#ffcc00";
		a_obj.color = a_color;
}

function windowOpen(file, name, prop) {
   w = window.open(file,name,prop);
   w.focus();
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function open_picture2(picture, sizeWidth, sizeHeight, text)
{
	// TODO Change it in production!!!!
	picture = "/medishare" + picture;
	props = "width=" + sizeWidth;
	props = props + ",height=" + sizeHeight;
	props = props + ",location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
	windowOpen(picture, "picture", props);
} 

function open_picture(picture, sizeWidth, sizeHeight, comments)
{
	// TODO Change it in production!!!!
	picture = "/medishare" + picture;
	props = "width=" + sizeWidth;
	if (comments.length == 0) {
		props = props + ",height=" + sizeHeight;
		} else {sizeHeight = sizeHeight + 50;
		props = props + ",height=" + sizeHeight;
		}
	props = props + ",location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
	url = "popup_picture.php?picture=" + picture + "&message=" + comments;
	windowOpen(url, "prop", props);
} 

 
