
// Log errors
function errorHandler(msg, url, line) {
	var errorHandlerimg = new Image;
	errorHandlerimg.src = '/images/c.gif?error=js&line=' + escape(line) + '&msg=' + escape(msg);
    return true;
}
window.onerror = errorHandler;

// Statistics
document.writeln('<scr'+'ipt src="http://www.google-analytics.com/urchin.js" type="text/javascript"></scr'+'ipt>');
document.writeln('<scr'+'ipt src="/common/stats.js" type="text/javascript"></scr'+'ipt>');

// Make sure file is not hosted in a different frameset
if ( top.location.href != window.location.href )
  { top.location.href=window.location.href }

//***********************************************************************

// var image = new Image;
// var sSrc='http://www.phonecardfolder.com/statistics/tracker/tracker.php?sScrRes=' + 
// 	window.screen.width + 'x'+ window.screen.height + '&iColorDepth='+ screen.colorDepth 
// 	+ '&sURL='+document.location.href+'&sReferrer='+ document.referrer;
// escape(sSrc);
// image.src=sSrc;

//***********************************************************************

// ------------------------------------------------------------------

function openWindow(url,wname,w,h,props) 
{
	var winTop=(screen.height-h)/2;
	var winLeft=(screen.width-w)/2;
	
	var windowprops = "width=" + w + ",height=" + h +",left="+winLeft+",top="+winTop+","+props;
	return window.open(url,wname,windowprops);
}

// ------------------------------------------------------------------
// Open PopUp window without standard titlebar and borders under IE
// ------------------------------------------------------------------
function openPop(winName,title,content,iWidth,iHeight) 
{
	var iTop=(screen.height-iHeight)/2;
	var iLeft=(screen.width-iWidth)/2;

	if (document.all) 
	{
		var win = window.open("",winName, "fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top="+iTop+",left="+iLeft+",width=" + iWidth + ",height=" + iHeight);
		//win.resizeTo( Math.ceil(iWidth), Math.ceil(iHeight) );
		//win.moveTo  ( Math.ceil(iLeft), Math.ceil(iTop) );
		
		win.document.write('<html>');
		win.document.write('<head>');
		win.document.write('<title>'+title+'</title>');
		win.document.write('<link href="common/cstyle.css" type="text/css" rel="stylesheet">');
		win.document.write('<meta name="robots" content="noindex,follow" />');
		win.document.write('<scr'+'ipt language="javascript" src="common/functions.js" type="text/javascript"></scr'+'ipt>');
		win.document.write('</head>');
		win.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="no">');
		win.document.write('<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" class="PopUpBorder">');
		win.document.write('<tr><td>');
		win.document.write('<table border="0" cellspacing="1" cellpadding="4" width="100%" height="100%">');
		win.document.write('<tr><td class="PopUpTitle" height="25">'+title+'</td></tr>');
		win.document.write('<tr><td class="PopUpBody" valign="top">'+content+'</td></tr>');
		win.document.write('</table>');
		win.document.write('</td></tr>');		
		win.document.write('</table></body></html>');
		win.document.close();
	} 
	else 
	{
		var win = window.open("",winName, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top=" + iTop + ",left=" + iLeft + ",outerwidth=" + (iWidth + 12) + ",outerheight=" + (iHeight + 29), true);

		win.document.write('<html>');
		win.document.write('<head>');
		win.document.write('<title>'+title+'</title>');
		win.document.write('<link href="common/cstyle.css" type=text/css rel=stylesheet>');
		win.document.write('<meta name="robots" content="noindex,follow" />');
		win.document.write('<scr'+'ipt language="javascript" src="common/functions.js" type="text/javascript"></scr'+'ipt>');
		win.document.write('</head>');
		win.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="no">');
		win.document.write( content );
		win.document.write('</body></html>');
		win.document.close();
	}
	
	win.focus();
}

// ------------------------------------------------------------------

function openPicture(pic,w,h) {
 
	var windowprops = "left=160,top=100,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=yes,width=" + w + ",height=" + h;
      
	picture = window.open('','newPicture',windowprops);
	picture.close();
    picture = window.open('','newPicture',windowprops);  
    picture.focus();
    
	picture.document.write('<html>');
	picture.document.write('<head>');
	picture.document.write('<title>Picture</title>');
	picture.document.write('<link href="common/cstyle.css" type=text/css rel=stylesheet>');
	picture.document.write('</head>');
	picture.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>")
	picture.document.write('<meta name="robots" content="noindex,follow" />');
	picture.document.write('<scr'+'ipt language="javascript" src="common/functions.js" type="text/javascript"></scr'+'ipt>');
	picture.document.writeln("<img src=" + pic + " width=" + w + " height=" + h + ">")
	picture.document.write("<\/body><\/html>")
}                

// ------------------------------------------------------------------

function showdate()
{
	
	// Determine the current date and display it
   	var today = new Date();
   	var day = today.getDay();
   	var date = today.getDate();
   	var month = today.getMonth();
   	var year = today.getFullYear();
   	//January,February,March,April,May,June,July,August,September,October,November,December
   	if (month == 0) {month='Jan'};
   	if (month == 1) {month='Feb'};
   	if (month == 2) {month='Mar'};
   	if (month == 3) {month='Apr'};
   	if (month == 4) {month='May'};
   	if (month == 5) {month='Jun'};
   	if (month == 6) {month='Jul'};
   	if (month == 7) {month='Aug'};
   	if (month == 8) {month='Sept'};
   	if (month == 9) {month='Oct'};
   	if (month == 10) {month='Nov'};
   	if (month == 11) {month='Dec'};
   
   	if (day == 0) {day='Sunday'};
   	if (day == 1) {day='Monday'};
   	if (day == 2) {day='Tuesday'};
   	if (day == 3) {day='Wednesday'};
   	if (day == 4) {day='Thursday'};
   	if (day == 5) {day='Friday'};
   	if (day == 6) {day='Saturday'};
   
   if ( document.all ) {
		document.write ('<span class="small">' + day + ', ' + month +  ' ' + date + ', ' + year + '</span>');
	} else {
		document.write ('<span class="smallNC">' + day + ', ' + month +  ' ' + date + ', ' + year +  '</span>');
	}
   
   
}

// ------------------------------------------------------------------

function switchClass(obj,strClassName) {
		obj.className	= strClassName;
}

// ------------------------------------------------------------------

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
// ------------------------------------------------------------------
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


// ------------------------------------------------------------------
// Email validation
// ------------------------------------------------------------------
	
function validEmail(email)
{
		
	if ((email.length < 3) || (email.length > 50) || 
		(email.charAt(0) == '@') || (email.charAt(email.length-1) == '@') || 
		(email.charAt(0) == '.') || (email.charAt(email.length-1) == '.') || 
		(email.indexOf('.') == -1) || (email.indexOf('@') == -1) ||
		(email.indexOf('@') != email.lastIndexOf('@')) || 
		(email.indexOf(' ') > 0) || (email.indexOf('?') > 0) || (email.indexOf('..') > 0)
		)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// ------------------------------------------------------------------
// Not used
// ------------------------------------------------------------------	
function CheckFormUploadPhoto()
{
	if (document.uploadform.image.value.length < 1)
	{
		alert ('Please select an image file to upload or type it\'s full path.');
		document.uploadform.image.focus;
		return false;
	}
	
	return true;
}

// ------------------------------------------------------------------

function checkProfileForm(tform)
{
	if (tform.description.value=="") 
	{
		alert("Please write some information about you.");
		tform.description.focus();
		return false
	}

	if (tform.timespent.value==0) 
	{
		alert("Please select how often you are busy with phonecard collecting.");
		tform.timespent.focus();
		return false
	}
	
	if (tform.forhowlong.value==0) 
	{
		alert("Please select for how long you are in phonecard collecting.");
		tform.forhowlong.focus();
		return false
	}
	
	if (tform.levelselfestimation.value==0) 
	{
		alert("Please estimate your level in phonecard collecting.");
		tform.levelselfestimation.focus();
		return false
	}
	
	if (tform.moneyspent.value==0) 
	{
		alert("Please select money you spend/would spend for phonecard collecting.");
		tform.moneyspent.focus();
		return false
	}
	
	if (tform.inthobbies.value=="") 
	{
		alert("Please enter other interests and hobbies.");
		tform.inthobbies.focus();
		return false
	}	
	
	return true;
}	

//---------------------------------------------------------------------
// Checks fields in Add Card to catalog form
//---------------------------------------------------------------------


function checkAddCardToCatalogForm(tform)
{

	if (tform.catalognumber.value=="")
	{
		alert("Please enter catalog number.");
		tform.catalognumber.focus();
		return false;
	}	
	
	if ((tform.tirage.value!="")&& (tform.tirage.value*1 != tform.tirage.value))
	{
		alert("Please enter a valid tirage.");
		tform.tirage.focus();
		return false;
	}	

	if (tform.name.value=="")
	{
		alert("Please enter the name of card.");
		tform.name.focus();
		return false;
	}	

	if (tform.value.value=="")
	{
		alert("Please enter card value.");
		tform.value.focus();
		return false;
	}	

	if (tform.publisher.value == 0 && tform.newpublisher.value == "")
	{
		alert("Please select Publisher or enter New Publisher.");
		tform.newpublisher.focus();
		return false;
	}
	

	return true;
}	

//-------------------------------------------------------------------
//	Transfers values from select box to text box
//------------------------------------------------------------------
function changeValue(Box)
{
	document.pform.pmReceiverID.value = Box.options[Box.selectedIndex].value;
}

// ------------------------------------------------------------------
//	
//-------------------------------------------------------------------
function validateIMsgDel(imsgform){	
	var bchecked = false;
	for (var i = 0; i < aBoxes.length; i++) { 
		
		if (aBoxes[i].checked == true) { 
      		bchecked = true;
  		}  	
	} 	
		if(bchecked == false){
			alert ("Please select message(s).");
      		return false;
		}
	
	return true; 
}

// ------------------------------------------------------------------
//	
//-------------------------------------------------------------------

// ------------------------------------------------------------------
// Add New Catalog check form
// ------------------------------------------------------------------

function checkAddNewCatalogForm(tform)
{
	if (tform.name.value == "")
	{
		alert("Please enter catalog name.");
		tform.name.focus();
		return false;	
	}

	return true;
}

function checkAdminForm(tform)
{
	
	if (tform.scmd[2].checked)
	{
		return true;
	}
	else
	{
		if (tform.catalogid.value == 0)
		{
			alert("Please select catalog.");
			tform.catalogid.focus();
			return false;
		}
		else
		{
			return true;
		}	
	}
	
	return false;
}	

function ToggleSelectTag(select)
{
	// Check if an option differ that "Any" is selected
	// and if does then unselect "Any"(the first option)
											
	for (var i=1;i<select.length-1;i++)
	{
		if (select.options[i].selected)
			if (select.options[0].selected)
			{
				select.options[0].selected=false;
				return;
			}
	}
}

function copyrightYear(startYear)
	{
		d = new Date();
		
		if (startYear != d.getFullYear())
			{
			return startYear + " - " + d.getFullYear();
			}
		else
			{
			return startYear;
			}
	}

