/*********************************************************************
 Imposes the length limit by cancelling the extra keypresses 
 Used for html inputs that do not have maxlength property available  
'*********************************************************************/
function MaxLength(obj, len)
{
  return (obj.value.length <= len);
}

/*********************************************************************************************
 Description: Validates the input data against regular expressions;
			  Marks invalid fields wiht a red asterisk   
			  (error message YahooToolti will be displayd at onmouseover event) 
			  Requires a built in advance JS array of validation information (fld, err msg, regExpr)
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions: 11/19/2008 CEY added validation for required checkbox
'*********************************************************************************************/
function validateForm(objForm, docObj){ 
  var fieldValue;
  var fieldName;
  var fieldStar;
  var a;
  var b;
  var re;
  var isValid = true;  
  var fieldArray;			
  var checked = false; 
  var focusSet = false;
  
 
  for (a=0; a<objForm.length; a++){//for1
	fieldValue = trim(objForm.elements[a].value);	
	fieldName = objForm.elements[a].name;	
	fieldStar = docObj.getElementById(fieldName+"STAR");
	
	if (fieldStar !=null){fieldStar.style.visibility='hidden';}
	
		//--check if the asterisk div exists for this field
		if (fieldStar !=null){				
			for (b=0; b<reArray.length; b++){//--for2									
				if (trim(fieldName.toUpperCase()) == trim(reArray[b][0].toUpperCase())){																
						fieldArray = docObj.getElementsByName(fieldName);	//--fieldArray.length=1 for fields other then radiobutton							
						
						if (fieldArray.length==1) {	//--not radiobutton
						        //check for checkbox
						        if(fieldArray[0].type=='checkbox'){
								    if (fieldArray[0].checked){		
									    //--hide red asterisk near invalid fields when the input data is corrected							
									    fieldStar.style.visibility='hidden';													
									    break;
								    }else{
									    fieldStar.style.visibility='';									
									    fieldStar.title =reArray[b][2];																		    	
									    if (!focusSet){if (setFocus(fieldName,docObj)){focusSet=true;}}				
    																
									    isValid=false;								
									    break;
								    }						        
						        }else{
    						    										
								    //re = new RegExp(reArray[b][1]);	
								    re = reArray[b][1];								
								    if (re.test(fieldValue)){		
									    //--hide red asterisk near invalid fields when the input data is corrected							
									    fieldStar.style.visibility='hidden';													
									    break;
								    }else{
									    fieldStar.style.visibility='';									
									    fieldStar.title =reArray[b][2];																		    	
									    if (!focusSet){if (setFocus(fieldName,docObj)){focusSet=true;}}				
    																
									    isValid=false;								
									    break;
								    }	
                                }														
						}else{//--radiobutton									 														 						
								for (c=0; c<fieldArray.length; c++)
								{																			
								  	if (fieldArray[c].checked)
								  	{
								  		checked = true; 
								  		fieldStar.style.visibility='hidden';									  		
								  		a=a+fieldArray.length-1;
								  		break;
								  	}else{checked=false;}																	
								 }											   	
								 if (!checked)
								 {
								  	fieldStar.style.visibility='';		
								  	fieldStar.title =reArray[b][2];																		    	
									if (!focusSet){if (setFocus(fieldName,docObj)){focusSet=true;}}	
																 														
								  	a=a+fieldArray.length-1;
								  	isValid=false;										
								  }
						}						
					break;		
			    }//--end if									       
		    }//--end for2
	    }//--end if
			
  }//--end for1  
   return isValid;
}


/***************************************************************************
 Description: Displays pointer and underline for onmouseover event of a link  
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
'***************************************************************************/
function showPointer(objElem){
   objElem.style.cursor= 'pointer';
   objElem.style.textDecoration = 'underline';
}

/************************************************************
 Description: Removes underline for onmousout event of a link 
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
'************************************************************/	
function removeUnderline(objElem){
    objElem.style.textDecoration = 'none';
}
	
/*********************************************
 Description: Resize an item to fit the screen
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
'*********************************************/	
function fixHeight_(margin,item){
	try{
		document.getElementById(item).style.height = document.body.clientHeight-margin;
	}catch(e){}
}


/*********************************************
 Description: Resize an item to fit the screen
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
'*********************************************/	
function fixHeight(objTarget, objBody, margin){
    try{
		objTarget.style.height = objBody.clientHeight-margin;
	}catch(e){}
}



/************************************************************
 Description: Trims leading and trailing spaces from a string
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
'************************************************************/
function trim (str) {
  while (str.charAt(0) == ' ')
    str = str.substring(1);
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
  return str;
}


/**********************************************************
 Description: Opens a new window with specified parameters
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
'**********************************************************/
function newSmallWindow(winName, newURL) { 
   window.open(newURL,winName,"height=500,width=500,status=no,toolbar=no,menubar=no,resizable=yes,top=2,left=2,location=no");
  }

/********************************************
 Description: Opens a new window 
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
********************************************/
function newWindow(winName, newURL) { 
   window.open(newURL,winName,"status=no,toolbar=no,menubar=no,resizable=yes,location=no");
  }
  
/********************************************
 Description: Sets focus to a given field
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
********************************************/
function setFocus(fld,doc){
	try {				
		doc.getElementById(fld).focus(); 				
		return true;				
	} catch (e) {													
		return false;
	}		
}
  
/*************************************************************
 Description: Creates document error messages tooltips 
			  for all <div> elements containing red asterisks 
			  on a given document
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
*************************************************************/
function addTooltips(doc){
	var j;
	var elemId;
	var elemIdTest;
	var contextElements = []; 
	var divs =doc.getElementsByTagName("div");

	//for (j in divs)// does not work in IE - j for some reason becomes a div's id string
	for (j=0; j<divs.length; j++){
		elemId=divs[j].id;		
		
		//alert("j:" + j + "\t divs[j].id:" + divs[j].id + "\t elemId:" + elemId);
		if(elemId !=null){					
			elemIdTest=elemId.toUpperCase();	
			if (elemIdTest.indexOf('STAR')>=0){
				contextElements[contextElements.length] = elemId; 
			}
		}
	}

	//create one yahoo tooltip for the all divs containing asterisks
	var tt = new YAHOO.widget.Tooltip("tt", { context:contextElements } );  
	
}

/***************************
 Description: Check/Uncheck form checkbox 
 Creator: Chris Yecker - RagnaSoft, Inc.
 Created Date: 
 Revisions:
***************************/
function checkObj(obj) {
  obj.checked = !obj.checked;  	
}

/***************************
 Description: Check/Uncheck form checkbox, Highlight row when checked;
 Creator: Chris Yecker - RagnaSoft, Inc.
 Created Date: 
 Revisions:
***************************/
function checkObjHighlight(obj,row) {
  var cssClass; 
  obj.checked = !obj.checked;  	
 		
	if(obj.checked){						
		row.className = row.className + 'HiLite';
	}else{
		cssClass=row.className;
		row.className = cssClass.substring(0,cssClass.indexOf('HiLite'));
	}
	
}

/*************************************************
 Returns selected value for the radio button group
 Creator: Nataliya Thompson - RagnaSoft, Inc.
 Created Date: 
 Revisions:
*************************************************/
function GetRadioValue(fldArr){
	var i;
	var value=""
			
	for (i=0; i<fldArr.length; i++){
		if(fldArr[i].checked){value=fldArr[i].value; break;}	
	}	
	return value;
}


/****************************************************************************************************
 Description: Reloads frame for a given frame set,frame name, and frame location(url + query string);
 Creator: Chris Yecker - RagnaSoft, Inc.
 Created Date: 
 Revisions:
****************************************************************************************************/
function ReloadFrame(objFrms, frmName, location){
   for(var i=0; i < objFrms.length; i++){
		if (objFrms[i].name == frmName){
			//objFrms[i].document.location = location;
			objFrms[i].location = location;
		}
	}
}

function showMessageAlert(){

	alert("There is a problem with some of your responses.\nPlease review the fields marked with the red *.\nPlace the mouse pointer over the red * to view the error message.");
	

}


//determines X position  
function findPosX(obj) {	
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

//determines Y position
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}				

//--Remove the gray top strip from the page if a page is loaded outside of the frameset
//--framesValue - number of frames in a frameset
function StandalonePage(objFrames, objTarget, framesValue){
	if(objFrames.length<framesValue){		
		if(objTarget){objTarget.className="";}
	}
}



//--------------------------------------------------------------------------
function PrintFrame(objFrms, frmName){
	var obj;
//	debugger
	for(var i=0; i < objFrms.length; i++){
		if (objFrms[i].name == frmName){
			//objFrms[i].location = location;
			obj=objFrms[i]
			break;
		}
	}
	
	/*var pp = frames[1];
	pp.focus();
	pp.print();*/
	obj.focus();
	obj.print();
}
//--------------------------------------------------------------------------

function MessagePanel(objDoc, objPosition, header, body){
	//debugger
	/*var myPanel;
	var eventX=0;
	var eventY=0;
	
		eventX=findPosX(objPosition);
		eventY=findPosY(objPosition);	

		myPanel = new YAHOO.widget.Panel("myPanel", {		
			width:"450px",
			constraintoviewport:true,			
			underlay:"shadow", 			
			close:true, 
			visible:false,  
			draggable:true} );							
	
	
		myPanel.setHeader("<div class='PanelHeader'>" + header + "</div>");
		//myPanel.setHeader("<table style='width:98%;' title='Click and drag to move this window'><tr><td class='PanelHeader' style='width:22%;'>Instance ID</td><td class='PanelHeader' style='width:44%;'>Insured</td><td class='PanelHeader' style='width:30%;'>Instance Date</td><td style='widht:4%'>&nbsp;</td></tr></table>");
		       
		myPanel.header.className="hd2";
				                    
      	
		//myPanel.setHeader("Hello");
		myPanel.setBody(body);                        
		myPanel.render(objDoc.body); 
		
		//myPanel.render(document.body); 
        //myPanel.body.className="bd1";
        //myPanel.close.className="close1";           
	    
		myPanel.cfg.setProperty("width", String(myPanel.element.offsetWidth));           
		//myPanel.cfg.setProperty("x", eventX - myPanel.element.offsetWidth);
		//myPanel.cfg.setProperty("y", eventY -(myPanel.element.offsetHeight/2));		
		myPanel.cfg.setProperty("x", eventX + 60);
		myPanel.cfg.setProperty("y", eventY + 21);		
		myPanel.show();   			     */
		
						// Instantiate the Dialog
		var myDialog; 
				myDialog = 	new YAHOO.widget.SimpleDialog("simpledialog1", 
												 { width: "300px",
												   fixedcenter: true,
												   visible: false,
												   draggable: false,
												   //close: true,
												   text: "Do you want to continue?",
												   //icon: YAHOO.widget.SimpleDialog.ICON_HELP,
												   icon: YAHOO.widget.SimpleDialog.ICON_WARN,
												   constraintoviewport: true,
												   buttons: [ { text:"Close", handler:handleNo, isDefault:true }]
												 } );
												 
					myDialog.setHeader("Are you sure?");
					myDialog.header.className="hd2";
					
					// Render the Dialog
					myDialog.render(document.body);
					myDialog.show();

					// Define various event handlers for Dialog
				var handleYes = function() {
					alert("You clicked yes!");
					this.hide();
				};

				var handleNo = function() {
					this.hide();
				};
								
			    
}

				
			
