var expDays = 14;

var page = "/message.html";

var windowprops = "width=300, height=325, location=nos, toolbar=no, menubar=no, scrollbars=no, resizable=no";

function loginSwap(imagepath){
	var logged = GetCookie("etopps");

	if (typeof(logged) == "string" && logged.indexOf("SessionID", 1)!= -1){
		imgloguser.src	=  imagepath +'/images/hdr_v2/btn_logout.gif';
		hrefloguser.href=  '/Authenticate/logout.asp';
	}
}

function displayUserName(){	
	var myCookie= GetCookie("etpUsernameCookie");
	if (myCookie != null){
		document.myData[0].LGNUSERNAME.value = myCookie;
		document.myData[0].USERNAMESAVED.checked = true;
	}
}

function GetCookie (name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen){
		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value){
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) { 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	var cval = GetCookie (name); 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
	var count = GetCookie('popupcount')

	if(count == null) {
	    SetCookie('popupcount','1')
	    return 1
	}else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('popupcount')
		SetCookie('popupcount',newcount,exp)
		return count
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
  var count = GetCookie('popupcount');

	if (count == null) {
		count=1;
		SetCookie('popupcount', count, exp);
		window.open(page, "", windowprops);
	}else if (count <3){
		count++;
		SetCookie('popupcount', count, exp);
		window.open(page, "", windowprops);
	}
}

function openebaywindow(){
	window.open("http://www.ebay.com/","my_new_window","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600"); 
}

function openebaywindowlist(){
	window.open("http://listings.ebay.com/aw/plistings/list/all/category25558/index.html", "eas");
}

function opentoppswindow(){
	window.open("http://www.topps.com/","my_new_window","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600"); 
}
function openchartwindow(url){
	window.open(url,"my_new_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=300"); 
}
function openstatswindow(url){
	window.open(url,"my_new_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=700,height=600"); 
}
function openprosperowindow(){
	window.open("http://www.delphi.com/etoppsz/start","my_new_window","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600"); 
}
function openparallaxwindow(){
	window.open("http://www.parallaxid.com","my_new_window","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600"); 
}
function OpenWindow(url, fucc){
	var winPopup = window.open(url, "PopUp", "");
	winPopup.focus();
}

function openviewaution(q){
    var s = new String(q);
    var s = s.substr(0, 50);
	window.open("http://search.ebay.com/search/search.dll?MfcISAPICommand=GetResult&ht=1&SortProperty=MetaEndSort&query=" + escape(s) + "&categoryid=&st=0&category1=25558&maxRecordsPerPage=200", "eas");
}

function ValidateField(theElement){
	var strSearchString = theElement.value;
	if (strSearchString=="") {
		alert("Please enter player name.");
		return false;
	}
	if (strSearchString.length < 3) {
		alert("Please enter at least 3 characters to search.");
		return false;
	}
	return true;
}

function opencarddetailwindow(p,t,c) {
	if (parseInt(c)==1){
		window.open("/Product/CardDetailsPopUp.asp?ID="+p+"","opencarddetailwindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=372,height=523");
	}																				
	if (parseInt(c)==2){
		window.open("/Product/CardDetailsPopUp.asp?ID="+p+"","opencarddetailwindow","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=800");
	}	
}

function OpeningWindow(url,name,width,height){
 	window.open(url,name,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width="+width+",height="+height+"");
}
function OpeningWindowScroll(url,name,width,height){
 	window.open(url,name,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+width+",height="+height+"");
}


function OpeningEbayWindows(url,name,width,height){
 	window.open(url,name,"toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width="+width+",height="+height+"");
}

function openvieworderwindow(t) {
    window.open("/MyOrders/MyOrder.asp?pfid="+t+"","my_new_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=700,height=500")
}

function openebayactionwindow(url) {
	window.open(url,"my_new_window","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=600,height=600");
}

function opendifshoporder() {
	window.open("/Orders/Diffshoporder.asp","opendifshoporder","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=380,height=150");
}

function Shippingcharges() {
	window.open("/Orders/shippingcarges.asp","Shippingcharges","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=510,height=170");
}

function opentoppstermswindow() {
	window.open("http://www.topps.com/terms.aspx","my_new_window","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600");
}

function reverseAll(cbList, chkSelectAll) {
	if (isNaN(cbList.length)){
		// Only one checkbox
		cbList.checked = chkSelectAll.checked;
	}else{
		// Array of checkboxes
		for (var i=0; i < cbList.length; i++) {
			cbList[i].checked = chkSelectAll.checked;
		}
	}
}

function SelectAll(cbList) {
	for (var i=0; i< cbList.length; i++) {
		var intValue=0;
		if(cbList[i].value!=""){
			cbList[i].value= cbList[i].value;
		}else{
			cbList[i].value =  1;
		}	
	}
}

function ConfirmDelete(objForm){	
	if (confirm("Are you sure you want to delete this address from your profile?")) {
		objForm.action = "/Profile/shp_ListAddr";
		objForm.submit();
	}else{
		objwindow = "/Profile/shp_ListAddr.asp";
	}
}

function ChooseCountry(objForm){	
	objForm.action = "/Profile/shp_AddNew.asp";
	objForm.submit();
}

function EditCountry(objForm){	
	objForm.action = "/Profile/shp_EditAddr.asp";
	objForm.submit();
}

function Vph(ID) {
	if (ID!=null) window.open('/product/last10tradespopup.asp?CardID=' + ID, "last10trades", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=550,height=400");
}

function c(ID){
	if (ID!=null) window.location.href = "/ipomarketplace/newcards.asp?ID=" + ID;
}

function t(NM){
	if (NM!=null) window.location.href = "/product/cardsearch.asp?sort_by=TEAM&order_by=ascending&searchcard=" + NM;
}

function ea(ID){
	if (ID!=null) window.open("http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=" + ID, "ea");
}

function eas(ttl){
    var s = new String(ttl);
    var s = s.substr(0, 50);
	window.open("http://search.ebay.com/search/search.dll?MfcISAPICommand=GetResult&ht=1&SortProperty=MetaEndSort&query=" + escape(s) + "&categoryid=&st=0&category1=25558&maxRecordsPerPage=200", "eas");
}

function eu(ID){
	if (ID!=null) window.open("http://myworld.ebay.com/" + ID + "/", "eu");
}

function chklist(iSecID, iYear){
	document.location.href = '/ipomarketplace/checklist.asp?SectionID=' + iSecID + '&YR=' + iYear;
}

function ol(ID){
	if (ID!=null) window.location.href = "/TradePost/ViewOffers.asp?CardID=" + ID;
}

function L10T(ID){
	return ajaxinclude("/product/last10tradespopup.asp?CardID=" + ID);
}

function cd(ID){
	return ajaxinclude("/Product/CardDetailsPopUp.asp?ID=" + ID);
}

var rootdomain="http://"+window.location.hostname;

function RedTxt(oF){
	if (oF != null){
		oF.style.background = "#ffcfce";
		oF.focus();
	}
}

function WhtTxt(oF){
	if (oF != null){
		oF.style.background = "#ffffff";
	}
}

function OffBtn(oB, sMsg){
	if (oB != null){
		oB.value    = sMsg;
		oB.disabled = true;
	}
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}

function alphatrim(str) {
   return str.replace(/[^0-9]/g,"");
}

function chkInt(n) {
	return /^\d+$/.test(n);								// Chk Int
}

function chkDate(n) {
	return /^\d{1,2}\/\d{1,2}\/\d{4}$/.test(n);			// Chk Date
}

function chkEmail(sEmail){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(sEmail);
}

function ajaxinclude(url){
	var page_request = false;

	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
	try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP");
		}catch (e){}
		}
	}
	else
		return false
	page_request.open('GET', url, false);	//get page synchronously 
	page_request.send(null);
	if (window.location.href.indexOf("http")==-1 || page_request.status==200)
		return page_request.responseText;
}

function inspect(elm){
	var str = "";
	for (var i in elm){
		str += i + ": " + elm.getAttribute(i) + "\n";
	}
	alert(str);
}

function addElement(divParent, divID, divContent) {
	var pardiv = document.getElementById(divParent);
	if (pardiv != null){
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', divID);
		newdiv.innerHTML = divContent;
		pardiv.appendChild(newdiv);
	}
}

function removeElement(divParent, divID) {
	var d = document.getElementById(divParent);
	var olddiv = document.getElementById(divID);
	d.removeChild(olddiv);
}

function updateElement(divID, divContent) {
	var d = document.getElementById(divID);
	d.innerHTML = "";
	d.innerHTML = divContent;
}

