/* Ultimater's edited version of:
   http://jibbering.com/2002/4/httprequest.html
   to serve IE7 with XMLHttpRequest instead of ActiveX */

var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 	try {
 		 xmlhttp = new XMLHttpRequest();
 	} catch (e) {
 		 xmlhttp=false;
 	}
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
if (!xmlhttp){
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
}
@end @*/

if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

/* Ultimater's edited version of:
   http://javascript.internet.com/ajax/ajax-navigation.html */

var please_wait = "";

function open_url(url, targetId) {
	if(!xmlhttp)return false;
    var e=document.getElementById(targetId);if(!e)return false;
    if(please_wait)e.innerHTML = please_wait;
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function() { response(url, e); }
    try{
      xmlhttp.send(null);
    }catch(l){
    while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
    e.appendChild(document.createTextNode("request failed"));
  }
}

function response(url, e) {
  if(xmlhttp.readyState != 4)return;
    var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " + xmlhttp.status+" "+xmlhttp.statusText+ "    " + url;
    var d=document.createElement("div");
    d.innerHTML=tmp;
    setTimeout(function(){
      while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
      e.appendChild(d);
    },10)
}

function visi(id,position){

	document.getElementById(id).style.visibility='visible';
	document.getElementById(id).style.left=position;
}

function hidi(id){

	document.getElementById(id).style.visibility='hidden';

}

function switchdisplay(id,record,word){
	if (document.getElementById(id).style.display==''){
		document.getElementById(id).style.display='none';
	}
	else{
		document.getElementById(id).style.display='';
		url='smartsearchpages.asp?id='+record+'&nPag=0&word='+word+'&div='+id;
		//alert(url);
		open_url(url,'div'+id);
	}
}

function switchdisplay_emb(id,record,word){
	if (document.getElementById(id).style.display==''){
		document.getElementById(id).style.display='none';
	}
	else{
		document.getElementById(id).style.display='';
		url='smartsearchpages_emb.asp?id='+record+'&nPag=0&word='+word+'&div='+id;
		//alert(url);
		open_url(url,'div'+id);
	}
}



function hidiallhome(id1,id2,id3){
	document.getElementById(id1).style.visibility='hidden';
	document.getElementById(id2).style.visibility='hidden';
	document.getElementById(id3).style.visibility='hidden';

}

function color(elem,color){
	elem.style.background=color;
}

var statusID=-1;
var statusDate=-1;
var statusLang=-1;
var statusPage=0;
//Default record per page number
var statusDispPage=2
var statuswhen = 'Today'
var statuslang= 'All Lang'

function open_page(theURL,whr,page,dispPage){
statusPage=page;
statusDispPage=dispPage;
theURL = theURL + '?id=' + statusID + '&dateint=' + statusDate + '&lang=' + statusLang + '&page=' + statusPage + '&dispPage=' + statusDispPage+ '&whenvalue='+statuswhen+'&langvalue='+statuslang;
//alert(theURL);
open_url(theURL,whr);
}

function open_urlme(theURL,whr,id,whenvalue,langvalue){
//alert('ok1');
if(id>=-1){
statusID=id;
statuswhen= whenvalue;
stauslang=langvalue;
}
//alert(statusID);
//alert(whr);
theURL = theURL + '?id=' + statusID + '&dateint=' + statusDate + '&lang=' + statusLang + '&page=' + statusPage + '&dispPage=' + statusDispPage+ '&whenvalue='+whenvalue+'&langvalue='+langvalue;
//alert(theURL);
open_url(theURL,whr);
}

function open_urlmedate(theURL,whr,dateint,whenvalue,langvalue){
statusDate=dateint;
statuswhen= whenvalue;
stauslang=langvalue;
theURL = theURL + '?id=' + statusID + '&dateint=' + statusDate + '&lang=' + statusLang + '&page=' + statusPage + '&dispPage=' + statusDispPage + '&whenvalue='+whenvalue+'&langvalue='+langvalue;
//alert(theURL);
open_url(theURL,whr);
}

function open_urlmelang(theURL,whr,lang,whenvalue,langvalue){
statusLang=lang;
statuswhen= whenvalue;
stauslang=langvalue;
theURL = theURL + '?id=' + statusID + '&dateint=' + statusDate + '&lang=' + statusLang + '&page=' + statusPage + '&dispPage=' + statusDispPage + '&whenvalue='+whenvalue+'&langvalue='+langvalue;
//alert(theURL);
open_url(theURL,whr);
}

var win2;
function fullScreenS(theURL,pagefound) {
	//var arrr = window.location.href.split('?');
	//var arrr2 =arrr[0].split('/');
	//var idd = arrr2[arrr2.length-2];
	//alert(idd);
	
	querys=location.search;
	querys=querys.split("&");
	for(i=1;i<querys.length;i++){
		x=querys[i].split("=");
		if (x[0]!="id"){
			if (x[0]=="gtp") {
				theURL= theURL + '&' + x[0] + '=' + pagefound;
			}
			else{
				theURL= theURL + '&' + x[0] + '=' + x[1];
			}
		}
	}

	//if (pagefound != undefined) {theURL = theURL + '&gtp=' + pagefound};
	//alert(theURL);
	win2 = window.open(theURL, '', 'width=' + (screen.width-5) + ',height=' + (screen.height-30) + ', scrollbars=auto, resizable=yes, ').focus();
}

function fullScreen(theURL,pagefound) {
	//var arrr = window.location.href.split('?');
	//var arrr2 =arrr[0].split('/');
	//var idd = arrr2[arrr2.length-2];
	//alert(idd);
	//alert(theURL);
	theURL= theURL +'&lan=' + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + '&gtp=' + document.getElementById('gotoo').value + '&bg=' +document.getElementById('color').value+ '&he=' +document.getElementById('he').value + '&align=' + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value;
	if (pagefound != undefined) {theURL = theURL + '&gtp=' + pagefound};
	//alert(theURL);
	win2 = window.open(theURL, '', 'width=' + (screen.width-5) + ',height=' + (screen.height-30) + ', scrollbars=auto, resizable=yes, ').focus();
}

function fullScreenSummary(theURL){
	//alert(theURL);
	win2 = window.open(theURL, '', 'width=' + (screen.width-5) + ',height=' + (screen.height-30) + ', scrollbars=auto, resizable=yes, ').focus();
}

function linnk(linkid) {
var idd3 = linkid;
document.getElementById('link').value = "http://www.paperator.com/user/" + idd3 + '/?id='+idd3+'&lan=' + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + '&gtp=' + document.getElementById('gotoo').value + '&bg=' +document.getElementById('color').value+ '&he=' +document.getElementById('he').value + '&align=' + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value;
document.getElementById('link1').value = "<iframe name=\"PAPERATOR_book\" width=\"100%\" height=\"100%\" src=" + "\"http://www.paperator.com/user/"+idd3+"/?id="+idd3+'&lan=' + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + '&gtp=' + document.getElementById('gotoo').value + '&bg=' +document.getElementById('color').value+ '&he=' +document.getElementById('he').value + '&align=' + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value + '&iframe=true' + "\" marginwidth=\"1\" marginheight=\"1\" border=\"0\" frameborder=\"0\" scrolling=\"no\"> Your browser does not suppot Iframes, please update it.</iframe>";
document.getElementById('link0').value ="smartsearchlist.asp?id="+idd3+'&lan=' + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + '&gtp=' + document.getElementById('gotoo').value + '&bg=' +document.getElementById('color').value+ '&he=' +document.getElementById('he').value + '&align=' + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value;
}

function linnkS(linkid) {
var idd3 = linkid;
//document.getElementById('link').value = "http://www.paperator.com/user/" + idd3 + '/?id='+idd3+'&lan=' + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + '&gtp=' + document.getElementById('gotoo').value + '&bg=' +document.getElementById('color').value+ '&he=' +document.getElementById('he').value + '&align=' + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value;
//document.getElementById('link1').value = "<iframe name=\"PAPERATOR_book\" width=\"100%\" height=\"100%\" src=" + "\"http://www.paperator.com/user/"+idd3+"/?id="+idd3+'&lan=' + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + '&gtp=' + document.getElementById('gotoo').value + '&bg=' +document.getElementById('color').value+ '&he=' +document.getElementById('he').value + '&align=' + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value +  "\" marginwidth=\"1\" marginheight=\"1\" border=\"0\" frameborder=\"0\"> Your browser does not suppot Iframes, please update it.</iframe>";
document.getElementById('link0').value ="smartsearchlist.asp?id="+idd3 +'&lan=' + queryString('lan') + '&gtp=' + queryString('gtp') + '&bg=' + queryString('bg') + '&he=' + queryString('he') + '&align=' + queryString('align');
}


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+''
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function rateup(elem){

document.getElementById(elem).src='images/fullrate.gif';
}

function ratedown(elem){
document.getElementById(elem).src='images/norate.gif';

}

function rate(rating,id){
	open_url('rate.asp?op=1&rati='+rating+"&val=1&id="+id,'rating');
}

function openNextPage(theURL,id,psearch,psearchtype,order,start,cmd){
theURL=theURL+'&id='+id+'&psearch='+psearch+'&psearchtype='+psearchtype+'&start='+start+'&cmd='+cmd;
//alert(theURL);
document.location.href=theURL;
}

function openNextPrev(theURL,id,pag,rpp){
theURL=theURL+'&id='+id+'&page='+pag+'&dispPage='+rpp;
//alert(theURL);
document.location.href=theURL;
}

function openIdUrl(theURL,order,start,a,cmd,idp){
var idd = idp; 
var search='';
var psearch=document.getElementById('psearch').value;
psearch=psearch;
var x=(psearch).split(" ");
theUrl="?sh=2s"
var bl=true;
	if((psearch!='' && bl) || cmd=='reset'){
	
		if(document.getElementById('psearchtype1').checked) search=document.getElementById('psearchtype1').value;
		if(document.getElementById('psearchtype2').checked) search=document.getElementById('psearchtype2').value;
		if(document.getElementById('psearchtype3').checked) search=document.getElementById('psearchtype3').value;
		
		if(a=='1'){
				if(cmd=='reset'){
				theURL=theURL + '&cmd=reset';
				psearch='';
				}
			if(queryString('psearch')) theURL=theURL + '&psearch=' + psearch; 
			if(queryString('psearchtype')) theURL=theURL + '&psearchtype='+search;
			if(queryString('pageno')) theURL=theURL + '&pageno='+document.ewpagerform.pageno.value;
			if(queryString('RecPerPage')) theURL=theURL + '&RecPerPage='+document.ewpagerform.pagine.value;
		
			if(order!='') theURL=theURL+'&order='+order;
		
			if(start!='') theURL=theURL+'&start='+start;
		}
		else{
			theURL= theURL +'&psearch='+psearch+'&psearchtype='+search;
		}
	
		theURL = theURL.replace("smartsearchlist.asp?","?sh=2s&") + "&id="+queryString('id');
	
		document.location.href=theURL;
	
	}
}

//Left Trim
function ltrim ( s )
{
	return s.replace( /^\s*/, "" );
}
//Right Trim
function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}
//Trim
function trim ( s )
{
	return rtrim(ltrim(s));
}

function paperatorSearch(word, gen, lang,full){
	//alert(word);
	var bl=true;
	var tmp=true;
	
	word=trim(word);
	tom=word.split(" ");
	if(tom.length==1) {
		//if(word.charAt(0)=="\"")
			word=word.replace("\"","");
	}
	
	theURL = '?sh=2se&word='+word;
	word=word.split(" ");
	
	for(i=0;i<word.length;i++){
		word[i]=word[i].replace(" ","");
	}
	
	for(i=0;i<word.length;i++){
		if (word[i].charAt(0)=="\"") {
			//tmp=false;
		}
		if (word[i].length<2 && tmp){
				//bl=false;
				//alert('Please search for 2 characters word length as minimum.');
				//break;
		}
		if (word[i].charAt(word.length-1)=="\"") {
			tmp=true;
		}
	}
	
	if (bl) {
	if (gen!='') theURL=theURL+'&gen='+gen;
	if (lang!='') theURL=theURL+'&lang='+lang;
	if (full==true) theURL=theURL+'&full=ON';
//window.alert(full);
document.location.href=theURL;
	}
}

function paperatorSearchFull(word, gen, lang,full){
	//alert(word);
	var bl=true;
	var tmp=true;
	
	word=trim(word);
	tom=word.split(" ");
	if(tom.length==1) {
		//if(word.charAt(0)=="\"")
			word=word.replace("\"","");
	}
	
	theURL = '?sh=2se&word='+word;
	word=word.split(" ");
	
	for(i=0;i<word.length;i++){
		word[i]=word[i].replace(" ","");
	}
	
	for(i=0;i<word.length;i++){
		if (word[i].charAt(0)=="\"") {
			//tmp=false;
		}
		if (word[i].length<2 && tmp){
				//bl=false;
				//alert('Please search for 2 characters word length as minimum.');
				//break;
		}
		if (word[i].charAt(word.length-1)=="\"") {
			tmp=true;
		}
	}
	
	if (bl) {
	if (gen!='') theURL=theURL+'&gen='+gen;
	if (lang!='') theURL=theURL+'&lang='+lang;
	theURL=theURL+'&full=ON';
//window.alert(full);
document.location.href=theURL;
	}
}



function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
//    return [ posX, posY ];
    return [ posX ];
  } else {
//    return [ oElement.x, oElement.y ];
    return [ oElement.x ];
  }
}



function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}

function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}

function testPaper(theURL){
	theURL = theURL + "&lan=" + document.getElementById('menu').options[document.getElementById('menu').selectedIndex].value + "&bg=" + document.getElementById('color').value + "&gtp=" + document.getElementById('gotoo').value + "&he=" + document.getElementById('he').value + "&align=" + document.getElementById('ali').options[document.getElementById('ali').selectedIndex].value; 
	win2 = window.open(theURL, '', 'width=' + (screen.width-5) + ',height=' + (screen.height-30) + ', scrollbars=auto, resizable=yes, ').focus();
	//location.href=theURL;
}

function checkBlank(val){
	if (val=="") return false;
	return true;
}



/////////////////////////////////////////////////////////////////////
function pubpreview(){
gSlideshowInterval = 1;

gNumberOfImages = 5;

gImages = new Array(gNumberOfImages);

gImages[0] = "images/0001/TileGroup0/0-0-0.jpg";
gImages[1] = "images/0002/TileGroup0/0-0-0.jpg";
gImages[2] = "images/0003/TileGroup0/0-0-0.jpg";
gImages[3] = "images/0004/TileGroup0/0-0-0.jpg";
gImages[4] = "images/0005/TileGroup0/0-0-0.jpg";

// ======================================================================
// 							DON'T CHANGE THIS PART
// ======================================================================

// canManipulateImages - check if the browser we're using can do
// clever stuff with document images.

function canManipulateImages() {
	if (document.images)
		return true;
	else
		return false;
}

// loadSlide
//
// Load a given image into place by substituting its URL for the URL 
// currently loaded by the <IMG> object called 'slide'. 

function loadSlide(imageURL) {
	if (gImageCapableBrowser) {
		document.slide.src = imageURL;
		return false;
	}
	else {
		return true;
	}
}

// nextSlide
//
// Update the counter that shows which slide is being displayed, and
// load it into place. The modulo (%) is there to ensure that we roll
// over when we reach the end of the slideshow.

function nextSlide() {
	gCurrentImage = (gCurrentImage + 1) % gNumberOfImages;
	loadSlide(gImages[gCurrentImage]);
}

// gImageCapableBrowser - is this browser hip to images? Set up
// a global variable so that we don't have to keep calling a function
// (useful if the function becomes costly to compute).

gImageCapableBrowser = canManipulateImages();

// gCurrentImage - a variable used to keep track of the image
// currently being displayed to the user.

gCurrentImage = 0;

// Set up the timer. This will call the 'nextSlide()' function repeatedly at 
// the specified interval (and will continue to do so until the page is unloaded).

setInterval("nextSlide()",gSlideshowInterval * 1000);

}



function pages_preview(slide) {
gSlideshowInterval = 1;
//window.alert(document[pippo].src);
gNumberOfImages = 4;

gImages = new Array(gNumberOfImages);
gImages[0] = "/user/" + slide + "/images/0001/TileGroup0/0-0-0.jpg";
gImages[1] = "/user/" + slide + "/images/0002/TileGroup0/0-0-0.jpg";
gImages[2] = "/user/" + slide + "/images/0003/TileGroup0/0-0-0.jpg";
gImages[3] = "/user/" + slide + "/images/0004/TileGroup0/0-0-0.jpg";


gCurrentImage = 0;

// Set up the timer. This will call the 'nextSlide()' function repeatedly at 
// the specified interval (and will continue to do so until the page is unloaded).

tumbp = setInterval("nextSlide('"+ slide + "')",gSlideshowInterval * 500);

}

function nextSlide(slide) {

	gCurrentImage = (gCurrentImage + 1) % gNumberOfImages;

	document[slide].src = gImages[gCurrentImage];

}



function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}


function DHTMLSound(surl) {

  document.getElementById("dummyspan").innerHTML="<embed src='/sounds/"+surl+"' hidden=true autostart=true loop=false type='audio/mpeg'>";
}



