﻿function CommandDialogShowStandard(title){
	document.getElementById('Advocar_DialogTitle').innerHTML = '&nbsp;' + title;
	document.getElementById('Advocar_DialogFrame').src = '../../Core/DialogMessage.aspx?Advocar_DialogTitle=' + escape(title);

	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialog';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogBackground';
	document.getElementById('Advocar_DialogFrame').className = 'Advocar_MessageDialogFrame';

	document.getElementById('Advocar_DialogBackground').style.width = '2000px'; //document.body.clientWidth;
	document.getElementById('Advocar_DialogBackground').style.height = '2000px'; //document.body.clientHeight;

	document.getElementById('Advocar_Dialog').style.left = eval((document.body.clientWidth - 500) / 2) + 'px';	
	document.getElementById('Advocar_Dialog').style.top = '100px';
	
	if (Page_IsInternetExplorer() == true){document.getElementById('Advocar_DialogBackground').style.filter = 'alpha(opacity=60);'}

	document.getElementById('Advocar_DialogTitleLine').style.display = 'block';
	document.getElementById('Advocar_DialogFooterLine').style.display = 'block';
	document.getElementById('Advocar_DialogFooter').style.display = 'block';
	
	CommandDialogDisable();	
}

function CommandDialogShowChat(destinationPage, cancelationPage){
    var isHttps;

	if (destinationPage == '' || destinationPage == undefined){destinationPage = document.getElementById('Advocar_RedirectTo').value;}
	if (cancelationPage == '' || cancelationPage == undefined){cancelationPage = document.getElementById('Advocar_PreviousPage').value;}
	
	if (document.URL.indexOf('https') != -1) {isHttps = 'yes';} else{isHttps = 'no';}		
	
	document.getElementById('Advocar_DialogTitle').innerHTML = '&nbsp;Chat With An Expert';
	document.getElementById('Advocar_DialogFrame').src = '../../Core/Help/Chat.aspx?DestinationPage=' + destinationPage + '&security=' + isHttps;

	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialog';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogBackground';
	document.getElementById('Advocar_DialogFrame').className = 'Advocar_MessageDialogFrame';

	document.getElementById('Advocar_DialogBackground').style.width = '2000px'; //document.body.clientWidth;
	document.getElementById('Advocar_DialogBackground').style.height = '2000px'; //document.body.clientHeight;
	
	document.getElementById('Advocar_Dialog').style.left = eval((document.body.clientWidth - 500) / 2) + 'px';	
	document.getElementById('Advocar_Dialog').style.top = '100px';
	
	if (Page_IsInternetExplorer() == true){document.getElementById('Advocar_DialogBackground').style.filter = 'alpha(opacity=60);';}
	document.getElementById('Advocar_DialogFrame').style.height = '460px';
	document.getElementById('Advocar_Dialog').style.height = '570px';		
	
	CommandDialogDisable();		

}

function CommandDialogShowLogin(destinationPage, cancelationPage){
	var isHttps;

	if (destinationPage == '' || destinationPage == undefined){destinationPage = document.getElementById('Advocar_RedirectTo').value;}
	if (cancelationPage == '' || cancelationPage == undefined){cancelationPage = document.getElementById('Advocar_PreviousPage').value;}
	
	if (document.URL.indexOf('https') != -1) {isHttps = 'yes';} else{isHttps = 'no';}		
	
	document.getElementById('Advocar_DialogTitle').innerHTML = '&nbsp;Member Login';
	document.getElementById('Advocar_DialogFrame').src = '../../Core/Member/Login.aspx?DestinationPage=' + destinationPage + '&security=' + isHttps;

	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialog';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogBackground';
	document.getElementById('Advocar_DialogFrame').className = 'Advocar_MessageDialogFrame';

	document.getElementById('Advocar_DialogBackground').style.width = '2000px'; //document.body.clientWidth;
	document.getElementById('Advocar_DialogBackground').style.height = '2000px'; //document.body.clientHeight;
	
	document.getElementById('Advocar_Dialog').style.left = eval((document.body.clientWidth - 500) / 2) + 'px';	
	document.getElementById('Advocar_Dialog').style.top = '100px';
	
	if (Page_IsInternetExplorer() == true){document.getElementById('Advocar_DialogBackground').style.filter = 'alpha(opacity=60);';}
	document.getElementById('Advocar_DialogFrame').style.height = '470px';
	document.getElementById('Advocar_Dialog').style.height = '580px';		
	
	CommandDialogDisable();		
}

function CommandDialogShowLogout(){
	var isHttps;
	
	if (document.URL.indexOf('https') != -1) {isHttps = 'yes';} else{isHttps = 'no';}		
	
	document.getElementById('Advocar_DialogTitle').innerHTML = '&nbsp;Log Out';
	document.getElementById('Advocar_DialogFrame').src = '../../Core/Member/Logout.aspx?DestinationPage=' + document.getElementById('Advocar_RedirectTo').value + '&security=' + isHttps;

	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialog';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogBackground';
	document.getElementById('Advocar_DialogFrame').className = 'Advocar_MessageDialogFrame';

	document.getElementById('Advocar_DialogBackground').style.width = '2000px'; //document.body.clientWidth;
	document.getElementById('Advocar_DialogBackground').style.height = '2000px'; //document.body.clientHeight;
	
	document.getElementById('Advocar_Dialog').style.left = eval((document.body.clientWidth - 500) / 2) + 'px';	
	document.getElementById('Advocar_Dialog').style.top = '100px';
	
	if (Page_IsInternetExplorer() == true){document.getElementById('Advocar_DialogBackground').style.filter = 'alpha(opacity=60);'}
	
	document.getElementById('Advocar_DialogFrame').style.height = '100px';
	document.getElementById('Advocar_Dialog').style.height = '200px';
	
	CommandDialogDisable();
}

function CommandDialogShowPaymentCalculator(){	
	document.getElementById('Advocar_DialogTitle').innerHTML = '&nbsp;Modify Payments';
	document.getElementById('Advocar_DialogFrame').src = '../../Core/PreOwned/PaymentPopup.aspx?DestinationPage=' + document.getElementById('Advocar_RedirectTo').value;

	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialog';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogBackground';
	document.getElementById('Advocar_DialogFrame').className = 'Advocar_MessageDialogFrame';

	document.getElementById('Advocar_DialogBackground').style.width = '2000px'; //document.body.clientWidth;
	document.getElementById('Advocar_DialogBackground').style.height = '2000px'; //document.body.clientHeight;
	
	document.getElementById('Advocar_Dialog').style.left = eval((document.body.clientWidth - 500) / 2) + 'px';	
	document.getElementById('Advocar_Dialog').style.top = '100px';
	
	if (Page_IsInternetExplorer() == true){document.getElementById('Advocar_DialogBackground').style.filter = 'alpha(opacity=60);'}
	
	document.getElementById('Advocar_DialogFrame').style.height = '415px';
	document.getElementById('Advocar_Dialog').style.height = '515px';
	
	CommandDialogDisable();
}

function CommandDialogShowPaymentCalculatorNew(){	
	document.getElementById('Advocar_DialogTitle').innerHTML = '&nbsp;Modify Payments';
	document.getElementById('Advocar_DialogFrame').src = '../../Core/NewCar/PaymentPopup.aspx?DestinationPage=' + document.getElementById('Advocar_RedirectTo').value;

	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialog';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogBackground';
	document.getElementById('Advocar_DialogFrame').className = 'Advocar_MessageDialogFrame';

	document.getElementById('Advocar_DialogBackground').style.width = '2000px'; //document.body.clientWidth;
	document.getElementById('Advocar_DialogBackground').style.height = '2000px'; //document.body.clientHeight;
	
	document.getElementById('Advocar_Dialog').style.left = eval((document.body.clientWidth - 500) / 2) + 'px';	
	document.getElementById('Advocar_Dialog').style.top = '10px';
	
	if (Page_IsInternetExplorer() == true){document.getElementById('Advocar_DialogBackground').style.filter = 'alpha(opacity=60);'}
	
	document.getElementById('Advocar_DialogFrame').style.height = '530px';
	document.getElementById('Advocar_Dialog').style.height = '630px';
	
	CommandDialogDisable();
}


function CommandDialogClose(){
	document.getElementById('Advocar_Dialog').className = 'Advocar_MessageDialogHide';
	document.getElementById('Advocar_DialogBackground').className = 'Advocar_MessageDialogHide';
	document.getElementById('Advocar_DialogFrame').src = '';
		
	if (document.body.id == 'SellTrade_SellOnline'){
		var destinationPage = document.getElementById('Advocar_RedirectTo').value;
		var cancelationPage = document.getElementById('Advocar_PreviousPage').value;
		if (cancelationPage == ''){cancelationPage = destinationPage;}

		document.form.Advocar_PreviousPage.value = cancelationPage;
		document.form.action = cancelationPage;
		document.form.target = '_self';
		document.form.submit();					
	}	
	CommandDialogEnable();
}

 function CommandDialogDisable(){
	for (var index = 0; document.forms[0].elements.length > index; index++){		
		if (document.forms[0].elements[index].type == 'select-one'){		
			document.forms[0].elements[index].style.display = "none";			
		}
		
		if (document.forms[0].elements[index].id.indexOf('flash') > -1){				    
			document.forms[0].elements[index].style.display = "none";			
		}					
	}
 }
 
 function CommandDialogEnable(){
	for (var index = 0; document.forms[0].elements.length > index; index++){
		if (document.forms[0].elements[index].type == 'select-one'){
			document.forms[0].elements[index].style.display = "block";
		}		
		if (document.forms[0].elements[index].id.indexOf('flash') > -1){		
			document.forms[0].elements[index].style.display = "block";			
		}
	}
 }
 
 
 /*New Dialog functions*/
function Advocar_Dialog_DisableElements(){
	   for (var index = 0; document.forms[0].elements.length > index; index++){
			  if (document.forms[0].elements[index].type == 'select-one'){  
					 document.forms[0].elements[index].style.display = "none";
			  }
	   }
}	 

function Advocar_Dialog_EnableElements(){
	   for (var index = 0; document.forms[0].elements.length > index; index++){
			  if (document.forms[0].elements[index].type == 'select-one'){
					 document.forms[0].elements[index].style.display = "block";
			  }
	   }
}			

function Advocar_Dialog_RecalcHeightWidth(){
	var object = document.getElementById('Advocar_Dialog_Background');
	
	object.style.height = Advocar_Dialog_GetDocumentHeight() + "px";
	object.style.width = Advocar_Dialog_GetDocumentWidth() + "px";
	object = document.getElementById('Advocar_Dialog_Window');
	
	var left = (document.width ? document.width : document.body.offsetWidth);
	left = ((left - 600) / 2); if (left < 5){left = 5;}
	object.style.left = left + "px";	    

	var top = (Advocar_Dialog_GetScrollTop() + 10);
	object.style.top = top + "px";
}

function Advocar_Dialog_GetScrollTop(){
   var scrollTop = document.body.scrollTop;
   
   if (scrollTop == 0){
		  if (window.pageYOffset){
				 scrollTop = window.pageYOffset;
		  } else {
				 scrollTop = ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0);
		  }
   }
   return scrollTop;
} 

function Advocar_Dialog_GetDocumentHeight(){
	var height = 0, scrollHeight, offsetHeight, docHeight, clientHeight;	    

	if (document.height){height = document.height;}
	   if (document.body){
		if (document.body.scrollHeight){scrollHeight = document.body.scrollHeight;}
		if (document.body.offsetHeight){offsetHeight = document.body.offsetHeight;}
		if (scrollHeight && offsetHeight){height = Math.max(scrollHeight, offsetHeight);}
	}  

	if (document.documentElement.scrollHeight){docHeight = document.documentElement.scrollHeight;}
	if (docHeight){height = Math.max(height, docHeight);}
	   if (document.documentElement.clientHeight){clientHeight = document.documentElement.clientHeight;}
	   if (clientHeight){height = Math.max(height, clientHeight);}

	   return height;
}	 

function Advocar_Dialog_GetDocumentWidth(){
	var width = 0, scrollWidth, offsetWidth;	     
    
    if (document.width){
	    width = document.width;
    } else if (document.body){
	    if (document.body.scrollWidth){width = scrollWidth = document.body.scrollWidth;}
		      if (document.body.offsetWidth){width = offsetWidth = document.body.offsetWidth;}
		      if (scrollWidth && offsetWidth){width = Math.max(scrollWidth, offsetWidth);}
    }	
    
	return width;
}	 