//' Pops up a new window at the upper left of screen
function popIt(page, widthVal, heightVal){ 
    var newWnd = window.open( page, 'popupWindow', 'status,resizable,scrollbars,width=' + widthVal + ',height=' + heightVal + ',left=' + screen.availLeft + ',top=' + screen.availTop + '', true ); 
    //newWnd.focus(); 
}

function popIt2(page2, widthVal, heightVal){ 
    var imgWnd2 = window.open( page2, 'imageIndex', 'status,resizable,scrollbars,width=' + widthVal + ',height=' + heightVal + ',left=' + screen.availLeft + ',top=' + screen.availTop + '', true ); 
    imgWnd2.focus(); 
}

function popIt3(page3, widthVal, heightVal){ 
    var imgWnd3 = window.open( page3, 'imageWindow', 'status,resizable,scrollbars,width=' + widthVal + ',height=' + heightVal + ',left=' + screen.availLeft + ',top=' + screen.availTop + '', true ); 
    imgWnd3.focus(); 
}

// Adds an option to the end of the drop down list.
//	ddRef = Reference to drop down(string). Must be: FormName.DropDownName
//	value = Value of the new option.
//	caption = Text of the new option.
//
// In a scenario when a popup window tries to use this function to operate on
// a drop down in parent window then this function must be loaded in parent
// window and called from popup.
function AddOptionToDropDown( ddRef, value, caption ) 
{
	ddRef = eval( "document." + ddRef );
	
	if ( ddRef == null )
		return;
	else if ( ddRef.options == null )
		return
	else if ( ddRef.options.length == null )
		return;
		
	ddRef.options[ddRef.options.length] = new Option();
	var opt = ddRef.options[ddRef.options.length - 1];
	opt.value = value + "";
	opt.text = caption + "";
	opt.selected = true;
	
	// If it's a Mailing List or Correspondence window then submit
	// form containing drop-down as soon as new item is added.
	var isFrame = top.frmTop != null;
	if ( isFrame )	top.frmTop.document.forms[0].submit();
}

function Trim( arg ) {
	return (arg + "").replace(/^\s+/,"").replace(/\s+$/,"");
}

// Refreshes window pointed to by windowRef with 
// argUrl and closes current window.
function RedirectAndClose( argUrl, windowRef ) {	
	try {
		windowRef.location.href = argUrl;
	} catch ( e ) {
	} finally {
		window.close();
	}
}

// Puts all form field values into one GET-formatted string.
// Returns resulting string.
// formName - Required. Name of form.
// ignoreParams - Optional. comma-delimited list of fields which will not be included.
function AccumulateFormParams( formName, ignoreParams ) {
	var frm = eval("document." + formName);		
	var strFormParams = "";
	ignoreParams = null == ignoreParams ? "" : ignoreParams + ",";	// Add comma after last name for ease of matching.
		
	if ( frm == null ) {
		alert("Invalid form name");
		return "";
	}

	for ( var j = 0; j < frm.elements.length; j++ ) {
		var element = frm.elements[j];
		
		if ( ignoreParams.indexOf(element.name + ",") != -1 )
			continue;		// do not append value of ignored field
		
		if ( strFormParams != "" )
			strFormParams += "&";
			
		if ( element.checked != null )		// Element is a checkbox or option button.
			if ( element.checked==true )
				strFormParams += element.name + "=" + escape(element.value);
		if ( element.value != null ) 		// Element is text or hidden field. Just append the value.
			strFormParams += element.name + "=" + escape(element.value);
		else if ( element.options != null ) {	// Element is drop down box. Apend values of all selected options.
			for ( var k = 0; k < elements.options.length; k++ ) 
				if ( element.options[k].selected ) 
					strFormParams += element.name + "=" + escape(elements.options[k].value);				
		}
	}
	return strFormParams;
}

function GetPhoneFocus(fieldName,intInputNum,formName){
	try{
		var f = document.forms[formName];
		elementName = fieldName + "_" + intInputNum;
		var strVal = f.elements[elementName].value;
		if(strVal.length==3 && intInputNum<3){
			elementName = fieldName + "_" + (++intInputNum);
			f.elements[elementName].focus();
		}
		f.elements[fieldName].value = f.elements[fieldName+"_1"].value + "-" + f.elements[fieldName+"_2"].value + "-" +f.elements[fieldName+"_3"].value;
		
	}
	catch(e){
		;
	}
}

function GetQueryString() {
	return top.location.href(/^[^\?]+\?/, "");
}

function ValidateEmail(arg){
	arg = arg + "";
	if(arg.indexOf("@")!=-1 && arg.indexOf(".")!=-1 && arg!="")
		return true;
	else 
		return false;
}

function ValidateDate(strDate){
	strDate = strDate + "";
	strDate = strDate.replace(/\s/g,"");
	var arrDatePart = strDate.split("/");
		
	if(arrDatePart.length==3){
		//' Check month, day, year, respectively
		if(arrDatePart[0]=="" || parseInt(arrDatePart[0])<1 || parseInt(arrDatePart[0])>12)
			return false;
		else if(arrDatePart[1]=="" || parseInt(arrDatePart[1])<1 || parseInt(arrDatePart[1])>31)
			return false;
		else if(arrDatePart[2].toString().length!=2 && arrDatePart[2].toString().length!=4)
			return false;
	}
	else{
		return false;	
	}
	return true;
}

function ValidateTime(strTime){
	strTime += "";
	strTime = strTime.replace(/\s/g,"");
	if(strTime.indexOf(":")!=-1){
		var hr = strTime.substr(0,strTime.indexOf(":"));
		var min = strTime.substr(strTime.indexOf(":")+1,strTime.indexOf(":")+3);
		var ampm = strTime.substr(strTime.length-2,strTime.length);
		if(hr="" || parseInt(hr)<1 || parseInt(hr)>12)
			return false;
		else if(min="" || parseInt(min)<0 || parseInt(min)>59)
			return false;
		else if(ampm.toLowerCase()!="am" && ampm.toLowerCase()!="pm")
			return false;
	}
	else
		return false;
	
	return true;
}

function ValidateDropdown(optionCollObj){
	var cntSelected=0;
	for(i=0;i<optionCollObj.length;i++){
		if(optionCollObj[i].selected && optionCollObj[i].value!="")
			cntSelected++;
	}
	if(cntSelected==0)
		return false;
		
	return true;
}

function ValidateCheckboxes(checkCollObj){
	var cntChecked=0;
	for(i=0;i<checkCollObj.length;i++){
		if(checkCollObj[i].checked)
			cntChecked++;
	}
	if(cntChecked==0)
		return false;
		
	return true;
}