/* *************************************************************************
Title : Master Javasciprt File
Author : Designkitchen, Inc.
Description : Sets up js for entire site, includes global addLoadEvent
Created : 08.10.2007 
Modified : 
************************************************************************* 

/* *************************************************************************
=LOAD SCRIPT
 Includes all common js files for the application
 Use for all files on page load
************************************************************************* */
var root;

if (window.location.href.indexOf("/Assurance") >= 0 )
{ 
    root = "/Assurance";
}
else if (window.location.href.indexOf("/KenticoCMS") >= 0 )
{ 
    root = "/KenticoCMS";
}
else if (window.location.href.indexOf("/AA.Kentico.Site") >= 0 )
{ 
    root = "/AA.Kentico.Site";
}
else{
    root = "";
}

function loadScript(url)
{
   document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
}
/*Add js file below*/

loadScript(root + "/resources/js/prototype.js");
loadScript(root + "/resources/js/scriptaculous/scriptaculous.js?load=effects");
loadScript(root + "/resources/js/slideshow.js");
loadScript(root + "/resources/js/casestudy.js");
loadScript(root + "/resources/js/ibox.js");
loadScript(root + "/resources/js/initializeJS.js");
loadScript(root + "/resources/flash/inc/swfobject.js");

/* *************************************************************************
=BIZ FORM RADIO SWAP
  - removes the radio buttons from the biz from generated table
  - adds the radio buttons to a new div
  - should be called on load of the biz form page
************************************************************************* */
function bizFormRadioSwap(){
  
	/* var radioDiv is the parent container of the generated table
	   You should wrap the biz form input in a div tag and hard code the id
	   example: <div id="radioList">$$input:ProductChoice$$</div> */
	 
	
	var radioDiv = document.getElementById("radioList");
	var radioTable = radioDiv.getElementsByTagName("table")[0];
	var newDiv = document.createElement("div");
	
	var allTD = radioTable.getElementsByTagName("td");
	var allLabels = radioDiv.getElementsByTagName("label");
	
	for(var i=0; i<allTD.length; i++){
		var thisDiv = document.createElement("div");
		thisDiv.innerHTML = allTD[i].innerHTML;
		thisDiv.className = "radioDiv_"+i; //adds a class 'radioDiv_#' to distinguish the divs
		newDiv.appendChild(thisDiv);
		
	}
	radioDiv.removeChild(radioTable);
	radioDiv.appendChild(newDiv);
}


/* *************************************************************************
=GOGGLE AUTOFILL COLOR CORRECT -  IE ONLY
************************************************************************* */
    
if(window.attachEvent)
	window.attachEvent("onload",setListeners);

function setListeners(){
	inputList = document.getElementsByTagName("INPUT");
	for(i=0;i<inputList.length;i++){
	  if(inputList[i].className.indexOf('text') == -1){
	  inputList[i].attachEvent("onpropertychange",restoreStyles);
	  inputList[i].style.backgroundColor = "#fff";
	  }
	}
	selectList = document.getElementsByTagName("SELECT");
	for(i=0;i<selectList.length;i++){
	  selectList[i].attachEvent("onpropertychange",restoreStyles);
	  selectList[i].style.backgroundColor = "";
	}
}

function restoreStyles(){
	if(event.srcElement.style.backgroundColor != "#fff")
	  event.srcElement.style.backgroundColor = "#fff";
}

function eventObserve(element, event, handler) {
	Event.observe(element, event, handler);
	Event.observe(window, 'unload', unloader);
	function unloader() {
		Event.stopObserving(element, event, handler);
		Event.observe(window, 'unload', unloader);
	}

	return true;
}

function setUnloadAttribute(attribute) {
	Event.observe(window, 'unload', unloader);
	function unloader() {
		attribute = null;
		Event.stopObserving(window, 'unload', unloader);
	}

	return true;
}

function changeFocus(inputField){
    if (inputField.className.indexOf("username") != -1){
	    inputValue = "Username";
	}
	
	if (inputField.className.indexOf("password") != -1){
	    inputValue = "Password";
	}
	
	var currentValue = inputField.value;

	if (currentValue == ""){
		inputField.setAttribute("value",inputValue);
	} else if (currentValue == inputValue){
		inputField.setAttribute("value","");
	}
}

function changeBlur(inputField){

	if (inputField.className.indexOf("username") != -1){
	    inputValue = "Username";
	}
	
	if (inputField.className.indexOf("password") != -1){
	    inputValue = "Password";
	}

	var currentValue = inputField.value;
		if (currentValue == ""){
		inputField.setAttribute("value",inputValue);
	} else if (currentValue == inputValue){
		inputField.setAttribute("value","");
	}
}

function goTo(link)
{
    
    window.location = link;
}

/*
Seminar registration popup windows
*/
function showCVV()
{
    window.open("Credit-Popup.aspx","","width=550,height=330,");
}

function showRP()
{
    window.open("../Seminars/Return-Policy.aspx","","width=550,height=150,scrollbars=yes");
}


function openWindow( 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 showbox(theTitle){
    var params = {
    "width":  581, 
    "height": 487, 
    "can_resize": false
    };
    iBox.showURL("#videoPlayer", '', params);
    var so = new SWFObject( root + "/resources/swf/video.swf", "videoHolder", "448", "408", "9.0.115.0", "#FFFFFF");
	so.addParam("swliveconnect", "true");
	so.addParam("allowFullScreen", "true");
	so.addParam("allowScriptAccess","always");		
	so.addParam("scale", "noScale");
	so.addParam("quality", "high");
	so.addVariable("vidPath", "../video/essence.f4v");
	so.addVariable("title", "get to know Assurance");
	so.write("videoHolder");
}