_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);

if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }

if (win_ie_ver >= 5.5) {
	document.write('<scr' + 'ipt src="editor.js"');
	document.write(' type="text/javascript"></scr' + 'ipt>');  
}
else { 
	document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); 
}

function open_customer(id, pid) {
	
	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.getElementById)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 502)/2, yOffset = (yMax - 412)/2;
	var url = 'edit_customer.php?id=' + id + '&prj_id=' + pid;
	var cust = window.open(url, '','left=0,top=0,locationbar=0,menubar=0,resizeable=0,width=516,height=412,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	cust.focus();
}
function help_window(file)
{
	window.open(file,'MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=400'); 
}

function check_form()
{
	frm = window.document.plan;
	if (frm.plan_name.value.length <= 0) {
		alert('Please enter plan name!');
		frm.plan_name.focus();
		return false;
	}
	return true;
}

function summary_print() {
	document.the_data.action="manage_data.php?act=print";
	document.the_data.submit();
}
function summary_download() {
	document.the_data.action="manage_data.php?act=download";
	document.the_data.submit();
}


function calculate_total (id)
{
	frm = window.document.addons;
	str_add = "s[add_quantity-" + id + "]";
	str_price = "element_price-" + id;
	str_total = "total-" + id;
	a = 0;
	b = 0;
	c = 0;
	for (i = 0; i < frm.length; i++){
		if (frm.elements[i].type == "text"){
			if (frm.elements[i].name == str_add){
				a = frm.elements[i].value;
			}
			else if (frm.elements[i].name == str_price){
				b = frm.elements[i].value;
			}
			else if (frm.elements[i].name == str_total){
				c = frm.elements[i];
			}
		}
	}
	total = a * b;
	c.value = total;
	return true;
}
function check_form ()
{
	frm = window.document.addons;
	have_element = false;
	for (i = 0; i < frm.length; i++){
		if (frm.elements[i].type == "text" && frm.elements[i].value != 0 && frm.elements[i].name.substr(2,4) == "add_"){
			have_element = true;
		}
	}
	if (have_element)
		frm.submit();
	return false;
}


function open_window(url) {
	
	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.getElementById)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 400)/2, yOffset = (yMax - 300)/2;
	var wind = window.open(url, '','left=0,top=0,locationbar=0,menubar=0,resizeable=0,width=400,height=300,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	wind.focus();
}

function open_window2(url) {
	
	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.getElementById)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 400)/2, yOffset = (yMax - 300)/2;
	var wind = window.open(url, '','left=0,top=0,locationbar=0,scrollbars=1,menubar=0,resizeable=0,width=400,height=300,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	wind.focus();
}

function cps_check()
{
    var d = document.cps;

	if (d.cps_val.value == '') {
		alert("Please enter value!");
		d.cps_val.focus();
		return false;
	}

	if (!/^([0-9]{1,2}|100)$/.test(d.cps_val.value)) {
		alert("Please enter digits between 0 and 100!");
		d.cps_val.focus();
		return false;
	}
	return true;
}