var _newWin = new Array;

function OpenNewWindow(winPar, urlPar, titlePar, widthPar, heightPar, topPar, leftPar, menubarPar, toolbarPar, scrollbarsPar, statusPar, resizablePar)
{
	try
	{
		_newWin[winPar] = window.open(urlPar, titlePar, 'width=' + widthPar + ',height=' + heightPar + ',top=' + topPar + ',left=' + leftPar + ',menubar=' + menubarPar + ',toolbar=' + toolbarPar + ',scrollbars=' + scrollbarsPar + ',status=' + statusPar + ',resizable=' + resizablePar);
	}
	catch (e) {
		window.status = "Cannot open new window - script.js";
		throw e;
	}
}

function CloseWindow(winPar)
{
	try
	{
		if (winPar == -1)
		{
			window.close()
		}
		else
		{
			_newWin[winPar].close();
		}
	}
	catch (e) {
		window.status = "Cannot close window - script.js";
		throw e;
	}	
}

function AlertTest()
{
	alert("Hello World");
}

function show(colid, imgid, coltext)
{
	try
	{
		var el = document.getElementById(colid);
		var el2 = document.getElementById(el.id + 'Status');
		var imgel = document.getElementById(imgid);
		
		if (el.style.display == 'none')
		{
			el.style.display = '';
			el2.innerHTML = 'Hide ' + coltext;
			imgel.src="images/org_right_arrow.gif";
		} else {
			el.style.display = 'none';
			el2.innerHTML = 'Show ' + coltext;
			imgel.src="images/org_down_arrow.gif";
		}
	}
	catch (e)
	{
		window.status = "Cannot show or hide column - script.js";
		throw e;
	}

}

function cookiesEnabled() {

	try
	{
		document.cookie = "temp=test";
		offset = -1;
			
			if(document.cookie.length > 0)
			{ 
				offset = document.cookie.indexOf("temp=");
			} 

			if (offset == -1) 
			{ 
				return false; 
			}
			else
			{  
				document.cookie = "temp=test; expires=Thu, 01-Jan-2000:00:01 GMT"; return true;
			} 
	}
	catch (e)
	{
		window.status = "Cannot check cookie enable - script.js";
		throw e;
	}
}

function CtrlFocus(userid)
{
	try
	{
		var ctrl = document.getElementById(userid);
		ctrl.focus();
		ctrl.select();
	}
	catch (e)
	{
		window.status = "Cannot set focus on the object - script.js";
		throw e;
	}
}

function ConfirmToGo(msg, trueurl, falseurl)
{
	try
	{
		var answer = confirm(msg);
		if (answer)
		{
			window.location.href = trueurl;
		}
		else
		{
			window.location.href = falseurl;
		}
	}
	catch (e)
	{
		window.status = "Cannot open confirmation - script.js";	
		throw e;
	}
}

function SearchGoogle(textfield)
{
	try
	{
		var obj1 = document.getElementById(textfield);
		
		if (obj1 != null)
		{
			var searchstr = obj1.value.replace(' ', '+');
			searchstr = 'http://www.google.com/search?hl=en&lr=&q=' + searchstr + '+site%3Awww.complexcoverage.com'
			
			window.location.href = searchstr;				
		}
		else
		{
			alert("Please enter text to the textbox");
			CtrlFocus(textfield);
		}
	}
	catch(e)
	{
		window.status = "Cannot redirect to the google - script.js";
		throw e;
	}
}

function throwme()
{
	try
	{
		throw new Error("test", "this is a testing message");
	}
	catch (e)
	{
		window.status = e.message & " - " & e.description
		throw e;
	}
}

function SetupTimeout(min)
{
    var msec = min * 60 * 1000;
    window.setTimeout('SessionTimeout()', msec);
}

function SessionTimeout()
{
    var msg = "Your session has been expired, please re-login to the system again.\n";
    msg += "If you are in the middle of processing a quote, you will find the quote in 'Continue Incomplete Quotes' section\n\n";
    msg += "Click the OK button and it will re-direct to the homepage";
    
    alert(msg);
    window.location = "./default.aspx";    
}


function noBack()
{
    window.history.forward();
}

function UpperCaseFirst(txtObj) {
    if (txtObj.value != null && txtObj.value != "") {
        var nameSeg = txtObj.value.split(" ");

        for (var i=0; i<nameSeg.length; i++)
        {
            var firstLetter = nameSeg[i].substr(0, 1);
            
            if (nameSeg[i].length > 1)
                otherLetter = nameSeg[i].substr(1);
            else
                otherLetter = "";

            nameSeg[i] = firstLetter.toUpperCase() + otherLetter.toLowerCase();
        }
        
        txtObj.value = nameSeg.join(" ");
    }

    return txtObj;
}

function UpperCaseFull(txtObj) {
    txtObj.value = txtObj.value.toUpperCase();

    return txtObj;
}

function DownloadAccordAppInstruction(popupBlocker) {
    if (!popupBlocker)
        alert("Important Notice: Please disable the pop-up blocker to download the Accord Application or Click on the link from the notice.");
    else
        OpenAccordInstruction();
}

function OpenAccordInstruction() {
    window.open('./printpage.aspx?ct=generatepdf&pdf=accordinstruction', 'AccordApplication', 'width=800,height=600,top=20,left=20,menubar=0,toolbar=0,scrollbars=1,status=0,resizable=0');
}
