// sbcus-default.js
// http://smallbiz.cjb.net/


// addLink

      function addLink(){

        var theHREF, theLink, theCode

        myName = window.name
        re = /^newWinX(\d+)?$/

        if (myName.match(re)) { 

          theHREF = "javascript:window.close()"
          theLink = "close this window"
    
        } else { 

          theHREF = "index.html"
          theLink = "home"

        }
    
        theCode = "<a href=\"" + theHREF + "\">" + theLink + "</a>"      

        document.write(theCode)

      }


// confirmReset

      function confirmReset() {

	confirmed = ""

	confirmed = confirm("\n\Warning: ALL data will be lost!\n\nProceed anyway?")

	return confirmed

      }


// dataChk - long email verification

      function dataChk(theForm){

        successful = false

	badChars=/[ ?{}|#*(),;:=%+\[\]'"&]/

        mesg = ""
        theProblem = ""

	emailSubmitted = theForm.replyemail.value

	emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/

        if (theForm.replyemail.value.length < 6) {

	  mesg = "\nInvalid email address " 
	  theProblem = theForm.replyemail

	} else if (theForm.msg.value.length < 3) {

	  mesg ="\nUnrecognized message, \nplease retype "
	  theProblem = theForm.msg

        } else if (badChars.test(emailSubmitted)) {

	  mesg = "Invalid email address,\nunrecognized characters or format"
	  theProblem = theForm.replyemail

	}  


	if (mesg) {

	  flagError(theProblem, mesg)
	  return successful

  	}


	if (emailSubmitted.match(emailFormat)) {

	  dataToSend = ""
	
          if (theForm.uname.value.length >= 2) dataToSend = "Name: \t" + theForm.uname.value + " \n"

          dataToSend = dataToSend + "Email: \t" + emailSubmitted

	  if (confirm(dataToSend + "\n\nClick OK to send ")) successful = true

	} else {

          mesg = "Invalid email format\n"
          theProblem = theForm.replyemail

          flagError(theProblem, mesg)
	  return successful

	}

        return successful

      }


// dataChk2 - verify two email addresses (short email verification)

      function dataChk2(){

        formName = document.EmailForm
	successful = false

	badChars=/[ ?{}|#*(),;:=%+\[\]'"&]/

        mesg = ""
        theProblem = ""

	emailSubmitted1 = formName.fromEmail.value
	emailSubmitted2 = formName.toEmail.value

	emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/

	if ((emailSubmitted1.match(emailFormat)) && (emailSubmitted2.match(emailFormat))) {

          theName = ""
	  dataToSend = ""
	
          if (formName.name.value.length > 2) theName = formName.name.value + " "

	  if (theName) {

	    dataToSend = "Your Name:\t" + theName + " \nYour Email:\t" + emailSubmitted1 + " \n\nFriend's Email:\t" + emailSubmitted2 + " "

	  } else {

	    dataToSend = "Your Email:       " + emailSubmitted1 + " \nFriend's Email:  " + emailSubmitted2 + " "

	  }

	  if (confirm(dataToSend + "\n\nClick OK to send ")) successful = true

	} else {

          mesg = "Invalid email format\n"
          theProblem = formName.fromEmail

          if (emailSubmitted1.match(emailFormat)) theProblem = formName.toEmail 
         
          flagError(theProblem, mesg)
	  return successful

	}

        return successful

      } 


// dataChk 3 - verify email address and url

      function dataChk3(theForm){

	successful = false

	badChars=/[ ?{}|#*(),;:=%+\[\]'"&]/
        uBadChars=/[ ]/

        mesg = ""
        theProblem = ""

	emailSubmitted = theForm.replyemail.value
        urlSubmitted = theForm.site_url.value

	emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
        urlFormat = /^((http|ftp):\/\/)?\w+([\.-]\w+)?(\.\w{2,4})+(\/?\S?)*$/i

	picked = theForm.theCategory.selectedIndex
	
        if (theForm.replyemail.value.length < 6) {

	  mesg = "\nInvalid email address " 
	  theProblem = theForm.replyemail
          selectable = true

	} else if (theForm.theCategory.options[picked].value == " ") {
 
	  mesg = "\nPlease tell us what category\nbest describes the resource.\n\nIf you're unsure, choose 'Not Sure' "
          theProblem = theForm.theCategory
          selectable = false

        } else if (badChars.test(emailSubmitted)) {

	  mesg = "Invalid email address,\nunrecognized characters or format"
	  theProblem = theForm.replyemail
          selectable = true

        } else if (uBadChars.test(urlSubmitted)) {

	  mesg = "Invalid Resource Location \nor URL format "
	  theProblem = theForm.site_url
          selectable = true 

        } else {

          if (!urlSubmitted.match(urlFormat)) {

	  mesg = "Invalid Resource Location \nor URL format "
	  theProblem = theForm.site_url
          selectable = true

	  }

	}

	if (mesg) {

	  flagError2(theProblem, mesg, selectable)
	  return successful

  	}


	if (emailSubmitted.match(emailFormat)) {

	  dataToSend = ""
	  urSite = ""
          rsrcType = ""

          urSite = theForm.site_url.value
	  rsrcType = theForm.theCategory.options[picked].value

          if (theForm.uname.value.length > 2) dataToSend = "Name: \t\t" + theForm.uname.value + " \n"

    	  dataToSend = dataToSend + "Email: \t\t" + emailSubmitted + " \n" + "Category: \t" + rsrcType + " \n"  + "Location: \t\t" + urSite + " \n"

	  if (confirm(dataToSend + "\n\nClick OK to send ")) successful = true

	} else {

          mesg = "Invalid email format\n"
          theProblem = theForm.replyemail
          selectable = true

          flagError2(theProblem, mesg, selectable)
	  return successful

	}

        return successful

      } 


// dataChk4 - verify two email addresses (short email verification)

      function dataChk4(){

        formName = document.EmailForm
	successful = false

	badChars=/[ ?{}|#*(),;:=%+\[\]'"&]/

        mesg = ""
        theProblem = ""

	emailSubmitted1 = formName.youremail.value
	emailSubmitted2 = formName.emailaddress.value

	emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/

	if ((emailSubmitted1.match(emailFormat)) && (emailSubmitted2.match(emailFormat))) {

          theName = ""
	  dataToSend = ""
	
          if (formName.name.value.length > 2) theName = formName.name.value + " "

	  if (theName) {

	    dataToSend = "Your Name:\t" + theName + " \nYour Email:\t" + emailSubmitted1 + " \n\nFriend's Email:\t" + emailSubmitted2 + " "

	  } else {

	    dataToSend = "Your Email:       " + emailSubmitted1 + " \nFriend's Email:  " + emailSubmitted2 + " "

	  }

	  if (confirm(dataToSend + "\n\nClick OK to send ")) successful = true

	} else {

          mesg = "Invalid email format\n"
          theProblem = formName.youremail

          if (emailSubmitted1.match(emailFormat)) theProblem = formName.emailaddress 
         
          flagError(theProblem, mesg)
	  return successful

	}

        return successful

      } 


// dataChk5 - verify one email and two submitted URLs

      function dataChk5(theForm){

	successful = false

	badChars=/[ ?{}|#*(),;:=%+\[\]'"&]/
        uBadChars=/[ ]/

        mesg = ""
        theProblem = ""

	emailSubmitted = theForm.replyemail.value
        urlSubmitted = theForm.site_url.value
        urlSubmitted2 = theForm.sbcus_link.value

	emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
        urlFormat = /^((http|ftp):\/\/)?\w+([\.-]\w+)?(\.\w{2,4})+(\/?\S?)*$/i

        if (theForm.replyemail.value.length < 6) {

	  mesg = "Invalid email address " 
	  theProblem = theForm.replyemail
          selectable = true

        } else if (badChars.test(emailSubmitted)) {

	  mesg = "Invalid email address,\nunrecognized characters or format"
	  theProblem = theForm.replyemail
          selectable = true

        } else if (uBadChars.test(urlSubmitted)) {

	  mesg = "Please enter a valid URL "
	  theProblem = theForm.site_url
          selectable = true 

        } else if (uBadChars.test(urlSubmitted2)) {

	  mesg = "Please enter a valid URL "
	  theProblem = theForm.sbcus_link
          selectable = true 

        } else {

          if (!urlSubmitted.match(urlFormat)) {

	    theProblem = theForm.site_url

	  } else if (!urlSubmitted2.match(urlFormat)) {

	    theProblem = theForm.sbcus_link

	  }

	  if (theProblem) {
            mesg = "Please enter a valid URL "
            selectable = true
          }
	}

	if (mesg) {

	  flagError2(theProblem, mesg, selectable)
	  return successful

  	}


	if (emailSubmitted.match(emailFormat)) {

	  dataToSend = ""
	  urSite = ""
          linkback = ""

          urSite = theForm.site_url.value
	  linkback = theForm.sbcus_link.value

          if (theForm.uname.value.length > 2) dataToSend = "Name: \t\t" + theForm.uname.value + " \n"

    	  dataToSend = dataToSend + "Email: \t\t" + emailSubmitted + " \n" + "Your Site: \t" + urSite + " \n" + "Link To Us: \t" + linkback

	  if (confirm(dataToSend + "\n\nClick OK to send ")) successful = true

	} else {

          mesg = "Invalid email format\n"
          theProblem = theForm.replyemail
          selectable = true

          flagError2(theProblem, mesg, selectable)
	  return successful

	}

        return successful

      }


// flagError

      function flagError(theError, theMesg){

	  alert(theMesg)
	  theError.focus()
	  theError.select()
      }


// flagError2

      function flagError2(theError, theMesg, objectSelectable){

	  alert(theMesg)
	  theError.focus()
	  if (objectSelectable) theError.select()
      }


// openNewWin

    function openNewWin(docName, winHeight, winWidth) {

      defaultHREF = 'http://wave.prohosting.com/sbcus/'
      if (location.href != defaultHREF) docName = defaultHREF + docName

      winSub = ""
      if (window.name == "newWinX") winSub = Math.floor(Math.random() * 2048)

      var theSpecs
      theSpecs = "menubar=no,scrollbars=yes,resizable=no,status=no,location=no,height=" + winHeight + ",width=" + winWidth + "\""
      newWin = window.open(docName, "newWinX" + winSub, theSpecs)
      setTimeout("newWin.focus()", 5 * 1000)
    }


// printAlert

    function printAlert() {
      if (navigator.appName.indexOf("Mac") != -1) {

      	mesg = "\tTo Print: \n\nPress Cmd+P on your keyboard. "

      } else {

      	mesg = "\tTo Print: \n\nClick your browser's 'print' icon\n\t   or\npress Ctrl+P on your keyboard. "

      }
        alert(mesg)
    }


// showLink()

      function showLink(theLink) {
  	window.status=theLink		
  	return true
      }




