/***********************************************************
 Standard functions used throughout the database
 COPYRIGHT © 1999-2001 IDX Group, Inc.

function UpdateViewLinks()
function initializepage()
function CheckChangePGroup()
function PrintDate()
function IDX_dspStsMsg()
function WelcomeWindow()
function validateEmail( obj )
function SendToAFriendWin(x,y)
function MM_reloadPage(init)
function opengipwindow(myURL, x, y)
function SendToAFriendWinCal(x,y)


**********************************************************/

//browser status bar
window.defaultStatus = '::: www.GreeceInPrint.com ::: The World"s Greek Literary Connection!'; 

function UpdateViewLinks() {
var plang = document.forms[1].PLang.value;
var pgroup = document.forms[1].PGroup.value;
var tab = document.forms[1].Tab.value;
for (i=0; i < document.links.length; i++) {
      obj = document.links[i]
      if (obj.href.indexOf("mailto:") == -1) {
	if (obj.search.indexOf("&ViewLink=") !== -1) {
		if (obj.search.indexOf("&DocType=") !== -1) {
			doctype = obj.search.substr(obj.search.indexOf("&DocType=") + 9)
			if (document.forms[1].DocType_Pos.value.indexOf(doctype) !== -1) {
				obj2 = document.forms[1].DocType_Pos.value
				prmTab = obj2.substr(obj2.indexOf(doctype) + doctype.length + 2, (obj2.indexOf("~~", obj2.indexOf(doctype) + doctype.length + 2)) - (obj2.indexOf(doctype) + doctype.length + 2))
				document.links[i].href += "&PLang=" + plang + "&PGroup=" + pgroup + "&Tab=" + prmTab + "&End="
			}
		}
	}
     }
}
}

/***********************************************************/

var cartID;
function initializepage() {
   //Look for CartID in cookie first
   var cookies=document.cookie;
   cartID = getcartid("cartid", cookies, ";");
   //If cookies aren't enabled, first determine if customer is coming from an external site.  If so, a new
   //CartID must be generated for them.  If they are changing pages within GIP, simply get the
   //CartID from the URL
   if (cartID==null) {
      if (document.referrer.substring (0, 19).toLowerCase() != "http://140.239.165.152" | document.referrer.substring (0, 28).toLowerCase() != "http://www.greeceinprint.com" | document.referrer.substring (0, 29).toLowerCase() != "https://www.greeceinprint.com") {
         cartID=randomnum();
        }
      else {
         var URLcartid = new String(document.URL);
         cartID=getcartid("cartid", URLcartid, "&");
        }
	}
    //Append CartID to all links on the current page, regardless of whether cookies are enabled or not   
    setlinks(cartID);    
 }

function randomnum() {
      var TodaysDate=new Date();
      var rn = Math.floor(16000*Math.random()+1)+"-"+TodaysDate.getHours()+TodaysDate.getMinutes()+TodaysDate.getSeconds(); 
      return rn;
 }

function setlinks(v) {
       for (var i = 0; i < document.links.length; i++) {
       if ((document.links[i].href.indexOf("://192.168.1.52") !==-1) | (document.links[i].href.indexOf("://140.239.165.152")!==-1) | (document.links[i].href.indexOf("://www.greeceinprint")!==-1)) {
	if (document.links[i].href.indexOf("&CartID=") ==-1) {
              //Use the search property of the link object to append the CartID
              document.links[i].href += "&CartID=" + v 
	}
             }
         }  
}

function getcartid(name, inputstring, trunc) {
        //Simply parses out CartID from either the cookie or URL passed to function
        inputstring = inputstring + trunc;
        inputstring = inputstring.toLowerCase();
        var start=inputstring.indexOf(name + "=");
        if (start>-1) {
             start=inputstring.indexOf("=", start)+1
           }
        var end = inputstring.indexOf(trunc, start);
        if (start==-1 || end==-1) {
              value=null
           } 
        else {
              var value=unescape(inputstring.substring(start,end))
           }
        return value;
 }

/***********************************************************/

function CheckChangePGroup() {
var plang = document.forms[1].PLang.value;
var pgroup = document.forms[1].PGroup.value;
var tab = document.forms[1].Tab.value;
var vUNIDsForSearch = document.forms[1].UNIDsForSearch.value;
newvUNIDsForSearch = vUNIDsForSearch.replace(/,/gi," OR ");
if (window.location.href.indexOf("&ChangePGroup=") !== -1) {
	window.location.href="/" + document.forms[1].ThisDB.value + "/publicBooks?SearchView&Query=" + escape("[ProductGroups] CONTAINS " + newvUNIDsForSearch) + "&Start=1&Count=10&PLang=" + plang + "&PGroup=" + pgroup + "&Tab=" + tab + "&End="
}
}

/***********************************************************/

function UpdateViewLinksCart() {
if (document.forms[2]) {
var plang = document.forms[2].PLang.value;
var pgroup = document.forms[2].PGroup.value;
var tab = document.forms[2].Tab.value;
for (i=0; i < document.links.length; i++) {
	obj = document.links[i]
	if (obj.search.indexOf("&ViewLink=") !== -1) {
		if (obj.search.indexOf("&DocType=") !== -1) {
			doctype = obj.search.substring(obj.search.indexOf("&DocType=") + 9, obj.search.indexOf("&", obj.search.indexOf("&DocType=") + 9))
			if (document.forms[2].DocType_Pos.value.indexOf(doctype) !== -1) {
				obj2 = document.forms[2].DocType_Pos.value
				prmTab = obj2.substr(obj2.indexOf(doctype) + doctype.length + 2, (obj2.indexOf("~~", obj2.indexOf(doctype) + doctype.length + 2)) - (obj2.indexOf(doctype) + doctype.length + 2))
				document.links[i].search += "&PLang=" + plang + "&PGroup=" + pgroup + "&Tab=" + prmTab + "&End="
			}
		}
	}
}
}
}
/***********************************************************/

function PrintDate()    {

   // Declare variables
   today = new Date();
   year = today.getYear();
   month_number = today.getMonth();
   date = today.getDate();
        day_number = today.getDay();
        var month;
        var day;
   // Change month from number to name
        month_name = new Array("January", "February", "March", "April",
         "May", "June", "July", "August", "September", "October", "November",
         "December");
        month = month_name[month_number];

        // Change day from number to name
        day_name = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
           "Thursday", "Friday", "Saturday");
        day = day_name[day_number];

        // Add correct century to year
        if (year < 1000)
                year = year + 1900;

        // Write the line to the document
        document.write(day + ' ');
        document.write(month + " " + date + ", " + year);
}
// Stop hiding script from non-script browsers -->

/***********************************************************/

function IDX_dspStsMsg(msgStr) { //v1.0
  status=msgStr;
  document.IDX_rtnValue = true;
}

/***********************************************************/

function  WelcomeWindow() {
if (document.referrer.substring (0, 19).toLowerCase() != "http://64.61.61.122" |       document.referrer.substring (0, 28).toLowerCase() != "http://www.greeceinprint.com") 
{
   popupWin = window.open('http://64.61.61.122/GiPProducts.nsf/Welcome?OpenForm', 'Welcome', 'width=350,height=450,left=200,top=150')
}
}

/***********************************************************/

function validateEmail( obj ) {
	var emailStr = obj.value;
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if ( !reg1.test( emailStr ) && reg2.test( emailStr ) ) {
		return true;
	} else {
	 	return false;
	}
}

/***********************************************************/

function SendToAFriendWin(x,y) {
var xMax = 640, yMax=480; // default
var  Source = escape(document.forms[0].ThisDB.value);
var Title = escape(document.forms[0].PRTitle.value);
var Refurl = location.pathname;
if (document.all) var xMax = screen.width, yMax = screen.height;
else if (document.layers) var xMax = window.outerWidth, yMax = 
window.outerHeight;
var xOffset = ((xMax - x) / 2 - 25), yOffset = ((yMax - y) / 2) + 50;

windowVar = window.open("http://www.greeceinprint.com/sendtoafriend.nsf/Memo?OpenForm&title=" + Title + "&url=" + Refurl + "&site=" + Source, "SendToAFriend", 
					'width='+x+',height='+y+',resizable=no,toolbar=no,scrollbars=yes,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+''  );
	windowVar.focus();
}

/***********************************************************/

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/***********************************************************/

function opengipwindow(myURL, x, y) {
var xMax = 640, yMax=480; // default
if (document.all) var xMax = screen.width, yMax = screen.height;
else if (document.layers) var xMax = window.outerWidth, yMax = 
window.outerHeight;
var xOffset = ((xMax - x) / 2 - 25), yOffset = ((yMax - y) / 2) + 75;
msgWindow2 = 
window.open('','newWin','width='+x+',height='+y+',resizable=yes,toolbar=no,scrollbars=yes,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
msgWindow2.location.href = myURL;
}

/***********************************************************/

function SendToAFriendWinCal(x,y) {
var xMax = 640, yMax=480; // default
var  Source = escape(document.forms[0].ThisDB.value);
var Title = escape(document.forms[0].EventTitleD.value);
var Refurl = location.pathname;
if (document.all) var xMax = screen.width, yMax = screen.height;
else if (document.layers) var xMax = window.outerWidth, yMax = 
window.outerHeight;
var xOffset = ((xMax - x) / 2 - 25), yOffset = ((yMax - y) / 2) + 50;

windowVar = window.open("http://64.61.61.122/sendtoafriend.nsf/Memo?OpenForm&title=" + Title + "&url=" + Refurl + "&site=" + Source, "SendToAFriend", 
					'width='+x+',height='+y+',resizable=no,toolbar=no,scrollbars=yes,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+''  );
	windowVar.focus();
}

/***********************************************************/
