// form validation function //

function CheckReq(form){
	
	
	var Name		=	form.Name.value;//alert(name);
  var Email			=	form.Email.value;
  
  var EmailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
  if(Name == "") {
    inlineMsg('Name','You must enter your name.',2);
    return false;
  }
  if(Email == "") {
    inlineMsg('Email','You must enter your e-mail address.',2);
    return false;
  }
  if(!Email.match(EmailRegex)) {
    inlineMsg('Email','You have entered an invalid e-mail address.',2);
    return false;
  }
  return true;
	
	}


function check(form) {
  var CatId			=	form.CatId.value;//alert(name);
  var SubCatId		=	form.SubCatId.value;
  var Ptitle		=	form.Ptitle.value;
  var OriginalPrice	=	form.OriginalPrice.value;
  var SalePrice		=	form.SalePrice.value;
  var Width			=	form.Width.value;
  var Height		=	form.Height.value;
  
  if(CatId == "") {
    inlineMsg('CatId','You must select a category.',2);
    return false;
  }
  if(SubCatId == "") {
    inlineMsg('SubCatId','You must select a sub-category.',2);
    return false;
  }
  if(Ptitle == "") {
    inlineMsg('Ptitle','You must enter a title.',2);
    return false;
  }
  if(OriginalPrice == "") {
    inlineMsg('age','You must enter an original price.',2);
    return false;
  }
  return true;
}

function loginCheck(form) {
  var user			=	form.user.value;//alert(name);
  var pass		=	form.pass.value;
  
  if(user == "") {
    inlineMsg('user','You must enter a username.',2);
    return false;
  }
  if(pass == "") {
    inlineMsg('pass','You must enter a password.',2);
    return false;
  }
  return true;
}




function check_join_hcn(form){

  var name_first		=	form.name_first.value;//alert(name);
  var name_last			=	form.name_last.value;
  var email				=	form.email.value;
  var zipcode			=	form.zipcode.value;
  var customercategory	=	form.customercategory.value;
  var howhear			=	form.howhear.value;
  
  var EmailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var NumRegex = /[0-9]/;
  
  if(name_first == "") {
    inlineMsg('name_first','You must enter first name.',2);
    return false;
  }
  if(name_last == "") {
    inlineMsg('name_last','You must enter last name.',2);
    return false;
  }
  if(email == "") {
    inlineMsg('email','You must enter e-mail address.',2);
    return false;
  }
  if(!email.match(EmailRegex)) {
    inlineMsg('email','You have entered an invalid e-mail address.',2);
    return false;
  }
  /*if(zipcode == "") {
    inlineMsg('zipcode','You must enter original price.',2);
    return false;
  }
  if(!zipcode.match(NumRegex)) {
    inlineMsg('email','Zipcode should be numeric.',2);
    return false;
  }
  if(customercategory == "") {
    inlineMsg('customercategory','You must enter original price.',2);
    return false;
  }
  if(howhear == "") {
    inlineMsg('howhear','You must enter original price.',2);
    return false;
  }*/
  return true;

}

function check_comment(form){
	
 var Name		=	form.Name.value;//alert(name);
  var Email			=	form.Email.value;
  var CommentText				=	form.CommentText.value;
  
  var EmailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var NumRegex = /[0-9]/;
  
  if(Name == "") {
    inlineMsg('Name','You must enter your name.',2);
    return false;
  }
  
  if(Email == "") {
    inlineMsg('Email','You must enter e-mail address.',2);
    return false;
  }
  if(!Email.match(EmailRegex)) {
    inlineMsg('Email','You have entered an invalid e-mail address.',2);
    return false;
  }
  
  if(CommentText == "") {
    inlineMsg('CommentText','You must enter a comment.',2);
    return false;
  }
  
  
  return true;
}















	//Date Format: mm/dd/yy (02/15/09)
	//if (!isValidDate(PosDate)){ 
//		inlineMsg('PosDate','You have entered an invalid date.',2);
//		return false;
//  }
//	
//
//
//
////Date Validation Code
//
//function isValidDate(ctrl){
//	
//	var dateStr = ctrl;
//	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
//	var matchArray = dateStr.match(datePat); // is the format ok?
//	if (matchArray == null){
//		//alert("Invalid date format. Please enter the date in the MM/DD/YY format (example: 1/15/08) or select a date by clicking the calendar icon.")
//		//ctrl.focus();
//		return false;
//	}
//	month = matchArray[1]; // parse date into variables
//	day = matchArray[3];
//	year = matchArray[4];
//	if (month < 1 || month > 12){ 
//	// check month range
//		//alert("Month must be between 1 and 12.");
//		return false;
//	}
//	if (day < 1 || day > 31){
//		//alert("Day must be between 1 and 31.");
//		return false;
//	}
//	if ((month==4 || month==6 || month==9 || month==11) && day==31){
//		//alert("Month "+month+" doesn't have 31 days!")
//		return false
//	}
//	if (month == 2){ 
//	// check for february 29th
//		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
//		if (day>29 || (day==29 && !isleap)) {
//		//alert("February " + year + " doesn't have " + day + " days!");
//		return false;
//		}
//	}
//	return true; // date is valid
//}
//End Date Validation Code



























////			RED ALERT FOR BIGNNERS			//////////////


// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}