/*
=============================================
 Development By: Infinity Arts Interactive, LLC - www.InfinityArts.com, © Copyright 2008 - All rights reserved.
 Description: Public JS Functions
 Last Revised Date: 5/17/2010
=============================================
*/

// ============================================================ FUNCTIONS: WINDOW & BROWSER ============================================================
	
	document.write('<script type="text/javascript" src="'+'/Scripts/js-core.min.js'+'"></scr'+'ipt>');
	document.write('<script type="text/javascript" src="'+'/Scripts/ccval.min.js'+'"></scr'+'ipt>');

	/*
	Shadowbox.loadSkin('classic', '/assets/files/shadowbox.2.0/skin');
	Shadowbox.loadLanguage('en', '/assets/jscripts/shadowbox.2.0/lang');
	Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], '/assets/jscripts/shadowbox.2.0/player');
	*/
	window.onload = function () {
		imageSet();
		/* if (document.getElementById('DIVphotoGalleryFrame')) Shadowbox.init(); */

		$(document).ready(function () {
			$('#DIVmainNav > a img').mouseover(function(){ iacore.imgswap.on($(this)); }).mouseout(function(){ iacore.imgswap.off($(this)); });
			
			if ($('#DIVsplashSlides').length > 0) { iacore.insertSWF({swf:'/assets/flash/showcase.swf', id:'DIVsplashSlides', b:'#000', w:580, h:277, m:'transparent', vars:'XML_PATH=http://www.customercentric.com/assets/xml/control_6476.xml'}); }

			if ($('#SWFhome_video').length > 0) { iacore.insertSWF({swf:'/Video/home_video.swf', id:'SWFhome_video', b:'#FFF', w:445, h:351, m:'transparent'}); }
			if ($('#SWFworkshop').length > 0) { iacore.insertSWF({swf:'/assets/flash/workshop.swf', id:'SWFworkshop', b:'#FFF', w:396, h:163, m:'transparent'}); }
			if ($('#SWFchallenge').length > 0) { iacore.insertSWF({swf:'/assets/flash/challenge.swf', id:'SWFchallenge', b:'#FFF', w:445, h:351, m:'transparent'}); }
			if ($('#SWFintro').length > 0) { iacore.insertSWF({swf:'/assets/flash/intro.swf', id:'SWFintro', b:'#FFF', w:260, h:198, m:'transparent'}); }
			if ($('#SWFget_started').length > 0) { iacore.insertSWF({swf:'/assets/flash/get_started.swf', id:'SWFget_started', b:'#FFF', w:445, h:351, m:'transparent'}); }
			if ($('#SWFaffiliates').length > 0) { iacore.insertSWF({swf:'/assets/flash/affiliates.swf', id:'SWFaffiliates', b:'#FFF', w:256, h:253, m:'transparent'}); }
			if ($('#SWFtestimonies').length > 0) { iacore.insertSWF({swf:'/assets/flash/testimonies.swf', id:'SWFtestimonies', b:'#FFF', w:256, h:253, m:'transparent'}); }
			if ($('#SWFfrankVisgatis').length > 0) { iacore.insertSWF({swf:'/assets/flash/frankvisgatis.swf', id:'SWFfrankVisgatis', b:'#FFF', w:256, h:253, m:'transparent'}); }

			$('form[name=CTAform]').keyup(function(e){ if (e.which == 13) { valCTAForm(document.CTAform); } });
			$('form[name=workshopForm]').keyup(function(e){ if (e.which == 13) { valWorkshopForm(document.workshopForm); } });
		});
	}

// ============================================================ FUNCTIONS: MISCELLANEOUS ==================================================================

	var xmlhttp=false;
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try { xmlhttp = new XMLHttpRequest(); } 
		catch (e) { xmlhttp=false; }  
	}

	/*
	START ADOBE CODE 
		//v1.0
		//Copyright 2006 Adobe Systems, Inc. All rights reserved.
	*/
	function AC_AddExtension(src, ext) {
	  if (src.indexOf('?') != -1)
	    return src.replace(/\\?/, ext+?/, ext+'?'); 
	  else
	    return src + ext;
	};
	
	function AC_Generateobj(objAttrs, params, embedAttrs)  { 
	  var str = '<object ';
	  for (var i in objAttrs)
	    str += i + '="' + objAttrs[i] + '" ';
	  str += '>';
	  for (var i in params)
	    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
	  str += '<embed ';
	  for (var i in embedAttrs)
	    str += i + '="' + embedAttrs[i] + '" ';
	  str += ' ></embed></object>';
	
	  document.write(str);
	};
	
	function AC_FL_RunContent(){
	  var ret = 
	    AC_GetArgs
	    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
	     , "application/x-shockwave-flash"
	    );
	  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
	};
	
	function AC_SW_RunContent(){
	  var ret = 
	    AC_GetArgs
	    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
	     , null
	    );
	  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
	};
	
	function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
	  var ret = new Object();
	  ret.embedAttrs = new Object();
	  ret.params = new Object();
	  ret.objAttrs = new Object();
	  for (var i=0; i < args.length; i=i+2){
	    var currArg = args[i].toLowerCase();    
	
	    switch (currArg){	
	      case "classid":
	        break;
	      case "pluginspage":
	        ret.embedAttrs[args[i]] = args[i+1];
	        break;
	      case "src":
	      case "movie":	
	        args[i+1] = AC_AddExtension(args[i+1], ext);
	        ret.embedAttrs["src"] = args[i+1];
	        ret.params[srcParamName] = args[i+1];
	        break;
	      case "wmode":
		ret.params[args[i]] = args[i+1];
		break;
	      case "onafterupdate":
	      case "onbeforeupdate":
	      case "onblur":
	      case "oncellchange":
	      case "onclick":
	      case "ondblClick":
	      case "ondrag":
	      case "ondragend":
	      case "ondragenter":
	      case "ondragleave":
	      case "ondragover":
	      case "ondrop":
	      case "onfinish":
	      case "onfocus":
	      case "onhelp":
	      case "onmousedown":
	      case "onmouseup":
	      case "onmouseover":
	      case "onmousemove":
	      case "onmouseout":
	      case "onkeypress":
	      case "onkeydown":
	      case "onkeyup":
	      case "onload":
	      case "onlosecapture":
	      case "onpropertychange":
	      case "onreadystatechange":
	      case "onrowsdelete":
	      case "onrowenter":
	      case "onrowexit":
	      case "onrowsinserted":
	      case "onstart":
	      case "onscroll":
	      case "onbeforeeditfocus":
	      case "onactivate":
	      case "onbeforedeactivate":
	      case "ondeactivate":
	      case "type":
	      case "codebase":
	        ret.objAttrs[args[i]] = args[i+1];
	        break;
	      case "width":
	      case "height":
	      case "align":
	      case "vspace": 
	      case "hspace":
	      case "class":
	      case "title":
	      case "accesskey":
	      case "name":
	      case "id":
	      case "tabindex":
	        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
	        break;
	      default:
	        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
	    }
	  }
	  ret.objAttrs["classid"] = classid;
	  if (mimeType) ret.embedAttrs["type"] = mimeType;
	  return ret;
	};
	/* END ADOBE CODE */

	function removeFlashElement(childDiv,parentDiv) {
		if(document.getElementById(childDiv)){
			var objParent = document.getElementById(parentDiv);
			var objChild = document.getElementById(childDiv);
			objParent.removeChild(objChild);
		}
	}

	function initBio() {
		setPopUpLinks();
	}

	function openBio(biography) {
		var strOptions = "location=no,menubar=no,toolbar=no,scrollbars=yes,width=600,height=750";
	
		var intRandom=Math.floor(Math.random()*999);
	
		var objWindow = window.open(biography, String(intRandom), strOptions);
		objWindow.focus();
	}
	function loadlink(url) {
		self.opener.location = url;
		self.close();
	}
	
	function deleteChild(parentDiv, childDiv) {
		

		if(document.getElementById(childDiv)) {
			//Get a reference to the parent.
			var objParent = document.getElementById(parentDiv);
			//Get a reference to the child.
			var objChild = document.getElementById(childDiv);
			//Remove the child.
			
			try { objParent.removeChild(objChild); } 
			catch (e) { /*alert(parentDiv+', '+childDiv+' '+e);*/ }  	
		}
	}

	function changeContent(parentDiv, childDiv,page) {
		var element = document.getElementById(parentDiv);
		
		xmlhttp.open("GET", page); 
		xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4){
				if(xmlhttp.status == 200 || xmlhttp.status == 0) {
					deleteChild(parentDiv, childDiv);
					element.innerHTML = xmlhttp.responseText;
				}
			}
		}
		 
		xmlhttp.send(null);
	}
	
	function changeVideo(parentDiv, childDiv, page) {
		//noMenuItemVideo(0);
		//Kill the Flash object if it exists
		//deleteChild(childDiv,videoId);
		deleteChild('video_left', 'tr');
		deleteChild('video_right', 'cc');
		//Remove the link Background
		links = document.getElementsByTagName('a');
					for (i = 0; i < links.length; i++) {
						 if (links[i].className =="center_nav_bg") {
							 links[i].className = "center_nav"; 
						}
					}	
		//Swap out the page.
		changeContent(parentDiv,childDiv,page);
	}
	function changeText(parentDiv, childDiv, page) {
		changeContent(parentDiv,childDiv,page);
	}
	
	function addNavBackground(linkId) {
		var nav = document.getElementById(linkId);
		nav.className = "center_nav_bg";
	}
	function removeNavBackground(linkId) {
		var nav = document.getElementById(linkId);
		nav.className = "center_nav";
	}

	function hideDiv(divname) {
		document.getElementById(divname).className="hide_div";
	}
	function showDiv(divname) {
		document.getElementById(divname).className="show_div";
	}


	function fillPrimaryAttendee() {
		if (document.workshopForm.p_attendee.checked) {
			//alert (document.workshopForm.title.value);
		document.workshopForm.p_attendee_name.value	= document.workshopForm.first_name.value + " " + document.workshopForm.last_name.value;
		document.workshopForm.p_attendee_title.value=document.workshopForm.title.value;
		document.workshopForm.p_attendee_company.value=document.workshopForm.company.value;
		document.workshopForm.p_attendee_email.value=document.workshopForm.email.value;
		}
	}

	function disableCreditcard() {
		if (document.workshopForm.state.value=='Outside' || document.workshopForm.role_playing[0].checked){
			document.getElementById("paybycredit").removeAttribute("checked");
			document.getElementById("paybycredit").setAttribute("disabled", "disabled");
			document.getElementById("div_creditcard").className="hide_div";
		}
		else document.getElementById("paybycredit").removeAttribute("disabled");
	}
	function enableCreditcard() {
		if (document.workshopForm.state.value!='Outside' && flagCreditcard!=1) document.getElementById("paybycredit").removeAttribute("disabled");
	}
	function displayWSCost() {
		if (document.workshopForm.slc_ws_name.value =='') {
			document.getElementById("div_ws_price").className="hide_div";
		} else {
			ws_vars=document.workshopForm.slc_ws_name.value.split("|");
			document.getElementById("div_ws_price").className="show_div";
			document.getElementById("div_ws_price").innerHTML ="<p>This workshop costs " + ws_vars[1] + ws_vars[2] + " per attendee.</p>";

			if (ws_vars[1]!='$') {
				document.getElementById("paybycredit").removeAttribute("checked");
				document.getElementById("paybycredit").setAttribute("disabled", "disabled");
				document.getElementById("div_creditcard").className="hide_div";
				flagCreditcard=1;
			} else {
				document.getElementById("paybycredit").removeAttribute("disabled");
				flagCreditcard=0;
			}
		
		}
	}
	function displayOversees(){
		if (document.workshopForm.state.value =='Outside') document.getElementById("div_oversees").className="show_div";
		else document.getElementById("div_oversees").className="hide_div"
	}



// ============================================================ FUNCTIONS: NAV BUTTON CONTROLS ============================================================
	
	function imageSet() {
		var idno = iacore.getPageID();
		
		switch (idno) {
			case 'XXXX': iacore.imgswap.on($('#DIVmainNav a img:eq(1)')); break;
		}
	};

// ============================================================ FUNCTIONS: FORM FUNCTIONS ============================================================
	
	function valCTAForm(oForm) {
		if (oForm.flname.value == "") {
			iacore.formErr($('form[name='+oForm.name+'] input[name=flname]'), 'Please enter your Name to continue.'); return;
		}
		
		if(isNaN(oForm.phone_area.value) || oForm.phone_area.value.search("[.*]") != -1 || oForm.phone_area.value.search("[-*]") != -1 || oForm.phone_area.value.length < 3) {
			iacore.formErr($('form[name='+oForm.name+'] input[name=phone_area]'), 'Please enter a valid Phone Number to continue (enter numbers only).'); return;
		}
		if(isNaN(oForm.phone_pre.value) || oForm.phone_pre.value.search("[.*]") != -1 || oForm.phone_pre.value.search("[-*]") != -1 || oForm.phone_pre.value.length < 3) {
			iacore.formErr($('form[name='+oForm.name+'] input[name=phone_pre]'), 'Please enter a valid Phone Number to continue (enter numbers only).'); return;
		}
		if(isNaN(oForm.phone_num.value) || oForm.phone_num.value.search("[.*]") != -1 || oForm.phone_num.value.search("[-*]") != -1 || oForm.phone_num.value.length < 4) {
			iacore.formErr($('form[name='+oForm.name+'] input[name=phone_num]'), 'Please enter a valid Phone Number to continue (enter numbers only).'); return;
		}

		if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
			iacore.formErr($('form[name='+oForm.name+'] input[name=email]'), 'Please enter a valid E-mail Address (for example: myemail@domain.com).'); return;
		}
		
		var name_arr = oForm.flname.value.split(' ');
		var fname = name_arr[0];
		var lname = '';
			if (name_arr.length > 1) lname = name_arr[1];
		
		oForm.actiontype.value = 'send';
		oForm.fname.value = fname;
		oForm.lname.value = lname;
		oForm.phone.value = oForm.phone_area.value+oForm.phone_pre.value+oForm.phone_num.value;
		
		iacore.formSend({obj:$('#DIVctaContentForm'), frm:oForm, trgt:'/webapp/request-callback.asp'});
	}
	
	function valForm_contactus(oForm, oAction) {
		if (oForm.directo.options[oForm.directo.selectedIndex].value == "") {
			iacore.formErr($('form[name='+oForm.name+'] select[name=directo]'), 'Please select a Message Topic to continue.'); return;
		}
		if (oForm.fname.value == "") {
			iacore.formErr($('form[name='+oForm.name+'] input[name=fname]'), 'Please enter your First Name to continue.'); return;
		}
		if (oForm.lname.value == "") {
			iacore.formErr($('form[name='+oForm.name+'] input[name=lname]'), 'Please enter your Last Name to continue.'); return;
		}
		if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
			iacore.formErr($('form[name='+oForm.name+'] input[name=email]'), 'Please enter a valid E-mail Address (for example: myemail@domain.com).'); return;
		}
		if (oForm.phone.value != "") {
		 	if (isNaN(oForm.phone.value) || oForm.phone.value.search("[.*]") != -1 || oForm.phone.value.search("[-*]") != -1 || oForm.phone.value.length < 10) {
				iacore.formErr($('form[name='+oForm.name+'] input[name=phone]'), 'Please enter a valid Phone Number to continue (enter numbers only).'); return;
			}
		}
		if (oForm.subject.value == "") {
			iacore.formErr($('form[name='+oForm.name+'] input[name=subject]'), 'Please enter the Subject to continue.'); return;
		}
		if (oForm.msg.value == "") {
			iacore.formErr($('form[name='+oForm.name+'] textarea[name=msg]'), 'Please enter your Message to continue.'); return;
		}
		
		$('#DIVcontactBTN').hide();
		$('#DIVcontactWait').show();
		
		oForm.actiontype.value = oAction;
		oForm.submit();
	}

	function valWorkshopForm(oForm) {
		if (!iacore.valForm.select($('select[name=slc_ws_name]'), 'Please select a Workshop to continue.')) { return; }

		if (!iacore.valForm.text($('input[name=first_name]'), 'Please enter your First Name to continue.')) { return; }
		if (!iacore.valForm.text($('input[name=last_name]'), 'Please enter your Last Name to continue.')) { return; }
		if (!iacore.valForm.text($('input[name=address1]'), 'Please enter your Address to continue.')) { return; }
		if (!iacore.valForm.text($('input[name=city]'), 'Please enter your City to continue.')) { return; }
		if (!iacore.valForm.select($('select[name=state]'), 'Please select your State to continue.')) { return; }
		if ($('select[name=state]').attr('selectedIndex') == 1) { if (!iacore.valForm.text($('input[name=state_outside]'), 'Please enter your Outside State to continue.')) { return; } }
		
		if (!iacore.valForm.select($('select[name=country]'), 'Please select your Country to continue.')) { return; }
		if ($('select[name=country]').val() == 'United States') { if (!iacore.valForm.numeric($('input[name=zip]'), 'Please enter your Zip Code to continue.') || !iacore.valForm.length($('input[name=zip]'), 5, 'Please enter a valid Zip Code to continue.')) { return; } }
		else { if (!iacore.valForm.text($('input[name=zip]'), 'Please enter a valid Postal Code to continue.')) { return; } }
		
		if (!iacore.valForm.phone($('input[name=phone]'), 'Please enter a valid Phone Number to continue.')) { return; }
		if (!iacore.valForm.email($('input[name=email]'), 'Please enter a valid Email Address to continue.')) { return; }
		if ($('input[name=email]').val() != $('input[name=email_confirm]').val()) { iacore.formErr($('input[name=email_confirm]'), 'Please make sure your Email Addresses Match to continue.'); return; }
		if (!iacore.valForm.select($('select[name=sales_size]'), 'Please select your Salse Force Size to continue.')) { return; }
		
		if ($('#affiliate_yes').attr('checked') && $('select[name=affiliate_name]').val() == '') { iacore.formErr($('select[name=affiliate_name]'), 'Please select your Business Partner to continue.'); return; }

		if (!iacore.valForm.text($('input[name=p_attendee_name]'), 'Please enter the Primary Attendee Name to continue.')) { return; }
		if (!iacore.valForm.email($('input[name=p_attendee_email]'), 'Please enter a valid Email Address to continue.')) { return; }
		if ($('#attendee1_yes').attr('checked')) {
			if (!iacore.valForm.text($('input[name=p_attendee1_name]'), 'Please enter the Attendee 1 Name to continue.')) { return; }
			if (!iacore.valForm.email($('input[name=attendee1_email]'), 'Please enter a valid Email Address to continue.')) { return; }
		}

		if (!$('#read_policy').attr('checked')) { iacore.formErr($('#read_policy'), 'Please check that you have Read and Agree to our Policies to continue.'); return; }

		if ($('#paybycredit').attr('checked')) {
			if (!iacore.valForm.select($('select[name=cc_type]'), 'Please select your Credit Cart Type to continue.')) { return; }
			if (!iacore.valForm.text($('input[name=cc_name]'), 'Please enter the Name as it appears on your credit card to continue.')) { return; }
			if (!checkCreditCard($('input[name=cc_num]').val(), $('select[name=cc_type]').val())) { iacore.formErr($('input[name=cc_num]'), 'Please enter a valid Credit Card Number to continue.'); return; }
			if (!iacore.valForm.numeric($('input[name=cc_ccv]'),  'Please enter your CCV/CCV2 to continue.') || !iacore.valForm.length($('input[name=cc_ccv]'), 3,  'Please enter a valid CCV/CCV2 to continue.')) { return; }
			if (!iacore.valForm.select($('select[name=exp1]'),  'Please enter a select a Expiration Month to continue.')) { return; }
			if (!iacore.valForm.select($('select[name=exp2]'),  'Please enter a select a Expiration Year to continue.')) { return; }
		}

		$('#DIVsubmit').html('<img src="http://www.customercentric.com/assets/images/icon_loader.gif" alt="" style="width:16px; height:16px;" /> <strong>Processing...</strong>');

		oForm.action = '/custom-apps-process.asp?actiontype=register';
		oForm.submit();
	};


// ============================================================ FUNCTIONS: BLOG CONTROLS ============================================================
	
	function IAcntrl_blogComments(oPos) {
		if (document.getElementById('IAcntrl_blogPostCount')) {
			for (var i=1;i<document.getElementById('IAcntrl_blogPostCount').value; i++) {
				if (document.getElementById('DIVblogComments'+i)) document.getElementById('DIVblogComments'+i).style.display = 'none';
			}
		}
		
		document.getElementById('DIVblogComments'+oPos).style.display = 'block';
		IAcntrl_blogReCaptcha('DIVreCaptcha'+oPos);
	}
	
	function IAcntrl_blogCommentsPost(oForm, oPos) {
		if (oForm.flname.value == '') {
			iacore.formErr($('form[name='+oForm.name+'] input[name=flname]'), 'Please enter your Name to continue.'); return;
		}
		if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
			iacore.formErr($('form[name='+oForm.name+'] input[name=email]'), 'Please enter a valid E-mail Address (for example: myemail@domain.com).'); return;
		}
		if (oForm.comments.value == "") {
			iacore.formErr($('form[name='+oForm.name+'] textarea[name=comments]'), 'Please enter your Comment to continue.'); return;
		}
		
		var http = false;
		var sendVars = iacore.getFormVars(oForm);
		
		document.getElementById('DIVblogComments'+oPos).innerHTML = '<img src="/assets/images/icon_loader.gif" align="absmiddle" style="margin-right:5px; width:16px; height:16px;" /> <strong>Processing...</strong>';
		
		if (window.ActiveXObject) http = new ActiveXObject("Microsoft.XMLHTTP");
		else if (window.XMLHttpRequest) http = new XMLHttpRequest();
		
		if (!http) { alert('Sorry, your Web Browser is not configured to work with this feature.'); return; }
		
		http.open("POST", oForm.action, true);
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				document.getElementById('DIVblogComments'+oPos).innerHTML = http.responseText;
				IAcntrl_blogReCaptcha('DIVreCaptcha'+oPos);
			}
		}
		
		http.send(sendVars);
	}
	
	function IAcntrl_blogReCaptcha(oEl) {
		Recaptcha.create('6LdhLgUAAAAAACKEVhxX069fDcpty41_hRER9tFf',oEl,{ theme: "red", callback: Recaptcha.focus_response_field });
	}

	function txtBlur(oObj, oTxt) {
		if (oObj.value == oTxt) oObj.value = '';
		else if (oObj.value == '') oObj.value = oTxt;
	}

