
var Explorer = new Class({

initialize:function(){

if(window.ActiveXObject && !window.XMLHttpRequest){
this.flickerFix();
this.positionFixedEmulation();
this.hoverSubmit();
}
},

flickerFix:function(){

document.execCommand('BackgroundImageCache',false,true);
},

positionFixedEmulation:function(){

var c= document.styleSheets[0];
c.addRule('.fixed','top: expression(eval(document.documentElement.scrollTop));');
c.addRule('body','background-attachment: fixed;');
},

hoverSubmit:function(){
if(window.ActiveXObject && !window.XMLHttpRequest){
var i= $S('input');
$A(i).each(function(el){
if(el.getProperty('type') == 'button'){
el.addEvent('mouseover',function(){ this.setStyle('backgroundPosition','bottom left'); });
el.addEvent('mouseout',function(){ this.setStyle('backgroundPosition','top left'); });
}
},this);
}
}

});


var Btns = new Class({

initialize: function(o){
this.o= o;
this.btns= o.getElementsByClassName('btn');

$A(this.btns).each(function(el){
el.o = el.effect('opacity', {duration: 750, transition: fx.sineInOut});

el.onmouseover= function(){

var curOpacity = el.getStyle('opacity') == undefined ? 1:Math.round((el.getStyle('opacity')) * 100) / 100;
this.fade(el,curOpacity,0.6);
}.bind(this);

el.onfocus= el.onmouseover;

el.onmouseout= function(){
if(el.getStyle){
var curOpacity = Math.round((el.getStyle('opacity')) * 100) / 100;
this.fade(el,curOpacity,1);
}
}.bind(this);

el.onclick= function(){
delete btns;
delete login;
}.bind(this);

el.onblur= el.onmouseout;
},this);
},

fade: function(el,curOpacity,opacity){
el.o.clearTimer();
el.o.custom(curOpacity,opacity);
}

});


var Pnav = new Class({

initialize: function(){

if($('pnav')){
this.items= $S('#pnav dd a');

$A(this.items).each(function(el){
if(!el.hasClassName('ignore')){
var o= new Element('div');
o.addClassName('over');

window.ActiveXObject && !window.XMLHttpRequest ? o.setStyle('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/pnav.item.over.bg.ie.html', sizingMethod='image')"):null;

if(el.hasClassName('dbl')){
o.addClassName('overDbl');
window.ActiveXObject && !window.XMLHttpRequest ? o.setStyle('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/pnav.item.dbl.over.bg.ie.html', sizingMethod='image')"):null;
}

o.over= o.effects('opacity', { duration: 750, transition: fx.sineOut });
o.out= o.effects('opacity', { duration: 50, transition: fx.sineOut });

o.onmouseover= function(){
el.delay ? $clear(el.delay):null;
el.isOver= true;
}

o.onclick= function(){ document.location= el.href; };


var oo= new Element('div');

var classNameAr= el.className.split(' ');

for(var x = 0; x < classNameAr.length; x++){
var c= classNameAr[x];
if(c.indexOf('icon') >= 0){
oo.addClassName(c);
}
}

oo.setHTML(el.innerHTML);

oo.injectInside(o);

o.injectInside(el);

el.o= o;

if(el.hasClassName('active')){
this.moveOver(el);
el.removeAttribute('href');
el.o.setStyle('cursor','default');
}else{
el.onmouseover= function(){ this.moveOver(el); }.bind(this);

el.onfocus= el.onmouseover;

el.onmouseout= function(){ this.moveOut(el); }.bind(this);

el.onblur= el.onmouseout;
}
}
},this);
}

},

moveOver:function(el){
if(el.isOver != true){
el.delay ? $clear(el.delay):null;
el.isOver= true;
el.o.out.clearTimer();
el.o.setStyle('left',194 + 'px');
el.o.over.move(0,-10);
}
},

moveOut:function(el){
el.delay= (function(){ el.o.over.clearTimer(); el.o.out.move(0,194); el.isOver = false; }).delay(100);
}

});


var Modal = new Class({

initialize:function($triggers,$panel,$endObj){
if($($panel)){

$endObj ? this.endObj = $endObj:null;

this.p= $($panel).clone().setProperty('id',$($panel).getProperty('id') + 'C').setStyle('visibility','hidden');
this.t= $triggers;

this.m= new Element('div');
this.m.maxOpacity= 0.97;

this.c = this.p.getElementsByClassName('btnClose');


this.pFadeIn= this.p.effect('opacity', { duration: 350, transition: fx.sineInOut });
this.pFadeOut= this.p.effect('opacity', { duration: 350, transition: fx.sineInOut, onComplete: function(){ this.mFadeOut.custom(this.m.maxOpacity,0); }.bind(this) });
this.mFadeOut= this.m.effect('opacity', { duration: 200, transition: fx.sineInOut, onComplete: function(){ this.cleanUp(); }.bind(this) });
this.mFadeIn= this.m.effect('opacity', { duration: 200, transition: fx.sineInOut, onComplete: function(){ this.showPanel(); }.bind(this) });

if(!$triggers){
this.createModal();
}else{

$A(this.t).each(function(el){
el.setProperty('href','javascript:void(0);');
el.addEvent('click',function(){ this.createModal()}.bind(this));
},this);
}


window.addEvent('resize',function(){ this.centerPanel(); }.bind(this));


$A(this.c).each(function(el){
el.addEvent('click',function(){ this.removeModal()}.bind(this));
},this);
this.m.addEvent('click',function(){ this.removeModal()}.bind(this));
}
},

centerPanel:function(){
this.p.setStyle('left', (Math.round((document.documentElement.clientWidth * .5) - (this.p.offsetWidth * .5)) + 'px'));
},

showPanel:function(){
$E('body').adopt(this.p);
new Btns(this.p);
this.p.setStyle('display','block').setOpacity(0);
this.pFadeIn.custom(0,1);
this.centerPanel();
},

createModal:function(){
var h= document.documentElement.scrollHeight > document.documentElement.offsetHeight ? document.documentElement.scrollHeight:document.documentElement.offsetHeight;

this.m.setProperty('id','modal').setStyle('height',h + 'px').addClassName('modal').setOpacity(0);
$E('body').adopt(this.m);
this.mFadeIn.custom(0,this.m.maxOpacity);
},

removeModal:function(){
this.pFadeOut.custom(1,0);
},

cleanUp:function(){

this.p.remove();

this.m.remove();

if(this.endObj){
eval(this.endObj).modalCleanup();
}
}

});


var ToTop= new Class({

s:new fx.Scroll({ duration: 300, transition: fx.sineInOut }),

initialize:function(){
var b= document.getElementsByClassName('btnToTop');

$A(b).each(function(el){
el.setAttribute('href','javascript:void(0);');
el.addEvent('click',function(){ this.ToTop()}.bind(this));
},this);
},

ToTop:function(){
this.s.scrollTo($('login'));
}

});


var Login= new Class({

maxHeight:274,
opacity:0,
Explorer:new Explorer('noinit'),

initialize:function(){
this.c= $('loginContent');
this.t= $('tabLogin');

this.t.setProperty('href','javascript:void(0)');

new ajax('inc/login.inc', { postBody: 'freak', update: 'loginContent', onComplete: function(){ this.switchPanels();  }.bind(this) }).request();
this.t.addEvent('click',function(){ this.expandCollapse()}.bind(this));
},

expandCollapse:function(){
if(this.opacity === 0){
this.c.eComplete= this.c.effect('height', { duration: 350, transition: fx.sineInOut, onComplete: function(){ this.showHide(); this.opacity = 1; }.bind(this) });
this.c.e= this.c.effect('height', { duration: 350, transition: fx.sineInOut });
this.c.eComplete.custom(0,this.maxHeight);
this.t.addClassName('clicked');
}else{
this.t.removeClassName('clicked');
this.showHide();
}
},

showHide:function(){
if(this.opacity === 0){
var h= $('hiddenLogin');
h.setStyle('opacity','0');
h.setStyle('display','block');
var hiddenMove= h.effect('opacity', { duration: 350, transition: fx.sineInOut });
hiddenMove.custom(0,1);
}else{
var h= $('hiddenLogin');
var hiddenMove= h.effect('opacity', { duration: 350, transition: fx.sineInOut, onComplete: function(){ this.c.e.custom(this.maxHeight,0); this.opacity = 0; }.bind(this) });
hiddenMove.custom(1,0);
}
},

switchPanels:function(){

this.Explorer.hoverSubmit();

frmLogin = new SmartForm('#frmLogin', { objNme: 'frmLogin', required: ['Username','Password'], processor: 'ajax.login.php', ignoreEmpty: true, evalScripts: true });
frmForgot = new SmartForm('#frmForgot', { objNme: 'frmForgot', required: [['forgotUser','email']], processor: 'ajax.forgot.php', ignoreEmpty: true });

this.la= $S('#frmLogin a');
this.la[0].addEvent('click', function(){ this.showHidePanel(this.frmLogin,1,0) }.bind(this));

this.fa= $S('#frmForgot a');
this.fa[0].addEvent('click', function(){ this.showHidePanel(this.frmForgot,1,0) }.bind(this));

this.frmLogin= $('frmLogin');
this.frmForgot= $('frmForgot');

this.frmForgot.setOpacity(0);
this.frmForgot.setStyle('display','block');

this.frmLogin.eOut= this.frmLogin.effect('opacity', { duration: 350, transition: fx.sineInOut, onComplete: function(){ this.showHidePanel(this.frmForgot,0,1) }.bind(this) });
this.frmLogin.eIn= this.frmLogin.effect('opacity', { duration: 350, transition: fx.sineInOut });
this.frmForgot.eOut= this.frmForgot.effect('opacity', { duration: 350, transition: fx.sineInOut, onComplete: function(){ this.showHidePanel(this.frmLogin,0,1) }.bind(this) });
this.frmForgot.eIn= this.frmForgot.effect('opacity', { duration: 350, transition: fx.sineInOut });
},

showHidePanel:function(panel,from,to){
if(from == 1){
panel.eOut.custom(from,to);
}else{
panel.eIn.custom(from,to);
}
}

});

var DemoLogin = new Class({

initialize:function(){
this.btn= $E('#header li.btnDemo a');
this.btn.addEvent('click', function(){ this.login()}.bind(this));
},

login:function(){
this.a= new ajax('ajax.login.html', { postBody: 'Username=demo&Password=demo&jsvalidated=true', onComplete: function(){ this.post(); }.bind(this) }).request();
},

post:function(){
this.response= this.a.transport.responseText.split('||');

if(this.response[0] == 'redirect'){
window.location= this.options.redirect;
}else if(this.response[0] == 'error'){
$('errorUpdate').setHTML(this.response[1]);
new Modal(null,'errorPanel',this.options.objNme);
}else if(this.response[0] == 'confirmation'){
$('confirmationUpdate').setHTML(this.response[1]);
new Modal(null,'confirmationPanel',this.options.objNme);
}else if(this.response[0] == 'continue'){

}

this.evalScripts();
},

evalScripts: function(){
if(scripts = this.response[1].match(/<script[^>]*?>.*?<\/script>/g)){
scripts.each(function(script){
eval(script.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
});
}
}

});

var SmartForm= new Class({

setOptions: function(frm,options){
this.options = {
objNme:'',
required:'',
btnSubmit:$S(frm + ' input.submit') ? $S(frm + ' input.submit')[0]:null,
submitting:$S(frm + ' div.submitting') ? $S(frm + ' div.submitting')[0]:null,
redirect:'',
ignoreEmpty:false,
evalScripts:false
};
Object.extend(this.options, options || {});
},

initialize:function(frm,options){

this.setOptions(frm,options);

this.frm= frm;

this.inputs= $S(this.frm + ' span.field', this.frm + ' span.textarea');

this.btn = this.options.btnSubmit;

if(this.btn){
this.btn.addEvent('focus',function(){ this.btn.setStyle('backgroundPosition','bottom left') }.bindAsEventListener(this) );
this.btn.addEvent('blur',function(){ this.btn.setStyle('backgroundPosition','top left') }.bindAsEventListener(this) );

this.btn.addEvent('mouseover',function(){ this.focus() } );
this.btn.addEvent('mouseout',function(){ this.blur() } );

this.btn.addEvent('click',this.validate.bind(this));
}

$A(this.inputs).each(function(el){
el.getFirst().addEvent('focus',function(){this.parentNode.addClassName('focus'); });
el.getFirst().addEvent('blur',function(){ this.parentNode.removeClassName('focus'); });
el.getFirst().addEvent('focus',function(){ this.parentNode.removeClassName('error'); });
},this);


this.helpers= $S(this.frm + ' a.help');
$A(this.helpers).each(function(el){
if(window.ActiveXObject && !window.XMLHttpRequest){
el.setStyle('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/icon.frm.help.html')");
}
},this);


},

validate:function(){

if(this.options.submitting){
this.submittingFx= this.options.submitting.effect('opacity', {duration: 200, transition: fx.sineInOut });
this.submittingFx.custom(0,1);
}

errorCnt= 0;
errorStr='<dl><dt><strong>The following problems have occured with your submission:</strong></dt>';
errorRequired= 0;
vals= '';
$A(this.options.required).each(function(el){
if($type(el) == 'array'){

val= el[0] + '=' + $(el[0]).value + '&';

for(var x = 1; x < el.length; x++){

if(this.options.ignoreEmpty == false){
if($(el[0]).value.isEmpty() == 'true'){
errorCnt++;
errorRequired++;
$(el[0]).parentNode.addClassName('error');
}
}

if(el[x] == 'string'){
if($(el[0]).value.isString() == 'false'){
errorCnt++;
errorStr+= '<dd><strong>' + $(el[0]).getProperty('title') + '</strong> Please do not enter numbers... </dd>';
$(el[0]).parentNode.addClassName('error');
}
}

if(el[x] == 'singleword'){
if($(el[0]).value.isSingleWord() == 'false'){
errorCnt++;
errorStr+= '<dd><strong>' + $(el[0]).getProperty('title') + '</strong> Please only enter a single word... </dd>';
$(el[0]).parentNode.addClassName('error');
}
}

if(el[x] == 'email'){
if($(el[0]).value.isEmpty() == 'false' && $(el[0]).value.isEmail() == 'false' || this.options.ignoreEmpty == true && $(el[0]).value.isEmail() == 'false'){
errorCnt++;
errorStr+= '<dd><strong>' + $(el[0]).getProperty('title') + '</strong> Please enter a valid email address... </dd>';
$(el[0]).parentNode.addClassName('error');
}
}

}

}else if($type(el) == 'string'){

val= el + '=' + $(el).value + '&';
if(this.options.ignoreEmpty == false){
if($(el).value.isEmpty() == 'true'){
errorCnt++;
errorRequired++;
$(el).parentNode.addClassName('error');
}
}
}

vals+= val;
},this);

if(errorCnt > 0){
errorRequired > 0 ? errorStr += '<dd>All fields marked with a <img src="images/icon.frm.required.wht.contextual.gif" width="14" height="14" />  are required. Please fill in all required fileds.</dd>':null;
$('errorUpdate').setHTML(errorStr + '</dl>');
new Modal(null,'errorPanel',this.options.objNme);
return false;
}else{
vals+= '&jsvalidated=true';
this.a= new ajax(this.options.processor, { postBody: vals, onComplete: function(){ this.post(); }.bind(this) }).request();
}
},

post:function(){
this.response= this.a.transport.responseText.split('||');

if(this.response[0] == 'redirect'){
window.location= this.options.redirect;
}else if(this.response[0] == 'error'){
$('errorUpdate').setHTML(this.response[1]);
new Modal(null,'errorPanel',this.options.objNme);
}else if(this.response[0] == 'confirmation'){
$('confirmationUpdate').setHTML(this.response[1]);
new Modal(null,'confirmationPanel',this.options.objNme);
}else if(this.response[0] == 'continue'){

}

this.options.evalScripts == true ? this.evalScripts():null;
},

evalScripts: function(){
if(scripts = this.response[1].match(/<script[^>]*?>.*?<\/script>/g)){
scripts.each(function(script){
eval(script.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
});
}
},

modalCleanup:function(){
if(this.options.submitting){
this.submittingFx.custom(1,0);
}
}

});

var btns, login,tips;

function delayOnload(){
tips= new Tips($S('a'));
}

var frmReseller;
var frmContact;
var frmForgot
var frmLogin

window.addEvent('load',function(){
new DemoLogin();
btns= new Btns($('oracle'));
new ToTop();
new Explorer();
new Pnav();

$('changeIndustry') ? new Modal([$('btnChangeIndustry'),$E('#breadcrumbs .changeIndustry')],'changeIndustry'):null;

$('frmReseller') ? frmReseller = new SmartForm('#frmReseller', { objNme: 'frmReseller', required: [['FirstName','string','singleword'],['LastName','string','singleword'],['Email','email'],'Message','Subject'], processor: 'ajax.reseller.php' }):null;
$('frmContact') ? frmContact = new SmartForm('#frmContact', { objNme: 'frmContact', required: [['FirstName','string','singleword'],['LastName','string','singleword'],['Email','email'],'Subject','Message'], processor: 'ajax.contact.php' }):null;

//$('frmForgot') ? frmForgot = new SmartForm('#frmForgot', { objNme: 'frmForgot', required: [['email','string','email']], processor: 'ajax.reseller.php' }):null;

login= new Login();
tips= new Tips($S('a'));

//delayOnload.delay(30);
});

