
var
month = new Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

var
day = new Array();
day[0]="Sunday";
day[1]="Monday";
day[2]="Tuesday";
day[3]="Wednesday";
day[4]="Thursday";
day[5]="Friday";
day[6]="Saturday";

today = new Date();
date = today.getDate();
day = (day[today.getDay()]);
month = (month[today.getMonth()]);
year = (today.getFullYear());

 suffix = (date==1 || date==21 || date==31) ? "st" : "th" &&
 (date==2 || date==22) ? "nd" : "th" && (date==3 || date==23) ? "rd" : "th"

function print_date()
{
  document.write(day + "," + "&nbsp;" + date  + "<sup>" + suffix + "</sup>" + "&nbsp;" +
  month + "," + "&nbsp;" + year);
}

function processSearch(level, category, page, order) {
   document.getElementById('SearchCategoryLevel').value = level;
   document.getElementById('SearchCategoryID').value    = category;
   document.getElementById('SearchOrder').value         = order;
   document.getElementById('StartPage').value           = page;
   document.getElementById('SearchForm').submit();
}

//-----------------------------------------------------
		function CheckLogin(){
			if(document.lform.us.value==""){
				window.alert('Enter your username, please!');
				document.lform.us.focus();
				return false;
			}

			if(document.lform.ps.value==""){
				window.alert('Enter your password, please!');
				document.lform.ps.focus();
				return false;
			}
		}
		function CheckForgot(){
			if(document.ForgotForm.u2.value=="")
			{
				window.alert('Enter your username, please!');
				document.ForgotForm.u2.focus();
				return false;
			}
		}

		function CheckSearch(){

       //return true;
//			if(document.SearchForm.what.value==""){
//				window.alert('Enter search term, please!');
//				document.SearchForm.what.focus();
//				return false;
//			}

			if(document.SearchForm.category.value==""){
				window.alert('Choose category, please!');
				document.SearchForm.what.focus();
				return false;
   }
		else if (!validateUSZip($('#zip-search').val())) {
      alert('Please, enter a valide zip code in order to help you calculate distance between your location and what we have listed for sale in Florida');
      return false;
   }
		}

function validateUSZip( strValue ) {

var objRegExp  = /(^\d{5}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}


		function CheckRegister() {

   var zip_val = document.RegForm.ZipCode.value;
			if(!validateUSZip(zip_val))// || (zip_val.substring(0,2)!='32' && zip_val.substring(0,2)!='33' && zip_val.substring(0,2)!='34'))
			{
      window.alert('Please, input valid US zip code.');//Your account zip code adress shall be in the sunshine state.');
      document.RegForm.ZipCode.focus();
      return false;
			}

			if(document.RegForm.NewUsername.value==""){
				window.alert('Enter your username, please!');
				document.RegForm.NewUsername.focus();
				return false;
			}

			if(document.RegForm.p1.value==""){
				window.alert('Enter your password, please!');
				document.RegForm.p1.focus();
				return false;
			}

			if(document.RegForm.p2.value==""){
				window.alert('Confirm your password, please!');
				document.RegForm.p2.focus();
				return false;
			}

			if(document.RegForm.p1.value != "" && document.RegForm.p2.value != "" && document.RegForm.p1.value != document.RegForm.p2.value){
				window.alert('Enter and confirm your password again!');
				document.RegForm.p1.value="";
				document.RegForm.p2.value="";
				document.RegForm.p1.focus();
				return false;
			}

			if(document.RegForm.FirstName.value=="")
			{
				window.alert('Enter your First Name, please!');
				document.RegForm.FirstName.focus();
				return false;
			}

			if(document.RegForm.LastName.value=="")
			{
				window.alert('Enter your Last Name, please!');
				document.RegForm.LastName.focus();
				return false;
			}

//			if(document.RegForm.Phone.value=="")
//			{
//				window.alert('Enter your Phone, please!');
//				document.RegForm.Phone.focus();
//				return false;
//			}

			if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.RegForm.email.value))
			{
				return true;
			}

			alert("Invalid E-mail Address! Please re-enter.");
			document.RegForm.email.focus();
			return false;
		}

		function CheckProfile(){

     var zip_val = document.RegForm.ZipCode.value;
     if(!validateUSZip(zip_val))// || (zip_val.substring(0,2)!='32' && zip_val.substring(0,2)!='33' && zip_val.substring(0,2)!='34'))
     {
        window.alert('Please, insert valid US zip code.');//Your account zip code adress shall be in the sunshine state.');
        document.RegForm.ZipCode.focus();
        return false;
     }

				if(document.RegForm.p1.value==""){
					window.alert('Enter your password, please!');
					document.RegForm.p1.focus();
					return false;
				}
				if(document.RegForm.p2.value==""){
					window.alert('Confirm your password, please!');
					document.RegForm.p2.focus();
					return false;
				}

				if(document.RegForm.p1.value != "" && document.RegForm.p2.value != "" && document.RegForm.p1.value != document.RegForm.p2.value){
					window.alert('Enter and confirm your password again!');
					document.RegForm.p1.value="";
					document.RegForm.p2.value="";
					document.RegForm.p1.focus();
					return false;
				}

				if(document.RegForm.FirstName.value==""){
					window.alert('Enter your First Name, please!');
					document.RegForm.FirstName.focus();
					return false;
				}

				if(document.RegForm.LastName.value==""){
					window.alert('Enter your Last Name, please!');
					document.RegForm.LastName.focus();
					return false;
				}
//				if(document.RegForm.phone.value==""){
//					window.alert('Enter your Phone, please!');
//					document.RegForm.phone.focus();
//					return false;
//				}

    if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.RegForm.email.value)){
					return true;
				}

				alert("Invalid E-mail Address! Please re-enter.");
				document.RegForm.email.focus();
				return false;

		}

		function CheckOffer(){

   var zip_val = document.PostForm.ZipCode.value;
   if(!validateUSZip(zip_val) || (zip_val.substring(0,2)!='32' && zip_val.substring(0,2)!='33' && zip_val.substring(0,2)!='34'))
   {
      window.alert('Your account zip code adress shall be in the sunshine state.');
      document.PostForm.ZipCode.focus();
      return false;
   }

   if (document.PostForm.FirstName.value == '' || document.PostForm.LastName.value=='') {
      alert('Please, specify your first/last name!');
      document.PostForm.FirstName.focus();
      return false;
   }

			if(document.PostForm.CategoryID != undefined && document.PostForm.CategoryID.value=="")
			{
				alert('Select the category in which your offer will appear!');
				document.PostForm.CategoryID.focus();
				return false;
			}

			if(document.PostForm.SubCategoryID != undefined && document.PostForm.SubCategoryID.value=="")
			{
				alert('Select the Subcategory in which your offer will appear!');
				document.PostForm.SubCategoryID.focus();
				return false;
			}

			if(document.PostForm.SubSubCategoryID.value=="")
			{
				alert('Select the Sub-Subcategory in which your offer will appear!');
				document.PostForm.SubSubCategoryID.focus();
				return false;
			}

			if(document.PostForm.ProductName.value=="")
			{
				alert('Enter the asset title or name, please!');
				document.PostForm.ProductName.focus();
				return false;
			}

			if(document.PostForm.Description.value==""){
				alert('Describe your asset, please!');
				document.PostForm.Description.focus();
				return false;
			}

//var objValue = new String(document.PostForm.Description.value);
			//objValue = objValue.replace(/[^\d\-() ]+/g,'');
   //alert("objValue::"+objValue);
			//var charpos = objValue.search("[^A-Z_-,a-z0-9/ /.//'/!/@/#/$/%/^/&/*/(/)/:]");
//			if(document.PostForm.Description.value.indexOf("'") != -1){
//				alert("Single quote is not allowed for the description");
//				return false;
//			}

			/*if(objValue.length > 0 &&  charpos >= 0){
				alert("Search text is not valid. Allowed characters are \nalphanumeric, space, comma, special characters, dot and single quote  ");
				document.PostForm.Description.focus();
				return false;
			}*/

			var checkone = uploadAtleastone('images[]');

				 if(checkone == false){
					alert("Please Upload atleast one asset image!");
					return false;
					   }

			if(document.PostForm.Price.value=="")
			{
				alert('Enter the requested price, please!\n\nDo not use currency symbols!\n\nFormat:\n\t125.95');
				document.PostForm.Price.focus();
				return false;
			}
			if(document.PostForm.Price.value=="."){
				alert('Price is invalid');
				document.PostForm.Price.focus();
				return false;
			}
			if(eval(document.PostForm.Price.value)==0){
				alert('Price cannot be zero');
				document.PostForm.Price.focus();
				return false;
			}
			var charpos = document.PostForm.Price.value.search("[^0-9.]");
            if(document.PostForm.Price.value.length > 0 &&  charpos >= 0){
				alert('Only digits allowed for price');
				document.PostForm.Price.focus();
				return false;
			}
			/*
			if(document.PostForm.sp.value=="")
			{
				alert('Select your prefered priority level!');
				document.PostForm.sp.focus();
				return false;
			}
			*/
		}

	/*  function for uploading image validation  */
	function uploadAtleastone(image){
		if(document.PostForm.OldImages.value==''){
			var checkfields;
			var numchecked=0;
			checkfields=document.getElementsByName(""+image);
			for(var i=0; i<checkfields.length; i++){
				if(checkfields[i].value != ""){
					numchecked = numchecked+1;
					return true;
				}
			}
			return false;
		}
		return true;
	 }

//---------------------------------

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

function numbersonly(myfield, e, dec)
{
   var key;
   var keychar;

   if (window.event)
      key = window.event.keyCode;
   else if (e)
      key = e.which;
   else
      return true;
   keychar = String.fromCharCode(key);

   // control keys
   if ((key==null) || (key==0) || (key==8) ||
       (key==9) || (key==13) || (key==27) )
      return true;

   // numbers
   else if ((("0123456789").indexOf(keychar) > -1))
      return true;

   // decimal point jump
   else if (dec && (keychar == "."))
      {
      myfield.form.elements[dec].focus();
      return false;
      }
   else
      return false;
}

