function BeginAppraisalTwoConditionsUpdateConditionHelp() {


   
    $('HelpConditionWorking').style.display = 'none';
    $('HelpConditionDefective').style.display = 'none';


    if ($('ConditionName').value == 'WORKING') {
        $('HelpConditionWorking').style.display = 'block';
        if ($('AssociateIDtr') != null)
            $('AssociateIDtr').style.display = 'block';
        $('ConditionImage').src = '/Content/images/cexchange/body/WorkingPhotoButton.png';
        $('ConditionImage2').href = '/views/cexchange/instore/Help/Working.html';
    }
    if ($('ConditionName').value == 'DAMAGED OR NOT WORKING' || $('ConditionName').value == 'NOT WORKING' || $('ConditionName').value == 'DAMAGED OR BROKEN') {
        $('HelpConditionDefective').style.display = 'block';
        if ($('AssociateIDtr') != null)
            $('AssociateIDtr').style.display = 'none';
        $('ConditionImage').src = '/Content/images/cexchange/body/DamagedPhotoButton.png';
        $('ConditionImage2').href = '/views/cexchange/instore/Help/Defective.html';
    }
}

function BeginAppraisalThreeConditionsUpdateConditionHelp() {
   
    
		$('HelpConditionLikeNew').style.display='none';
		$('HelpConditionWorking').style.display='none';
		$('HelpConditionDefective').style.display='none';

		
		if ($('ConditionName').value == 'LIKE NEW AS IF NEVER USED')
		{
			$('HelpConditionLikeNew').style.display='block';
			if ($('AssociateIDtr') != null)
				$('AssociateIDtr').style.display='block';
			$('ConditionImage').src='/Content/images/cexchange/body/LikeNewPhotoButton.png';
			$('ConditionImage2').href='/views/cexchange/instore/Help/LikeNew.html';
			
		}
		if ($('ConditionName').value == 'WORKING')
		{
			$('HelpConditionWorking').style.display='block';
			if ($('AssociateIDtr') != null)
				$('AssociateIDtr').style.display='block';
			$('ConditionImage').src='/Content/images/cexchange/body/WorkingPhotoButton.png';
			$('ConditionImage2').href='/views/cexchange/instore/Help/Working.html';
		}
		if ($('ConditionName').value == 'DAMAGED OR NOT WORKING')
		{
			$('HelpConditionDefective').style.display='block';
			if ($('AssociateIDtr') != null)
				$('AssociateIDtr').style.display='none';
			$('ConditionImage').src='/Content/images/cexchange/body/DamagedPhotoButton.png';
			$('ConditionImage2').href='/views/cexchange/instore/Help/Defective.html';
		}
	}
	
	var theWindow = null;
	var theWindowOpen = false;
	var curPageHeight = 0;
	var curPageWidth = 0;
	var curPageX = 0;
	var curPageY = 0;
    
	var RadioShackOnlineAppraisalFormSave = "";

	function Delete_Cookie(name, path, domain) {
	    if (Get_Cookie(name)) document.cookie = name + "=" +
            ((path) ? ";path=" + path : "") +
            ((domain) ? ";domain=" + domain : "") +
            ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}

	function Set_Cookie(name, value, expires, path, domain, secure) {
	    // set time, it's in milliseconds
	    var today = new Date();
	    today.setTime(today.getTime());

	    /*
	    if the expires variable is set, make the correct
	    expires time, the current script below will set
	    it for x number of days, to make it for hours,
	    delete * 24, for minutes, delete * 60 * 24
	    */
	    if (expires) {
	        expires = expires * 1000 * 60 * 60 * 24;
	    }
	    var expires_date = new Date(today.getTime() + (expires));

	    document.cookie = name + "=" + escape(value) +
        ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
        ((path) ? ";path=" + path : "") +
        ((domain) ? ";domain=" + domain : "") +
        ((secure) ? ";secure" : "");
	}

	function Get_Cookie(check_name) {
	    // first we'll split this cookie up into name/value pairs
	    // note: document.cookie only returns name=value, not the other components
	    var a_all_cookies = document.cookie.split(';');
	    var a_temp_cookie = '';
	    var cookie_name = '';
	    var cookie_value = '';
	    var b_cookie_found = false; // set boolean t/f default f

	    for (i = 0; i < a_all_cookies.length; i++) {
	        // now we'll split apart each name=value pair
	        a_temp_cookie = a_all_cookies[i].split('=');


	        // and trim left/right whitespace while we're at it
	        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

	        // if the extracted name matches passed check_name
	        if (cookie_name == check_name) {
	            b_cookie_found = true;
	            // we need to handle case where cookie has no value but exists (no = sign, that is):
	            if (a_temp_cookie.length > 1) {
	                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
	            }
	            // note that in cases where cookie is initialized but no value, null is returned
	            return cookie_value;
	            break;
	        }
	        a_temp_cookie = null;
	        cookie_name = '';
	    }
	    if (!b_cookie_found) {
	        return null;
	    }
	}

    //Validate Conditions
	function RadioShackOnlineAppraisalValidateConditions() {
	    
        var errorDiv = null;
        var conditions = $$('.ValidateCondition');
        var test = false;
        if (conditions.length > 0) {
            for (i = 0; i < conditions.length; i++) {
                var errorDiv = $('Condition-Error');
                errorDiv.style.display = "none";

                if (conditions[i].title == "ButtonSelected")
                    test = true;
            }

            if (test == false) {
                errorDiv.style.display = "block";
                return false;
            }
        }

	    return true;
	}

    //Validate Questions
	function RadioShackOnlineAppraisalValidateQuestions() {
	    var errorDiv = null;
	    var questions = $$('.ValidateQuestion');
	    var test = false;
	    var elementID = "";
	    var returnValue = true;

	    if (questions.length > 0) {
	        elementID = questions[0].id.substr(0, questions[0].id.lastIndexOf('-'));

	        var errorDiv = $(questions[0].id.substr(0, questions[0].id.lastIndexOf('-')) + '-Error');
	        errorDiv.style.display = "none";

	        for (i = 0; i < questions.length; i++) {
	            
	            if (elementID != questions[i].id.substr(0, questions[i].id.lastIndexOf('-'))) {
	                elementID = questions[i].id.substr(0, questions[i].id.lastIndexOf('-'));
	                if (test == false) {
	                    errorDiv.style.display = "block";
	                }
	                test = false;
	            }

	            if (questions[i].title == "ButtonSelected")
	                test = true;

	            errorDiv = $(questions[i].id.substr(0, questions[i].id.lastIndexOf('-')) + '-Error');
	            errorDiv.style.display = "none";
	        }
	        if (test == false) {
	            errorDiv.style.display = "block";
	            returnValue = false;
	        }
	    }

	    return returnValue;
	}

    //Validate Accessories
	function RadioShackOnlineAppraisalValidateAccessories() {
	    var errorDiv = null;
	    var accessories = $$('.ValidateAccessory');
	    var test = false;
	    var elementID = "";
	    var returnValue = true;

	    if (accessories.length > 0) {
	        elementID = accessories[0].id.substr(0, accessories[0].id.lastIndexOf('-'));
	        
            var errorDiv = $(accessories[0].id.substr(0, accessories[0].id.lastIndexOf('-')) + '-Error');
	        errorDiv.style.display = "none";

	        for (i = 0; i < accessories.length; i++) {

	            if (elementID != accessories[i].id.substr(0, accessories[0].id.lastIndexOf('-'))) {
	                elementID = accessories[i].id.substr(0, accessories[0].id.lastIndexOf('-')); 
	                if (test == false) {
	                    errorDiv.style.display = "block";
	                }
	                test = false;
	            }

	            if (accessories[i].title == "ButtonSelected")
	                test = true;

	            errorDiv = $(accessories[i].id.substr(0, accessories[i].id.lastIndexOf('-')) + '-Error');
	            errorDiv.style.display = "none";
	        }

	        if (test == false) {
	            errorDiv.style.display = "block";
	            returnValue = false;
	        }
	    }

	    return returnValue;
	}

    //Validate Components
	function RadioShackOnlineAppraisalValidateComponents() {
	    var components = $$('.ValidateComponent');
	    var errorDiv = null;
	    var returnValue = true;

	    for (i = 0; i < components.length; i++) {
	        if (components[i].style.display != 'none') {
	            errorDiv = $(components[i].id + '-Error');
	            errorDiv.style.display = "none";

	            if (components[i].value == 0) {
	                returnValue = false;
	                errorDiv.style.display = "block";
	            }
	        }
	    }

	    return returnValue;
	}

	function RadioShackOnlineResetAppraisedValue() {
	    //new Effect.Fade('WhatIsValueProtectionImage', { duration: 0.4 });
	    new Effect.Fade('AppraisalButtonAddAnotherLeft', { duration: 0.4 });
	    new Effect.Fade('AppraisalButtonAddAnotherCenter', { duration: 0.4 });
	    new Effect.Fade('AppraisalButtonAddAnotherRight', { duration: 0.4 });
	    new Effect.Fade('submitContainer', { duration: 0.4 });
	}

	function RadioShackOnlineDeleteAppraisalForm(appraisalId) {
	    if (appraisalId == "") {
	        return;
	    }

	    var appraisalForm = Get_Cookie('RadioShackOnlineAppraisalFormSave');
	    if (appraisalForm == null) {
	        return;
	    }

	    var startIndex = appraisalForm.indexOf('[AppraisalId][' + appraisalId + '];');

	    if (startIndex == -1) {
	        return;
	    }

	    var subString = appraisalForm.substr(startIndex);
	    var endIndex = subString.indexOf('^');
	    var finalString = subString.substr(0, endIndex + 1);
	    appraisalForm = appraisalForm.replace(finalString, '');
        Set_Cookie('RadioShackOnlineAppraisalFormSave', appraisalForm, '', '/', '', '');
	}

    //Cookie Saved In Format:
	//[AppraisalId][1160924];[Condition][16];[QuestionId-7][16];[AccessoryId-1565][yes];[Component-7][917];^[AppraisalId][1160925];.....
	function RadioShackOnlineRestoreAppraisalForm(appraisalId) {
	    appraisalForm = Get_Cookie('RadioShackOnlineAppraisalFormSave');
	    if (appraisalForm == null) {
	        return;
	    }

	    var appraisalList = appraisalForm.split("^");

	    for (i = 0; i < appraisalList.length; i++) {
	        if (appraisalList[i].indexOf('[AppraisalId][' + appraisalId + '];') != -1) {
	            
	            appraisal = appraisalList[i].replace('[AppraisalId][' + appraisalId + '];', '');
	            appraisalQuestionList = appraisal.split(";");
	            for (x = 0; x < appraisalQuestionList.length; x++) {
	                if (appraisalQuestionList[x].indexOf('[Condition') != -1) {
	                    var name = appraisalQuestionList[x].substr(1, appraisalQuestionList[x].indexOf(']')-1);
	                    var value = appraisalQuestionList[x].substr(appraisalQuestionList[x].indexOf(']') + 2).replace(']', '');
	                    var element = name + '-' + value;

	                    RadioShackOnlineAppraiseOnClick(document.getElementById(element), name, value);
	                }
	                if (appraisalQuestionList[x].indexOf('[QuestionId') != -1) {
	                    var name = appraisalQuestionList[x].substr(1, appraisalQuestionList[x].indexOf(']') - 1);
	                    var value = appraisalQuestionList[x].substr(appraisalQuestionList[x].indexOf(']') + 2).replace(']', '');
	                    var element = name + '-' + value;

	                    RadioShackOnlineAppraiseOnClick(document.getElementById(element), name, value);
	                }
	                if (appraisalQuestionList[x].indexOf('[Accessory') != -1) {
	                    var name = appraisalQuestionList[x].substr(1, appraisalQuestionList[x].indexOf(']') - 1);
	                    var value = appraisalQuestionList[x].substr(appraisalQuestionList[x].indexOf(']') + 2).replace(']', '');
	                    var element = name + '-' + value;

	                    RadioShackOnlineAppraiseOnClick(document.getElementById(element), name, value);
	                }
	                if (appraisalQuestionList[x].indexOf('[Component') != -1) {
	                    var name = appraisalQuestionList[x].substr(1, appraisalQuestionList[x].indexOf(']') - 1);
	                    var value = appraisalQuestionList[x].substr(appraisalQuestionList[x].indexOf(']') + 2).replace(']', '');
	                    selectList = document.getElementsByTagName('select');

	                    for (z = 0; z < selectList.length; z++) {
	                        if (selectList[z].id == name && selectList[z].style.display != 'none') {
	                            selectList[z].value = value;
	                            ValidateComponentSets(selectList[z]);
	                            RadioShackOnlineComponentOnChange(selectList[z]);
	                        }
	                    }
	                }
	            }
	        }
	    }
	}

	function RadioShackOnlineSaveAppraisalForm() {
	    AppraisalForm = Get_Cookie('RadioShackOnlineAppraisalFormSave');

	    if (AppraisalForm == null) {
	        Set_Cookie('RadioShackOnlineAppraisalFormSave', "[AppraisalId][" + $('AppraisalId').value + "];" + RadioShackOnlineAppraisalFormSave + "^", '', '/', '', '');
	    }
	    else {
	        Set_Cookie('RadioShackOnlineAppraisalFormSave', AppraisalForm + "[AppraisalId][" + $('AppraisalId').value + "];" + RadioShackOnlineAppraisalFormSave + "^", '', '/', '', '');
	    }
	}

	function RadioShackOnlineAppraisalValidateAndSubmit(area) {
	    var returnValueConditions = RadioShackOnlineAppraisalValidateConditions();
	    var returnValueQuestions = RadioShackOnlineAppraisalValidateQuestions();
	    var returnValueAccessories = RadioShackOnlineAppraisalValidateAccessories();
	    var returnValueComponents = RadioShackOnlineAppraisalValidateComponents();

	    if (returnValueConditions == false || returnValueQuestions == false || returnValueAccessories == false || returnValueComponents == false) {
	        return;
	    }

	    new Ajax.Updater(
                'AppraisalValue', '/' + area + '/Cart/BeginAppraisal-UpdatePrice.rails',
                { parameters: $('form1').serialize(),
                    onComplete: function () {

                        $('UpdateButton').innerHTML = "UPDATE";
                        $('TradeInValueTextLabel').innerHTML = "Today your trade-in value is:";

                        //new Effect.Appear('WhatIsValueProtectionImage');

                        new Effect.Appear('AppraisalButtonAddAnotherLeft');
                        new Effect.Appear('AppraisalButtonAddAnotherCenter');
                        new Effect.Appear('AppraisalButtonAddAnotherRight');

                        new Effect.Appear('submitContainer');
                        new Effect.Highlight('AppraisalValue');

                        //Save the AppraisalId so we can use it in RadioShackOnlineSaveAppraisalForm()
                        $('AppraisalId').value = $('AppraisalValue').innerHTML.substr($('AppraisalValue').innerHTML.indexOf("-") + 1);

                        //Remove the the AppraisalId from the results to be displayed
                        $('AppraisalValue').innerHTML = $('AppraisalValue').innerHTML.substr(0, $('AppraisalValue').innerHTML.indexOf("-"));
                    }
                });
	}
	
	function RadioShackOnlineGetElementTopLeft(id) {
    var ele = document.getElementById(id);
    var top = 0;
    var left = 0;
    while(ele.tagName != "BODY") {
        top += ele.offsetTop;
        left += ele.offsetLeft;
        ele = ele.offsetParent;
    }
    return { top: top, left: left };
	}


	function RadioShackOnlineButtonOnMouseOver(elment) {

		if ($(elment).attributes["name"]) {
		
		var y = $('beginAppraisalTitleContainer').getHeight() + 110;
		
		var w = RadioShackOnlineGetElementTopLeft('beginAppraisalTitleContainer')
			if ($(elment).attributes["name"].value == "Condition-1") {
				$("ConditionPopUp1").setStyle({ left: w.left + 80 + 'px', top: w.top + y + 'px', display: 'block' });
			}
			if ($(elment).attributes["name"].value == "Condition-2") {
				$("ConditionPopUp2").setStyle({ left: w.left + 220  + 'px', top: w.top + y + 'px', display: 'block' });
			}
			if ($(elment).attributes["name"].value == "Condition-3") {
				$("ConditionPopUp3").setStyle({ left: w.left + 360  + 'px', top: w.top + y + 'px', display: 'block' });
			}
		}

	    $(elment).previousSiblings()[0].style.backgroundImage = "url('/Content/images/radioshack/body/ButtonGreenLeft.gif')";
	    $(elment).setStyle({ backgroundColor: '#8dc63f' });
	    $(elment).nextSiblings()[0].style.backgroundImage = "url('/Content/images/radioshack/body/ButtonGreenRight.gif')";
	}

	function RadioShackOnlineButtonOnMouseOut(elment) 
    {
		if ($(elment).attributes["name"]) {
			if ($(elment).attributes["name"].value == "Condition-1" || $(elment).attributes["name"].value== "Condition-2" || $(elment).name == "FAIR" || $(elment).attributes["name"].value == "Condition-3") {
				$("ConditionPopUp1").setStyle({ display: 'none' });
				$("ConditionPopUp2").setStyle({ display: 'none' });
				$("ConditionPopUp3").setStyle({ display: 'none' });
			}
		}

        if ($(elment).title != "ButtonSelected") 
        {
            $(elment).previousSiblings()[0].style.backgroundImage = "url('/Content/images/radioshack/body/ButtonBlackLeft.gif')";
            $(elment).setStyle({ backgroundColor: '#333333' });
            $(elment).nextSiblings()[0].style.backgroundImage = "url('/Content/images/radioshack/body/ButtonBlackRight.gif')";
        }
    }

    function RadioShackOnlineComponentOnChange(element) {
       
        var elementString = "[" + element.id + "]";
        if (RadioShackOnlineAppraisalFormSave.indexOf(elementString) == -1) {
            RadioShackOnlineAppraisalFormSave += elementString + "[" + element.value + "];";
        }
        else {
            var index = RadioShackOnlineAppraisalFormSave.indexOf(elementString);
            var subString = RadioShackOnlineAppraisalFormSave.substr(index);
            var finalString = subString.substr(0, subString.indexOf(";") + 1);

            RadioShackOnlineAppraisalFormSave = RadioShackOnlineAppraisalFormSave.replace(finalString, elementString + "[" + element.value + "];");
        }

    }

	function RadioShackOnlineAppraiseOnClick(element, questionid, answerid) {

	    RadioShackOnlineResetAppraisedValue();

        if (questionid != null) {
            var elementString = "[" + questionid + "]";
            if (RadioShackOnlineAppraisalFormSave.indexOf(elementString) == -1) {
                RadioShackOnlineAppraisalFormSave += elementString + "[" + answerid + "];";
            }
            else {
                var index = RadioShackOnlineAppraisalFormSave.indexOf(elementString);
                var subString = RadioShackOnlineAppraisalFormSave.substr(index);
                var finalString = subString.substr(0, subString.indexOf(";") + 1);

                RadioShackOnlineAppraisalFormSave = RadioShackOnlineAppraisalFormSave.replace(finalString, elementString + "[" + answerid + "];");
            }
            $(questionid).value = answerid;
        }

        e = $(element).up().childElements();

        for (var i in e) 
        {
            if (e[i].title == "ButtonSelected") 
            {
                e[i].title = "";
                RadioShackOnlineButtonOnMouseOut(e[i]);
            }
        }

        element.title = "ButtonSelected";
        element.previousSiblings()[0].style.backgroundImage = "url('/Content/images/radioshack/body/ButtonGreenLeft.gif')";
        element.setStyle({ backgroundColor: '#8dc63f' });
        element.nextSiblings()[0].style.backgroundImage = "url('/Content/images/radioshack/body/ButtonGreenRight.gif')";
	}
	
	//handle all scroll events
	if ("onmousewheel" in document)
	{
		document.onmousewheel = ScrollDetected;
	}
	if (window.addEventListener)
	{
		window.addEventListener("DOMMouseScroll", ScrollDetected, false);
		window.addEventListener("scroll", ScrollDetected, false);
		window.addEventListener("mousemove", ScrollDetected, true);
	}
	else if (document.addEventListener) // Opera 7+
	{
		document.addEventListener("scroll", ScrollDetected, false);
	}
	else if (document.all && document.compatMode && document.compatMode == "CSS1Compat")
	{
		if ("onscroll" in self)
		{	
			window.onscroll = ScrollDetected;
		}
	}
	
	function ScrollDetected()
	{
		if (theWindowOpen)
		{
			getPageDimensions();
			getScroll();
			
			var nTop = curPageY - curPageHeight;
			if(nTop < 0)
				nTop = 0;
				
			var nHeight = curPageHeight * 2;
			$('lightwindow_overlay').setStyle(
				{
					left: 0,
					top: nTop + 'px',
					width: curPageWidth + 'px',
					height: nHeight + 'px'
				});
			
		}
	}
	
	function getPageDimensions()
	{
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) 
		{
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} 
		else if (document.body.scrollHeight > document.body.offsetHeight)
		{
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} 
		else 
		{
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) 
		{
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} 
		else if (document.documentElement && document.documentElement.clientHeight) 
		{
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} 
		else if (document.body) 
		{
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	

		//if (yScroll < windowHeight)
		//{
			curPageHeight = windowHeight;
		//} 
		//else 
		//{
		//	curPageHeight = yScroll;
		//}

		//if (xScroll < windowWidth)
		//{
			curPageWidth = windowWidth;
		//} 
		//else 
		//{
		//	curPageWidth = xScroll;
		//}
	}
	
	function getScroll()
	{
		if ( typeof(window.pageYOffset) == 'number') 
		{
        	curPageX = window.pageXOffset;
        	curPageY = window.pageYOffset;
      	} 
      	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
      	{
	       	curPageX = document.body.scrollLeft;
        	curPageY = document.body.scrollTop;
		} 
		else if (document.documentElement) 
		{
        	curPageX = document.documentElement.scrollLeft;
        	curPageY = document.documentElement.scrollTop;
      	}
	}

	function ShowLightbox(link)
	{	
		if(!theWindowOpen)
		{
			theWindowOpen = true;
			
			if(!theWindow)
				theWindow = new lightwindow();
				
			theWindow.activateWindow(
			{
				href: link,
				title: '',
				type: 'page'
			});
			
			ScrollDetected();
		}
	}

	function ShowLightboxIframe(link)
	{
		if(!theWindowOpen)
		{
			theWindowOpen = true;	
		
			if(!theWindow)
				theWindow = new lightwindow();
				
			theWindow.activateWindow(
			{
				href: link,
				title: '',
				type: 'external'
			});	
			
			ScrollDetected();
		}
	}
	
	function SimplexityTradeWindow_ValidateAndSubmit(area)
	{
		//alert("HI");
		var valid = new Validation('form1', {onSubmit:false});
		var result = valid.validate();
		
		if(result == true)
		{
			//alert("good");
			
			//new Ajax.Updater('AppraisalValue', '/' + area + '/Cart/BeginAppraisal-UpdatePrice.rails', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)});
			
			//valid.reset();
			//$('AcceptButtonImage').show();
			
			new Ajax.Updater('AppraisalValue', '/' + area + '/Cart/BeginAppraisal-SimplexityTradeWindow_UpdatePrice.rails', {parameters:$('form1').serialize(),onComplete:function(){ new Effect.Appear('submitContainer');new Effect.Highlight('AppraisalValue'); setTimeout("$('AcceptButtonImage').focus()",1000)  } });

			
		}
		else
		{
			//alert("bad");
			//$('acceptButtonImage').hide();
			ResetTheElements();
		}
		
		return false;
}

    function ValidateAppraisalForm() {
        var valid = new Validation('form1', { onSubmit: false });
        var result = valid.validate();
        return result;
    }
	
	function ValidateAndSubmit(area) {
	    var result = ValidateAppraisalForm();
		
		if(result == true)
		{
		    new Ajax.Updater(
                'AppraisalValue', '/' + area + '/Cart/BeginAppraisal-UpdatePrice.rails',
                { parameters: $('form1').serialize(),
                    onComplete: function () {
                        if ($('ESN') != undefined) {
                            $('ESN').addClassName('required');
                            if ($('ESN').value != "") {
                                new Effect.Appear('submitContainer')
                            }
                        }
                        else {
                            new Effect.Appear('submitContainer')
                        };

                        if ($('GhostAcceptImage') != undefined) {
                            $('GhostAcceptImage').hide();
                        }
                        new Effect.Highlight('AppraisalValue'); setTimeout("$('AcceptButtonImage').focus()", 1000)
                        //                        //if($('AppraisalValue').value ==
                        //                        var amt = $('AppraisalValue').value.replace('$', '');
                        //                        var dAmt = parseFloat(amt);
                        //                        var arQrystring = window.location.search.parseQuery();
                        //                        if (dAmt > 200.00 && arQrystring[arQrystring.inxexOf('pcat')] == '9') {
                        //                            alert('HI');
                        //                            new Effect.Appear('tooMuchLaptop');
                        //                        }
                    }
                });
 
			retVal = true;
		}
		else
		{
		    ResetTheElements();
		    retVal = false;
		}
		
		return retVal;
    }

    function SubmitAppraisal(area) {
        var valid = ValidateAppraisalForm();

        if (valid == true) {
            document.appraisalForm.submit();
        }

        return false;
    }
	
	function ValidateShippingAndSubmit()
	{
		var valid = new Validation('form1', {useTitles : true});

	    
		var result = valid.validate();
		
		if(result == true)
		{
			$('form1').submit();
		}
		else
		{
			//$('AgreeToTermsText').className = 'validation-failed';
			
			 new Effect.Highlight('AgreeToTermsText', {duration:2.0});
			 new Effect.Highlight('AgreeToTermsText2', {duration:2.0});
			
			$('errors').update('Please Complete All Fields.');
			$('errors').className = 'visible';
			$('errors').addClassName('validation-failed');
		}
		
		return false;
	}	
	
	function ValidateWireFlyEmailAndSubmit()
	{
		var valid = new Validation('form1', {useTitles : true});

	    
		var result = valid.validate();
		
		if(result == true)
		{
			$('form1').submit();
		}
		else
		{
			//$('AgreeToTermsText').className = 'validation-failed';
			
			$('errors').update('Please Complete All Fields.');
			$('errors').className = 'visible';
			$('errors').addClassName('validation-failed');
		}
		
		return false;
	}	
	
	function ValidatePartnerAdditionAndSubmit(formid)
	{
		var valid = new Validation(formid, {useTitles : true});

	    
		var result = valid.validate();
		
		if(result == true)
		{
			$(formid).submit();
		}
		else
		{
			//$('AgreeToTermsText').className = 'validation-failed';
			
			//$('errors').update('Please Complete All Fields.');
			//$('errors').className = 'visible';
			//$('errors').addClassName('validation-failed');
		}
		
		return false;
	}	
	
	function ValidateDealerAdditionAndSubmit()
	{
		var valid = new Validation('form1', {useTitles : true});

	    
		var result = valid.validate();
		
		if(result == true)
		{
			$('form1').submit();
		}
		else
		{
			//$('AgreeToTermsText').className = 'validation-failed';
			
			//$('errors').update('Please Complete All Fields.');
			//$('errors').className = 'visible';
			//$('errors').addClassName('validation-failed');
		}
		
		return false;
	}	
	
	function getViewport(){
		var viewportwidth;
		var viewportheight;
		var ret = new Array();
	
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
		if (typeof window.innerWidth != 'undefined')
		{
			viewportwidth = window.innerWidth,
			viewportheight = window.innerHeight
		}
	
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
		else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
		{
			viewportwidth = document.documentElement.clientWidth,
			viewportheight = document.documentElement.clientHeight
		}
		
		// older versions of IE
		
		else
		{
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
		ret[0] = viewportwidth;
		ret[1] = viewportheight;
		return ret;
	}
		
	function ResetTheElements() {

	    if ($('GhostAcceptImage') != undefined) 
        {
            $('submitContainer').hide();
	        $('GhostAcceptImage').show();
	    }
        else
            new Effect.Fade('submitContainer', { duration: 0.4 });


		$('AppraisalValue').update('--');
		if ($('ESN') != undefined) {
		    $('ESN').removeClassName('required');
		}

		
		
		return false;
	}
	
	function ValidateComponentSets(el)
	{
		// Find and set the parents.
		var idOfSelectedItem = $F(el);
		var objectSelectedItem = $(idOfSelectedItem);
		var objectSelectedItemClassSplitArray = $A(objectSelectedItem.classNames())[0];
		var parentIdOfSelectedItem = objectSelectedItemClassSplitArray.split('-')[1];

		// Find all SELECT OPTION items with a VALUE of idOfSelectedItem and select it.
		//console.log($(parentIdOfSelectedItem));
		if($(parentIdOfSelectedItem) != null) {
			$(parentIdOfSelectedItem).selected = true;	
		}
		
		// Find and switch the set for children of set parent.  In the loop of each
		// SELECT element that has the parentSet-[id], find the other SELECT elements
		// with the same modelComponentTypeId-[componentTypeId] as the current.  Hide it,
		// and show the current.

		var childSets = $$('.parentSet-' + parentIdOfSelectedItem + '');
		//console.log(childSets);

		// Hide all of the SELECT elements with the same modelComponentTypeId-[]
		childSets.each(function(s) {
				// Get this SELECT elements current modelComponentTypeId
				var parent_classNamesArray = $A(s.classNames());
				var sibling_componentTypeName = parent_classNamesArray[0];
				//console.log(sibling_componentTypeName);

				// Find the modelComponentTypeId-[] siblings.
				var siblings = $$('.' + sibling_componentTypeName + '');
				//console.log(siblings);
				
				// Hide the siblings.
				siblings.each(function(c) {
						//console.log(c);
						c.hide();
					}
				);
				
				// Show the correct one, with .parentSet-[parentIdOfSelectedItem].
				var correctSet = $$('.parentSet-' + parentIdOfSelectedItem + '').each(function(i) {
						i.show();
					}
				);
				
				// Reset the selectedIndex on all HIDDEN siblings.
				siblings.each(function(c) {
						if(!$(c).visible())
						{
							$(c).selectedIndex = 0;
						}
					}
				);
			}
		);
		
		// Find and switch the set for children of selected item.  In the loop of each
		// SELECT element that has the parentSet-[id], find the other SELECT elements
		// with the same modelComponentTypeId-[componentTypeId] as the current.  Hide it,
		// and show the current.
		var childSets = $$('.parentSet-' + idOfSelectedItem + '');
		//console.log(childSets);

		// Hide all of the SELECT elements with the same modelComponentTypeId-[]
		childSets.each(function(s) {
				// Get this SELECT elements current modelComponentTypeId
				var parent_classNamesArray = $A(s.classNames());
				var sibling_componentTypeName = parent_classNamesArray[0];
				//console.log(sibling_componentTypeName);

				// Find the modelComponentTypeId-[] siblings.
				var siblings = $$('.' + sibling_componentTypeName + '');
				//console.log(siblings);
				
				// Hide the siblings.
				siblings.each(function(c) {
						//console.log(c);
						c.hide();
					}
				);
				
				// Show the correct one, with .parentSet-[parentIdOfSelectedItem].
				var correctSet = $$('.parentSet-' + idOfSelectedItem + '').each(function(i) {
						i.show();
					}
				);
				
				// Reset the selectedIndex on all HIDDEN siblings.
				siblings.each(function(c) {
						if(!$(c).visible())
						{
							$(c).selectedIndex = 0;
						}
					}
				);
			}
		);
	}
	
    function UpdateCondition(conditionId, area, idToUpdate, updateMessage) {
        $('ConditionStars').className = 'rating star_' + conditionId;
        $('Condition').value = conditionId;
        $('Condition_DisplayName').value = updateMessage;
        UpdateConditionDescription(idToUpdate, updateMessage);

        //new Effect.Fade('SubmitContainer',{duration:0.1});

        ValidateAndSubmit(area);

        //var t=setTimeout("$('AcceptButtonImage').focus()",1000);
        //$('AcceptButtonImage').AddClassName('visible');
    }
	
	function SimplexityTradeWindow_UpdateCondition(conditionId, area, idToUpdate, updateMessage)
	{
		$('ConditionStars').className = 'rating star_' + conditionId;
		$('Condition').value = conditionId;
		$('Condition_DisplayName').value = updateMessage;
		UpdateConditionDescription(idToUpdate, updateMessage);

		//new Effect.Fade('SubmitContainer',{duration:0.1});
		
		SimplexityTradeWindow_ValidateAndSubmit(area);
		
		//var t=setTimeout("$('AcceptButtonImage').focus()",1000);
		//$('AcceptButtonImage').AddClassName('visible');
	}
	
	function UpdateConditionDescription(theElementId, message)
	{
		//new Effect.Fade(theElementId,{duration:0.3});
		$(theElementId).update(message);
		//new Effect.Appear(theElementId,{duration:0.3});
	}
	
	function ResetSelectedDescription(theElementId)
	{
		UpdateConditionDescription(theElementId, $('Condition_DisplayName').value);
	}
	
	
	function ShowModelPopupNew(imagePath, modelName, width, height)
	{
		var day = new Date();
		var id = day.getTime();
		var ww = width;
		var wh = height + 125;
		var params = 'width=' + ww + ',height=' + wh + ',menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no';
		var msg = '<html><head><title>' + modelName + '</title></head><body style="margin: 0; padding: 0;"><div style="margin: 0; padding: 0;" align="center"><img style="margin: 0; padding: 0;" height="' + height + 'px" width="' + width + 'px" src="' + imagePath + '" alt="' + modelName + '" />\n' +
				  '<hr style="margin: 0; padding: 0;" width="100%" /><form><input style="margin: 0; padding: 0;" type="button" onClick="javascript:window.close()" value="Close Window"></form></div></body></html>\n';
		
		var win = window.open('', id, params);
		win.document.write(msg);
		win.document.close();
	}
	function ShowModelPopup(modelId, modelName, width, height)
	{
		var day = new Date();
		var id = day.getTime();
		var ww = width;
		var wh = height + 125;
		var params = 'width=' + ww + ',height=' + wh + ',menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no';
		var imgSrc = '/showModelThumb/Show.rails?modelId=' + modelId + '&h=' + height + '&w=' + width;
		var msg = '<html><head><title>' + modelName + '</title></head><body style="margin: 0; padding: 0;"><div style="margin: 0; padding: 0;" align="center"><img style="margin: 0; padding: 0;" src="' + imgSrc + '" alt="' + modelName + '" />\n' +
				  '<hr style="margin: 0; padding: 0;" width="100%" /><form><input style="margin: 0; padding: 0;" type="button" onClick="javascript:window.close()" value="Close Window"></form></div></body></html>\n';
		
		var win = window.open('', id, params);
		win.document.write(msg);
		win.document.close();
    }

    // This takes a date string that MIGHT have a two digit year
    // as the last two digits. If it does, this function replaces
    // the two digit year with what it *assumes* is the proper
    // four digit year.
    function CleanDate(strDate) {

        // Return the cleaned date.
        return (
		strDate.replace(

        // This regular expression will search for a slash
        // followed by EXACTLY two digits at the end of
        // this date string. The two digits are being
        // grouped together for future referencing.
			new RegExp("/(\\d{2})$", ""),

        // We are going to pass the match made by the
        // regular expression off to this function literal.
        // Our arguments are as follows:
        // $0 : The entire match found.
        // $1 : The first group within the match.
			function ($0, $1) {

			    // Check to see if our first group begins with
			    // a zero or a one. If so, replace with 20 else
			    // replace with 19.
			    if ($1.match(new RegExp("^[01]{1}", ""))) {

			        // Replace with 20.
			        return ("/20" + $1);

			    } else {

			        // Replace with 19.
			        return ("/19" + $1);

			    }

			}
			)
		);


}

function LNF_ValidateAndSubmit() {


        var valid = new Validation('form1', { onSubmit: false });
        var result = valid.validate();

        if (result == true) {
          //  if ($F("AppraisalMasterId").length > 0) {
         //      new Ajax.Updater('InvalidAppraisalMasterId', '/' + area + '/Cart/BeginAppraisal-LNF_CheckMasterAppraisalIdAction.rails', { parameters: $('form1').serialize(), onComplete: function () {  } });
         //  }

            document.forms["form1"].submit();
        }
        else {
            ResetTheElements();
        }

        return false;
    }

    function filterList() {
        var evalType = $("SelectedType");
        var text = evalType.options[evalType.selectedIndex].innerHTML;

        $("LnfList").removeClassName("visibleList").addClassName("hiddenList");
        $("RmaList").removeClassName("visibleList").addClassName("hiddenList");
        $("RmaComment").removeClassName("visibleList").addClassName("hiddenList");
        $("RmaAppraisalMasterId").removeClassName("visibleList").addClassName("hiddenList");
        $("CalculateButton").addClassName("hiddenList"); 

        $("AppraisalMasterId").removeClassName("validate-selection");
        $("SelectedLnfReason").removeClassName("validate-selection");
        $("SelectedRmaReason").removeClassName("validate-selection");

      if (text == "LNF") {
          $("LnfList").removeClassName("hiddenList").addClassName("visibleList");
          $("SelectedLnfReason").addClassName("validate-selection");
          $("CalculateButton").removeClassName("hiddenList"); 
        }

        if (text == "RMA") {
            $("RmaList").removeClassName("hiddenList").addClassName("visibleList");
            $("RmaAppraisalMasterId").removeClassName("hiddenList").addClassName("visibleList");
            $("RmaComment").removeClassName("hiddenList").addClassName("visibleList");
            $("SelectedRmaReason").addClassName("validate-selection");
            $("AppraisalMasterId").addClassName("validate-selection");
        }
      
    }

	function ShowTutorialPopup(url)
	{
		var day = new Date();
		var id = day.getTime();
		var params = 'width=775,height=715,menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no';
		window.open(url, id, params);
	}
	
	function renewSession()
	{
		$("renewSession").src = "/renewSession.aspx?par=" + Math.random();
		//alert("Session Is New Again!");
	}	

	function page_loaded(evt)
	{
	  //Event.observe('my_menu', 'mouseover', menus, false)
	  window.setInterval("renewSession()", 240000);
	}
	
	Event.observe(window, 'load', page_loaded, false);
	
	newimage0 = new Image();
	newimage0.src = "/Content/images/lightwindow/black-80.png";
	newimage1 = new Image();
	newimage1.src = "/Content/images/lightwindow/black.png";
	newimage2 = new Image();
	newimage2.src = "/Content/images/lightwindow/ajax-loading.gif";
	newimage3 = new Image();
	newimage3.src = "/Content/images/cexchange/star_rating/star-matrix2.jpg";
	newimage4 = new Image();
	newimage4.src = "/Content/images/cexchange/body/grdButtonAccept.gif";
	newimage5 = new Image();
	newimage5.src = "/Content/images/cexchange/body/grdButtonAccept_1.gif";
	newimage6 = new Image();
	newimage6.src = "/Content/images/cexchange/body/grdButtonCalc.gif";
	newimage7 = new Image();
	newimage7.src = "/Content/images/cexchange/body/grdButtonCalc_1.gif";

