var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

function DropDownCheck(DropDown, AlertMessage) 
{ 
	if (AlertMessage == null) AlertMessage = "Please select an item in the drop down.";
  	SelectedPosition = DropDown.selectedIndex;
  	if (SelectedPosition != -1 && DropDown.options[SelectedPosition].value > "") {
		return true;
  	} else {
    	alert(AlertMessage);
		return false;
  	}
}

function TextCheck(inString,AlertMessage) {
	if (AlertMessage == null) AlertMessage = "Please fill in the text box.";
	if (inString == null || inString == "") {
		alert(AlertMessage);
		return false;
	}
	return true;
}

function ValidEmail(email) 
{
	invalidChars = " /:,;"
	
	if (email == "") {      // cannot be empty
		alert('Please provide an email.');
		return false;
	}
	for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			alert('Email contains invalid characters.');
			return false;
		}
	}
	atPos = email.indexOf("@",1)   // there must be one "@" symbol
	if (atPos == -1) {
		alert('Email must have one "@" symbol');
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) { // and only one "@" symbol
		alert('Email must have only one "@" symbol');
		return false;
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {     // and at least one "." after the "@"
		alert('Email must have at least one "." after the "@".');
		return false;
	}
	if (periodPos+3 > email.length) {  // must be at least 2 characters after the "."
		alert('Email must have at least 2 characters after the ".".');
		return false;
	}
	return true;
}

function ValidateForm(Form) 
{
	if (DropDownCheck(Form.Gender,'Please select a Gender.') 
			&& DropDownCheck(Form.Age,'Please select an Age.') 
			&& DropDownCheck(Form.Ethnicity,'Please select a Ethnicity.')
			&& TextCheck(Form.UploadedPicture.value,'Please provide an image.')
			&& TextCheck(Form.FullName.value,'Please provide a Name.')
			&& ValidEmail(Form.Email.value)
	   ) {
		Form.submit();
		return true;
	}
	return false;
}


function ValidateCropUpload(Form) 
{ 
	if (TextCheck(Form.UploadedPicture.value,'Please provide a new image.')) {
		Form.A.value='NewImage';
		Form.submit();
		return true;
	}
	return false;
}

function ValidateCrop(Form) 
{ 
	if (Form.cropimage_width.value > 20 && Form.cropimage_height.value > 20) {
		Form.A.value='CropImage';
		Form.submit();
		return true;
	} else {
		alert('Make sure you crop around the face in the picture provided.')
	}
	return false;
}

function ViewIt(one,way){
	//alert(one);
	on = 1;
	style	= (way == "vis")? "visibility" : "display";
	chek1	= (way == "vis")? "visible" : "block";
	chekon	= (way == "vis")? "hidden" : "none";
	chekoff	= (way == "vis")? "visible" : "block";
	
	var left = "document.getElementById('"+one+"').style."+style;
	//alert(eval(left));
	if(eval(left) == chek1){
		eval(left+" = \""+chekon+"\"");
	}else{
		eval(left+" = \""+chekoff+"\"");
	}
	//alert(eval(left))
}
