var msie = checkIt('msie') > 0;
var opera = checkIt('opera') > 0;
var mozilla = checkIt('gecko/') > 0;

function getViewPortHeight()
{
 var viewportheight;
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportheight = window.innerHeight;
 }
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportheight = document.documentElement.clientHeight
 }
 else
 {
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
 return viewportheight;  
}

function curH()
{
    return getViewPortHeight() - 25;
}

function checkIt(string)
{
    var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	return place;
}

function findcontrol(partialname){
    var sx = $$('[id*='+partialname+']');
    if (sx.length>0){
        return sx[0];
    } else {
        return null;
    }
}

String.prototype.replace = function(pattern, replacement) {
  return this.split(pattern).join(replacement);
}

function showMentorPopup(popup)
{
	$(popup).style.zIndex = 500;
	$(popup).style.display = '';
	$(popup).style.marginTop = (-1 * parseInt($(popup).offsetHeight)) + 'px';
	//new Effect.Appear($(popup),{beforeUpdate:function(){$(popup).style.marginTop = (-1 * parseInt($(popup).offsetHeight)) + 'px';},duration:0.125});	
}

function hideMentorPopup(popup)
{
	$(popup).style.zIndex = -100;
	$(popup).style.display = 'none';
	//new Effect.Fade($(popup),{duration:0.125,afterFinish:function(){ $(popup).style.zIndex = -100; }});
}

function subscribeSlide()
{
	new Effect.toggle('blog_signup', 'slide', {duration:.3});
}	

function subscribeToggle()
{
	var e = $('blog_signup');
	if(e.style.display == 'none')
	{
		$('blog_signup').style.display = '';
	} else {
		$('blog_signup').style.display = 'none';
	}
}

function startRSE()
{
        new RSV({
                displayType: "display-html",
                errorFieldClass: "errorFieldDemo5",
                formID: "aspnetForm",
                rules: [
                        "required,"+findcontrol('txtFirstName').id+",Please enter your first name.",
                        "required,"+findcontrol('txtLastName').id+",Please enter your last name.",
                        "required,"+findcontrol('txtCity').id+",Please enter your last name.",
                        "required,"+findcontrol('txtPhone').id+",Please enter your last name.",                        
                        "required,"+findcontrol('txtEmail').id+",Please enter your email address.",
                        "valid_email,"+findcontrol('txtEmail').id+",Please enter a valid email address.",
                        "required,"+findcontrol('txtPass1').id+",Please enter your email address.",
                        "same_as,"+findcontrol('txtPass1').id+","+findcontrol('txtPass2').id+",Please ensure the passwords you enter are the same.",
                        "function,checkSelection"
                ]
        });

}
//                onCompleteHandler: myOnComplete,


function checkSelection()
{
        
        var any = findcontrol('chkWriter').checked || findcontrol('chkTranslator').checked || findcontrol('chkVoiceOver').checked || findcontrol('chkFilmmaker').checked || findcontrol('chkVoiceOver2').checked || findcontrol('chkWriter2').checked;
        
        if (!any) {
               showVL();
               return false;
               }
               //return [[$('#arPos'), "Please check youir position at EmergingCast."]];

        return true;
}

function showVL(){
    //alert(findcontrol('errXX').innerHTML);
    findcontrol('vlSum').innerHTML = findcontrol('errXX').innerHTML;
    findcontrol('vlSum').show();
}

function fixApl(){
    if ($('fixedapply')){
        Element.absolutize('fixedapply');
        $('fixedapply').style.position = 'fixed';        
        $('fixedapply').style.top = (parseInt($('fixedapply').style.top.replace('px', '')) + 136) + 'px';
        if (mozilla) {
            $('fixedapply').style.left = (parseInt($('fixedapply').style.left.replace('px', '')) + 133) + 'px';
        }
        else
        {
            $('fixedapply').style.left = (parseInt($('fixedapply').style.left.replace('px', '')) + 155) + 'px';        
        }
        //alert((parseInt($('fixedapply').style.top.replace('px', '')) + 100));
    }
}

function disMe(xid)
{
    if (Page_ClientValidate()){
        //alert($('imgWait').src);
        $('imgWait').src = '/images/waitLoad.gif';
        $('imgWait').width = 120;
        $('imgWait').height = 40;
        //$('imgWait').className = 'transMe';
        findcontrol('btnApply').hide();
        //alert($('imgWait').src);
    }
    else
    {
        if (msie){
            findcontrol('vlSum').hide();
            findcontrol('vlSum').removeClassName = 'errMsg';
            findcontrol('vlSum').addClassName('errMsg');        
            findcontrol('vlSum').show();
            findcontrol('vlSum').addClassName('errMsg');        
            /*new PeriodicalExecuter(function(pe){
                pe.stop();
                //findcontrol('vlSum').hide();
                //findcontrol('vlSum').show();
                findcontrol('vlSum').removeClassName = 'errMsg';
                findcontrol('vlSum').addClassName('errMsg2');        
                findcontrol('vlSum').removeClassName = 'errMsg2';
                //findcontrol('vlSum').className = '';                
                //alert(findcontrol('vlSum').className);
                //alert(findcontrol('vlSum').className);
                //findcontrol('vlSum').addClassName = 'errMsg2';        
                //alert(findcontrol('vlSum').className);
                findcontrol('vlSum').addClassName('errMsg');        
                //alert(findcontrol('vlSum').className);
                //findcontrol('vlSum').hide();
                //findcontrol('vlSum').show();
                //$('imgWait').className = 
            }, 0.5);*/
        }
    }
}

function disMe2(xid)
{
    if (Page_ClientValidate()){
        $('imgWait').src = '/images/waitLoad.gif';
        $('imgWait').width = 120;
        $('imgWait').height = 40;
        findcontrol('btnUpdateprofile').hide();
    }
    else
    {
        if (msie){
            new PeriodicalExecuter(function(pe){
                pe.stop();
                findcontrol('vlSum').hide();
                findcontrol('vlSum').show();
                findcontrol('vlSum').removeClassName = 'errMsg';
                findcontrol('vlSum').className = '';                
                //alert(findcontrol('vlSum').className);
                findcontrol('vlSum').className = 'errMsg';        
                //alert(findcontrol('vlSum').className);
                //$('imgWait').className = 
            }, 0.5);
        }
    }
}

function chkValFrm(){
    if (!Page_ClientValidate()){
    }
}

function hideObj(name){
    findcontrol(name).hide();
}

function openDoc(id){
    //myLightWindow.activate(null, './documents/'+id+'.htm');
    
    myLightWindow.activateWindow({href: './documents/'+id+'.htm', width: 600, height: curH(), title: '&nbsp;'});
}

//Event.observe(window, 'load', fixApl);

