/**********************************************************************************************************
* Javascript Functions For Rick Damelian
*
*
*File Create By: CustomerCommunity
*File Create On: 11/Dec/07
*
************************************************************************************************************/

/****************************************************************************
* This Toggle function is used for toggling between elements.
* The only 1 element will be visible and others are hidden
* For Example: Toggle("group1", 1) ; group1 will be visible
*															   group2 will be hidden
*						  Toggle("group2", 2) ; group1 will be hidden
*															   group2 will be visible
* The length of group must be initialized, by using
* groupTotals.[group] = [length]
*****************************************************************************/
function toggle( group, index )
{
	var list = [];
	var i = groupTotals[group]; // get length of group
	while( i > 0 )
	{
		var o = document.getElementById( group + i ); // get element in the group
		if( i == index ) // check index
		{
			o.className = "visible"; // show
		}
		else
		{
			o.className = "hidden"; // hide other
		}
		i --;
	}
}
/*****************************************************************
* This Toggle function will only be used for toggling 
* Feature and specifications by ajax loading.
* The group length and group name are gotten from 
* a hidden input generated by ASP.
******************************************************************/
function toggleFeatureSpec(group, index)
{
	var list = [];	
	var length = document.getElementById(group).value;	// get the value of that hidden input
	var groupTotals = [];
	groupTotals.featureGroup = length;	

    var i = length;
	while( i > 0 )
	{
		var o = document.getElementById( group + i ); // get element in that group
		if( i == index )
		{
			o.className = "visible"; // show 
		}
		else
		{
			o.className = "hidden"; // hide others
		}
		i --;
	}
}

/*****************************************************************
* This function is used for switch between Image, Top5,
* Enquire Form and Contact Detail.
* Only one of four element will be visible
******************************************************************/
function switch1(div)
{
	if (document.getElementById('one')) //check if get first element
	{
		var option=['one','two','three','four']; 
		for(var i=0; i<option.length; i++)
		{ 
			obj=document.getElementById(option[i]); // get element one by one
			obj.style.display=(option[i]==div)? "block" : "none";  // only current one display, hide others
		}
	}
}

/*****************************************************************
*Function is used to show hidden div
******************************************************************/
function showDiv(divID)
{
	document.getElementById(divID).className = "visible";
}

/*****************************************************************
* Function is used for show or hide div depend on 
* check box is checked or not
******************************************************************/
function checkShowDiv(checkBoxID, divID)
{
	var checkbox = document.getElementById(checkBoxID); // get checkbox

	if (checkbox.checked==true) // checked
	{
		document.getElementById(divID).className = "visible"; // div show
	}
	if (checkbox.checked == false) // not checked
	{
		document.getElementById(divID).className = "hidden"; // div hide
	}
}

/*****************************************************************
* Function is used to show or hide image navigation link
* for derivative image
* type = "s", show the link
* type = other, hide the link
******************************************************************/
function showHideImageNav(type)
{
	var imageNavLink = document.getElementById("ImageNavLink") // get link 
	if (type=="s") // check type
	{
		imageNavLink.className="visible"; // show
	}
	else
	{
		imageNavLink.className="hidden"; // hide
	}
}

/*****************************************************************
* This Function is used to call ajax loading 
* Derivative Navigation Menu
******************************************************************/
function showDerivative(ModelID)
{
	if (document.getElementById("derivativeContent")) // check existance of div where load the content to
	{
		ajax_loadContent('derivativeContent','admin/getDerivativeContent.asp?Model_ID=' + ModelID,''); //loading
	}
}

/*****************************************************************
* This Function is used to load the feature, specification 
* or Overview by calling ajax
* Type could be "F", "S" or other
******************************************************************/
function showFeatureSpecs(Derivative_ID, type)
{	
	if (document.getElementById("Feature_Spec")) // check existance of place where load the content to
	{	
		if (type=="F") // "Feature"
		{
			ajax_loadContent('Feature_Spec', 'admin/getFeatureSpecs.asp?Derivative_ID=' + Derivative_ID + "&Type=" + type,'');	
		}
		else if (type=="S") // "Specification"
		{
			ajax_loadContent('Feature_Spec', 'admin/getFeatureSpecs.asp?Derivative_ID=' + Derivative_ID+"&Type=" + type,'');
		}
		else // "Overview"
		{
			ajax_loadContent('Feature_Spec','admin/getOverview.asp?Derivative_ID=' + Derivative_ID,'');
		}
		
	}
}

/*****************************************************************
* This Function is used to load the top navigation menu
* of feature, specification and overview
******************************************************************/
function showFeatureSpecHeader(Derivative_ID)
{
	if (document.getElementById("FeatureSpecs")) // check existance of place where loading content to
	{
		ajax_loadContent('FeatureSpecs', 'admin/getFeatureSpecsHeader.asp?Derivative_ID=' + Derivative_ID, '')
	}
}

/*****************************************************************
* This Function is used to load the Derivative Details
* by calling ajax
******************************************************************/
function showDerivativeDetail(Derivative_ID)
{
	if(document.getElementById("derivativeDetail")) // check existance of place where loading content to
	{
		ajax_loadContent('derivativeDetail','admin/getDerivativeDetail.asp?derivative_id=' + Derivative_ID,'');
	}
}

/********************************************************************
* This Function is used for toggling the image of derivative
*********************************************************************/
function ToggleDerivativeImage(imgID, imageSource)
{
	if (document.getElementById(imgID)) // check existance of image
	{
		document.getElementById(imgID).src = imageSource; // change image to input one
	}
}


/**********************************************************************
* This function has been used on default.asp
* Generated by Dreamweaver automatically
************************************************************************/
function MM_preloadImages() //v3.0
{ 
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{ 
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}
/**********************************************************************
* This function has been used on default.asp
* Generated by Dreamweaver automatically
************************************************************************/
function MM_swapImgRestore()  //v3.0
{
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
	  x.src=x.oSrc;
}

/**********************************************************************
* This function has been used on default.asp
* Generated by Dreamweaver automatically
************************************************************************/
function MM_findObj(n, d) //v4.01
{ 
	var p,i,x;  
	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}
/**********************************************************************
* This function has been used on default.asp
* Generated by Dreamweaver automatically
************************************************************************/
function MM_swapImage()  //v3.0
{
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null)
	{
		document.MM_sr[j++]=x; 
		if(!x.oSrc) 
			x.oSrc=x.src; 
		x.src=a[i+2];
	}
}
/**********************************************************************
* This function is used to toggle the link, 
* if link is clicked underline disappear
************************************************************************/
function toggleLink(group,v)
{ 
	if (v==1) // check input
	{
		document.getElementById(group+1).className = "none"; // non-underline
		document.getElementById(group+2).className="underline"; // underline
	}
	if (v==2) // check input
	{
		document.getElementById(group+2).className = "none"; // non-underline
		document.getElementById(group+1).className="underline"; // underline
	}
}
/**********************************************************************
* This function has been used on default.asp
* Generated by Dreamweaver automatically
************************************************************************/
function handlePageLoad( )
{
	document.getElementById("pageCaption").innerHTML = document.getElementById("pageCaption_default").innerHTML;
	setTimeout("togglePrestigeMenu(true, 3000)",3000);
}

/**********************************************************************
* This Function is used to toggle prestige menu
************************************************************************/
function togglePrestigeMenu(showHide, timeToLive)
{
	if (showHide) // validate first parameter
	{
		ypSlideOutMenu.showMenu('PrestigeMenu'); // show menu
		if(timeToLive) 
			t = setTimeout("togglePrestigeMenu(false)",3000); //hide menu after 3 seconds
	}
	else
	{
		ypSlideOutMenu.hideMenu('PrestigeMenu'); //hide menu
	}
}
/***********************************************************
* Function used to combine campaign codes from Enquire form
***********************************************************/

function combine(){
  if (document.getElementById("chk1").checked == 1) 
  	if (document.getElementById("chk2").checked ==1)
    	document.getElementById("campaign_code").value = "Test drive and Finance";
	else
		document.getElementById("campaign_code").value = "Test drive";
  else if (document.getElementById("chk2").checked == 1)
  	if (document.getElementById("chk1").checked == 1)
    	document.getElementById("campaign_code").value = "Test drive and Finance";
	else 
		document.getElementById("campaign_code").value = "Finance";
  else 
  		document.getElementById("campaign_code").value = "None";
}

/**********************************************************************
* Function used to change the Tab style on Honda page Feature
* and specification.
***************************************************************************/
function SelectedTab(TabId)
{
	if (TabId == "OverviewTab")
	{
		document.getElementById("OverviewTab").className = "current";  //set as selected
		document.getElementById("FeaturesTab").className="NotSelected"; 
		document.getElementById("SpecificationTab").className="NotSelected";
		
	}
	if (TabId == "FeaturesTab")
	{
		document.getElementById("OverviewTab").className = "NotSelected";
		document.getElementById("FeaturesTab").className="current"; //set as selected
		document.getElementById("SpecificationTab").className="NotSelected";
	}
	if (TabId == "SpecificationTab")
	{
		document.getElementById("OverviewTab").className = "NotSelected";
		document.getElementById("FeaturesTab").className="NotSelected";
		document.getElementById("SpecificationTab").className="current"; //set as selected
	}
}

/*****************************************************************
* This Function is used to load the accessory for model
******************************************************************/
function showModelAccessory(Model_ID)
{
	if (document.getElementById("AccessoryTable")) // check existance of place where loading content to
	{
		//alert(Model_ID);
		ajax_loadContent('AccessoryTable', 'admin/getModelAccessories.asp?Model_ID=' + Model_ID, '');
		
	}
}

/******************************************************************************
* This Function is used to load the form from file
********************************************************************************/
function showFormFromFile(FormName)
{
	if(document.getElementById("AccessoryTable"))
	{
		ajax_loadContent('AccessoryTable', 'admin/GetFormFromFile.asp?FormName=' + FormName, '');
	}
}

function showEnquireFormFromFile(DerivativeID)
{
	if(document.getElementById("three"))
	{
		ajax_loadContent('three', 'admin/GetEnquireFormFromFile.asp?DerivativeID=' + DerivativeID, '');
	}
}

/***************************************************************************
* This function is used for home page search
****************************************************************************/
function submitSearch()
{
	var returnvalue;
	var Marques = document.getElementById("Marques").value;
	var ListPrice = document.getElementById("listPrice").value;

	var UsedQueryString = (document.getElementById("SearchUsed").checked)?"&s_Used=1":"";
	var DemoQueryString = (document.getElementById("SearchDemo").checked)?"&s_Demo=1":"";

	if (UsedQueryString + DemoQueryString == "")
	{
		alert("Please select at least one Vehicle Type.");
		returnvalue = false;
	}
	else
	{
		//document.getElementById("HomePageVehicleSearch").action = "VehiclesSearch.asp?active_page_id=999&s_Marque="+MarqueID+"&s_Model="+ModelName+"&ListPrice=" +ListPrice+NewQueryString + UsedQueryString + DemoQueryString;
		//window.open ("rickdameliangeneral.asp?active_page_id=999&Marque_Name="+Marques, "","status=1,toolbar=1, scrollbars=1,resizable=1, location=1, menubar=1"); 
		document.SearchVehicle.action = "RickDamelianGeneral.asp?active_page_id=999&Marque_Name="+Marques + "&listprice=" +ListPrice+ UsedQueryString + DemoQueryString;
		returnvalue = true;
	}

	return returnvalue;
}

/******************************************************************************
* Rick Cafe Functions *****************************************************
*******************************************************************************/

/******************************************************************************
* Function to get menu content
*******************************************************************************/
function ShowMenuContent(MenuTypeID)
{
	if(document.getElementById("MenuContent"))
	{
		ajax_loadContent('MenuContent', 'admin/GetCafeMenuContent.asp?MenuTypeID=' + MenuTypeID, '');
	}
}

/******************************************************************************
*function to rollover the category image
*******************************************************************************/
function ShowMenuCategoryImage(MenuCategoryID)
{
	if(document.getElementById("MenuCategoryImage"))
	{
		ajax_loadContent('MenuCategoryImage', 'admin/GetMenuCategoryImage.asp?MenuCategoryid=' + MenuCategoryID, '');
	}
}

function ShowMenuItem(MenuCategoryID)
{
	if(document.getElementById("MenuDetail"))
	{
		ajax_loadContent('MenuDetail', 'admin/GetCafeMenuItem.asp?MenuCategoryid=' + MenuCategoryID, '');
	}
}

function ShowMenuItemImage(MenuItemID)
{
	if(document.getElementById("MenuCategoryImage"))
	{
		ajax_loadContent('MenuCategoryImage', 'admin/GetMenuItemImage.asp?MenuItemID=' + MenuItemID, '');
		
	}
}

function SaveContact()
{
	if(document.getElementById("AccessoryTable"))
	{
		if(document.getElementById("ContactUs"))
		{
			document.getElementById("ContactUs").innerHTML = "";
			//alert (document.getElementById("ContactUs").innerHTML)
			document.getElementById("ContactUs").innerHTML = document.getElementById("AccessoryTable").innerHTML;
			//alert (document.getElementById("ContactUs").innerHTML)
		}
	}
}

function LoadContact()
{
	if(document.getElementById("AccessoryTable"))
	{
		if(document.getElementById("ContactUs"))
		{
			document.getElementById("AccessoryTable").innerHTML = ""
			document.getElementById("AccessoryTable").innerHTML = document.getElementById("ContactUs").innerHTML;
		}
	}
}
/************************************************************************************************************************
* functions for used honda
***********************************************************************************************************************/
function showUsedSearch()
{
	var UsedSearchHTML
	UsedSearchHTML = '<table cellspacing="0" cellpadding="0" width="100%" border="0">'
	UsedSearchHTML = UsedSearchHTML + '<tr>'
	UsedSearchHTML = UsedSearchHTML + '<td height="20">'
	UsedSearchHTML = UsedSearchHTML + '<img height="1" src="images/1/spacer.gif" width="1" />'
	UsedSearchHTML = UsedSearchHTML + '</td>'
	UsedSearchHTML = UsedSearchHTML + '</tr>'
	UsedSearchHTML = UsedSearchHTML + '<tr>'
	UsedSearchHTML = UsedSearchHTML + '<td>'
	UsedSearchHTML = UsedSearchHTML + '<iframe id="vehicles" style="HEIGHT: 600px" name="vehicles" src="admin/Vehicles_list.asp?s_marqueid=39" frameborder="0" width="100%" scrolling="no" allowTransparency>'
	UsedSearchHTML = UsedSearchHTML + '</iframe>'
	UsedSearchHTML = UsedSearchHTML + '</td>'
	UsedSearchHTML = UsedSearchHTML + '</tr>'
	UsedSearchHTML = UsedSearchHTML + '</table>'

	if (document.getElementById("UsedSearch"))
	{
		document.getElementById("UsedSearch").innerHTML = UsedSearchHTML;
	}

}

function showLocation(Page_ID)
{
	if(document.getElementById("AccessoryTable"))
	{
		ajax_loadContent('AccessoryTable', 'admin/ShowLocation.asp?page_id=' + Page_ID, '');
	}
}

function GetFullArticle(Page_ID)
{
	if(document.getElementById("MenuContent"))
	{
		ajax_loadContent('MenuContent', 'admin/ShowLocation.asp?page_id=' + Page_ID, '');
	}
}

function GetLocation(MarqueID, LocationTypeID)
{
	if(document.getElementById("AccessoryTable"))
	{
		ajax_loadContent('AccessoryTable', 'admin/GetLocation.asp?MarqueID=' + MarqueID + '&LocationTypeID=' + LocationTypeID, '');
	}
}

function toggleHomePageContent(groupName, index)
{
	for(var i = 1; i<=10; i++)
	{
		if(document.getElementById(groupName + i) && document.getElementById(groupName + "Link" + i))
		{
			if (i == index)
			{
				document.getElementById(groupName + i).style.display = "";
				document.getElementById(groupName + "Link" + i).className = "none";
			}
			else
			{
				document.getElementById(groupName + i).style.display = "none";
				document.getElementById(groupName + "Link" + i).className = "underline";
			}
		}
	}
}

function RefreshCaptchaImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

/***************************************************************************
* This functions are used for new home page search
****************************************************************************/
function submitSearchNew()
{
	var returnvalue;

	var MarqueID = document.getElementById("s_MarqueID").value;
	var ModelName = document.getElementById("s_ModelName").value;
	var ListPrice = document.getElementById("listPrice").value;

	var NewQueryString = (document.getElementById("SearchNew").checked)?"&s_New=1":"";
	var UsedQueryString = (document.getElementById("SearchUsed").checked)?"&s_Used=1":"";
	var DemoQueryString = (document.getElementById("SearchDemo").checked)?"&s_Demo=1":"";

	if (NewQueryString + UsedQueryString + DemoQueryString == "")
	{
		alert("Please select at least one Vehicle Type.");
		returnvalue = false;
	}
	else
	{
		document.getElementById("HomePageVehicleSearch").action = "VehiclesSearch.asp?active_page_id=999&s_Marque="+MarqueID+"&s_Model="+ModelName+"&ListPrice=" +ListPrice+NewQueryString + UsedQueryString + DemoQueryString;
		returnvalue = true;
	}

	return returnvalue;
}

function changeModelFromMarque()
{
	var MarqueID = document.getElementById("s_MarqueID").value;
	ajax_loadContent('ModelsListBox','admin/getModelFromMarque.asp?s_MarqueID=' + MarqueID,'');
}

function submitHomePageServiceBookingForm()
{
	
	var returnvalue = true;
	var servicebookingform, firstname, lastname, email, manufacturer, verificationcode, unsubscribed, registration, preferredapptdatetime, validationerrormessage;
	servicebookingform = document.getElementById("HomePageServiceBookingForm");
	validationerrormessage = "Following validation errors occured:\n\n";
	
	var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;

	if (servicebookingform)
	{
		firstname = servicebookingform["FIRSTNAME"].value;
		lastname = servicebookingform["LASTNAME"].value;
		email = servicebookingform["EMAIL"].value;
		manufacturer = servicebookingform["MANUFACTURER"].value;
		verificationcode = servicebookingform["VerificationCode"].value;
		registration = servicebookingform["REGISTRATION"].value;
		preferredapptdatetime = servicebookingform["PREFERRED_APPT_DATETIME"].value;
		
		if(firstname.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "First name is required.\n";
				returnvalue = false;
		}

		if(lastname.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "Surname is required.\n";
				returnvalue = false;
		}

		if(email.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "Email is required.\n";
				returnvalue = false;
		}
		else
		{
			if(!emailfmt.test(email.replace(/^\s+|\s+$/g, '')))
			{
					validationerrormessage += "Email is invalid.\n";
					returnvalue = false;
			}
		}

		if(manufacturer.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "Manufacturer is required.\n";
				returnvalue = false;
		}

		if(registration.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "Registration is required.\n";
				returnvalue = false;
		}

		if(preferredapptdatetime.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "Preferred Appointment Date/Time is required.\n";
				returnvalue = false;
		}

		if(verificationcode.replace(/^\s+|\s+$/g, '')  == '')
		{
				validationerrormessage += "Verification code is required.\n";
				returnvalue = false;
		}			
	}
	
	if (!returnvalue)
	{
		alert(validationerrormessage);
	}
	else
	{
		// Change the unsubscribed
		servicebookingform["unsubscribed"].value = servicebookingform["unsubscribed"].checked?'1':'0';


		// All good, change the action based on manufacturer

		//	Prestige http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3614 prestserv@rickdamelian.com.au
		//	Honda http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3780 honserv@rickdamelian.com.au
		//	Suzuki http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3620 euroserv@rickdamelian.com.au
		//	Alfa Romeo http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3602 euroserv@rickdamelian.com.au
		//	Citroen http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3606 euroserv@rickdamelian.com.au
		//	Renault http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3615 euroserv@rickdamelian.com.au
		//	Fiat http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3612 euroserv@rickdamelian.com.au

		switch (manufacturer.toUpperCase())
		{
			case "PRESTIGE":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3614";
				servicebookingform["EmailTo"].value = "prestserv@rickdamelian.com.au"
				break;

			case "HONDA":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3780";
				servicebookingform["EmailTo"].value = "honserv@rickdamelian.com.au"
				break;

			case "SUZUKI":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3620";
				servicebookingform["EmailTo"].value = "euroserv@rickdamelian.com.au"
				break;

			case "ALFA ROMEO":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3602";
				servicebookingform["EmailTo"].value = "euroserv@rickdamelian.com.au"
				break;

			case "CITROEN":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3606";
				servicebookingform["EmailTo"].value = "euroserv@rickdamelian.com.au"
				break;

			case "RENAULT":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3615";
				servicebookingform["EmailTo"].value = "euroserv@rickdamelian.com.au"
				break;

			case "FIAT":
				
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3612";
				servicebookingform["EmailTo"].value = "euroserv@rickdamelian.com.au"
				break;
								
			default:
			  
				servicebookingform.action = "http://www.rickdamelian.com.au/forms/subscribe.asp?Template_id=3614";
				servicebookingform["EmailTo"].value = "prestserv@rickdamelian.com.au"
				break;

		}		

	}
	//return false;
	return returnvalue;
}