function _(id){return document.getElementById(id) || false; } //prototype like shortcut, moving on to jQuery


function ajax_upload(form,url_action){
	window.parent._('loading').style.display='block';
	if(jQuery("#virtualart .errors")){jQuery("#virtualart .errors").remove();;}
	var id_element = 'virtualart'; // change as necessary
	var detectWebKit = isWebKit();
	var erro="";
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id","ajax-temp");
	iframe.setAttribute("name","ajax-temp");
	iframe.setAttribute("width","0");
	iframe.setAttribute("height","0");
	iframe.setAttribute("border","0");
	iframe.setAttribute("style","width: 0; height: 0; border: none;");
	form.parentNode.appendChild(iframe);
	window.frames['ajax-temp'].name="ajax-temp";
	var do_upload = function(){
		removeEvent(_('ajax-temp'),"load", do_upload);
	
		var cross = "javascript: ";
		var js ='var img = jQuery("#virtualart body:last div img", window.parent.document).attr("src");img = img.split("src=");phpsrc = img[1].split("&w=");virt = phpsrc[0].split("/");newpath = virt.slice(-3).join("/");jQuery("#virtualart body:last div",window.parent.document).data("link", {source:"internal",path:newpath});';
		cross += "window.parent._('loading').style.display='none';window.parent._('"+id_element+"').appendChild(document.body);"+js+"; void(0);";
		_('ajax-temp').src = cross;
		if(detectWebKit){
        	remove(_('ajax-temp'));
        }else{
        	setTimeout(function(){ 	
        		if(jQuery("#virtualart body:last div img", window.parent.document).size()>0){
				var img = jQuery("#virtualart body:last div img", window.parent.document).attr("src");
				
				img = img.split("src=");
				phpsrc = img[1].split("&w=");
				virt = phpsrc[0].split("/");
				newpath = virt.slice(-3).join("/");
				jQuery("#virtualart body:last div",window.parent.document).data("link", {source:"internal",path:newpath});
				}
				remove(_('ajax-temp'))}, 250);
        }
		
    }
	jQuery('#ajax-temp').load(do_upload);

	form.setAttribute("target","ajax-temp");
	form.setAttribute("action",url_action);
	form.setAttribute("method","post");
	form.setAttribute("enctype","multipart/form-data");
	form.setAttribute("encoding","multipart/form-data");
	
	//$('file_ui').style.display = 'none';
	//_(id_element).style.display = 'block';
	form.submit();
}
function gatherArt()
{
	link = new Array();
	art = new Array();
jQuery("#virtualart div").each(function(){
	link = new Array();
	link['source'] = jQuery(this).data("link").source;
	link['path'] = jQuery(this).data("link").path;
	art.push(link);
	});	
	return art;
}
function utf8_encode ( argString ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}
function serialize (mixed_value) {
    // http://kevin.vanzonneveld.net
    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // +   improved by: Dino
    // +   bugfixed by: Andrej Pavlovic
    // +   bugfixed by: Garagoth
    // +      input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html)
    // +   bugfixed by: Russell Walker (http://www.nbill.co.uk/)
    // +   bugfixed by: Jamie Beck (http://www.terabit.ca/)
    // +      input by: Martin (http://www.erlenwiese.de/)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/)
    // +   improved by: Le Torbi (http://www.letorbi.de/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/)
    // -    depends on: utf8_encode
    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'

	var _utf8Size = function (str) {
	    var size = 0, i = 0, l = str.length, code = '';
	    for (i = 0; i < l; i++) {
	        code = str[i].charCodeAt(0);
	        if (code < 0x0080) {
	            size += 1;
	        } else if (code < 0x0800) {
	            size += 2;
	        } else {
	        	size += 3;
			}
	    }
	    return size;
	};
    var _getType = function (inp) {
        var type = typeof inp, match;
        var key;

        if (type === 'object' && !inp) {
            return 'null';
        }
        if (type === "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
			val = "s:" + _utf8Size(mixed_value) + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = this.serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
			    if (mixed_value.hasOwnProperty(key)) {
               	   ktype = _getType(mixed_value[key]);
	               if (ktype === "function") { 
	                   continue; 
	               }
               
	               okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
	               vals += this.serialize(okey) +
	                       this.serialize(mixed_value[key]);
	               count++;
		        }
            }
            val += ":" + count + ":{" + vals + "}";
            break;
        case "undefined": // Fall-through
        default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
            val = "N";
            break;
    }
    if (type !== "object" && type !== "array") {
        val += ";";
    }
    return val;
}
function isWebKit(){
	return RegExp(" AppleWebKit/").test(navigator.userAgent);
}
function remove(theVar){
	var theParent = theVar.parentNode;
	theParent.removeChild(theVar);
}
function removeEvent(obj, type, fn){
	if(obj.detachEvent){
		obj.detachEvent('on'+type, fn);
	}else{
		obj.removeEventListener(type, fn, false);
	}
}
/*
Class for associative arrays in javascript
*/
function Hash()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}

	//myHash.removeItem(i)
	this.removeItem = function(in_key)
	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
   
		return tmp_value;
	}

	//myHash.getItem(i)
	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	// myHash.setItem('foobar', 'hey')
	this.setItem = function(in_key, in_value)
	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}

			this.items[in_key] = in_value;
		}
   
		return in_value;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}
}

var WinORContact = null; // global variable
var WinORNew = null;
var WinORProject = null;
var WinORAction = null;
var WinORCusRequest = null;
var WinORInternal = null;
var WinORIK = null;

function addContact(cid, add)
{
	if(WinORContact == null || WinORContact.closed)
	/* if the pointer to the window object in memory does not exist
    or if such pointer exists but the window was closed */
	{
	WinORContact = window.open('add_contact.php?cid='+cid+'&add='+add,
   	"individualContactWin", "resizable=yes,scrollbars=no,status=yes,toolbar=no,menubar=no,width=580,height=400px;");
    /* then create it. The new window will be created and
       will be brought on top of any other window. */
	}
	else
	{
	WinORContact.focus();
    /* else the window reference must exist and the window
       is not closed; therefore, we can bring it back on top of any other
       window with the focus() method. There would be no need to re-create
       the window or to reload the referenced resource. */
	};
}

function openNewProject(tid,query,sort,aod)
{
	if(WinORNew == null || WinORNew.closed){
	WinORNew = window.open('handle_win.php?tid='+tid+'&q='+query+'&st='+sort+'&aod='+aod+'&new=1',
   	"newWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=858;");
	}else{
	WinORNew.focus();
	};
}
	//seperate instance of openNewProject so that both windows can be simultaneously open
	function openProject(tid,cid,query,sort,aod)
	{
		if(WinORProject == null || WinORProject.closed){
		WinORProject = window.open('/dashboard/handle_win.php?tid='+tid+'&cid='+cid+'&q='+query+'&st='+sort+'&aod='+aod,
	   	"openWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=858;");
		}else{
		WinORProject.focus();
		};
	}
	
	//seperate instance of openNewProject so that both windows can be simultaneously open
	function openContact(cid)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('edit_contact.php?cid='+cid,
	   	"contactWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=760;");
		}else{
		WinORContact.focus();
		};
	}
		
	function openJob(id)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('view_job.php?id='+id,
	   	"tickettWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=760;");
		}else{
		WinORContact.focus();
		};
	}
	
	function openTicket(id)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('tickets/view_ticket.php?id='+id,
	   	"tickettWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=760;");
		}else{
		WinORContact.focus();
		};
	}
		
	function admin_openTicket(id)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('user_inc/admin/view_ticket.php?id='+id,
	   	"adminWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=760;");
		}else{
		WinORContact.focus();
		};
	}
	
	function open_artJob(jid)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('art_worksheet.php?jid='+jid,
	   	"artWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=580,height=760;");
		}else{
		WinORContact.focus();
		};
	}
	
	function printTickets(filter, st, aod)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('user_inc/admin/ticketList.php?ft='+filter+'&st='+st+'&aod='+aod,
	   	"printtWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=620,height=760;");
		}else{
		WinORContact.focus();
		};
	}
	
	function printContacts(query, qtype, filter, st, aod)
	{
		if(WinORContact == null || WinORContact.closed){
		WinORContact = window.open('contactsList.php?ft='+filter+'&q='+query+'&qt='+qtype+'&st='+st+'&aod='+aod,
	   	"printtWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=620,height=760;");
		}else{
		WinORContact.focus();
		};
	}
	
	function openAction(url,width,height,scroll)
	{
		if (!width || width=='undefined') width = 530;
		if (!height || height=='undefined') height = 620;
		if (!scroll || scroll=='undefined') scroll = 'yes';
		if(WinORAction == null || WinORAction.closed){
		WinORAction = window.open(url,
	   	"actionWin", "resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,width="+width+",height="+height+";");
		}else{
		WinORAction.focus();
		};
	}
	
	function openTodo(url,width,height,scroll)
	{
		if (!width || width=='undefined') width = 530;
		if (!height || height=='undefined') height = 620;
		if (!scroll || scroll=='undefined') scroll = 'yes';
		if(WinORAction == null || WinORAction.closed){
		WinORAction = window.open(url,
	   	"todoWin", "resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,width="+width+",height="+height+";");
		}else{
		WinORAction.focus();
		};
	}

function openCusRequest(cid,width,height,cds)
{
	if (!width || width=='undefined') width=520;
	if (!height || height=='undefined') height=300;
	if(WinORCusRequest == null || WinORCusRequest.closed){
	WinORCusRequest = window.open('customer_request.php?cid='+cid+(cds!='undefined'?'&cds='+cds:''),
   	"cusReqWin", "resizable=yes,scrollbars=no,status=yes,toolbar=no,menubar=no,width="+width+",height="+height);
	}else{
	WinORCusRequest.focus();
	};
}

function openInternal()
{
	if(WinORInternal == null || WinORInternal.closed){
	WinORInternal = window.open('internal_request.php',
   	"intReqWin", "resizable=yes,scrollbars=no,status=yes,toolbar=no,menubar=no,width=520,height=300;");
	}else{
	WinORInternal.focus();
	};
}

function openIdeaKit(ikID)
{
	if(WinORIK == null || WinORIK.closed){
	WinORIK = window.open('common/edit_ideakit.php?ik_id='+ikID,
   	"IKWin", "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,width=700,height=800;");
	}else{
	WinORIK.focus();
	};
}

function get(obj) {  
	var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
		if (obj.childNodes[i].tagName == "TEXTAREA") {
            var ta = obj.childNodes[i];
            getstr += ta.name + "=" + escape(ta.value) + "&";
         }

      }
	if (obj==document.getElementById('contactForm')){
		saveForm('queries/save_customer.inc.php'+getstr,'savedMsg');
	}else if (obj==document.getElementById('tickerForm')){
		saveForm('queries/save_internal.php'+getstr,'savedMsg2');
	}else if (obj==document.getElementById("prodSearchForm")){
		saveForm('queries/search_man.php'+getstr,'showMan');
	}else if (obj==document.getElementById("adminForm")){
		saveForm('queries/save_user.php'+getstr,'saveAdmin');
	}
	//document.write(getstr);
   }
   
// saves the Reports Accessible form
function saveReport(form){
	var q = (form.iid ? '?iid='+form.iid.value : '?iid=');
	var els = form.getElementsByTagName('input');
	for(var i=0;i<els.length;i++)
	{
		if(els[i].type=='checkbox')
			q += '&' + els[i].name + '=' + (els[i].checked==true ? els[i].value : '0');
		else
			q += '&' + els[i].name + '=' + escape(els[i].value);
	}
	var tels = form.getElementsByTagName('textarea');
	for(var i=0;i<tels.length;i++)
	{
			q += '&' + tels[i].name + '=' + escape(tels[i].value);
	}
	
	var sels = form.getElementsByTagName('select');
	for(var i=0;i<sels.length;i++)
	{
		q += '&' + sels[i].name + '='
		for (var j=0; j<sels[i].options.length; j++)
			if (sels[i].options[j].selected)
				q += escape(sels[i].options[j].value)+',';
	}
	//alert(q);
	saveForm('queries/save_reportAcc.php'+q,'saveMsg');
}

// allows you to SELECT ALL in a multiple select field
function selectAllOptions(id)
	{
		var ref = document.getElementById(id);
		
		for(i=0; i<ref.options.length; i++)
			ref.options[i].selected = true;
	}

// takes in the url and parses it for get variable values
// specifically the var act
function getActionType(url){
	strings1 = url.split('?');
	strings2 = strings1[1].split('&');
	for (i=0;i<=strings2.length;i++){
		if (strings2[i].indexOf("act")==0){
			strings3 = strings2[i].split("=");
			return strings3[1];
		}
	}
}

//explode task items to interact
function toggleTask(row) {
	rowno = document.getElementById('rowNum').value;
	for (i=1;i<=rowno;i++){
		document.getElementById('task' + i).style.height = '17px';
	}

	if (document.getElementById('task' + row).style.height!= 'auto'){
		//alert(row);
		document.getElementById('task' + row).style.height = 'auto';
		document.getElementById('openTask').value = row;
	}else{
		document.getElementById('task' + row).style.height = '17px';
		
	}
	document.getElementById('openTaskVal').value='';
}

function toggleTaskColor(row) {
	if (document.getElementById('contact' + row).style.backgroundColor!= '#c5d5e5'){
		document.getElementById('contact' + row).style.backgroundColor = '#c5d5e5';
		if (document.getElementById('openTask').value){
			document.getElementById('contact' + document.getElementById('openTask').value).style.backgroundColor = '#fff';
		}
		document.getElementById('openTask').value = row;
	}
}

//highlight an element on mouseover
function hLite(el){
	el.style.border = '1px solid #003793';
}
function dLite(el){
	el.style.border = '1px solid #dedede';
}

function hLight(el,hoverColor){
	if (hoverColor=='undefined' || !hoverColor) hoverColor='#FAFAD2';
	el.style.border = '1px solid #003793';
	el.style.backgroundColor = hoverColor;
}
function dLight(el,origColor){
	if (origColor=='undefined' || !origColor) origColor='#ffffff';
	el.style.border = '1px solid #dedede';
	el.style.backgroundColor = origColor;
}

function hideDiv(id){
	if (document.getElementById(id)){
		document.getElementById(id).style.display='none';
	}
}

function toggleHistory(id){
	rowno = document.getElementById('rowNumHistory').value;
	for (i=1;i<=rowno;i++){
		document.getElementById('requestHistory' + i).style.display = 'none';
	}
	document.getElementById(id).style.display='block';
}

function toggle(target) {
	alert(target);
	obj=document.getElementById(target);
	obj.style.display=( (obj.style.display=='none') ? '' : 'none');
}

var intervalID;
var intIntervalID;
var amIntervalID;
function setLeads(user,sort,aod){
	showDash('user_inc/account_manager/leads_xml.php?du='+user+'&st='+sort+'&aod='+aod, 'internalDiv');
}
function setProjects(user,query,sort,aod){
	showDash('user_inc/account_manager/active_xml.php?du='+user+'&q='+query+'&st='+sort+'&aod='+aod, 'internalDiv');
}
function setToDo(url,query,filter,sort,aod,nbd){
	showDash(url+'&q='+query+'&ft='+filter+'&st='+sort+'&aod='+aod+'&nbd='+nbd, 'internalDiv');
}

function showTicket(url,query,filter,sort,aod){
	showDash(url+'&q='+query+'&filter='+filter+'&st='+sort+'&aod='+aod, 'internalDiv');
}


function setSalesManager(user,sort,aod){
	str = 'user_inc/sales_manager/leads_xml.php?du='+user+'&st='+sort+'&aod='+aod;
	showDash(str, 'internalDiv');
}

function setCsManager(user,sort,aod){
	str = 'user_inc/cs_manager/clients_xml.php?du='+user+'&st='+sort+'&aod='+aod;
	showDash(str, 'internalDiv');
}

function setHR(user,sort,aod){
	str = 'user_inc/human_resources/jobs_xml.php?du='+user+'&st='+sort+'&aod='+aod;
	showDash(str, 'internalDiv');
}

function setProduction(user,sort,aod){
	str = 'user_inc/prod_manager/active_xml.php?du='+user+'&st='+sort+'&aod='+aod;
	showDash(str, 'internalDiv');
}

function setSC(user,sort,aod){
	str = 'user_inc/sales_coordinator/active_xml.php?du='+user+'&st='+sort+'&aod='+aod;
	showDash(str, 'internalDiv');
}

function setPM(user,program,sort,aod,query){
	showDash('user_inc/program_manager/leads_xml.php?du='+user+'&pm='+program+'&st='+sort+'&aod='+aod+'&q='+query, 'internalDiv');
}

function setCatalog(user,sort,aod){
	showDash('user_inc/catalog_dept/active_xml.php?du='+user+'&st='+sort+'&aod='+aod, 'internalDiv');
}
function setSample(user){
	showDash('user_inc/sample_dept/active_xml.php?du='+user, 'internalDiv');
}
function setVirtualSample(user){
	showDash('user_inc/art_department/active_xml.php?du='+user, 'internalDiv');
}
function setMarketing(user,filter,sort,aod){
	showDash('user_inc/marketing_dept/projects_xml.php?du='+user+'&ft='+filter+'&st='+sort+'&aod='+aod, 'internalDiv');
}
function setAdmin(user,adminUser){
	showDash('user_inc/admin/active_xml.php?du='+user+'&au='+adminUser, 'internalDiv');
}
function setReporting(user,adminUser){
	showDash('user_inc/admin/reportsAdmin.php?du='+user+'&au='+adminUser, 'internalDiv');
}

function setAcct(user,sort,aod){
	showDash('user_inc/accounting/active_xml.php?du='+user+'&st='+sort+'&aod='+aod, 'internalDiv');
}

function clearamInt(){
	clearInterval(amIntervalID);
}
function setNew(user){
	showDash('new_xml.php?du='+user, 'newProjects');
}
function setOpen(user){
	showInternal('open_xml.php?du='+user, 'openProjects');
}
function setNews(popup){
	showInternal('news_xml.php?pu='+popup, 'internalDiv');
}
function setTools(user){
	showInternal('tools_xml.php?du='+user, 'internalDiv');
}
function setContact(filter, query, qtype, all, sort, aod){
	showContact('contacts_xml.php?du='+filter+'&q='+query+'&qt='+qtype+'&all='+all+'&st='+sort+'&aod='+aod, 'contacts');
	document.getElementById('accountRep').value=filter;
}
function setClient(filter, query, qtype, all, sort, aod){
	showDash('user_inc/cs_manager/clients_xml.php?filter='+filter+'&q='+query+'&qt='+qtype+'&all='+all+'&st='+sort+'&aod='+aod, 'internalDiv');
	document.getElementById('accountRep').value=filter;
}
function setIdeaKit(query, filter, sort, aod){
	showInternal('ideakit_xml.php?q='+query+'&ft='+filter+'&st='+sort+'&aod='+aod, 'ideaKits');
}
function setQuote(query, filter, am_ft, sort, aod){
	showInternal('ideakit_xml.php?q='+query+'&ft='+filter+'&am_ft='+am_ft+'&st='+sort+'&aod='+aod, 'ideaKits');
}
function setReport(user, report, filter, from, to, sort, aod){
	showInternal('report/index.php?du='+user+'&rid='+report+'&ft='+filter+'&fm='+from+'&to='+to+'&st='+sort+'&aod='+aod, 'body');
}
/*
function searchContacts(query){
	//(document.searchForm.all.checked==true)?cb=1:cb=0;
	//if (query.length==0) cb=0;
	setContact(document.getElementById('accountRep').value, query, 1);
}
*/
function searchIdeaKits(query){
	if (query.length<3){
		alert("Please enter at least 3 characters");
		return false;
	}
	setIdeaKit(query);
	return false;
}

function handleBio(){
	var url = 'queries/save_bio.php'; var q = '';
	var bio = document.getElementById('bioContent');
	var iputs=bio.getElementsByTagName("input")
	for(var i=0;i<iputs.length;i++)
		q += (i!=0?'&':'')+iputs[i].name+'='+escape(iputs[i].value);

	showContact(url+'?'+q,'savedMsg2');	
}
function validate(aForm){
	if (aForm.assignto){
		if (aForm.assignto.value==''){
			alert("Please assign the project");
			return valid = false;
		}
	}else if (document.requestForm.status){
		for (var i=0; i<=aForm.childNodes.length; i++){
			if (aForm.elements[i].value == ''){
				aForm.elements[i].style.backgroundColor = '#eee';
				alert("Please complete the form");
				return valid = false;
			}
		}
	}
	
	aForm.submit()
};

function processAdmin(checkbox){
	var makeString='';
	accessArr = document.getElementById("accessLevels").value.split(",");
	if (accessArr.indexOf(checkbox.value)>=0){
		accessArr.splice(accessArr.indexOf(checkbox.value),1);
	}else{
		accessArr.push(checkbox.value);
	}
	
	for (var i=0;i<accessArr.length;i++){
		makeString += accessArr[i];
		if (i!=accessArr.length-1){
			makeString += ",";
		}
	}
	document.getElementById("accessLevels").value = makeString;
}

function toggleLegend(id){
	if (document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display='none';
	}else{
		left = (document.documentElement.clientWidth/2)+140;
		document.getElementById(id).style.left = left+'px';
		document.getElementById(id).style.display='block';
	}
}

function navDivs(el){
	navs = document.getElementById("headers").getElementsByTagName("DIV");
	for (i=0;i<navs.length;i++){
		navs[i].className="header";
	}
	document.getElementById("one").style.display="none";	
	document.getElementById("two").style.display="none";
	document.getElementById("three").style.display="none";
	document.getElementById("four").style.display="none";
	
	document.getElementById(el).style.display="block";
	document.getElementById('header_'+el).className="selected";
}

var WindowObjectReference = null; // global variable
var WindowObjectReference_a = null; // global variable
var WindowObjectReference_b = null; // global variable
var WindowObjectReference_c = null; // global variable

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;
	  }
	
	if(WindowObjectReference == null || WindowObjectReference.closed){
		WindowObjectReference = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth +',height='+myHeight);
	}else{
		WindowObjectReference.focus();
	}
}

/*OpenDIV( divname )

This function will make a div visible. It is only one way! If you want open and close then see below. Takes the id of a div

*/
function OpenDIV( divname ) {

    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(divname).style.display == "none"){
            document.getElementById(divname).style.display = 'block';
        }
    } else {
        if (document.layers) {
            if (document.divname.display == "none"){
                document.divname.display = 'block';
            }
        } else {
            if (document.all.divname.style.visibility == "none"){
                document.all.divname.style.display = 'block';
            }
        }
    }
}


/*

CloseDIV( divname )

This function will make a div invisible. It is only one way! If you want open and close then see below. Takes the id of a div

*/
function CloseDIV( divname ) {

    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(divname).style.display != "none"){
            document.getElementById(divname).style.display = 'none';
        }
    } else {
        if (document.layers) {
            if (document.divname.display != "none"){
                document.divname.display = 'none';
            }
        } else {
            if (document.all.divname.style.visibility != "none"){
                document.all.divname.style.display = 'none';
            }
        }
    }
}

/* 

OpenCloseDIV( id )

This function takes an id. The function will look for a div named (id)_block and change the visibility of it. In addition to the _block div it will also try to switch images for (id)_img image tag. It will do a plus sign when (id)_block is not visible and minus when it is

*/
function OpenCloseDIV(id,img_path,table,image_open,image_close,custom_path) {
    var divname = id + "_block";
    var imgname = id + "_img";

    var newimg

    // make this useful to tables as well
    var type = 'block';
    if ( table == 1 ) { type = 'table'; }

    if (document.getElementById) { // DOM3 = IE5, NS6
      if ( type == 'block' ){
        if (document.getElementById(divname).style.display == "none"){
            document.getElementById(divname).style.display = "block";
            newimg = 'minus'
        } else {
            document.getElementById(divname).style.display = 'none';
            newimg = 'plus' 
        }
      } else {
        if (document.getElementById(divname).style.display == 'none'){
            document.getElementById(divname).style.display = '';
            newimg = 'minus'
        } else {
            document.getElementById(divname).style.display = 'none';
            newimg = 'plus'
        }

      }
    } else {
        if (document.layers) {
            if (document.divname.display == "none"){
                document.divname.display = "block";
                newimg = 'minus'
            } else {
                document.divname.display = 'none';
                newimg = 'plus' 
            }
        } else {
            if (document.all.divname.style.visibility == "none"){
                document.all.divname.style.display = "block";
                newimg = 'minus'
            } else {
                document.all.divname.style.display = 'none';
                newimg = 'plus' 
            }
        }
    }

    if ( document.images[imgname] ) {
	    var Imgs = new Object;

        if ( img_path ) {
          Imgs.minus = img_path+"square_close.gif";
          Imgs.plus = img_path+"square_open.gif";
        } 
        else if ( custom_path ) {
          Imgs.minus = custom_path+image_close;
          Imgs.plus  = custom_path+image_open;
        }
        else if ( image_open ) {
          Imgs.minus = "images/"+image_close;
          Imgs.plus  = "images/"+image_open;
        }
        else {
      	  Imgs.minus = "../images/square_close.gif";
          Imgs.plus = "../images/square_open.gif";
        }

      switchimg(imgname,Imgs[ newimg ]);
    }
    
}


/*
switchimg( image_name , imgsrc )

Internal function to change a specific image src

*/
function switchimg( image_name , imgsrc){
    if (document.images){
        document.images[image_name].src = imgsrc;
    }
}
