
function writeCookie(name, value) {
	if(name != "") {
		document.cookie = name + "=" + escape(value);
	}
}

function readCookie(name) {
	var cookieSet=document.cookie;
	
	var cookieNum=cookieSet.indexOf(name+'=');
	if(cookieNum < 0) {
		return '';
	}
	cookieSet=cookieSet.substring(cookieNum);

	cookieNum=cookieSet.indexOf(';');
	if(cookieNum >= 0) {
		cookieSet=cookieSet.substring(0, cookieNum);
	}

	var cookieArray=cookieSet.split('=');
	if(cookieArray.length > 1) {
		return unescape(cookieArray[1]);
	} else {
		return '';
	}
} 

/*
 * 'varName' is the name of the
 * variable in the URL address
 * to be read in.
 *
 * 'def' is the value returned
 * if the variable is not found.
 *
 */
function getURLvar(varName, def) {
	var str = '' + location.search;
	if(str == '') {
		return def;
	} else {
		var fullURL, start, end;

		varName = (varName.toLowerCase()) + '=';
		fullURL = str.toLowerCase();

		start = fullURL.indexOf(varName, start);
		if(start == -1) {
			return def;
		} else {
			end = fullURL.indexOf('&', start);
			if(end == -1) {
				end = fullURL.indexOf('#', start);
				if(end == -1) {
					end = fullURL.length;
				}
			}
			return str.substring(start + varName.length, end);
		}
	}
}


/*
 * This gets around the parseInt() bug.
 *
 * ie. Try this: parseInt('012');
 */
function trueInt(zerostart) {
	return parseInt(parseFloat(zerostart));
}


function fullimage(fname) {
	   
		 var imagepath = '<BODY BGCOLOR="#323792"><TABLE><TR><TD><CENTER><IMG SRC="../portfolios/'+fname+'"></TD></TR>';
		 imagepath += '<TR><TD><CENTER><INPUT TYPE="button" NAME="close" VALUE="Close" onClick="self.close()"></TD></TR></TABLE></BODY>'; 
//		 alert(imagepath);
		 newWin = open('./popup_image.html', 'image','width=400, height=300, scrollbars=yes, resizable=yes');
       newWin.document.write(imagepath);
       newWin.focus();
					 
} 

function emailCheck (emailStr) {

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)")
	return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
	// user is not valid
	    alert("The Email username doesn't seem to be valid.")
	    return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Email Destination IP address is invalid!")
		return false
	    }
    	}
	return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The Email domain name doesn't seem to be valid.")
		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	   domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   alert("The Email address must end in a three-letter domain, or two letter country.")
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This Email address is missing a hostname!"
	   alert(errStr)
	   return false
	}

	return true;
}
//  End -->


