
function myopen(filename){
        window.open(filename,'_blank','left=10,top=10,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600,height=480')
}

function displaynonemainpot() {
    mainpot.className='displaynone';
    close2.className='displaynone';
    spand2.className='displayyes';
}

function displayyesmainpot() {
    mainpot.className='displayyes';
    close2.className='displayyes';
    spand2.className='displaynone';
}


function checkdel(form,a)
{   
    var ids ="";
    for (var i=0;i < form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name.indexOf(a) > -1){
       if(e.checked){
          ids = ids + e.value + ",";
       }
    }
    }
    form.id.value = ids + "0";
    return true;
}

function isDel(tagName) {
	var x = window.confirm(tagName);
	if (x)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function CheckAll(form,a)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name.indexOf(a) > -1)
       e.checked = form.chkall.checked;
    }
}

function fill_checkbox(box, vals)
{
    var i;
    for (i=0; i<box.length; i++){
        var s = box[i].value;
        if ( s.length > 0 && vals.indexOf(s.charAt(0)) > -1 ) {
             box[i].checked=true;
        }
    }
}
function collect_checkbox_values(box)
{
    var val = "";
    var i;
    for (i=0; i<box.length; i++){
        if ( box[i].value.length > 0 && box[i].checked == true) {
            val = val + box[i].value.charAt(0);
        }
    }
    return val;
}

/* Obtains the string of character the byte length */
function strlen(str)
{
	var i;
	var len;
	
	len = 0;
	for (i=0;i<str.length;i++)
	{
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}

/* Examination string of character whether for spatial */
function isnull(str)
{
    var i;
    
    for (i=0;i<str.length;i++)
    {
        if (str.charAt(i)!=' ') return false;
    }
    return true;
}

/* Whether the examination string of character all is a numeral */
function isnumber(str)
{
	var number_chars = "1234567890";
	var i;

	for (i=0;i<str.length;i++)
	{
		if (number_chars.indexOf(str.charAt(i))==-1) return false;
	}
	return true;
}

/* The examination assigns the text frame to input whether legitimately */
function verifyInput(input)
{
	var image;
	var i;
	var error = false;

	/* Length verification */
	if (strlen(input.value)>parseInt(input.maxsize))
	{
		alert(input.chname+"Surpasses the greatest length"+input.maxsize);
		error = true;
	}
	else
	/* Non-spatial verification */
	if (input.nullable=="no"&&isnull(input.value))
	{
		alert(input.chname+"Cannot be spatial");
		error = true;
	}
	else
	{
 		/* Data type verification */
		switch(input.datatype)
		{
		 	case "number": if (isnumber(input.value)==false)
							{
								alert(input.chname+"The value should all be a numeral");
								error = true;
							}
							break;
		        case "email": if (checkemail(input.value)==false && !isnull(input.value))
							{
								alert(input.chname+"The correct form isabc@abc.com!");
								error = true;
							}
							break;
			case "date": if (IsDate(input.value,'-')==false && !isnull(input.value))
							{
								alert(input.chname+"The date form should be2005-08-12 !");
								error = true;
							}
							break;
			/* May increase many in here from the definition data type verification judgment */
			/*  case datatype1: ... ; break;        */
			/*  case datatype2: ... ; break;        */
			/*  ....................................*/
			default		: break;
		}
	}
	/* Or cancels the police whether there is according to the wrong establishment to show the symbol */
	if (error)
	{
		image = document.getElementById("img_"+input.name);
		image.src="http://pub.chemindex.com/js/img/warning.gif";
		return false;
	}
	else
	{
		image = document.getElementById("img_"+input.name);
		image.src="http://pub.chemindex.com/js/img/space.gif";
		return true;
	}
}

/* The examination assignsFORMThe form all should the element which examines (these have from definition attribute element) whether legitimate, this function uses in the formonsubmitEvent */
function verifyAll(myform)
{
	var i;

	for (i=0;i<myform.elements.length;i++)
	{
	    /* Must does not give from the definition attribute element pays attention to */
		if (myform.elements[i].chname+""=="undefined") continue;
		/* Verifies the current element */
		if (verifyInput(myform.elements[i])==false)
		{
			myform.elements[i].focus();
			return false;
		}
	 }
	 return true;
}

function checkemail(string){
   if(string.length!=0){
    if (string.charAt(0)=="." || string.charAt(0)=="@"|| string.indexOf('@', 0) == -1 || string.indexOf('.', 0) == -1 || string.lastIndexOf("@")==string.length-1 || string.lastIndexOf(".") ==string.length-1)
     {
      //alert("EmailThe address form is not correct! The correct form isabc@abc.com!!");
      return false;
      }
   }
   else{
     //alert("EmailThe address cannot be spatial!");
     return false;
   }
   return true;
}

function IsDate(DateString , Dilimeter)
{
if (DateString==null) return false;
if (Dilimeter=='' || Dilimeter==null)
Dilimeter = '-';
var tempy='';
var tempm='';
var tempd='';
var tempArray;
if (DateString.length<8 && DateString.length>10)
return false; 
tempArray = DateString.split(Dilimeter);
if (tempArray.length!=3)
return false;
if (tempArray[0].length==4)
{
tempy = parseInt(tempArray[0],10);
tempd = parseInt(tempArray[2],10);
}
else
{
tempy = parseInt(tempArray[2],10);
tempd = parseInt(tempArray[1],10);
}
tempm = parseInt(tempArray[1],10);

var tDateString = tempy + '/'+tempm + '/'+tempd+' 8:0:0';//Adds for eight hours east is because we are in eight areas
var tempDate = new Date(tDateString);
if (isNaN(tempDate))
return false;
if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm)-1) && (tempDate.getDate()==parseInt(tempd)))
{
return true;
}
else
{
return false;
}
}

function setCookie(name,value,expiry,path,domain,secure){
var nameString = name + "=" + value;
var expiryString = (expiry == null) ? "" : " ;expires = "+ expiry.toGMTString();
var pathString = (path == null) ? "" : " ;path = "+ path;
var domainString = (path == null) ? "" : " ;domain = "+ domain;
var secureString = (secure) ?";secure" :"";
document.cookie = nameString + expiryString + pathString + domainString + secureString;
} 

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function deleteCookie(name){
var expires = new Date();
expires.setTime (expires.getTime() - 1);

setCookie( name , "Delete Cookie", expires,null,null,false);
} 
