//ADDED BY MELCHOR B. PINEDA JR.
// Scripts For Manipulating Country Region Point
var tester
tester=1;

function showCountryData(){
	document.getElementById("ctryList").style.display="block";		
}

function hideCountryData(){
	document.getElementById("ctryList").style.display="none";	
}
  
  
function countryHover(id){
	document.getElementById("selectedCountry").value=document.getElementById(id).innerHTML;
}

function setValue(val,country){
	var str = country;  
	var result = str.replace(/_/gi, " ");
    var strValue=val;
	var ctryArray = strValue.replace(/_/gi, " ");
	
	document.getElementById("ctryList").style.display="none";
	document.getElementById("REGION").value=ctryArray;
	redirectLocation(result);
}


function redirectLocation(val){ 

	var strRegion,region_text;	
	
	strRegion=document.getElementById("REGION").value;
	//MDH added the condition for IBC Russia //
	if(val == 'Russia' && strRegion == 'Other'){
		strRegion="Russia"
	}
	//IBC Russia Ends here //

	if(strRegion.search(/Africa/) > -1 ){
		region_text="Africa";
	}else if(strRegion.search(/North America/) > -1 ){
		region_text="NAmericas";
	}else if(strRegion.search(/Caribbean/)> -1 ){
		region_text="Caribbean";
	}else if(strRegion.search(/Asia/) > -1 ){
		region_text="Asia";
	}else if(strRegion.search(/Australia/)> -1 ){
		region_text="Australia";
	}else if(strRegion.search(/Europe/)> -1 ){
		region_text="Europe";
	}else if(strRegion.search(/New Zealand/)> -1 ){
		region_text="New Zealand";
	}else if(strRegion.search(/Oceania/)> -1 ){
		region_text="Oceania";
	}else if(strRegion.search(/Russia/)> -1 ){
		region_text="Russia";
	}else if(strRegion.search(/Japan/)> -1 ){
		region_text="Japan";
	}else if(strRegion.search(/South America/)> -1 ){
		region_text="SAmericas";
	}else if(strRegion.search(/UK/)> -1 ){
		region_text="Europe";
	}else{
		region_text="Asia";
	}
	

	switch (region_text){ 
		case "Africa" :
			pageURL_1 = "/ataf/home.asp";
			betaURL = "betaafrica.autoterminal.com/home.asp";
			liveURL = "africa.autoterminal.com/home.asp";
			break;
		case "NAmericas" :
			pageURL_1 = "/ata/home.asp";
			betaURL = "betaamericas.autoterminal.com/home.asp";
			liveURL = "americas.autoterminal.com/home.asp";

			break;
		case "Caribbean" :
			pageURL_1 = "/ata/home.asp";
			betaURL = "betaamericas.autoterminal.com/home.asp";
			liveURL = "americas.autoterminal.com/home.asp";

			break;
		case "SAmericas" :
			pageURL_1 = "/atsam/home.asp";
			betaURL = "betasouthamerica.autoterminal.com/home.asp";
			liveURL = "southamerica.autoterminal.com/home.asp";

			break;
		case "Asia" :
			pageURL_1 = "/oth/home.asp";
			betaURL = "betaasia.autoterminal.com/home.asp";
			liveURL = "asia.autoterminal.com/home.asp";

			break;
		case "Australia" :
			pageURL_1 = "/atoz/home.asp";
			betaURL = "betaaustralia.autoterminal.com/home.asp";
			liveURL = "australia.autoterminal.com/home.asp";

			break;
		case "Europe" :
			pageURL_1 = "/atuk/home.asp";
			betaURL = "betaunitedkingdom.autoterminal.com/home.asp";
			liveURL = "unitedkingdom.autoterminal.com/home.asp";

			break;
		case "New Zealand" :
			pageURL_1 = "/atnz/home.asp";
			betaURL = "betanewzealand.autoterminal.com/home.asp";
			liveURL = "newzealand.autoterminal.com/home.asp";

			break;
		case "Oceania" :
			pageURL_1 = "/oth/home.asp";
			betaURL = "betaasia.autoterminal.com/home.asp";
			liveURL = "asia.autoterminal.com/home.asp";

			break;
		case "Russia" :
			pageURL_1 = "/oth/home.asp";
			betaURL = "betaasia.autoterminal.com/home.asp";
			liveURL = "asia.autoterminal.com/home.asp";

			break;
		case "UK, Ireland, Cyprus" :
			pageURL_1 = "/atuk/home.asp";
			betaURL = "betaunitedkingdom.autoterminal.com/home.asp";
			liveURL = "unitedkingdom.autoterminal.com/home.asp";

			break;
		case "Japan" :
			pageURL_1 = "/oth/home.asp";
			betaURL = "betaasia.autoterminal.com/home.asp";
			liveURL = "asia.autoterminal.com/home.asp";

			break;
		default:
			pageURL_1 = "/oth/home.asp";
			betaURL = "betaasia.autoterminal.com/home.asp";
			liveURL = "asia.autoterminal.com/home.asp";

	}
	
		//document.getElementById("REDIRECT").value=pageURL_1;
		//temporary http://192.168.23.184:8081 -- change this with your local port 
		//to http://www.autoterminal.com when deploying to live
		
		 var yLocation = location.href ;
		 var answer = yLocation.search("beta");
		 if (answer > -1){
			window.location.href = "http://" + betaURL;
		 }else{
			//window.location.href = "http://192.168.23.184:8081" +pageURL_1;
			window.location.href = "http://" + liveURL;
		}
}

function recommendFriend(){
		var sURL;		
		sURL="recommend_a_friend.asp";
		var isMozilla;
		isMozilla = (document.all) ? 0 : 1;	
		if (!newwin_chat || newwin_chat.closed) {
				
			if (isMozilla) {       
				newwin_chat = window.open(sURL,'','toolbars=no,menubar=no,resize=no,scrollbars = no, status = no, resizable = no,name=ts, width=450, height=450, screenX=400,screenY=200');
			}else{
				newwin_chat = window.open(sURL,'','toolbars=no,menubar=no,resize=no,scrollbars = no, status = no, resizable = no,name=ts, width=450, height=450, left=350, top=250');
			}	
					
			if(newwin_chat) newwin_chat.focus();
		}else{
			if(newwin_chat) newwin_chat.focus();
		}
		
		newwin_chat.document.title = "Recommend A Friend";
}


/*print this page function*/
var gAutoPrint = true; // Flag for whether or not to automatically call the print function
function printSpecial()
{
	if (document.getElementById != null)
{
	var html = '<HTML>\n<HEAD>\n';
	if (document.getElementsByTagName != null)
{
	var headTags = document.getElementsByTagName("head");
	if (headTags.length > 0)
		html += headTags[0].innerHTML;
	}
var printReadyElem = document.getElementById("checklistdata");
var v2 = false;
if (printReadyElem == null)
{
	try{
		printReadyElem = document.getElementById("checklistdatav2");
		v2 = true;
	}
	catch(e){
	}
}
html += '\n</HE' + 'AD>\n<BODY>\n';

if(v2)
{
html += '\n<div style="width:50%">\n';
}


if (printReadyElem != null)
{
	html += printReadyElem.innerHTML;
}
else
{
	alert("Could not find the printReady section in the HTML");
	return;
}


if(v2)
{
html += '\n</div>\n';
}

html += '\n</BO' + 'DY>\n</HT' + 'ML>';
var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();

if (gAutoPrint)
	printWin.print();
}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}

function showtip(thetext, thecolor, thewidth){	
	var containerTemp;
	if (ns6||ie){
	if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
	if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
	
	containerTemp = "<div id='note_Grade2' >";
	containerTemp = containerTemp + thetext;
	containerTemp = containerTemp + "</div>";
	tipobj.innerHTML=containerTemp;
	
	//alert( document.getElementById("note_Grade2").style.visibility );
	
	//document.getElementById("note_Grade2").style.top = 500+"px";
	//alert( document.getElementById("note_Grade2").style.top );
	
	//document.onmousemove=getMouseCoordinates;
	
	//getMouseCoordinates(document.onmousemove);
	
	enabletip=true
	return false
	}
}

function getMouseCoordinates(event)
{	
	var ypos;
	ev = event || window.event;
	ypos = ev.pagey;
	alert(event);
	//document.getElementById("note_Grade2").style.top = ypos+"px";

}

function positiontip(e){
	if (enabletip){
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
	var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

	var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<tipobj.offsetWidth)
	{
	//move the horizontal position of the menu to the left by it's width
	tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
	}
	else if (curX<leftedge)
	{
	
	tipobj.style.left="5px"
	}
	else
	{
	//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=100+curX+offsetxpoint+"px";
		if(document.getElementById("note_Grade2") != null)
			{
				document.getElementById("note_Grade2").style.left=(curX-400)+"px";
				document.getElementById("note_Grade2").style.top=(curY-130)+"px";
			}
	}

	//same concept with the vertical position
	if (bottomedge<tipobj.offsetHeight)
	tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
	else
	tipobj.style.top=curY+offsetypoint+"px"
	tipobj.style.visibility="visible"
	}
}

function hidetip(){
	if (ns6||ie){
	enabletip=false
	tipobj.style.visibility="hidden"
	tipobj.style.left="-1000px"
	tipobj.style.backgroundColor=''
	tipobj.style.width=''
	}
}

