﻿// JScript File
var g_retry = 0;
var g_sValidChars = "";
g_sValidChars = "0123456789";
var g_arOrder = new Array();
var DialogElement = null;
var x = null;
var y = null;



//update the cart
function Update(productid3, productname, productqty, productamount,productvariant,productsize,productadditionalinfo)
{
		var params = new Array();
		params[0] = productid3;
		params[1] = productname;
		params[2] = productqty;
		params[3] = productamount;
		params[4] = productvariant;
		params[5] = productsize;
		params[6] = productadditionalinfo;
		params[7] =	'Update';	

	callbMainCart.Callback( params );
}


//when the user entered his/her details
function btnSubmit_Click()
{
	var retVal = false;
	var required	= false;
	var regex		= false;
	

	required = ValidateRequired(g_sTextValidationList)
	
	
	if (required)
	{	
		required = ValidateRequiredDropDown(g_sDropDownDetailQuestionValidationList);
	}
	else
	{
		ValidateRequiredDropDown(g_sDropDownDetailQuestionValidationList);
	}
	
	if (required)
	{	
		//set regex
		var patern = /\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3}/;

		regex = ValidateRegex(g_sTextRegexValidationList, patern);
	}
	
	if (!required)
	{
		alert("One of more of the questions contain no or invalid answers. Please see the fileds highlighted in red.");
	}
	else if (required && !regex)
	{
		alert("Please enter a valid email adress")
	}
	else
	{
		retVal = true;
	}
	
	if (retVal == true)
	{
		SubmitEntry();
	}
}

//show cart
function ShowCart2()
{
	var params = new Array();
	params[0] = 'Back';
	callbCart.Callback( params );
	document.getElementById('FloatingCart').style.visibility = "visible";
}


//Hide the cart.
function HideCart2()
{
	document.getElementById('FloatingCart').style.visibility = "hidden";
}


//submit the entry
function SubmitEntry()
{
	var params = new Array();
	
	//LEAD DETAILS
	params[0] =	txtName2.value;
	params[1] =	txtSurname2.value;
	params[2] =	txtContact2.value;
	params[3] =	txtEmail2.value;
	params[4] =	document.getElementById('ddlGender').options[ document.getElementById('ddlGender').selectedIndex ].value;
	params[5] =	document.getElementById('ddlAge').options[ document.getElementById('ddlAge').selectedIndex ].value;
	params[6] =	document.getElementById('ddlHandicap').options[ document.getElementById('ddlHandicap').selectedIndex ].value;
	params[7] =	txtPostalCode2.value;
	
	doCallBack_SubmitEntry(params);
}


//when an error has occured
function CallbackError()
{
	if (g_retry < 3)
	{
		SubmitEntry();
		g_retry + 1;
		
	}
	else
	{
		alert('A problem has occured when placing your order');

	}
}


function ProductColorChange(ddl,ddl2)
{
	if(ddl.selectedIndex > 0)
	{
		ddl.style.backgroundColor = '#FFFFFF';
	}
	if(ddl.selectedIndex <= 0)
	{
		ddl.style.backgroundColor = '#FF0A0A';
	}
	if(ddl2.selectedIndex > 0)
	{
		ddl.style.backgroundColor = '#FFFFFF';
	}
	if(ddl.selectedIndex > 0)
	{
		ddl2.style.backgroundColor = '#FFFFFF';
	}
	if(ddl.selectedIndex <= 0 && ddl2.selectedIndex <= 0)
	{
		ddl.style.backgroundColor = '#FF0A0A';
		ddl2.style.backgroundColor = '#FF0A0A';
	}
}


//do the callback	
function doCallBack_SubmitEntry(params)
{
	callbSubmitEntry.Callback( params );
	mpNikon.setPageIndex(2);
}


//Validate the order
function ValidateOrder()
{
	var product1 = false;
	var product2 = false;
	

	
	if(document.getElementById('ddlProduct1Quantity').selectedIndex > 0 || document.getElementById('ddlProduct2Quantity').selectedIndex )
	{	
	
		if(document.getElementById('ddlProduct1Quantity').selectedIndex > 0)
		{
			g_arOrder[0] += 1 + ',' + 'Nikon 350G' + ',' + document.getElementById('ddlProduct1Quantity').value + ',' + 199 + ',' + 'N/A' + ',' + 'N/A' + ',' + 'N/A' + '|';
			product1 = true;
		}
		if(document.getElementById('ddlProduct1Quantity').selectedIndex <= 0)
		{
			if(document.getElementById('ddlProduct2Quantity').selectedIndex <= 0)
			{
				document.getElementById('ddlProduct1Quantity').style.backgroundColor = '#FF0A0A';
			}
			product1 = false;
		}
		if(document.getElementById('ddlProduct2Quantity').selectedIndex > 0)
		{
			g_arOrder[0] += 2 + ',' + 'Nikon 550AS' + ',' + document.getElementById('ddlProduct2Quantity').value + ',' + 299 + ',' + 'N/A' + ',' + 'N/A' + ',' + 'N/A' + '|';
			product2 = true;
		}
		if(document.getElementById('ddlProduct2Quantity').selectedIndex <= 0)
		{
			if(document.getElementById('ddlProduct1Quantity').selectedIndex <= 0)
			{
				document.getElementById('ddlProduct2Quantity').style.backgroundColor = '#FF0A0A';
			}
			product2 = false;
		}
		
		
		if(!product1 && !product2)
		{
			alert("One of more of the orders contain no or invalid products. Please see the fileds highlighted in red.");
		}
		
		if(product1 || product2)
		{
			
			//Add to cart
			AddToCart( g_arOrder);
			mpNikon.setPageIndex(1);
		}
	}
	else
	{
		alert("Please select at least one product. Please see the fileds highlighted in red.");
		document.getElementById('ddlProduct1Quantity').style.backgroundColor = '#FF0A0A';
		document.getElementById('ddlProduct2Quantity').style.backgroundColor = '#FF0A0A';
	}

}



function Calculate(ddl,span,price)
{
	var amount = 0;
	
	amount = ddl.value * price;
	span.innerHTML = Math.round(amount*100)/100;
	
}







function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}



function SetFloatingCart()
{
	JSFX_FloatDiv("FloatingCart", screen.availWidth-240,0).floatIt();
}



function DisplayExtraInfo(product)
{
	if(product == 'Product1')
	{
		document.getElementById('dlgDisplayImg').src = 'Images/350g_small.jpg';
		document.getElementById('spanProducDialogHeading').innerHTML = 'Nikon 350G';
		document.getElementById('spanProductDetails').innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt. Donec pharetra orci et quam convallis posuere. Nullam eget magna et lectus pharetra sagittis. Sed non arcu. Nunc elementum felis a ante. Nunc hendrerit hendrerit erat. Ut eleifend rhoncus lacus. Morbi vel sapien eu purus sollicitudin ullamcorper.';
		var test2 = (document.body.clientWidth) - (32 * document.body.clientWidth / 100) ;
		dlgProductImage.set_x(test2);
		var test = (document.body.clientHeight/2)- 160;
		//reset dialog position
		document.getElementById(DialogElement).style.top = document.body.scrollTop + test;
		
		dlgProductImage.Show();
	}
	if(product == 'Product2')
	{
		document.getElementById('dlgDisplayImg').src = 'Images/550as_small.jpg';
		document.getElementById('spanProducDialogHeading').innerHTML = 'Nikon 550AS';
		document.getElementById('spanProductDetails').innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt. Donec pharetra orci et quam convallis posuere. Nullam eget magna et lectus pharetra sagittis. Sed non arcu. Nunc elementum felis a ante. Nunc hendrerit hendrerit erat. Ut eleifend rhoncus lacus. Morbi vel sapien eu purus sollicitudin ullamcorper.';
		var test2 = (document.body.clientWidth) - (32 * document.body.clientWidth / 100);
		dlgProductImage.set_x(test2);
		var test = (document.body.clientHeight/2)- 160 ;
		//reset dialog position
		document.getElementById(DialogElement).style.top = document.body.scrollTop + test;
		dlgProductImage.Show();
	}
}




