
//remove error message-http://www.webreference.com/js/column6/ignore.html or http://www.javascripter.net/faq/suppress.htm
//remove it when testing the js otherwise does not report errors
function stopError() {
  return true;
}

window.onerror = stopError;


//from http://www.codetoad.com/javascript/isnumeric.asp
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function checkchars(cur){

var price = cur.Price.value.length;
var contact = cur.Contact.value.length;
var details = cur.Details.value.length;
var contactlines;
var detailslines;

if (!IsNumeric(cur.Price.value)) { 
	alert('Please enter only numbers in the Price field (no dollar signs or commas or letters)') 
	cur.Price.focus();
	return false; 
} 
if (price<4){
	alert("Please make your 'Price' at least 4 numbers in length, currently there are " + price + " .");
	cur.Price.focus();
	return false;
}
if (cur.Location.value == ""){
	alert("Please choose a Location");
	cur.Location.focus();
	return false;
}
if (cur.Username.value == ""){
	alert("Please enter a Username. It is needed to delete ads with.");
	cur.Username.focus();	
	return false;
}
if (cur.Contact.value.length<10 || cur.Contact.value.length>150){
	alert("Please enter Contact Information at least 10 characters in length and no more than 150, currently there are " + contact + " .");
	cur.Contact.focus();
	return false;
}



//http://www.devguru.com/Technologies/ecmascript/quickref/string_match.html

myString2 = new String(cur.Contact.value);
myRE2 = new RegExp("\n", "g");
results2 = myString2.match(myRE2);

//first line does not have a \n i think
contactlines = results2.length + 1;

if (contactlines>6){
    alert("Please enter Contact Information with no more than 6 lines, currently there are " + contactlines + " .");
    cur.Contact.focus();
    return false;
}



if (cur.Details.value.length>1500){
	alert("Please enter Details Information no more than 1500 characters in length, currently there are " + details + " .");
	cur.Details.focus();
	return false;
}

//http://www.devguru.com/Technologies/ecmascript/quickref/string_match.html
myString3 = new String(cur.Details.value)
myRE3 = new RegExp("\n", "g")
results3 = myString3.match(myRE3)

//first line does not have a \n i think
detailslines = results3.length + 1;

if (detailslines>20){
    alert("Please enter Details Information with no more than 20 lines, currently there are " + detailslines + " .");
    cur.Details.focus();
    return false;
}


// http://www.jennifermadden.com/162/examples/stringEscape.html 
// limit return characters   \r\n http://www.webreference.com/programming/javascript/beginning/chap6/4/ 
// function escapeVal(textarea,replaceWith){ -->
// textarea is reference to that object, replaceWith is string that will replace the encoded return 
// loop through string, replacing carriage return encoding with HTML break tag 
// if(textarea.value.indexOf("%0D%0A") > -1){ 



//////http://www.codestore.net/store.nsf/unid/DOMM-4Q8LSJ?OpenDocument///////////////
//It will fill an array with the positions of each upload
///////////////////FIRST FILE check file format extension////////////////////////////////////////////
///////////////////from http://www.chestysoft.com/upload/jsdemo.asp
////////////////// repeated 4 times as it did not work in for next loop, not sure why

var filename = cur.elements[5].value;
var extension;

// is it a GIF being uploaded
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'GIF')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.) GIF's, bitmaps, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.GIF");
	//cur.file1.value = ""; //does not work
	cur.elements[5].focus();
	return false;
}
// is it a BMP
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'BMP')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Bitmaps, GIFs, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.BMP");
	//cur.file1.value = ""; //does not work
	cur.elements[5].focus();
	return false;
}
// is it a PSD photoshop
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'PSD')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Photoshop PSDs, GIFs, Bitmaps and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad. PSD");
	//cur.file1.value = ""; //does not work
	cur.elements[5].focus();
	return false;
}
///////end check file format extension///////////////////////////////////////////////

///////////////////SECOND FILE check file format extension////////////////////////////////////////////
//////////////////////from http://www.chestysoft.com/upload/jsdemo.asp
var filename = cur.elements[6].value;
var extension;


// is it a GIF being uploaded
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'GIF')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.) GIF's, bitmaps, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.GIF");
	//cur.file1.value = ""; //does not work
	cur.elements[6].focus();
	return false;
}
// is it a BMP
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'BMP')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Bitmaps, GIFs, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.BMP");
	//cur.file1.value = ""; //does not work
	cur.elements[6].focus();
	return false;
}
// is it a PSD photoshop
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'PSD')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Photoshop PSDs, GIFs, Bitmaps and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad. PSD");
	//cur.file1.value = ""; //does not work
	cur.elements[6].focus();
	return false;
}
///////end 2 check file format extension///////////////////////////////////////////////

///////////////////THIRD FILE check file format extension////////////////////////////////////////////
//////////////////////from http://www.chestysoft.com/upload/jsdemo.asp
var filename = cur.elements[7].value;
var extension;


// is it a GIF being uploaded
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'GIF')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.) GIF's, bitmaps, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.GIF");
	//cur.file1.value = ""; //does not work
	cur.elements[7].focus();
	return false;
}
// is it a BMP
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'BMP')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Bitmaps, GIFs, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.BMP");
	//cur.file1.value = ""; //does not work
	cur.elements[7].focus();
	return false;
}
// is it a PSD photoshop
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'PSD')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Photoshop PSDs, GIFs, Bitmaps and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad. PSD");
	//cur.file1.value = ""; //does not work
	cur.elements[7].focus();
	return false;
}
///////end 3 check file format extension///////////////////////////////////////////////

///////////////////FOURTH FILE check file format extension////////////////////////////////////////////
//////////////////////from http://www.chestysoft.com/upload/jsdemo.asp
var filename = cur.elements[8].value;
var extension;


// is it a GIF being uploaded
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'GIF')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.) GIF's, bitmaps, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.GIF");
	//cur.file1.value = ""; //does not work
	cur.elements[8].focus();
	return false;
}
// is it a BMP
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'BMP')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Bitmaps, GIFs, PSDs and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad.BMP");
	//cur.file1.value = ""; //does not work
	cur.elements[8].focus();
	return false;
}
// is it a PSD photoshop
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() == 'PSD')
{
	alert("Please upload only jpeg formats (.jpg, .jpe, .jpeg.). Photoshop PSDs, GIFs, Bitmaps and other formats can be emailed to res@real-estate-shopping.com Include ad number, username and county posted in and we will attach it to your ad. PSD");
	//cur.file1.value = ""; //does not work
	cur.elements[8].focus();
	return false;
}
///////end 4 check file format extension///////////////////////////////////////////////

} //end function checkchars//



