function RedirectParentAndClose(url)
{
	opener.location=url;
	self.close();
}

function RedirectParentAndCloseWL(url, qs)
{
	window.opener.location.href= (url + "?skupeURL=" + escape(qs));
	self.close();
}

//Called by the searchsort
function SubmitFeedback()
{
	if(ValidateFeedback())
	{
		document.searchForm.action = "http://transaction.skupe.net/feedback.do";
		document.searchForm.method.value = "add";
		document.searchForm.submit();
	}
}

var feedbackHTML = "";
function ShowHideFeedback()
{
	var elem1 = document.getElementById("feedbackimg");
	var elem2 = document.getElementById("feedbacklink");
	var elem3 = document.getElementById("complainsection");

	if(feedbackHTML=="")
	{
		feedbackHTML = elem3.innerHTML;
		elem3.innerHTML = "";
		elem2.className = "skupe_link";
		elem1.src="http://ads.skupe.net/images/list_icon.gif";
		elem2.blur();
	}
	else
	{
		elem2.className = "activelink";
		elem1.src="http://ads.skupe.net/images/list_icon_d.gif";
		elem3.innerHTML = feedbackHTML;
		feedbackHTML = "";
		document.searchForm.feedback.focus();
		//window.scroll(0,9999);
	}
}

//Called by the searchsort
function SubmitEmailAFriend()
{
	if(ValidateEmailAFriend())
	{
		document.searchForm.action = "http://transaction.skupe.net/emailafriend.do";
		document.searchForm.method.value = "add";
		document.searchForm.submit();
	}
}

var emailafriendHTML = "";
function ShowHideEmailAFriend()
{
	var elem1 = document.getElementById("emailafriendimg");
	var elem2 = document.getElementById("emailafriendlink");
	var elem3 = document.getElementById("emailafriendsection");

	if(emailafriendHTML=="")
	{
		emailafriendHTML = elem3.innerHTML;
		elem3.innerHTML = "";
		elem2.className = "skupe_link";
		elem1.src="http://ads.skupe.net/images/list_icon.gif";
		elem2.blur();
	}
	else
	{
		elem2.className = "activelink";
		elem1.src="http://ads.skupe.net/images/list_icon_d.gif";
		elem3.innerHTML = emailafriendHTML;
		emailafriendHTML = "";
		document.searchForm.senderName.focus();
		//window.scroll(0,9999);
	}
}

function ValidateFeedback()
{
  var sError;
  sError = "";

  if(document.searchForm.feedback.value==null||document.searchForm.feedback.value.length==0)
  {
    sError += "Please enter your report details\n";
  }

  if(sError.length==0)
  {
    return true;
  }
  else
  {
    alert(sError);
    return false;
  }
}

function ValidateEmailAFriend()
{
  var sError;
  sError = "";

  if(document.searchForm.senderName.value==null||document.searchForm.senderName.value.length==0)
  {
    sError += "Please enter your name\n";
  }

  if(document.searchForm.senderEmail.value==null||document.searchForm.senderEmail.value.length==0 || !echeck(document.searchForm.senderEmail.value))
  {
    sError += "Please enter your email address\n";
  }

  if(document.searchForm.friendEmail.value==null||document.searchForm.friendEmail.value.length==0 || !echeck(document.searchForm.friendEmail.value))
  {
    sError += "Please enter your friend's email\n";
  }

  if(sError.length==0)
  {
    return true;
  }
  else
  {
    alert(sError);
    return false;
  }
}

function ChangeImage(pNewSource, pHeight, pWidth, pPubId)
{
	var mainImg = document.getElementById("mainImg");
	var daImage = new Image();
	daImage.src = "http://images.skupe.net/getImage?URL='" + pNewSource + "'&height=" + pHeight + "&width=" + pWidth + "&pubid=" + pPubId;
	if(daImage.height>30)
	{
		mainImg.style.height = daImage.height;
		mainImg.style.width = daImage.width;
	}

	mainImg.innerHTML = "<img id=\"daImg\" src=\"http://images.skupe.net/getImage?URL='" + pNewSource + "'&height=" + pHeight + "&width=" + pWidth + "&pubid=" + pPubId + "\" border=\"1\">";
}

function ChangeMap(pLat, pLong, pHeight, pWidth)
{
	var mainImg = document.getElementById("mainImg");
	mainImg.style.height = pHeight + "px";
	mainImg.style.width = pWidth + "px";
	mainImg.innerHTML = "";
	
    var map = new GMap(mainImg);

    map.clearOverlays();
    var point = new GPoint(pLong, pLat);    
    map.addControl(new GSmallMapControl());
    map.centerAndZoom(point, 11);
	var marker = new GMarker(point);
	map.addOverlay(marker);
	
	var b=window;
	var e=null;
	
	if(b.myLat!=e && b.myLong!=e)
	{
		var myIcon = new GIcon();
        myIcon.image = "/images/home_icon.png";
		myIcon.iconSize = new GSize(10, 10);
		myIcon.iconAnchor = new GPoint(5, 5);
		var myPoint = new GLatLng(b.myLat, b.myLong);    
        map.addOverlay(new GMarker(myPoint, myIcon));
	}
}

function ChangeImageRefresh(pNewSource, pHeight, pWidth, pPubId)
{
	var imageUrl = "http://images.skupe.net/getImage?URL='" + pNewSource + "'&height=" + pHeight + "&width=" + pWidth + "&pubid=" + pPubId;
	var url = document.location.href;
	if(url.indexOf("&imgurl")>0) url = url.substring(0, url.indexOf("&imgurl"));
	if(url.indexOf("&maplat")>0) url = url.substring(0, url.indexOf("&maplat"));
	url += "&imgurl=" + escape(imageUrl);
	document.location.href = url;
}

function ChangeMapRefresh(pLat, pLong)
{
	var url = document.location.href;
	if(url.indexOf("&imgurl")>0) url = url.substring(0, url.indexOf("&imgurl"));
	if(url.indexOf("&maplat")>0) url = url.substring(0, url.indexOf("&maplat"));
	url += "&maplat=" + escape(pLat) + "&maplong=" + escape(pLong);
	document.location.href = url;
}
