// JavaScript Document

/**********************************************************************************************************/

// BEGIN CLOCK
function clock()
{
    if ( !document.getElementById ) return;
    var d = new Date ();
    var hours = d.getHours ();
    var minutes = d.getMinutes ();
    var seconds = d.getSeconds ();
    var ampm = hours > 11 ? "pm" : "am";
    hours %= 12;
    if (hours == 0) hours = "12";
    if (minutes < 10) minutes = "0" + minutes;
    if (seconds < 10) seconds = "0" + seconds;
    document.getElementById ( "pendule" ).innerHTML = hours + ":" + minutes + ":" + seconds + " " + ampm;
    setTimeout( "clock()", 1000 );
}
// END CLOCK

/**********************************************************************************************************/

// FORM CHECKING FUNCTIONS BELOW
function checkSubmitTicket(){
    var strError
    strError = "";
    if(document.frmSubmitTicket.name.value == ""){
        strError = strError + "Please enter your name\n";
    }
    if(document.frmSubmitTicket.email.value == ""){
        strError = strError + "Please enter your email address\n";
    }
    if(document.frmSubmitTicket.title.value == ""){
        strError = strError + "Please enter a title for your ticket\n";
    }
/*
	if(document.frmSubmitTicket.description.value == ""){
        strError = strError + "Please enter a description of your problem\n";
    }
*/
    if(document.frmSubmitTicket.priority_ID.value == ""){
        strError = strError + "Please select a priority for this ticket\n";
    }
	/*if(document.frmSubmitTicket.FileDescription.value == ""){
		strError = strError + "Document description required\n";
	}
	if(document.frmSubmitTicket.File1.value == ""){
		strError = strError + "Document required\n";
	}*/

    if(strError.length > 0){
        alert(strError);
        return false;
        }else{
        return true;
    }
}

function checkSubmitTicket2(){
	
	
    var strError
    strError = "";
    if(document.frmSubmitTicket.Contact_ID.value <= "0"){
        strError = strError + "Please select a contact\n";
    }
    if(document.frmSubmitTicket.title.value == ""){
        strError = strError + "Please enter a title for your ticket\n";
    }
/*
	if(document.frmSubmitTicket.description.value == ""){
        strError = strError + "Please enter a description of your problem\n";
    }
*/
    if(document.frmSubmitTicket.priority_ID.value == ""){
        strError = strError + "Please select a priority for this ticket\n";
    }
    if(strError.length > 0){
        alert(strError);
        return false;
        }else{
        return true;
    }
}


function checkSubmitResponse(){
    var strError
    strError = "";
    if(document.frmSubmitResponse.description.value == ""){
        strError = strError + "Please enter your response\n";
    }
    if(strError.length > 0){
        alert(strError);
        return false;
        }else{
        return true;
    }
}

function confirmChangeStatus()
{
	var agree=confirm("Are you sure you want to change the status of this ticket?");
	if (agree)
		document.forms[0].submit();
}

function confirmChangePriority()
{
	var agree=confirm("Are you sure you want to change the priority of this ticket?");
	if (agree)
		document.forms[1].submit();
}

// FORM CHECKING FUNCTIONS ABOVE

/**********************************************************************************************************/

// FORM CHECKING FUNCTIONS BELOW
var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ 
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj,imgID){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
	var img = document.getElementById(imgID);
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") 
				ar[i].style.display = "none";
			}
			el.style.display = "block";
			//img.src = '/images/up.gif';
		}else{
			el.style.display = "none";
			//img.src = '/images/down.gif';
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate
// FORM CHECKING FUNCTIONS ABOVE


var popUpWin=0;
function popUpWindow(URLStr, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  
  var left = (screen.width-width)/2;
  var top = (screen.height-height)/2;
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// BEGIN AJAX 
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(action,id,timer) {
	//alert(action);
	//alert(id);
	if (timer == '0') {
		//alert(action);
		http.open('get', '/projects/ajax_response.asp?action='+action+'&id='+id);
		http.onreadystatechange = handleResponse;
		http.send(null);
	} else {
		setTimeout("sndReq('"+action+"','"+id+"','0')",1000);		
	}
}

function sndReqTimer(action,id,id2,timer) {
	if (timer == '0') {
		//alert(action);
		http.open('get', '/admin/ajax/ajax_response.asp?action='+action+'&id='+id+'&id2='+id2);
		/*if(confirm('Open Page?')){
			window.location.href = '/admin/ajax/ajax_response.asp?action='+action+'&id='+id+'&id2='+id2;
		}*/
		http.onreadystatechange = handleResponse;
		http.send(null);
	} else if (timer == '1'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",500);		
	} else if (timer == '2'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",1000);		
	} else if (timer == '3'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",1500);		
	} else if (timer == '4'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",2000);		
	} else if (timer == '5'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",2500);		
	}
	
}

function sndReqTimerClient(action,id,id2,timer) {
	//alert(action + '\n' + id + '\n' + id2);
	if (timer == '0') {
		//alert(action);
		http.open('get', '/includes/ajax_response.asp?action='+action+'&id='+id+'&id2='+id2);
		/*if(confirm('Open Page?')){
			window.location.href = '/admin/ajax/ajax_response.asp?action='+action+'&id='+id+'&id2='+id2;
		}*/
		http.onreadystatechange = handleResponse;
		http.send(null);
	} else if (timer == '1'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",500);		
	} else if (timer == '2'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",1000);		
	} else if (timer == '3'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",1500);		
	} else if (timer == '4'){
		setTimeout("sndReqTimer('"+action+"','"+id+"','"+id2+"','0')",2000);		
	}
}

function showloading(layer) {
	document.getElementById(layer).innerHTML = '<img src="/images/ajax-loader.gif">';
}


function ajaxContractType(layer,id,id2,timer) {
	//alert(layer + '\n' + id + '\n' + id2);
	if (timer == '0') {
		//alert(layer);
		var sURL = '/ajax_response.asp?layer='+layer+'&id='+id+'&id2='+id2
		http.open('get', sURL);
		http.onreadystatechange = handleResponsetest;
		http.send(null);
	} else if (timer == '1'){
		showloading(layer);
		setTimeout("ajaxContractType('"+layer+"','"+id+"','"+id2+"','0')",500);		
	} else if (timer == '2'){
		showloading(layer);
		setTimeout("ajaxContractType('"+layer+"','"+id+"','"+id2+"','0')",1000);		
	} else if (timer == '3'){
		showloading(layer);
		setTimeout("ajaxContractType('"+layer+"','"+id+"','"+id2+"','0')",1500);		
	} else if (timer == '4'){
		showloading(layer);
		setTimeout("ajaxContractType('"+layer+"','"+id+"','"+id2+"','0')",2000);		
	} else if (timer == '5'){
		showloading(layer);
		setTimeout("ajaxContractType('"+layer+"','"+id+"','"+id2+"','0')",10000);		
	}
}

function handleResponsetest() {
    if(http.readyState == 4){
        var response = http.responseText;
		//alert(http.responseText);
        var update = new Array();
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
		//alert(http.responseText);
        var update = new Array();
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}
// END AJAX
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

//	'Check All' checkbox script
var checkflag = true;

function check(field) {
	checkflag = document.getElementById('copyinall_Check').checked;
	if (checkflag == true) {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;}
			checkflag = "true";
			return "Uncheck All";
		}
	else {
		for (i = 0; i < field.length; i++) {
		field[i].checked = false; }
		checkflag = "false";
		return "Check All";
	}
}

var popUpWin=0;
function popUpWindow(URLStr, width, height)
{
  if(popUpWin) { if(!popUpWin.closed) popUpWin.close(); }
  var left = (screen.width-width)/2;
  var top = (screen.height-height)/2;
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function TimedPopupCloser(iTimeMiliSecs) { 
	setTimeout(this.window.close(),iTimeMiliSecs); 
}

function grayOut(vis, options) {

var options = options || {}; 
	var zindex = options.zindex || 100;
	var opacity = options.opacity || 70;
	var opaque = (opacity / 100);
	var bgcolor = options.bgcolor || '#000000';
	var dark=document.getElementById('darkenScreenObject');
	if (!dark) {
		// The dark layer doesn't exist, it's never been created.  So we'll
		// create it here and apply some basic styles.
		// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('div');           // Create the layer.
		tnode.style.position='absolute';                 // Position absolutely
		tnode.style.top='0px';                           // In the top
		tnode.style.left='0px';                          // Left corner of the page
		tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
		tnode.style.display='none';                      // Start out Hidden
		tnode.id='darkenScreenObject';                   // Name it so we can find it later
		tbody.appendChild(tnode);                            // Add it to the web page
		tbody.onclick="alert('')"
		dark=document.getElementById('darkenScreenObject');  // Get the object.
	}
	if (vis) {
		sSelectHide = 'none';
		// Calculate the page width and height 
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
			var pageWidth = document.body.scrollWidth+'px';
			var pageHeight = document.body.scrollHeight+'px';
		} else if( document.body.offsetWidth ) {
			var pageWidth = document.body.offsetWidth+'px';
			var pageHeight = document.body.offsetHeight+'px';
		} else {
			var pageWidth='100%';
			var pageHeight='100%';
		}   
		//set the shader to cover the entire page and make it visible.
		dark.style.opacity=opaque;                      
		dark.style.MozOpacity=opaque;                   
		dark.style.filter='alpha(opacity='+opacity+')'; 
		dark.style.zIndex=zindex;        
		dark.style.backgroundColor=bgcolor;  
		dark.style.width= pageWidth;
		dark.style.height= pageHeight;
		dark.style.display='block';				 
	} else {
		dark.style.display='none';
		sSelectHide = '';
	}
}
var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

function object_attach(id)
{
obj = document.getElementById(id);
	return obj;
}

function div_switch(id, bShow, bBlock)
{
	if(document.getElementById(id)){
		//if(id!='cars'){
			temp_Obj = object_attach(id);
			if(ns4)
			{
				if(bShow==true)
				{
					if(bBlock==true) { temp_Obj.display = ""; }
					else { temp_Obj.visibility = "show"; }
				}
				else
				{
					if(bBlock==true) { temp_Obj.display = "none"; }
					else { temp_Obj.visibility = "hide"; }
				}
			}
			else
			{
				if(bShow==true)
				{
					if(bBlock==true) { temp_Obj.style.display = ""; }
					else { temp_Obj.style.visibility = "visible"; }
				}
				else
				{
					if(bBlock==true) { temp_Obj.style.display = "none"; 
					}else{ 
						if(temp_Obj){
							//alert("Yes");
							temp_Obj.style.visibility = "hidden"; 
						}else{
							//alert("No");
						}
					}
				}
			}
		//}
	}
}
function ShowHomePageMap(vis){
	grayOut(vis);
	div_switch('HomepageMap',vis,true);
}
function showhideResponse(){
	if(document.getElementById('No_Response').checked == true){
		document.getElementById('div_Response').style.display = 'none';
	}else{
		document.getElementById('div_Response').style.display = '';
	}
}
function openCloseTimesheet(){
    tSheet1 = document.getElementById("timeSheetHide");
    tSheet2 = document.getElementById("timeSheetHide2");
    if (tSheet1.style.display == "none"){
        tSheet1.style.display = "block";
        tSheet2.style.display = "block";
    }else{
        tSheet1.style.display = "none";
        tSheet2.style.display = "none";
    }
}
