//Cactus Javascript
//Script for double submit
var submitFlag = 1;
var clickedTabFlag = 1;
function submitForm(form) {
 	if ( submitFlag == 1 ) {
 		submitFlag = 2;
 		return true;
 	} else {
 		return false;
 	}
}

function setAutoComplete(){
    var formelements = document.getElementsByTagName("form");
     for (var i = 0; i < formelements.length; i++) {
       formelements[i].setAttribute("AUTOCOMPLETE", "OFF");
     }
}


function setFocus(buttonInd){
	if (buttonInd == "policyMainOccList"){
		findPos(document.getElementById("body1:maindriver:mainOccuResults"));
		document.getElementById("body1:maindriver:mainOccuResults").focus();
	}else if(buttonInd == "policyMainOccSingle"){
		findPos(document.getElementById("body1:maindriver:employerbusinessformain"));
		document.getElementById("body1:maindriver:employerbusinessformain").focus();
	}else if(buttonInd == "policyOthrOccList"){
		findPos(document.getElementById("body1:maindriver:otherOccuResults"));
		document.getElementById("body1:maindriver:otherOccuResults").focus();
	}else if(buttonInd == "policyOthrOccSingle"){
		findPos(document.getElementById("body1:maindriver:employerbusinessforother"));
		document.getElementById("body1:maindriver:employerbusinessforother").focus();
	}else if(buttonInd == "policyAddrList"){
		findPos(document.getElementById("body1:maindriver:addressResultList"));
		document.getElementById("body1:maindriver:addressResultList").focus();
	}else if(buttonInd == "policyAddrSingle"){
		findPos(document.getElementById("body1:maindriver:residentialStatusRefData"));
		document.getElementById("body1:maindriver:residentialStatusRefData").focus();
	}else if(buttonInd == "addMainOccList"){
		findPos(document.getElementById("body1:additionalDriverDetails:mainOccuResults"));
		document.getElementById("body1:additionalDriverDetails:mainOccuResults").focus();
	}else if(buttonInd == "addMainOccSingle"){
		findPos(document.getElementById("body1:additionalDriverDetails:employerbusinessformain"));
		document.getElementById("body1:additionalDriverDetails:employerbusinessformain").focus();
	}else if(buttonInd == "addOthrOccList"){
		findPos(document.getElementById("body1:additionalDriverDetails:otherOccuResults"));
		document.getElementById("body1:additionalDriverDetails:otherOccuResults").focus();
	}else if(buttonInd == "addOthrOccSingle"){
		findPos(document.getElementById("body1:additionalDriverDetails:employerbusinessforother"));
		document.getElementById("body1:additionalDriverDetails:employerbusinessforother").focus();
	}else if(buttonInd == "emailAddressHelp"){
	    if (document.getElementById("body1:login:emailAddressHelp")!= null){
		findPos(document.getElementById("body1:login:emailAddressHelp"));
		document.getElementById("body1:login:emailAddressHelp").focus();
		}else{
		findPos(document.getElementById("body1:logina:emailAddressHelp"));
		document.getElementById("body1:logina:emailAddressHelp").focus();
		}		
	}else if(buttonInd == "passwordHelp"){
	if (document.getElementById("body1:login:passwordHelp")!= null){
		findPos(document.getElementById("body1:login:passwordHelp"));
		document.getElementById("body1:login:passwordHelp").focus();
		}else{
		findPos(document.getElementById("body1:logina:passwordHelp"));
		document.getElementById("body1:logina:passwordHelp").focus();
		}		
	}
	else
	{ 
		if(buttonInd != "null" && buttonInd != ""){
			findPos(document.getElementById(buttonInd));
			document.getElementById(buttonInd).focus();
		}
	}
}

//This method finds the position of the element on
//screen and then scrolls to that position
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	window.scrollTo(0,curtop-50);
}

//function for pop ups
	function popwin(url, name, width, height, location, menubar, status, toolbar)
	{

		if (name == null)
		{
			name = "stdWin";
		}		
		if (location == null)
		{
			location = "no"
		}
		if (menubar == null)
		{
			menubar = "no"
		}
		if (status == null)
		{
			status = "yes"
		}
		if (toolbar == null)
		{
			toolbar = "no"
		}

		popup = window.open(url, name, 'width=' + screen.width + ',height=' + screen.height + ',location=' + location + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar +',scrollbars=yes,resizable=yes,screenx=0,screeny=0,left=0,top=0');
		if (window.focus) setTimeout("popup.focus()",100);
	} 
	
//function for pop ups
function popwinsecure(url)
{
	var win = window.open(url,'stdWin','scrollbars=1,toolbar=1,menubar=1,location=1');
	if (window.screen) {
	    var aw = screen.availWidth;
	    var ah = screen.availHeight;
	    win.moveTo(0, 0);
	    win.resizeTo(aw, ah);
  	}
}

	//function for pop ups
	function popwinresizable(url, name, width, height, location, menubar, status, toolbar)
	{

		if (name == null)
		{
			name = "stdWin";
		}		
		if (location == null)
		{
			location = "no"
		}
		if (menubar == null)
		{
			menubar = "no"
		}
		if (status == null)
		{
			status = "yes"
		}
		if (toolbar == null)
		{
			toolbar = "no"
		}

		popup = window.open(url, name, 'width=' + screen.width + ',height=' + screen.height + ',location=' + location + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar +',scrollbars=yes,resizable=yes,screenx=0,screeny=0,left=0,top=0');
		if (window.focus) setTimeout("popup.focus()",100);
	}
	
//Following function will explicitely trigger onclick event for IE browser//
function fnonclick(link){
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		link.onclick();
	}
}

//function to close thw window
function closeButtonJS()
	{
	window.close();
	}
	
	// function to open in a new window.
function newwindow()
		{
  		  	window.open('../login/confirmpopup.jsp','new','height=20,width=400,resizable=0,toolbars=0,location=0,menubar=no,left = 270,top = 325,scrollbars=0,minimize=disabled');
		}
//function in confirm popup
function alert_confirm(temp){       

            if(temp=='N'){   
            self.close();             
            }

            if(temp=='Y'){     
            opener.parent.window.close();       
            }

            self.close();

}
function showTab(i) {
hideelement('tab-block-1');
hideelement('tab-block-2');
hideelement('tab-block-3');
hideelement('tab-block-4');
displayelement("tab-block-"+i);
clickedTabFlag = i;
}
function printTab(){
		
		if(document.getElementById('tab-block-1')!=null){
			displayelement('tab-block-1');
		}
		if(document.getElementById('tab-block-2')!=null){
			displayelement('tab-block-2');
		}
		if(document.getElementById('tab-block-3')!=null){
			displayelement('tab-block-3');
		}
		if(document.getElementById('tab-block-4')!=null){
			displayelement('tab-block-4');
		}
		window.print();
		
		showTab(clickedTabFlag);
}	
function displayelement(element){
 document.getElementById(element).style.display = '';
}
function hideelement(element){
 document.getElementById(element).style.display = 'none';
}
