
_isFormValid=true;
var win=null;


function checksalutation(){
    salutationOptions=document.getElementsByName('salutation');
    var check=false;
    for(var i=0;i<salutationOptions.length;i++)
    {
        check=(check || salutationOptions[i].checked);
    }
    return check;
}

function validateElement(Element,Caption,Type){
    isValid=false;

    switch(Type)
    {
        case "salutation":  isValid=checksalutation();
                            break;
        case "firstname":   isValid=myValidator.validateFirstName(Element);
                            break;
        case "lastname":    isValid=myValidator.validateLastName(Element);
                            break;     
        case "address1":    isValid=myValidator.validateAddress1(Element);
                            break;
        case "address2":    isValid=myValidator.validateAddress2(Element);
                            break;
        case "city":        isValid=myValidator.validateCity(Element);
                            break;
        case "state":       isValid=myValidator.validateState(Element);
                            break;
        case "zip":         isValid=myValidator.validateZipCode(Element);
                            break;
        case "email":       isValid=myValidator.validateEmailAddress(Element);
                            break;
        case "age":         isValid=(Element.checked);
                            break;
      
        default :           isValid=(Element.value.trim().length > 0);
                            break;                                        
    }
    
    if(!isValid)
    {
        changeElementClass(Caption,true);
        _isFormValid=false;
    }
    else
    {
        changeElementClass(Caption,false);
        _isFormValid=true;
    }
}

function changeElementClass(Caption,isSetRemove)
{
    //----------------------------------------------------------------------------------------------------
    //isSetRemove=true -  add error class if not already added, otherwise remove error class.
    //Change class name of multiple elements in case of error. These element Ids must be seperated by '~'.
    //----------------------------------------------------------------------------------------------------
    if(Caption==null) {return;}
    for(k=0;k<Caption.split("~").length;k++)
    {
        var caption=document.getElementById(Caption.split("~")[k]);
        if(isSetRemove)
        {
            if(caption.className.indexOf("error") == -1)
                caption.className=caption.className+" error";
        }
        else
        {
            if(caption.className.split(' ')[0]!='error')
                caption.className=caption.className.split(' ')[0];
            else
                caption.className=""; 
        }
    }
}

function validateEmailForm(){
    var flag=true;
    for(var i=0;i < frmEleArr.length;i++)
    {
        validateElement(document.getElementById(frmEleArr[i].split("|")[0]),frmEleArr[i].split("|")[1],frmEleArr[i].split("|")[2]);
        flag=flag && _isFormValid;
    }

    //if(!flag)
    {
        document.getElementById("dvErrorMessage").style.display=(flag?"none":"block");
        //return false;                
        return flag;
    }                
}

function validateForm(){
    var flag=true;
    for(var i=0;i < frmEleArr.length;i++)
    {
        validateElement(document.getElementById(frmEleArr[i].split("|")[0]),frmEleArr[i].split("|")[1],frmEleArr[i].split("|")[2]);
        flag=flag && _isFormValid;
    }
    if(document.getElementById("addressTwo")!=null && document.getElementById("addressTwo").value!="")
    {
        validateElement(document.getElementById("addressTwo"),"lbladdressTwo","address2");
        flag=flag && _isFormValid;
    }
    if(document.getElementById("othere")!=null && document.getElementById("othere").checked && document.getElementById("othermed").value.trim().length > 0)
    {
        validateElement(document.getElementById("othermed"),"lblOtherMeds","lastname");
        flag= flag && _isFormValid;
    }
//    else
//    {
//        if(document.getElementById("lblOtherMeds").className.indexOf("error")>-1){document.getElementById("lblOtherMeds").className=document.getElementById("lblOtherMeds").className.split(" ")[0];}
//        flag= flag && true;
//    }
    if(document.getElementById("email")!=null && document.getElementById("email").value.trim().length > 0)
    {
        try{
            validateElement(document.getElementById("email"),"lblemail","email");
            flag=flag && _isFormValid;
            
            validateElement(document.getElementById("emailConfirm"),"lblemailConfirm","email");            
            flag=flag && _isFormValid;
            
            var confirmEmail=(document.getElementById("email").value==document.getElementById("emailConfirm").value)
            if(!confirmEmail || !_isFormValid)
                changeElementClass("lblemailConfirm",true);
            else
                changeElementClass("lblemailConfirm",false);
            
            flag=flag && confirmEmail;
        }
        catch(e){}
    }
    
    BMSIs_PageValid=flag;
    
    //if(!flag)
    {
        document.getElementById("dvErrorMessage").style.display=(flag?"none":"block");
        //return false;                
        return flag;
    }    
}

     
function validateSearch(searchbox) {
    	//var val = document.forms[0].rslt_search.value;
	var val = document.getElementById(searchbox).value.trim();
	if (val == "" || val == null)
	{
		alert("Please type the word or words you wish to search for in the search box.");
	} 
	else 
	{
		location.href = 'searchresults.aspx?q=' + val;
	}
}



var popupWindow;

function newWindow(page, height, width) 
{/*
	var x = (640 - width)/2;
	var y = (480 - height)/2;
	if (screen)
	{
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	var features =
        'width='	+ width +
        ',height='	+ height +
        ',screenX='	+ x +
        ',screenY='	+ y +
        ',left='	+ x +
        ',top='		+ y +
        ',resizable= 1'	
	popupWindow = window.open(page, 'popupWindow', features);*/
	popupWindow = window.open(page, 'popupWindow', 'width=625,height=457,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes');
}


//Search - Press Enter Key

 function checkKey()
    {
        if (window.event.keyCode == 13)
        {
          
var bt = document.getElementById("searchbtn_123");  
bt.click();
return false;

        }

return true;
    }


function searchkeyword()
{
  	
	var val = document.getElementById("rslt_search").value.trim();
    // Keyword        
	if (val == "" || val == null)
	{
		alert("Please type the word or words you wish to search for in the search box.");
	} 
	else 
	{

	      location.href = 'searchresults.aspx?q=' + val;    
//    var url = 'searchresults.aspx?q=' + val;
//	window.open(url,"fs", 'width=1200, height=1200, scrollbars=yes, location=yes, directories=yes, menubar=yes, resizable=yes, toolbar=yes, status=yes, top=0, left=0'); 

////Current Window

//if(window.name != 'fs')
//{
//self.focus();
//self.opener = self;
//self.close();
//}

	}
}


function doSearch()
{
  var searchKeywords = document.getElementById("rslt_search");
  var searchKeywords_res = document.getElementById("search");

if (searchKeywords != null &&
    searchKeywords.value != "")
    {
   AjaxProxy.SetSearchKeywords(searchKeywords.value);
   window.location.href = 'searchresults.aspx';
    }
    else if(searchKeywords_res != null &&
    searchKeywords_res.value != "")
    {
    AjaxProxy.SetSearchKeywords(searchKeywords_res.value);
    window.location.href = 'searchresults.aspx';    
    }
    else
    {
    alert("Please type the word or words you wish to search for in the search box.");
    }    

}

