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_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_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];}
}

/* Validate Forms */
function validate_text(this_value, this_name) 
{
	if (this_value == '') 
	{
		return this_name+'\n';
	} 
	else 
	{
		return '';
	}
}

function validate_select(this_value, this_name, this_error_choice) 
{
	if (this_value == this_error_choice) 
	{
		return this_name+'\n';
	}
	else 
	{
		return '';
	}
}

function validate_select_multiple(objField, intMin, strName) 
{
	intLenOption = objField.length;
	if (intLenOption < intMin)
	{
		return strName + '\n';	
	}	
	else
	{
		return '';
	}
}

function validate_email(this_value) {
	var re = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if (!re.test(this_value)) {
		return 'Invalid email address \n';
	} else {
		return '';
	}
}

function with_space(strValue)
{
	var i, isWithSpace, strValue, intStrLength, chrToken

	isWithSpace  = false;
	strValue     = strValue.toString()
	intStrLength = strValue.length
	for (i = 0; i < intStrLength; i++) {
		chrToken = strValue.charAt(i)
		if (chrToken == " ") 
		{
			isWithSpace = true
		}
	}
	return isWithSpace
}

function validate_password(strPasswd, strConfirmPasswd) 
{
	strErrorMsg = ''
	if (strPasswd != strConfirmPasswd) 
	{
        strErrorMsg = 'Password doesn\'t match \n'
	}
	else if (strPasswd.length < 4)
	{
		strErrorMsg = 'Password should not be less than 4 characters \n'
	}
	else if (with_space(strPasswd))
	{
		strErrorMsg = 'Password should not be contain spaces \n'
	}
	else
	{
		strErrorMsg = ''
	}
	return strErrorMsg
}

function is_integer(value) {
	var blnInt = true;
	inputStr = value.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);			
		if ((oneChar < "0" || oneChar > "9")) {
			blnInt = false;
		}
	}
	return (blnInt);
}

function is_float(value)
{
     var template = "x.ff";
     new_value = value/1;
     if(isNaN(new_value)) 
	 {	
	 	return false
	 }
     if ((pos = value.indexOf(".")) > 0)
     {
          templatepos = template.indexOf(".");
          tmpf = template.length-templatepos-1;
          valf = value.length-pos-1;
          if(valf > tmpf) return false;
          else return true;
     }
     return true;
}

function display_error_msg(strErrorMsg) 
{
	strErrorMsg = 'Please fill out the following fields correctly : \n' + strErrorMsg;
	alert(strErrorMsg);
	return true;
}

function validate_feedback_form(objForm)
{
	strErrorMsg = ''
	strErrorMsg = strErrorMsg + validate_text(objForm.name.value, 'Name');
	strErrorMsg = strErrorMsg + validate_email(objForm.email.value);
	strErrorMsg = strErrorMsg + validate_select(objForm.recipient.options[objForm.recipient.selectedIndex].value, 'Recipient', '');
	strErrorMsg = strErrorMsg + validate_text(objForm.subject.value, 'Subject');
	strErrorMsg = strErrorMsg + validate_text(objForm.message.value, 'Message');

	if (strErrorMsg) 
	{
		display_error_msg(strErrorMsg);
		return false
	}
	else
	{
		return true
	}
}

function validate_email_to_a_friend_form(objForm)
{
	strErrorMsg = ''
	strErrorMsg = strErrorMsg + validate_text(objForm.your_name.value, 'Your Name');
	strErrorMsg = strErrorMsg + validate_email(objForm.your_email.value);
	strErrorMsg = strErrorMsg + validate_text(objForm.friend_name.value, 'Your Friend\'s Name');
	strErrorMsg = strErrorMsg + validate_email(objForm.friend_email.value);

	if (strErrorMsg) 
	{
		display_error_msg(strErrorMsg);
		return false
	}
	else
	{
		return true
	}
}
