var bgColor = "";
var delToggle = new Array();
delToggle[0] = new Object();
delToggle[0]['poBoxDelToggleEmails'] = true;
delToggle[0]['poBoxDelToggleList'] = true;
delToggle[0]['sentDelToggleEmails'] = true;
delToggle[0]['inboxDelToggle'] = true;


function changeBgColor (obj) {
	bgColor = obj.style.backgroundColor;
	obj.style.backgroundColor = "#EBA358"; //FFCC00";
}

function restoreBgColor (obj) {
	obj.style.backgroundColor = bgColor;
}

function changeSelectBoxBgColor (obj, colorBrg) {

	if (typeof(colorBrg)=="undefined") colorBrg = "#ffffff";
	
	bgColor = obj.style.backgroundColor;
	obj.style.backgroundColor = "#316AC5"; //FFCC00";
	obj.style.color = colorBrg;
	
	var count = stringToNumber(obj.id);
	var prefix = stringWithoutNumber(obj.id);
	
	for (c = 1; c < count; c++) {
		var modColorBrg = (c*1)%2!=0?colorBrg:'#ffffff';
		eval("getElement('id', '"+prefix+(c*1)+"', null).style.backgroundColor = modColorBrg");
		eval("getElement('id', '"+prefix+(c*1)+"', null).style.color = '#818181'");		
	}
	c++;
	while (eval("getElement('id', '"+prefix+(c*1)+"', null)")) {
		var modColorBrg = (c*1)%2!=0?colorBrg:'#ffffff';	
		eval("getElement('id', '"+prefix+(c*1)+"', null).style.backgroundColor = modColorBrg");
		eval("getElement('id', '"+prefix+(c*1)+"', null).style.color = '#818181'");						
		c++;		
	} 
}

function restoreSelectBoxBgColor (obj) {
	obj.style.backgroundColor = "#ffffff";
	obj.style.color = "#818181";	
}

function changeBgColorRow (obj, cols) {
//	alert(obj.id.substr(0,1));
	bgColor = obj.style.backgroundColor;
	for (var i = 1; i <= cols; i++)
		if (document.getElementById(obj.id.substr(0,1)+i+obj.id.substr(2)))
			changeBgColor (document.getElementById(obj.id.substr(0,1)+i+obj.id.substr(2)));
}

function restoreBgColorRow (obj, cols) {
	for (var i = 1; i <= cols; i++)
		if (document.getElementById(obj.id.substr(0,1)+i+obj.id.substr(2)))
			restoreBgColor (document.getElementById(obj.id.substr(0,1)+i+obj.id.substr(2)));
}

function ismaxlength(obj,mlength){
	if (obj && obj.value.length>=mlength)
		obj.value=obj.value.substring(0,(mlength-1));
}

function delPost(frmName, chbName, text, altText, withCheck) {
	if (withCheck) {
		if (checkIfChecked(frmName, chbName)) {
			Check = confirm(text);
			if (Check == true)
				submitForm(frmName);
		} else
			alert(altText);
	} else {
		Check = confirm(text);
		if (Check == true)
			submitForm(frmName);		
	}
}

function delPost2(frmName, chbName, text) {

	if (checkIfChecked(frmName, chbName)) {
		submitForm(frmName);		
	} else {
		alert(text);		
	}
}

function delPost3(frmName, chbName1, chbName2, text1, text2) {

	frm1Checked	= checkIfChecked(frmName, chbName1);
	frm2Checked	= checkIfChecked(frmName, chbName2);
	
	if (frm1Checked && frm2Checked) {
		submitForm(frmName);		
	} else if (!frm1Checked && !frm2Checked) {
		alert(text1 + '\n' + text2);		
	} else if (frm1Checked && !frm2Checked) {
		alert(text2);		
	} else if (!frm1Checked && frm2Checked) {
		alert(text1);		
	}
}

function submitForm(name) {
	eval("document."+name+".submit();");
}

function del(obj, text) {
	Check = confirm(text);
	if (Check == true)
		saveScrollPos(obj);
}

function saveScrollPos(value) {
	var over1Str = "";
	var over2Str = "";	
	windowY = (document.body.scrollTop?document.body.scrollTop:window.pageYOffset);
	if (document.getElementById('overview'))
		over1Str = "&overview="+document.getElementById('overview').scrollTop;
	if (document.getElementById('overview2'))
		over2Str = "&overview2="+document.getElementById('overview2').scrollTop;
	window.location.href=value+"&window="+windowY+over1Str+over2Str;
}

function saveScrollPosPost(frmName) {
	var over1Str = "";
	var over2Str = "";	
	windowY = (document.body.scrollTop?document.body.scrollTop:window.pageYOffset);
	if (document.getElementById('overview'))
		getElement('id', 'overview').value = document.getElementById('overview').scrollTop;
	if (document.getElementById('overview2'))
		getElement('id', 'overview2').value = document.getElementById('overview2').scrollTop;
	getElement('id', 'window').value = windowY;
	eval("document."+frmName+".submit()");
}

function enableActiveX (containerID) {
	// No IE = no need to enable
//    if (getInternetExplorerVersion () != -1)
//    {
        // Get container
        var container = document.getElementById (containerID);
        // Get html in noscript 
        var html = container.innerHTML; 
        // Write html back to container
        container.innerHTML = html;
//    }
}
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        var ua = navigator.userAgent;
        var re  = new RegExp ("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec (ua) != null)
        {
        	rv = parseFloat (RegExp.$1);
        }
    }
    return rv;
}

function returnKeyCode(wEvent) {
//	alert(wEvent);
	if (!wEvent)
		wEvent = window.event;
	if (wEvent.which) {
		eCode = wEvent.which;
	} else if (wEvent.keyCode) {
		eCode = wEvent.keyCode;
	}	
/*  
	if (window.event) kCode = window.event.keyCode;
	else if (kEvent.which) kCode = kEvent.which;
*/
	return eCode;
}


function stringToNumber(noInString) {
	var intString = ""
	for (c = 0; c < noInString.length; c++) 
		if (parseInt(noInString.substr(c,1)) || noInString.substr(c,1)==0) 
			intString = intString + noInString.substr(c,1);

	return (intString);
//		alert(noInString.substr(c,1)+" - "+parseInt(noInString.substr(c,1)));
}

function stringWithoutNumber(stringWithNumber) {
	var onlyString = ""
	for (c = 0; c < stringWithNumber.length; c++) 
		if (!parseInt(stringWithNumber.substr(c,1)) && stringWithNumber.substr(c,1)!=0) 
			onlyString = onlyString + stringWithNumber.substr(c,1);

	return (onlyString);
//		alert(noInString.substr(c,1)+" - "+parseInt(noInString.substr(c,1)));
}

function checkIfChecked(frmName, chbName) {
	var isOneChecked = false;
	
	f = eval("document."+frmName+";");
	for(i=0; i<f.elements.length;i++) {
		res = f.elements[i].name;
		if (res.match(chbName)=="del" || res.match(chbName)=="listItem") 
			if (f.elements[i].checked == true) isOneChecked = true;		
	}
	
	return isOneChecked;
}

function checkAll(frmName, chbName , activeText, inActiveText, elementId) {
	f = eval("document."+frmName+";");
	for(i=0; i<f.elements.length;i++) {
		res = f.elements[i].name;
		if (res.match(chbName)=="del") f.elements[i].checked = delToggle[0][elementId];		
	}
	if (chbName="del") delToggle[0][elementId] = !delToggle[0][elementId];		
	if (delToggle[0][elementId]) setContent ('id', elementId, null, activeText);
	else setContent ('id', elementId, null, inActiveText);	
}	


function getFileName(pathFile) {
	var parts;

	if (pathFile.indexOf('/')>=0)
		parts = pathFile.split("/");
	else
		parts = pathFile.split("\\");
	
//	alert(parts[(parts.length-1)]);
	return parts[(parts.length-1)];
}

function removeFromArray(array, kickOut) {
	var retArray1 = new Array();
	var retArray2 = new Array();

	for(y=0; y<array.length;y++)
		if (array[i]==kickOut) {
			retArray1 = array.slice(0,y);
			retArray2 = array.slice(y+1,array.length);			
			break;
		} 
	return retArray1+retArray2;
}

function isInArray(array, searchString) {
	var retVal = -1;
	
	for(x=0; x<array.length;x++)
		if (array[x]==searchString) {		
			retVal = x;
		}
	return retVal;
}

function documentHeight() {
var myWidth = 0, myHeight = 0;	

	myHeight = getElementPos(getElement('id', 'pageEnd')).y+5;
	
	if (document.documentElement.clientHeight > myHeight)
		myHeight = document.documentElement.clientHeight;
	if (document.body.clientHeight > myHeight)
		myHeight = document.body.clientHeight;
	if (document.body.height > myHeight)
		myHeight = document.body.height;
	if (document.documentElement.scrollHeight > myHeight)
		myHeight = document.documentElement.scrollHeight;
	if (document.body.scrollHeight > myHeight)
		myHeight = document.body.scrollHeight;

	if (document.documentElement.clientWidth > myWidth)
		myWidth = document.documentElement.clientWidth;
	if (document.body.clientWidth > myWidth)
		myWidth = document.body.clientWidth;
	if (document.body.width > myWidth)
		myWidth = document.body.width;
	if (document.documentElement.scrollWidth > myWidth)
		myWidth = document.documentElement.scrollWidth;
	if (document.body.scrollWidth > myWidth)
		myWidth = document.body.scrollWidth;

  position=new Object();
  position.width=myWidth;
  position.height=myHeight;
  return position;
}

function documentInnerHeight() {
var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  position=new Object();
  position.width=myWidth;
  position.height=myHeight;
  return position;
}

function showPageDisableLayer() {
	var docMaxH = documentHeight().height;

	if (getElement('id', 'pageDisable')) {
		showSelectBoxes ('hidden');
		getElement('id', 'pageDisable').style.height = docMaxH+'px';	
		getElement('id', 'pageDisable').style.visibility = 'visible';	
	}
}

function showSelectBoxes (showHide) {	// true -> visible 	false -> hidden; showSelectBoxes ('visible');

	if (getInternetExplorerVersion()<=6 && getInternetExplorerVersion()!=-1) {	
		var selectBoxes = document.getElementsByTagName("SELECT");	
		for (var i = 0; i < selectBoxes.length; i++) {
				eval("document.all."+selectBoxes[i].name+".style.visibility = '"+showHide+"'");
		}
	}
}

var inquiryQueueId		= new Array();
var inquiryQueueFrom	= new Array();
var inquiryQueueTo		= new Array();

function inquiryCallback(inqueryStateId, fromNickname, toNickname) {

	if (inqueryStateId!=0) {
		inquiryQueueId.push(inqueryStateId);
		inquiryQueueFrom.push(fromNickname);
		inquiryQueueTo.push(toNickname);
	}
		
	if(getElement('id', 'pageDisable').style.visibility=="hidden") {
		var maxHeight = documentHeight();

		for (var i = 0; i < document.getElementsByTagName("SPAN").length; i++) {
			if (document.getElementsByTagName("SPAN")[i].getAttribute("name")=="inquiryCustTo")
				document.getElementsByTagName("SPAN")[i].innerHTML = inquiryQueueTo[0];		
			if (document.getElementsByTagName("SPAN")[i].getAttribute("name")=="inquiryCustFrom")
				document.getElementsByTagName("SPAN")[i].innerHTML = inquiryQueueFrom[0];		
		}
		if (inquiryQueueId[0]!=1) {
			showPageDisableLayer();
			getElement('id', 'inquiryMsg'+inquiryQueueId[0]).style.visibility = 'visible';
		}		
		if (inquiryQueueId[0]==1 && vchatAlert==1) {	
			showPageDisableLayer();
			getElement('id', 'inquiryMsg'+inquiryQueueId[0]).style.visibility = 'visible';	
		}				
		inquiryQueueId.shift();
		inquiryQueueFrom.shift();
		inquiryQueueTo.shift();
	}	
	return true;
}


function checkInquiryQueue () {
	closeInquiryMsg();
	
	if (inquiryQueueId.length>0)
		inquiryCallback(0, 0, 0);
}

function closeInquiryMsg() {
	if(getElement('id', 'pageDisable'))
		getElement('id', 'pageDisable').style.visibility = 'hidden';	
	if(getElement('id', 'inquiryMsg1'))
		getElement('id', 'inquiryMsg1').style.visibility = 'hidden';
	if(getElement('id', 'inquiryMsg3'))	
		getElement('id', 'inquiryMsg3').style.visibility = 'hidden';
	if(getElement('id', 'inquiryMsg4'))	
		getElement('id', 'inquiryMsg4').style.visibility = 'hidden';
	if(getElement('id', 'inquiryMsg5'))	
		getElement('id', 'inquiryMsg5').style.visibility = 'hidden';
	if(getElement('id', 'inquiryMsg6'))	
		getElement('id', 'inquiryMsg6').style.visibility = 'hidden';		
}

function getInquiryAlert(answer) {
/*	
	var maxHeight = documentHeight();

	answer	= answer.split("|");
	answer	= answer.slice(1);

	if (answer[0]==1) {
		getElement('id', 'sendInquiryAlert').checked = true;
	} else {
		getElement('id', 'sendInquiryAlert').checked = false;
	}
*/
}

function setInquiryAlert(obj) {
	var inquiryAlertValue;
	
	if(getElement('id', 'sendInquiryAlert').checked)
		inquiryAlertValue = 0;
	else
		inquiryAlertValue = 1;

	makeRequest('/scripts/inquiryAlert.php?sess='+session+'&inquiryAlertValue='+inquiryAlertValue);		
}


var blinkInterval		= 1000;

function blinkElement (tag) {
	tagElements	= document.getElementsByTagName(tag);
		for (var i = 0; i < tagElements.length; i++) {
			found = tagElements[i].className.match(/blink/);			
			if (found == "blink") 
				if (tagElements[i].style.visibility=="" || tagElements[i].style.visibility=="visible") {
					tagElements[i].style.visibility = 'hidden';
				} else
					tagElements[i].style.visibility = 'visible';
		}
}

function initBlink(tag) {
	window.setInterval("blinkElement('"+tag+"')", blinkInterval);
}

function trim (stripString) {
  return stripString.replace (/^\s+/, '').replace (/\s+$/, '');
}

function chkForm(name) {

	var formElements	= document.forms[name].elements;
	var errorMsg		= "";

	for (i=0; i<formElements.length; i++) {
		found = formElements[i].className.match(/mandatory/);		
		if (found == "mandatory")								// must have a value!
			if (formElements[i].value=="" || formElements[i].value=="Email")
				errorMsg = errorMsg + formElements[i].id + '\n\n';		
//alert(formElements[i]+ ' - '+formElements[i].type+ ' - '+formElements[i].name+ ' - '+formElements[i].id+ ' - '+formElements[i].value);					
	}
	if (errorMsg.length > 1) alert(errorMsg);
	else document.forms[name].submit();
}

function goTo (urlToGo) {
	document.location.href = urlToGo;
}