﻿

active_flag=false
var id=0
var price_id=0




function $(div){return document.getElementById(div)}
	
function refundRequest()
{
	refund_request=$('refund-request')
	refund_request.style.display='block'
	refund_request.onfocus=function(){id++;id==1?this.value='':''}
	
	refund_submit=$('refund-submit')
	refund_submit.style.display='inline'
	refund_submit.onclick=function()
	{
		if (!active_flag)
		{
			refund_iso=refund_request.value
			success=false
			
			if (refund_iso.length==22 && refund_iso.charAt(0)=='E' && refund_iso.charAt(1)==9 && refund_iso.charAt(2)=='-' && refund_iso.charAt(15)=='-')
			{
				check=refund_iso.split("-")
				
				if (!isNaN(check[1]) && !isNaN(check[2]))
				{
					success=true
				}
			}
			if(success)
			{
				active_flag=true
				$('throbber').style.display='inline'
				ajaxGet('refund-iso.php?iso='+refund_iso, 'refund')
			}
			else
			{
				alert('sorry, your order id is invalid')
			}
		}
	}
}

function priceMatch()
{
	price_match=$('price-match')
	price_match.style.display='block'
	price_match.onfocus=function(){price_id++;price_id==1?this.value='':''}
	
	price_submit=$('price-submit')
	price_submit.style.display='inline'
	price_submit.onclick=function()
	{
		if (!active_flag)
		{
			iso=price_match.value
			success=false
			
			if (iso.length==22 && iso.charAt(0)=='E' && iso.charAt(1)==9 && iso.charAt(2)=='-' && iso.charAt(15)=='-')
			{
				check=iso.split("-")
				
				if (!isNaN(check[1]) && !isNaN(check[2]))
				{
					success=true
				}
			}
			if(success)
			{
				active_flag=true
				$('price-throbber').style.display='inline'
				ajaxGet('lowest-price-guarantee.php?iso='+iso, 'price-match')
			}
			else
			{
				alert('sorry, your order id is invalid')
			}
		}
	}
}

function XHR(method)
{
	http_request=false
	if (window.XMLHttpRequest)
	{
		http_request=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		try {http_request=new ActiveXObject('Msxml2.XMLHTTP')}
		catch (e)
		{
			try {http_request=new ActiveXObject('Microsoft.XMLHTTP')}
			catch (e){}
		}
	}
	else return false
}

function ajaxGet(url, referrer)
{
	XHR('get')
	http_request.onreadystatechange=function() {loadPage(http_request, referrer)}
	http_request.open('GET', url, true)
	http_request.send(null)
}

function loadPage(http_request, referrer)
{
	if (http_request.readyState==4 && http_request.status==200)
	{
		referrer=='refund'?location.href="http://www.easy9001.com/pdf/MoneyBackGuarantee.pdf":location.href="http://www.easy9001.com/pdf/LowestPriceGuarantee.pdf"
	}
}

