﻿//Moved Script from Master Page to a Include file
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
win.window.focus();
}

function EmptySB(obj)
	{   
		var con=confirm("Do you really want to empty shopping basket")
		if (con==true)
		    window.location.replace =obj
		return false;
	}
function setCookie(NameOfCookie, value, expiredays) 
{
    var ExpireDate = new Date ();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    document.cookie = NameOfCookie + "=" + escape(value)  + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function clearText(obj)
{
  if (obj.value=='Put "multiple word" terms in quotes'){obj.value='';}
}
function checkKeyword(id)
{
	var txtKey = document.getElementById(id);

	if (txtKey.value=='Put "multiple word" terms in quotes' || txtKey.value == "")
	{
		alert("Please enter keyword(s) to search.");
		return false;
	}
	return true;
}


   function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}   function SaveToLightbox(trans_no,imgID)
{ 
    var strImageTitle = document.getElementById(imgID).title

    if ( strImageTitle.indexOf('already')>0)
    {
    alert("This image is in current LightBox already!")
    return;
    }

  	try
	{
		oXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			oXMLHTTP = null;
		}
	}
	
	// Creating object of XMLHTTP in different browsers
	if (!oXMLHTTP && typeof XMLHttpRequest != "undefined")
	{
		oXMLHTTP = new XMLHttpRequest();
	}
	
	//Error handler 
	oXMLHTTP.onreadystatechange =function(){
		if (oXMLHTTP.readyState==4){
		   if (oXMLHTTP.status==200) {
			document.getElementById(imgID).title = "image in Lightbox already"
			document.getElementById(imgID).src = "../media/lightbox full_search.jpg"
			//Increment Lightbox Count
			var lbl = document.getElementById("ctl00_lblLightboxImageCount");
			var iCartCount = parseInt(lbl.innerHTML,10)
			iCartCount = iCartCount+1 
			lbl.innerHTML = iCartCount}
		    else alert("There were problems adding the selected image to the LightBox. Please Try again later.") }
		}	
	
	//Make request to the SaveLightboxShoppingbasket.asp Page
	oXMLHTTP.open("POST", "../respages/SaveLightboxShoppingbasket.asp?trans_no="+ trans_no +"&Light=True", true)
    oXMLHTTP.send('');
}

function ADD_DeleteFromLightbox(trans_no,imgID,lblID)
{
   try
	{
		oXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			oXMLHTTP = null;
		}
	}
	
	// Creating object of XMLHTTP in different browsers
	if (!oXMLHTTP && typeof XMLHttpRequest != "undefined")
	{
		oXMLHTTP = new XMLHttpRequest();
	}
	
	oXMLHTTP.onreadystatechange =function(){
		if (oXMLHTTP.readyState==4)
		{
		   if (oXMLHTTP.status==200) 
		   {
		   		if (document.getElementById(imgID).title == "Add to Lightbox")
				{
				document.getElementById(imgID).title = "Remove Image from Lightbox"
				document.getElementById(imgID).src = "../media/lightbox remove.jpg"
				document.getElementById(lblID).title = "Remove Image from Lightbox"
				document.getElementById(lblID).src = "../media/removefromlightbox.gif"
				
				var lbl = document.getElementById("ctl00_lblLightboxImageCount");
				var iLightboxCount = parseInt(lbl.innerHTML,10)
				iLightboxCount = iLightboxCount+1 
				lbl.innerHTML = iLightboxCount
				
				}
				else	
				{
				document.getElementById(imgID).title = "Add to Lightbox"
				document.getElementById(imgID).src = "../media/lightbox.jpg"
				document.getElementById(lblID).title = "Add to Lightbox"
				document.getElementById(lblID).src = "../media/addtolightbox.gif"
				
				var lbl = document.getElementById("ctl00_lblLightboxImageCount");
				var iLightboxCount = parseInt(lbl.innerHTML,10)
				iLightboxCount = iLightboxCount-1 
				lbl.innerHTML = iLightboxCount
				}

			}
			else alert("There were problems performing this operation. Please Try again later.")
		 }
		}

	if (document.getElementById(imgID).title == "Add to Lightbox")
	{
		oXMLHTTP.open("POST", "SaveLightboxShoppingbasket.asp?trans_no="+ trans_no +"&Light=True", true)
	}
	else	
    {
      oXMLHTTP.open("POST", "SaveLightboxShoppingbasket.asp?trans_no="+ trans_no +"&DeleteLight=True", true)
    }
	
    oXMLHTTP.send('');
  }




/* Saves the image to the Shopping basket by Ajax Method */
function SaveToShoppingBasket(trans_no,imgID,calledfrom)
{
    var strImageTitle = document.getElementById(imgID).title
    if ( strImageTitle.indexOf('already')>0)
    {
    alert('This Image is in the shopping basket already')
    return;
    }

   try
	{
		oXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			oXMLHTTP = null;
		}
	}
	
	// Creating object of XMLHTTP in different browsers
	if (!oXMLHTTP && typeof XMLHttpRequest != "undefined")
	{
		oXMLHTTP = new XMLHttpRequest();
	}
	
	oXMLHTTP.onreadystatechange =function(){
		if (oXMLHTTP.readyState==4){
		   if (oXMLHTTP.status==200) {
			document.getElementById(imgID).title = "image in shopping basket already"
			if (calledfrom=="PreviewPage")
			    document.getElementById(imgID).src = "../media/basketfull.jpg"
			else
			    document.getElementById(imgID).src = "../media/basketfull.jpg"

			//Increment the value of Shopping basket Count
			var lbl = document.getElementById("ctl00_lblCartCount");
			var iCartCount = parseInt(lbl.innerHTML,10)
			iCartCount = iCartCount+1 
			lbl.innerHTML = iCartCount}
			else alert("There were problems adding the selected image to the shopping basket. Please Try again later.") }
		}
		
	oXMLHTTP.open("POST", "SaveLightboxShoppingbasket.asp?trans_no="+ trans_no +"&sb=True", true)
    oXMLHTTP.send('');
  }

   function SetScroll()
   {
    //TurnAutoCompleteOff();
    var PrevPage = document.referrer;
    
    if (PrevPage.indexOf("Preview.aspx",0) != -1)
        {
            var currPage = window.location.href;       
            if (currPage.indexOf("Search.aspx",0) !=-1)
            {
                var x = readCookie('xCoordHolder')
                var y = readCookie('yCoordHolder')
                document.getElementById("xCoordHolder").value = x
                document.getElementById("yCoordHolder").value = y
                if (x ==null)
                    x= 0;
                if (y==null)
                    y=0;
                window.scrollTo(x, y);
            }
        }
        return ;
   }
   function Scroll(x,y)
   {
      window.scrollTo(x, y);
   }
   
   function TurnAutoCompleteOff()
   {
    //document.forms[0].setAttribute("autocomplete", "off"); 
   }
   