//var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
//return (filter.test(str))?true:false

function load_tip(caller, tip_id){ try {
	if(typeof tips_title[tip_id] != "undefined" && typeof tips_text[tip_id] != "undefined"){
		ie =(typeof document.all == "undefined")?false:true;
		div = document.createElement("div");
		div.style.display = "none";
		div.innerHTML = "<div style='background-color:#aaaaaa; font-weight:700'>"+ tips_title[tip_id] +"<\/div><div style='padding: 1px 3px 1px 3px;'>"+ tips_text[tip_id] +"<\/div>";
		div.style.top = findPosY(caller)-div.offsetHeight + "px";
		div.style.left = findPosX(caller)+caller.offsetWidth+(ie==true?10:0) + "px";
		div.style.width = "200px";
		div.style.position = "absolute";
		div.className = "over_tip";
		document.body.appendChild(div);
		caller.temp_div = div;
		div.style.display = "block";
		div.style.top = findPosY(caller)-div.offsetHeight+(ie==true?15:0) + "px";
	} } catch(e) { ;}
}
function unload_tip(caller){ try { document.body.removeChild(caller.temp_div);  } catch(e) { ;} }
function Mod10(ccNumb) {  // v2.0 For Credit Card Number Validation
	var valid = "0123456789"  // Valid digits in a credit card number
	ccNumb = ccNumb.replace(/\D/g,"");
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit
	// Determine if it is the proper length 
	if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
		bResult = false;
	} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
		if(len >= 15){  // 15 or 16 for Amex or V/MC
			for(var i=len;i>0;i--){  // LOOP throught the digits of the card
				calc = parseInt(iCCN) % 10;  // right most digit
				calc = parseInt(calc);  // assure it is an integer
				iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
				i--;  // decrement the count - move to the next digit in the card
				iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
				calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
				calc = calc *2;                                 // multiply the digit by two
				// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
				// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
				switch(calc){
				case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
				case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
				case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
				case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
				case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
				default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
				}                                               
				iCCN = iCCN / 10;  // subtracts right most digit from ccNum
				iTotal += calc;  // running total of the card number as we loop
			}  // END OF LOOP
			bResult = (iTotal%10)==0?true:false;
		}
	}
	return bResult; // Return the results
}

function alt_color(obj_select, color0, color1){
	try {
		var color = Array(); color[0] = color0; color[1] = color1;
		for(var i = 0; i < obj_select.options.length; i++){ obj_select.options[i].style.backgroundColor = color[i%2]; }
	} catch(e) {}
}

function deletethisrow(v, v1, v2){
	objects = document.getElementById(v1).getElementsByTagName('td');
	for(var i = 0; i < objects.length; i++){ if(v.checked){ objects[i].style.backgroundColor = v2; } else { objects[i].style.backgroundColor = ''; } }
}
function mouseovertr(v, v1){ objects = v.getElementsByTagName('td'); for(var i = 0; i < objects.length; i++){ objects[i].style.backgroundColor = v1; } }
function mouseouttr(v){ objects = v.getElementsByTagName('td'); for(var i = 0; i < objects.length; i++){ objects[i].style.backgroundColor = ''; } }

function editthisrow(v, v2){
	objects = document.getElementById(v2).getElementsByTagName('input');
	for(var i = 0; i < objects.length; i++){
		if(objects[i].type=='text'){
			if(v.checked){
				objects[i].style.borderWidth = "2px"; objects[i].readOnly = false;
			} else {
				objects[i].style.borderWidth = "0px"; objects[i].readOnly = true;
			}
		}
	}
	objects = document.getElementById(v2).getElementsByTagName('select');
	for(var i = 0; i < objects.length; i++){
		if(v.checked){
			objects[i].style.borderWidth = "2px"; objects[i].disabled = false;
		} else {
			objects[i].style.borderWidth = "0px"; objects[i].disabled = true;
		}
	}
}
//------------------------------------------------------

function loadSurvey(v1, cmp_id){ var frame = document.getElementById('response'); var r = ""; 
if(ie){ frame.location.href = "./crm_response.php?company_id="+cmp_id+"&survey_id=" + v1.value; } 
else { response.location.href = "./crm_response.php?company_id="+cmp_id+"&survey_id=" + v1.value; } 
}
//------------------------------------------------------
function removeOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--){ if(selectbox.options[i].selected) { selectbox.remove(i); } } }
function removeAllOptions(selectbox){ var i; for(i=selectbox.options.length-1;i>=0;i--){ selectbox.remove(i); } }
function move_list(src, dest, if_all){
	for (var i = src.options.length - 1; i >= 0; i--){
		if (src.options[i].selected || if_all==true){
			var option = document.createElement("option");
			dest.options[dest.length] = option;
			option.text = src.options[i].text;
			option.value = src.options[i].value;
			src.remove(i);
		}
	}
}

function sortOptions(obj){
        var values = new Array();
        for(var no=0;no<obj.options.length;no++){
            values.push(obj.options[no].text+","+obj.options[no].value);
        }
        values = values.sort();
        obj.options.length=0;
        for(var no=0;no<values.length;no++){
            valueArray = values[no].split(',');
            obj.options[obj.options.length] = new Option(valueArray[1],valueArray[0]);
        }        
}

function if_exist(v1, v2){ for(var i=0; i<v2.length; i++){ if(v2.options[i].value==v1){ return true;} } return false; }

function copy_list(src, dest, if_all, splitter){
	for (var i = 0; i < src.options.length; i++){
		if ((src.options[i].selected || if_all==true) && if_exist(src.options[i].value, dest) == false){
			var option = document.createElement("option");
			dest.options[dest.length] = option;
			if(splitter==' as '){
				option.text = src.options[i].text;
				tmp = src.options[i].value.split(" as ");
				if(typeof(tmp[1]) != 'undefined' && tmp[1]!=''){
					option.value = tmp[1];
				} else {
					option.text = src.options[i].text;
					option.value = src.options[i].value;
				}
			} else {
				option.text = src.options[i].text;
				option.value = src.options[i].value;
			}
		}
	}
}
function selectAll(obj) {
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	if (obj.tagName.toLowerCase() != "select") return;
	for (var i=0; i<obj.length; i++) { obj[i].selected = true; }
}

function selectNone(obj) { /* NEW added from version 1.1 */
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	if (obj.tagName.toLowerCase() != "select") return;
	for (var i=0; i<obj.length; i++) { obj[i].selected = false;	}
}

function moveUp(element) { try {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
} catch(e) {; } }
function moveDown(element) { try {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
} catch(e) {; } }
function moveTopd(obj, dir) { try {
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	if (obj.tagName.toLowerCase() != "select" && obj.length < 2) return false;
	var elements = new Array();
	for (var i=0; i<obj.length; i++) {
		if (obj[i].selected  && dir == "top") { elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); }
		if (!obj[i].selected && dir != "top") { elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); }
	}
	for (vari=0; i<obj.length; i++) {
		if (!obj[i].selected && dir == "top") { elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); }
		if (obj[i].selected  && dir != "top") { elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); }
	}
	for (var i=0; i<obj.length; i++) {
	}
	for (var i=obj.length-1; i>-1; i--) {
	}
} catch(e) {; } }
function moveTop(obj) { try {
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	if (obj.tagName.toLowerCase() != "select" && obj.length < 2) return false;
	var elements = new Array();
	for (var i=0; i<obj.length; i++) { if (obj[i].selected) { elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); } }
	for (var i=0; i<obj.length; i++) { if (!obj[i].selected){ elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); } }
	for (var i=0; i<obj.length; i++) {
		if (document.body.innerHTML) obj[i].innerHTML = elements[i][0]; else obj[i].text = elements[i][0];
		obj[i].value 		= elements[i][1];
		obj[i].style.color 	= elements[i][2];
		obj[i].style.backgroundColor = elements[i][3];
		obj[i].className 		= elements[i][4];
		obj[i].id 				= elements[i][5];
		obj[i].selected 		= elements[i][6];
	}
} catch(e) {; } }

function moveBottom(obj) { try {
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	if (obj.tagName.toLowerCase() != "select" && obj.length < 2) return false;
	var elements = new Array();
	for (var i=0; i<obj.length; i++) { if (!obj[i].selected){ elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); } }
	for (var i=0; i<obj.length; i++) { if (obj[i].selected) { elements[elements.length] = new Array((document.body.innerHTML ? obj[i].innerHTML : obj[i].text), obj[i].value, obj[i].style.color, obj[i].style.backgroundColor, obj[i].className, obj[i].id, obj[i].selected); } }
	for (var i=obj.length-1; i>-1; i--) {
		if (document.body.innerHTML) obj[i].innerHTML = elements[i][0]; else obj[i].text = elements[i][0];
		obj[i].value 		= elements[i][1];
		obj[i].style.color 	= elements[i][2];
		obj[i].style.backgroundColor = elements[i][3];
		obj[i].className 	= elements[i][4];
		obj[i].id 			= elements[i][5];
		obj[i].selected 	= elements[i][6];
	}
} catch(e) {; } }


function grp_selector(caller, target){ try { 
		caller = (typeof caller == "string") ? document.getElementById(caller) : caller;
		target = (typeof target == "string") ? caller.form[target] : target;
		if (caller.tagName.toLowerCase() != "select" || target.tagName.toLowerCase() != "select") return false;
		var groups = target.getElementsByTagName('optgroup');
		for(i = 0; i < groups.length; i++) {
			groups[i].style.display = (groups[i].label == caller.options[caller.selectedIndex].value ? "" : "none");
			///groups[i].isDisabled = (groups[i].label == caller.options[caller.selectedIndex].value ? false : true);
			if(groups[i].label != caller.options[caller.selectedIndex].value){
				//caller.form.t1.value = dumpprop(groups[i]);
				//for(j=0; j < groups[i].childNodes.length; j++){ groups[i].childNodes[j].style.display = "none"; return; }
			}
		}
} catch(e) { alert(e); } }

function show_select(caller, targets, target){ try {
	caller = (typeof caller == "string") ? document.getElementById(caller) : caller;
	if(typeof targets != "string") return;
	if(typeof target != "string") return;
	targets = document.getElementsByName(targets);
	for(i = 0; i < targets.length; i++){
		targets[i].style.display = (targets[i].id != target)?"none":"";
	}
} catch(e) { alert(e); } }


function count_sel(thissel) { try { var selCount = 0; for (var i=0; i<thissel.length; i++) if (thissel[i].selected) selCount ++; return selCount; } catch(e) {} }

function add_order(src, v){
	for (var i = 0; i < src.options.length; i++){
		if (src.options[i].selected){
			src.options[i].value = src.options[i].value.replace("desc","");
			src.options[i].text = src.options[i].text.replace("desc","");
			src.options[i].value = src.options[i].value.replace("asc","");
			src.options[i].text = src.options[i].text.replace("asc","");
			src.options[i].value += v;
			src.options[i].text += v;
		}
	}

}

function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:	var i1 = i; var temp  = new Option(list.options[i].text, list.options[i].value); break;
        case 2: var i2 = i; var temp2 = new Option(list.options[i].text, list.options[i].value); break;
      }
    }
  }
  if (j != 2) { alert('Only 2 items can be swapped'); } else {
    list.options[i1] = temp2; list.options[i1].selected = true;
    list.options[i2] = temp;  list.options[i2].selected = true;
  }
}
function select_all_options(vSelect){
	try { for(var x = 0; x < vSelect.length; x++){ vSelect.options[x].selected = true; }  
	} catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
}
//---------------------------------------------------------------------
function findPosX(obj){ var curleft = 0; if (obj.offsetParent){ while (obj.offsetParent){ curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) { curleft += obj.x; } return curleft; }
function findPosY(obj){ var curtop = 0; if (obj.offsetParent){ while (obj.offsetParent){ curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) { curtop += obj.y; } return curtop; }
//---------------------------------------------------------------------
function makeRequest(url, id) {
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { 
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(http_request, id); };
	http_request.open('GET', url, true);
	http_request.send(null);

}

function alertContents(http_request, id) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			 id.innerHTML = http_request.responseText;
		} else {
			alert('There was a problem with the request.');
		}
	}

}
//---------------------------------------------------------------------
function half_full(v1, v2){
	if(document.getElementById(v1).style.overflow=='auto'){
		document.getElementById(v1).style.overflow='visible';
	} else {
		document.getElementById(v1).style.overflow='auto';
	}
}
//---------------------------------------------------------------------
function sendToClipboard(s){
	if( window.clipboardData && clipboardData.setData ){
		clipboardData.setData("Text", s);
	} else {
		alert("Please use Ctrl+C to Copy and then Ctrl+V to Paste because only Internet Explorer support Auto Copy");
	}
}
//---------------------------------------------------------------------
function resize_me(){
	try {	var oBody = document.body;
			self.window.resizeTo(oBody.scrollWidth, oBody.scrollHeight);
		}	catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
}
function resize_frame(v1, extra){ 
	try {	var oBody = document.body;
			window.self.parent.document.getElementById(v1).height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight) + extra;
		}	catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
}
//---------------------------------------------------------------------
function selectValue(o, v) { for(var i=0; i<o.length; i++){ if(o[i].value==v){ o[i].selected=true; i=o.length; } } }
//---------------------------------------------------------------------
function dump_prop(o){
	var text ='';
	for (p in o) { 
		try { if(typeof o[p] != "function") text += p +" : "+ o[p] +"\n"; }  catch(e) { continue; }
	}
	return text;
}
function dump_func(o){
	var text ='';
	try { for (p in o) if(typeof o[p] == "function") { text += p +" : "+ o[p] +"\n"; } } catch(e) { return text; }
	return text;
}

function dump_props1(obj, obj_name) {
	var text = "";
	try { for (var i in obj) if(typeof obj[i] != "function") { text += obj_name + "." + i + " = " + obj[i] + "\n"; } } catch(e) { return text; }
	return text;
}


var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction){
	var theDefaultColor = '#FFFFFF';
	var thePointerColor = '#CCFFCC';
	var theMarkColor    = '#FFCC99';
	var theCells = null;
    // 1. Pointer and mark feature are disabled or the browser can't get the row -> exits
    if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') { return false; }
    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') { theCells = theRow.getElementsByTagName('td'); }
    else if (typeof(theRow.cells) != 'undefined') { theCells = theRow.cells; } else { return false; }
    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    } else { // 3.2 ... with other browsers
        currentColor = theCells[0].style.backgroundColor; domDetect    = false;
    } // end 3
    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if(currentColor == null ) { currentColor =""; };
    if (currentColor.indexOf("rgb") >= 0) {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1, currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++) {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color 4.1 Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
// Garvin: deactivated onclick marking of the checkbox because it's also executed  when an action (like edit/delete) on a single item is performed. Then the checkbox
// would get deactived, even though we need it activated. Maybe there is a way to detect if the row was clicked, and not an item therein...
// document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '') ? thePointerColor : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) ? true : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4
    // 5. Sets the new color...
    if (newColor) {
        var c = null; // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) { for (c = 0; c < rowCellsCnt; c++) { theCells[c].setAttribute('bgcolor', newColor, 0); } }
        else { for (c = 0; c < rowCellsCnt; c++) { theCells[c].style.backgroundColor = newColor; } } // 5.2 ... with other browsers
    } // end 5
    return true;
} // end of the 'setPointer()' function


function checkallswitch(v1, v2, v3){
	for(var i=0; i < v3.length; i++)	if(v3[i].name==v2) v3[i].checked = v1.checked;
}

function show_hide_column(table_id, col_no, do_show) {
	var stl;
	if (do_show){stl = 'block'; } else { stl = 'none'; }
	var tbl  = document.getElementById(table_id);
	var rows = tbl.getElementsByTagName('tr');
	for (var row=0; row<rows.length;row++) {
		var cels = rows[row].getElementsByTagName('td');
		if(cels[col_no]){ cels[col_no].style.display=stl; }
	}
}


function load_file(v1, v2){
	var frame = document.getElementById(v1);
	if(ie){		frame.location.href = v2;	} else {			window.frames[v1].location.href = v2;	}
}
//---------------------------------------- copy paste 

function copyPaste(v1){
	if(tempDiv.style.display=="block"){ pasteThis(v1); } else { copyThis(v1); }
}

function copyThis(v1){
	if(v1.nodeName == "INPUT" || v1.nodeName == "OPTION"){ tempDiv.innerHTML = v1.value; } else { tempDiv.innerHTML = v1.innerHTML; }
	tempDiv.style.display = "block";
	document.onmousemove = getMouseXY;
}

function copyThisVal(v1, v2){
	tempDiv.innerHTML = v2;
	tempDiv.style.display = "block";
	document.onmousemove = getMouseXY;
}

function copyThis1(v1){
	tempDiv.innerHTML = v1;
	tempDiv.style.display = "block";
	document.onmousemove = getMouseXY;
}
function pasteThis(v1){
	if(tempDiv.style.display=="block"){
		insertAtCursor(v1, tempDiv.innerHTML);
		//if(v1.nodeName == "INPUT" || v1.nodeName == "OPTION"){ v1.value = tempDiv.innerHTML; } else { v1.innerHTML = tempDiv.innerHTML; }
		tempDiv.innerHTML="";
		document.onmousemove = "";
		tempDiv.style.display = "none";
	}
}
function pasteThis1(v1){
	if(tempDiv.style.display=="block"){
		if(v1.nodeName == "INPUT" || v1.nodeName == "OPTION"){ v1.value = tempDiv.innerHTML; } else { v1.innerHTML = tempDiv.innerHTML; }
		tempDiv.innerHTML="";
		document.onmousemove = "";
		tempDiv.style.display = "none";
	}
}

function getMouseXY(e) {
  if (IE) { tempX = event.x;    tempY = event.y + document.body.scrollTop; } else {  tempX = e.pageX;	 tempY = e.pageY;  }  
  tempDiv.style.top=tempY + "px";
  tempDiv.style.left=tempX+12 + "px";
  // catch possible negative values in NS4
  if (tempX < 0){ tempX = 0; }	if (tempY < 0){ tempY = 0; }
  return true;
}

function insertAtCursor(myField, myValue) {
	if (document.selection) { //IE support
		myField.focus(); sel = document.selection.createRange(); sel.text = myValue;
	} else if (myField.selectionStart || myField.selectionStart == '0') { //MOZILLA/NETSCAPE support
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	} else { myField.value += myValue; }
}
//---------------------------------------------------------------------------------------
function format_phone(n) {
	var s = String(n.value);
	var re = /\D/g;
	s = s.replace(re,"");
	if(s.length<5){ return n.value = s; }
	try{
		s = s.substr(0, s.length-4)+"-"+s.substr(s.length-4, 4);
	} catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
	try { if (s.length>8) s = s.substr(0, s.length-8)+"-"+s.substr(s.length-8, 8);
	} catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
	try { if(s.length>12) s = s.substr(0, s.length-12)+"-"+s.substr(s.length-12, 12);
		  if(s.length==12) s = '1'+s.substr(0, s.length-12)+"-"+s.substr(s.length-12, 12);
	} catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
	n.value = s;
}
//---------------------------------------------------------------------------------------
function getElementsByTagNames(list,obj){
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++)	{
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++)		{			resultArray.push(tags[j]);		}
	}
	var testNode = resultArray[0];
	if (testNode.sourceIndex)	{
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}	else if (testNode.compareDocumentPosition)	{
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}
//---------------------------------------------------------------------------------------
function OpenBrWindow(theURL, winName, features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter == true ){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+='left='+myLeft+',top='+myTop;
  }
  features = features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight
  var win = window.open(theURL, winName, features, false);
  win.focus();
}

var WindowObjectReference; // global variable

function openRequestedPopup()
{
  WindowObjectReference = window.open("http://www.google.com",
        "DescriptiveWindowName",
        "width=420,height=230,resizable,scrollbars=yes,status=1");
}
//<A href="javascript:;" onClick="OpenBrWindow('test.html','Test','','300','300','true')">
//<A href="javascript:;" onClick="OpenBrWindow('test.html','Test2','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes','400','350','true')">
//--------------------------------------------------------------------------------------------
function list(values){
	var selectbox = document.createElement('select');
	selectbox.size = 15;
	selectbox.style.display = "none";
	selectbox.style.width = "400px";
	selectbox.style.zIndex = "99999999";
	option = document.createElement("OPTION");	option.text = ""; option.value = ""; selectbox.options.add(option);
	option = document.createElement("OPTION");	option.text = "no change"; option.value = "no change"; selectbox.options.add(option);
	this.source = selectbox;
	this.pick = list_pick;
	this.pick2 = list_pick2;
	this.hide = list_hide;
	this.source.onchange = list_onchange;
	this.source.onblur = list_hide;
	this.add = list_add;
	this.add2 = list_add2;
	this.add_opt = list_add2;
	this.add_grp = list_add_grp;
	this.add_in_grp = list_add_in_grp;
	this.set_size = list_set_size;
	//this.source.onblur == list_onblur; //this.source.addEventListener("blur", list_onblur, false); 
	//if( this.source.addEventListener ) this.source.addEventListener('blur', list_onblur, false);
	//else if( this.source.attachEvent ) this.source.attachEvent('onblur', list_onblur);
}
function list_set_size(size){
	this.source.size = size;
}
function list_add(values, group){
	if(group){
		optiongrp = document.createElement("optgroup"); optiongrp.setAttribute("label", group);
		this.source.appendChild(optiongrp);
		for(i = 0; i < values.length; i++){ option = new Option();	option.innerHTML = values[i]; option.value = values[i]; optiongrp.appendChild(option); }
	} else { 
		for(i = 0; i < values.length; i++){ option = document.createElement("OPTION");	option.text = values[i]; option.value = values[i]; this.source.options.add(option);	}
	}
}
function list_add_grp(group){ optiongrp = document.createElement("optgroup"); optiongrp.setAttribute("label", group); this.source.appendChild(optiongrp); return optiongrp; }
function list_add_in_grp(group, text, value){ 
	if(group){ 
		var option = document.createElement("option");
		option.innerText = text;	option.text = text;	option.value = value;	group.appendChild(option);
		//var option = new Option();	option.value = value; option.text = text; group.appendChild(option);
	}
}
function list_add2(text, value){ option = document.createElement("OPTION");	option.text = text; option.value = value; this.source.options.add(option); }
function list_pick(target, target_obj){
	if(target_obj){
		target = target_obj;
	} else {
		target1 = target;
		target = document.getElementById(target); if(!target){ return false; }
		this.target = target;
	}
	if(!this.source){ return false; }
	target.form.appendChild(this.source);
	target.style.position = 'relative';
	for(i=0; i < this.source.options.length; i++){  if(this.source.options[i].value == target.value) { this.source.options[i].selected = true; } }
	this.target = target; this.source.selectedIndex = 0; this.source.style.position = 'absolute';
	//this.source.style.width=target.offsetWidth + "px";
	this.source.style.top=target.offsetTop+target.offsetHeight + "px";
	this.source.style.left=target.offsetLeft + "px";
	this.source.setAttribute('target', target_obj.id);
	this.source.style.display = "block";
	this.source.focus();
}
function list_pick2(target){
	if(typeof(target) == "object"){ this.target = target; } else { target = document.getElementById(target); }
	if(!target){ return false; }
	if(!this.source){ return false; }
	target.form.appendChild(this.source);
	target.style.position = 'relative';
	for(i=0; i < this.source.options.length; i++){  if(this.source.options[i].value == target.value) { this.source.options[i].selected = true; } }
	this.target = target; this.source.selectedIndex = 0; this.source.style.position = 'absolute';
	//this.source.style.width=target.offsetWidth + "px";
	this.source.style.top=target.offsetTop+target.offsetHeight + "px";
	this.source.style.left=target.offsetLeft + "px";
	this.source.setAttribute('target', target.id);
	this.source.style.display = "block";
	this.source.focus();
}
function list_onchange() {
	if(typeof(this.getAttribute('target')) == "object"){
		target = this.getAttribute('target');
	} else {
		target = document.getElementById(this.getAttribute('target'));
	}
	if(this.selectedIndex == 0){
		target.value = "";
	} else if(this.selectedIndex == 1){ 
	} else if(target.type == "text" && this.selectedIndex > 1){
		target.value = this.options[this.selectedIndex].value;
	} else if(target.type == "select-one" && this.selectedIndex > 1) {
		target.options[0].value = this.options[this.selectedIndex].value;
		target.options[0].text = this.options[this.selectedIndex].text;
	}
	this.style.display = "none";
	this.form.removeChild(this);
}
function list_hide() { this.style.display = "none"; }
//-------------------------------------------------------------------------------
function orgs_perm(s, t){
	s = document.getElementById(s);
	t = document.getElementById(t);
	var tmp = Array();
	if(!s || !t) return;
	for(var i =0; i < s.options.length; i++){ if(s.options[i].selected){ tmp[tmp.length] = s.options[i].text;} }
	for(var i = 0; i < t.childNodes.length; i++){
		if(!t.childNodes[i].tagName) continue;
		t.childNodes[i].style.display = (inarray(tmp, t.childNodes[i].label))?"block":"none";
	}
}
function inarray( ary, val ) { for(var j = 0; j < ary.length; j++){ if(ary[j] == val) return true; } return false; }
//-------------------------------------------------------------------------------
function disable_form(frm){
	try {
		if(frm.tagName && frm.tagName.toLowerCase()=="form"){
		} else if(frm.form && frm.form.tagName && frm.form.tagName.toLowerCase()=="form"){
			frm = frm.form;
		} else if(document.getElementById(frm) && document.getElementById(frm).tagName.toLowerCase()=="form") {
			frm = document.getElementById(frm);
		} else if(document.forms[frm] && document.forms[frm].tagName.toLowerCase()=="form") {
			frm = document.forms[frm];
		} else { return; }
		for (var i=0; i < frm.length; i++) { frm[i].disabled = true; frm[i].style.backgroundColor = "#cccccc"; }
	} catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
}
//-------------------------------------------------------------------------------
function enable_form(frm){
	try {
		if(frm.tagName && frm.tagName.toLowerCase()=="form"){
		} else if(frm.form && frm.form.tagName && frm.form.tagName.toLowerCase()=="form"){
			frm = frm.form;
		} else if(document.getElementById(frm) && document.getElementById(frm).tagName.toLowerCase()=="form") {
			frm = document.getElementById(frm);
		} else if(document.forms[frm] && document.forms[frm].tagName.toLowerCase()=="form") {
			frm = document.forms[frm];
		} else { return; }
		for (var i=0; i < frm.length; i++) { frm[i].disabled = false; frm[i].style.backgroundColor = ""; }
	} catch(e){ window.status = 'Error: ' + e.number + '; ' + e.description; }
}
//-------------------------------------------------------------------------------
function radio_value(obj){
	if(!obj) return;
	for( i = 0; i < obj.length; i++ ){ if( obj[i].checked == true ) return obj[i].value; }
	return "";
}
//--------------------------------------------------------------------------------
function show_pane(caller, pane, div, test){
	if(test=='test'){ }
	try {
	var obj = document.getElementById(div);
	var divs = obj.getElementsByTagName('DIV');
	for (var j=0; j<divs.length; j++) if(divs[j].parentNode==obj) divs[j].style.display = "none";
	obj = document.getElementById(pane);
	obj.style.display = "block";
	var frms = obj.getElementsByTagName('IFRAME');
	for (var j=0; j<frms.length; j++) {
		if(frms[j].parentNode==obj)	if(frms[j].src=="") frms[j].src = frms[j].title;
		resize_iframe(frms[j]);
	}
	var imgs = caller.parentNode.getElementsByTagName('IMG');
	for (var j=0; j<imgs.length; j++) {
		if(imgs[j]==caller){
			caller.src = caller.src.replace(/_out_/, "_active_");
			caller.src = caller.src.replace(/_over_/, "_active_");
			caller.name = 1;
		//} else if(imgs[j].name==1) {
		} else {
			imgs[j].src = imgs[j].src.replace(/_active_/, "_out_");
			imgs[j].src = imgs[j].src.replace(/_over_/, "_out_");
			imgs[j].name = 0;
		}
	}
} catch(e) {}
}
//-------------------------------------------------------------------------------/
function resize_iframe(frm){ try { frm.style.height = (frm.contentWindow.document.body.scrollHeight+40)+"px"; } catch(e) {} }
//-------------------------------------------------------------------------------/
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+''+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '' + num + '.' + cents);
}
//--------------------------------
function get_form_by_object(v){ try { if(v.tagName=="FORM") return v; return get_form_by_object(v.parentNode); } catch(e) {} }
// DYS-------------------------------------------------------------------------------/
function calc_dys_budget(v1, v2){ try {
	var frm = get_form_by_object(v1);
	var one_day=1000*60*60*24; var frq = ""; var difft = 0; var total = 0; var actual = 0; 
	for(i = 0; i < v2; i++){
		frq = "frequency["+i+"]"; dst = "date_start["+i+"]"; den = "date_end["+i+"]"; fam = "freq_amount["+i+"]";
		tam = "total_amount["+i+"]"; act = "actual["+i+"]"; dif = "diff["+i+"]"; det = "details["+i+"]";
		if(frm[frq].options[frm[frq].selectedIndex].value=="" || frm[dst].value=="" || frm[den].value==""){ frm[tam].value = "0.0"; continue; }
		ds  = frm[dst].value.split("-"); std = new Date(); std.setFullYear(ds[0]); std.setMonth(ds[1]-1); std.setDate(ds[2]); std.setHours(0); std.setMinutes(0);  std.setSeconds(0);
		de  = frm[den].value.split("-"); end = new Date(); end.setFullYear(de[0]); end.setMonth(de[1]-1); end.setDate(de[2]); end.setHours(0); end.setMinutes(0);  end.setSeconds(0);
		frm[fam].value.replace(",", "");
		switch(frm[frq].options[frm[frq].selectedIndex].value){
		case "daily":   diff = Math.round((end.getTime()-std.getTime())/(one_day))+1;   t = frm[fam].value * diff; frm[tam].value = formatCurrency(t); break;
		case "weekly":  diff = (Math.round((end.getTime()-std.getTime())/(one_day))+1)/7; t = frm[fam].value * diff; frm[tam].value = formatCurrency(t); break;
		case "monthly": diff = (Math.round((end.getTime()-std.getTime())/(one_day))+1)/30.4166666;t = frm[fam].value * diff; frm[tam].value = formatCurrency(t); break;
		case "quarterly": diff = (Math.round((end.getTime()-std.getTime())/(one_day))+1)/91.25;t = frm[fam].value * diff; frm[tam].value = formatCurrency(t); break;
		case "bi-annual": diff = (Math.round((end.getTime()-std.getTime())/(one_day))+1)/182.5;t = frm[fam].value * diff; frm[tam].value = formatCurrency(t); break;
		case "one time": t = frm[fam].value * 1; frm[tam].value = formatCurrency(t); break;
		}
		frm[dif].value = formatCurrency(t - parseFloat(frm[act].value));
		total = parseFloat(total) + parseFloat(t);
		actual = parseFloat(actual) + parseFloat(frm[act].value);
		difft = parseFloat(difft) + parseFloat(t - parseFloat(frm[act].value));
	}
	frm.g_total.value = formatCurrency(total); frm.f_total.value = formatCurrency(actual); frm.d_total.value = formatCurrency(difft);
	return true;
} catch(e) {} }

function check_all(obj, name){ try {
	elms = obj.form.elements;
	for(var i=0; i < elms.length; i++){ if(elms[i].type=="checkbox" && elms[i].name.match(new RegExp(name))) elms[i].checked = obj.checked; }
} catch(e) {} }
function sh(v1){ v = document.getElementById(v1).style; v.height = (v.height=='60px')?'16px':'60px'; }
//-------------------------------------------------------------------------------/
function edit_select(e, obj){ try {
	if(obj.title=="--Edit--"){
		var keynum = (window.event)?e.keyCode:e.which;
		if(keynum==8 && obj.options[0].text != "--Edit--" && obj.options[0].text.length>0){
			obj.options[0].value = obj.options[0].text = obj.options[0].text.substr(0, obj.options[0].text.length-1);
		}else if(keynum==46){
			obj.options[0].value="";	obj.options[0].text="--Edit--";
		}else if(keynum<32){
		}else if(keynum==32){
			obj.options[0].label = keynum;
		}else{
			if(obj.options[0].text == "--Edit--"){
				obj.options[0].value = obj.options[0].text  = String.fromCharCode(keynum);
			} else {
				if(obj.options[0].label==32){
					obj.options[0].value = obj.options[0].text += " ".concat(String.fromCharCode(keynum));
				} else {
					obj.options[0].value = obj.options[0].text += String.fromCharCode(keynum);
				}
			}
			obj.options[0].label = "";
		}
	}
	if(obj.options[0].text=="--Edit--")	obj.options[0].value="";
} catch(e) {} }
//-------------------------------------------------------------------------------/
function show_all_camp(id){ try {
	var grps = document.getElementById(id).getElementsByTagName('optgroup');
	//grps[i].style.display = "block";
	//for(var i = 0; i< grps.length; i++)  if(grps[i].lang!=1) grps[i].style.display = (grps[i].style.display == "block")?"none":"block";
} catch(e) {} }
//-------------------------------------------------------------------------------/
function frm_focus(caller){ }
function frm_blur(caller){ }
//-------------------------------------------------------------------------------/
function closeOut(){
	if (confirm("Do you really want to close this window")){ return true; }
	return false;
	location.href = document.URL;
}
//-------------------------------------------------------------------------------/
function insertAtCursor(myField, myValue) {
	if (document.selection) { //IE support
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}  else if (myField.selectionStart || myField.selectionStart == '0') {   //MOZILLA/NETSCAPE support
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}
//-------------------------------------------------------------------------------/

