function switchRegion(select){
    var region= select[select.selectedIndex].value;
    document.location= '/index.aspx?regionCode=' + region;
}   

// DOCUCORP Main JavaScript Document
IMG_ROOT = '/images/';

/* This functions makes expandable content divs work */
function containerOpenClose(currObj)
{

	
	renderedImgRoot = getRenderedImgSrc(currObj);	
	currentStatus = checkStatusOfContainer(currObj);
	titleDiv = getFirstChild(currObj);
	btnDiv = getNextDiv(titleDiv);
	contentDiv = getNextDiv(btnDiv);
	renderedBtnImgRoot = getRenderedImgSrc(btnDiv);	
	parentDiv = currObj.parentNode;
	//alert(IMG_ROOT+renderedImgRoot+'_over.gif');
	//alert(IMG_ROOT+renderedImgRoot+"_open.gif");

	//alert(currentStatus);
	
	var docimg=false;
	if (currentStatus == 'off' || currentStatus == 'on'){
		docimg = true;
	}

	//alert(docimg);

	if(currentStatus == 'closed' || currentStatus == 'off')
	{
		currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_over.gif')";		 
		titleDiv.onclick = clickOnState;
		btnDiv.onclick = clickOnState;
		currObj.onmouseout = turnBackState;
	}
	else
	{ 
		titleDiv.onclick = clickOnState;
		btnDiv.onclick = clickOnState;
	}
	
	/* Function executes when the DIV is clicked on */
	function clickOnState(stateObj)
	{
		/* Checks whether content child div is visible */
		currentStatus = getCSSValue(contentDiv,'display');
		if(currentStatus == 'none'){
			
			if(docimg){
				currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_on.gif')";
			}else{
				currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_open.gif')";
			}
			if(currentImg!=false)
				btnDiv.style.backgroundImage= "url('"+IMG_ROOT+renderedBtnImgRoot+"_collapse.gif')";
			contentDiv.style.display="block";			
			titleDiv.style.color="#666666";
		}
		else
		{
			if(docimg){
			
				currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_off.gif')";
			}else{
				currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_closed.gif')";
			}
			if(currentImg!=false)
				btnDiv.style.backgroundImage= "url('"+IMG_ROOT+renderedBtnImgRoot+"_expand.gif')";
			
			contentDiv.style.display="none";			
			titleDiv.style.color = currObj.style.color;
		}		
	}
	
	/* When mouse.rollout then this function gets executed. */
	function turnBackState()
	{
		/* Checks whether content child div is visible */
		currentStatusOnOut = getCSSValue(contentDiv,'display');		
		if(currentStatusOnOut == 'none'){
			if(docimg){
				currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_off.gif')";			
			}else{
				currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_closed.gif')";			
			}
		}
	}
	
}

function containerOpenCloseX(currObj)
{

	renderedImgRoot = getRenderedImgSrc(currObj);	
	currentStatus = checkStatusOfContainer(currObj);
	titleDiv = getFirstChild(currObj);
	btnDiv = getNextDiv(titleDiv);
	contentDiv = getNextDiv(btnDiv);
	renderedBtnImgRoot = getRenderedImgSrc(btnDiv);	
	parentDiv = currObj.parentNode;
	//alert(IMG_ROOT+renderedImgRoot+'_over.gif');
	//alert(IMG_ROOT+renderedImgRoot+"_open.gif");

	var docimg=false;
	if (currentStatus == 'off' || currentStatus == 'on'){
		docimg = true;
	}

	//alert(currentStatus);
	//alert(docimg);

	/*if(currentStatus == 'closed' || currentStatus == 'off')
	{
		currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_over.gif')";		 
		titleDiv.onclick = clickOnState;
		btnDiv.onclick = clickOnState;
		currObj.onmouseout = turnBackState;
	}
	else
	{ 
		titleDiv.onclick = clickOnState;
		btnDiv.onclick = clickOnState;
	}*/

	currentStatus = getCSSValue(contentDiv,'display');
	//alert(currentStatus);
	
	if(currentStatus == 'none'){
		
		if(docimg){
			currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_on.gif')";
		}else{
			currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_open.gif')";
		}
		if(currentImg!=false)
			btnDiv.style.backgroundImage= "url('"+IMG_ROOT+renderedBtnImgRoot+"_collapse.gif')";
		contentDiv.style.display="block";			
		titleDiv.style.color="#666666";
	}
	else
	{
		if(docimg){
		
			currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_off.gif')";
		}else{
			currObj.style.backgroundImage= "url('"+IMG_ROOT+renderedImgRoot+"_closed.gif')";
		}
		if(currentImg!=false)
			btnDiv.style.backgroundImage= "url('"+IMG_ROOT+renderedBtnImgRoot+"_expand.gif')";
		
		contentDiv.style.display="none";			
		titleDiv.style.color = currObj.style.color;
	}			
}

function getCSSValue(objName,cssProperty,styleSheet)
{
	returnVal = objName.style[cssProperty];
	
	//alert(returnVal);
	//alert(objName.className+' '+cssProperty);
	//alert("Class Name: "+objName.className+" Property: "+cssProperty+" Getting Prop: "+returnVal);
	
	if(returnVal == ''){
	
		//alert(eval(testObj));
		
		  var cssValue= false;
		
		  var ss = document.styleSheets[0];
		
		//cssRules[0] for mozila, rules for explorer
		
			if (navigator.appName=="Microsoft Internet Explorer")
			{
				
		 		 for(i= 0; i< ss.rules.length; i++)
		  			{
		  			
		   			 if(ss.rules[i].selectorText== ('.'+objName.className))
		    			{
		    				  cssValue= ss.rules[i].style[cssProperty];
							  break;
		   				 }
		
		 			 }
		 	 }//end of the if nav name statement
		 	 else
		 	 {
		 	 	for(i= 0; i< ss.cssRules.length; i++)
		  			{
		
					 if(ss.cssRules[i].selectorText== ('.'+objName.className))
		    			{
		    				  cssValue= ss.cssRules[i].style[cssProperty];
		    				  break;
		   				 }
		
		 			 }
		 	}
		 	 	
		  return(cssValue);
	}
	else
		return returnVal;

}

/* Checks whether the container is open or closed */
function checkStatusOfContainer(currObj)
{
	currentImg = getCSSValue(currObj,'backgroundImage');
		
	img_root = currentImg.split("_");
	currentStatus = img_root[img_root.length-1].split(".");
	
	return currentStatus[0];
}

/* Returns img src that allows OPEN or CLOSE to be concatinated at the end */
function getRenderedImgSrc(imgObj)
{
	currentImg = getCSSValue(imgObj,'backgroundImage');
	
	if(currentImg==false){
		return currentImg;
	}else{
	//alert("Class Name :"+imgObj.className+' Img:'+currentImg);
	
	img_root = currentImg.split("/");
	img_name = img_root[img_root.length-1];
	img_name = img_name.split("_");
	
	return img_name[0]+'_'+img_name[1];
	}
}

/* Checks the Browser Returns 0 for Netscape and 1 for Internet Explorer */
function checkBrowser()
{
	if(navigator.appName == "Netscape")
		return 0;
	if(navigator.appName == "Microsoft Internet Explorer")
		return 1;
}


function sampleDocs(docObj, imgObj)
{
	docObj.className="sampleDocs_title_over";
	parentDiv = docObj.parentNode;
	sampleDocDiv = getNextDiv(parentDiv);
	
	//alert(sampleDocDiv.className);
	
	sampleDocDiv.innerHTML = '<img src="'+IMG_ROOT+imgObj+'">';
	
	docObj.onmouseout = goBackFunc;	
	function goBackFunc()
	{
		docObj.className="sampleDocs_title";
	}
}

function getStyle(el,styleProp)
{
	var x = el;
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function getNextDiv(d){
	var nextDiv= d.nextSibling;
	
	while(nextDiv){
		if(nextDiv.tagName && nextDiv.tagName=='DIV')
			break;
		else
			nextDiv= nextDiv.nextSibling;
	}	
	return nextDiv
}

function getFirstChild(g)
{
		var prevDiv= g.firstChild;
		while(prevDiv)
		{
				if(prevDiv.tagName && prevDiv.tagName=='DIV')
					break;
				else 
					prevDiv= prevDiv.nextSibling;
		}
		return prevDiv;
}

function getPreviousDiv(g)
{
		var prevDiv= g.previousSibling;
		while(prevDiv)
		{
				if(prevDiv.tagName && prevDiv.tagName=='DIV')
					break;
				else 
					prevDiv= prevDiv.previousSibling;
		}
		return prevDiv;
}

function goTo(url, urlType)
{
	if(urlType == "parent")
		window.location=url;
	else window.open=url;
	
}

function addTableDiffTr(tableId,darkBg,lightBg)
{
	var tableObj = document.getElementById(tableId);
	var tBody = tableObj.getElementsByTagName('TBODY');
	if(tBody){
		var rows = tBody[0].getElementsByTagName('TR');
	}else{
		var rows = tableObj.getElementsByTagName('TR');
	}
	for(var no=0;no<rows.length;no++){
		if(no%2 == 0)
			rows[no].className=lightBg;
		else 
			rows[no].className=darkBg;
	}
	
}



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0  
  var i,p,q,nm,test,num,min,max,errors='',
  args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

/* Used in the ASP Tours page */
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_findDemoObj(n, d) { //v4.01
  
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.demoform.all) x=d.demoform.all[n]; for (i=0;!x&&i<d.demoform.forms.length;i++) x=d.demoform.forms[i][n];
  for(i=0;!x&&d.demoform.layers&&i<d.demoform.layers.length;i++) x=MM_findDemoObj(n,d.demoform.layers[i].document);
  if(!x && d.demoform.getElementById) x=d.demoform.getElementById(n); return x;
}

function MM_validateDemoForm() { //v4.0
  
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateDemoForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findDemoObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_findSeminarObj(n, d) { //v4.01
  
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.seminarform.all) x=d.seminarform.all[n]; for (i=0;!x&&i<d.seminarform.forms.length;i++) x=d.seminarform.forms[i][n];
  for(i=0;!x&&d.seminarform.layers&&i<d.seminarform.layers.length;i++) x=MM_findSeminarObj(n,d.seminarform.layers[i].document);
  if(!x && d.seminarform.getElementById) x=d.seminarform.getElementById(n); return x;
}

function MM_validateSeminarForm() { //v4.0
  
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateSeminarForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findSeminarObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
/*	This function places the footer on the very bottom of a 100% height page */
function footerPlacement()
{	
	toggelDivDisplay('footer_holder');
	var mainContentDiv = getMainContentDiv();/*gets the main content div, since there are different ones for different solutions */
	
	//alert(mainContentDiv);
	
	var userScreenHeight = screen.height;
	var pageHeight = getHeightOfDiv('holder','id');
	var headerHeight = getHeightOfDiv('header_holder','id');
	var bodyHeight = getHeightOfDiv(mainContentDiv,'id');
	var footerHeight = getHeightOfDiv('footer_holder','id');
	
	/*If the Content extends more than the height of the screen, then skip this */
	if(bodyHeight < userScreenHeight ){
			
		var heightToAdd = pageHeight - (headerHeight + bodyHeight + footerHeight);		
		
		//alert(userScreenHeight);		
		//alert(heightToAdd);		
		
		if(heightToAdd < 1)
			heightToAdd = '40';
			
		if(document.getElementById('footer_holder')!= null){
			if(document.getElementById('footer_holder').style!= null){
				if(document.getElementById('footer_holder').style.paddingTop!= null){
					document.getElementById('footer_holder').style.paddingTop= heightToAdd+"px";
				}
			}
		}
	}		

	toggelDivDisplay('footer_holder');
	window.onScroll = footerPlacement;
}



/* This function gets a height of a div */
function getHeightOfDiv(divName, divType)
{
	//alert(divName);
	if(divType =='id')
		return document.getElementById(divName).offsetHeight;
	else
		return document.getElementByClassName(divName).offsetHeight;
	
}
/* This function gets a height of a div */
function getHeightOfDiv(divName, divType)
{
	//alert(divName);
	if(divType =='id')
		return document.getElementById(divName).offsetHeight;
	else
		return document.getElementByClassName(divName).offsetHeight;
	
}

function getMainContentDiv()
{
	if(document.getElementById('mainContent'))
		return 'mainContent';
	else if(document.getElementById('mainContent_green'))
		return 'mainContent_green'; 
	else if(document.getElementById('mainContent_default'))
		return 'mainContent_default'; 
	else if(document.getElementById('mainContent_lgreen'))
		return 'mainContent_lgreen'; 
	else if(document.getElementById('mainContent_mgreen'))
		return 'mainContent_mgreen'; 
	else if(document.getElementById('mainContent_orange'))
		return 'mainContent_orange'; 	
}


/* Toggles display property between block or none */
function toggelDivDisplay(divName)
{	
	property = getStyleProperty(divName, 'display');
	if(property == "block" || property == "inline" )
		document.getElementById(divName).style.display = "none";
	else document.getElementById(divName).style.display = "block";
	
}


function getStyleProperty(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;

}
						  
						 
						  
				  
