/* pageSpecific.js */

/*
	Various functions that apply to specific pages, Error handlers, etc... not site wide
*/

/* function to just check email */

function checkemailonly() {

//check the SenderEmail
        if (isEmpty(document.theform.SenderEmail.value)){
                alert('Please fill in your SenderEmail');
		document.theform.SenderEmail.focus();
                return false;   
        }
		
// check for valid SenderEmail address
	else if ( document.theform.SenderEmail.value.length <= 6 ||
      	document.theform.SenderEmail.value.indexOf ('@', 0) == -1 ||
      	document.theform.SenderEmail.value.indexOf ('.', 0) == -1){

      	alert("'' " + theform.SenderEmail.value + " '', is not valid e-mail Address.");
	document.theform.SenderEmail.focus();
      	return false;

}

}
function isEmpty(s) {
   return ((s == null) || (s.length == 0));
}

/* end function to just check email */


/*  functions for donation print form */
function checkform2() {
//check the Gift Amount
        if (isEmpty(document.theform.giftAmount.value)){
                alert('Please fill in your gift designation amount');
	       theform.giftAmount.focus();
                return false;   
        }

//check the Fund designation
        if (isEmpty(document.theform.Fund.value || document.theform.otherFund.value)){
                alert('Donation cannot be processed without a designation. \n Please select among designations or fill in "Other".');
		theform.Fund.focus();
                return false;   
        }

//check the Name
        if (isEmpty(document.theform.Name.value)){
                alert('Please fill in your name');
		theform.Name.focus();
                return false;   
        }
		
//check the Address
        if (isEmpty(document.theform.Address.value)){
                alert('Please fill in your address');
		theform.Address.focus();
                return false;   
        }

//check the City
        if (isEmpty(document.theform.City.value)){
                alert('Please fill in your city');
		theform.City.focus();
                return false;   
        }

//check the State
  //      if (isEmpty(document.theform.State.value||document.theform.Country.value)){
   //             alert('Please fill in your state and/or country');
//		theform.State.focus();
  //              return false;   
    //    }
		
//if state is entered, require zip
//	inputValue = document.theform.State.value
//		if (inputValue != "" && (isEmpty(document.theform.ZIP.value))){
//				alert('Please fill in your ZIP code');
//			theform.ZIP.focus();
//				return false;
	//			}
				
//check the Country
       if (isEmpty(document.theform.Country.value)){
               alert('Please select your Country');
		theform.Country.focus();
              return false;   
       }			

//check the ZIP/postal coode
       if (isEmpty(document.theform.ZIP.value)){
               alert('Please fill in your ZIP or postal code');
			   		theform.ZIP.focus();
             return false;   
       }
	   
	   //if state is entered, require zip
		if (document.theform.Country.value == " US" && (isEmpty(document.theform.State.value))){
				alert('Your country selection is the United States, please fill in your State');
				theform.State.focus();
				return false;
				}

//check the Email
        if (isEmpty(document.theform.Email.value)){
                alert('Please fill in your email');
		theform.Email.focus();
                return false;   
        }
		
// check for valid Email address
//	else if ( document.theform.Email.value.length <= 6 ||
//      	document.theform.Email.value.indexOf ('@', 0) == -1 ||
//      	document.theform.Email.value.indexOf ('.', 0) == -1){

//      	alert("'' " + theform.Email.value + " '', is not valid e-mail Address.");
//	theform.Email.focus();
//      	return false;

//}

        //if we got to here the form is ok
        document.theform.submit();
}
function isEmpty(s) {
   return ((s == null) || (s.length == 0));
}

function clearFund() {
	document.theform.Fund.value = ""
}
/* end donation mail form functions */

/* generic audio controls... don't work as is in Firefox */  

function ShutMeDown ()
   {
       player.controls.stop();
   }

function StartMeUp ()
   {
       player.controls.play();
   }


/* swapimage functions */
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_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];}
}
/* end these */
/* validate lockup forms */
function validate() {

		if (isEmpty(document.theForm.ChapName.value)){
                alert('Please enter your State name');
                theForm.ChapName.focus();
                return false;      
        }


 		if (isEmpty(document.theForm.ChapCode.value)){
                alert('Please enter your 5-digit chapter code');
                theForm.ChapCode.focus();
                return false;      
        }
		
        if (isEmpty(document.theForm.SenderEmail.value)){
                alert('Please fill in your e-mail');
				theForm.SenderEmail.focus();
                return false;   
        }

	else if ( document.theForm.SenderEmail.value.length <= 6 ||
      	document.theForm.SenderEmail.value.indexOf ('@', 0) == -1 ||
      	document.theForm.SenderEmail.value.indexOf ('.', 0) == -1){

      	alert("'' " + theForm.SenderEmail.value + " '', is not valid Email Address.");
      	return false;
}

 if (document.theForm.RegionName.value == "notselected"){
                alert('Please select a Blood Services Region');
				theForm.RegionName.focus();
                return false;   
        }

        //if we got to here the form is ok
       
}
function isEmpty(s) {
   return ((s == null) || (s.length == 0));
}
/* end this */


/* validate instant service forms */
/* Scott, Dec 24, 2008 */

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) { 
if(e){ 
e = e 
} else {
e = window.event 
} 
if(e.which){ 
var keycode = e.which 
} else {
var keycode = e.keyCode 
}

ParseForNumber1(object)

if(keycode >= 48){
ValidatePhone(object)
}
}

function backspacerDOWN(object,e) { 
if(e){ 
e = e 
} else {
e = window.event 
} 
if(e.which){ 
var keycode = e.which 
} else {
var keycode = e.keyCode 
}
ParseForNumber2(object)
} 

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i<t1.length; i++)
{
if (t1.substring(i,1) != t2.substring(i,1)) {
if(!bool) {
cursorposition=i
bool=true
}
}
}
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
object.value=p
} else if(p.length==3){
pp=p;
d4=p.indexOf('(')
d5=p.indexOf(')')
if(d4==-1){
pp="("+pp;
}
if(d5==-1){
pp=pp+")";
}
object.value = pp;
} else if(p.length>3 && p.length < 7){
p ="(" + p; 
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

object.value = pp; 

} else if(p.length >= 7){
p ="(" + p; 
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

l40 = pp.length;
p40 = pp.substring(0,8);
p40 = p40 + "-"

p41 = pp.substring(8,l40);
ppp = p40 + p41;

object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
if (sChar.length == null) 
{
zChar = new Array(sChar);
}
else zChar = sChar;

for (i=0; i<zChar.length; i++)
{
sNewStr = "";

var iStart = 0;
var iEnd = sStr.indexOf(sChar[i]);

while (iEnd != -1)
{
sNewStr += sStr.substring(iStart, iEnd);
iStart = iEnd + 1;
iEnd = sStr.indexOf(sChar[i], iStart);
}
sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

sStr = sNewStr;
}

return sNewStr;
}


function checkformIS() {
 
 //check the fname
        if (isEmpty(document.theform.fname.value)){
                alert('Please provide your first name');
  theform.fname.focus();
                return false;   
        }
		
		//check the lname
        if (isEmpty(document.theform.lname.value)){
                alert('Please provide your last name');
  theform.lname.focus();
                return false;   
        }
 
 
//check the Address
        if (isEmpty(document.theform.address.value)){
                alert('Please fill in your address');
  theform.address.focus();
                return false;   
        }
 
//check the ZIP
        if (isEmpty(document.theform.zip.value)){
                alert('Please fill in your ZIP code');
                return false;   
        }
 
//check the email
        if (isEmpty(document.theform.email.value)){
                alert('Please fill in your e-mail');
                return false;   
        }
 
//check the question
        if (isEmpty(document.theform.questions.value)){
                alert('Please fill in your question');
                return false;   
        }
 
// check for valid email address
 else if ( document.theform.email.value.length <= 6 ||
       document.theform.email.value.indexOf ('@', 0) == -1 ||
       document.theform.email.value.indexOf ('.', 0) == -1){
 
       alert("'' " + theform.email.value + " '', is not valid Email Address.");
       return false;
}
 
//check inquirytype
        if (document.theform.inquirytype.selectedIndex <1){
                alert('Please select Inquiry Type');
                return false;   
        }
 

        //if we got to here the form is ok
        document.theform.submit();
}
function isEmpty(s) {
   return ((s == null) || (s.length == 0));
}

//*  END THIS for Instant Service *//


/* end this */
function popUp(filename, dimensions) {
	window.open(filename, '', dimensions);
}


