var prosalocation = document.location;
var orderlocation = document.location;
var orderident = "oaseShowBasket";
var schillinglistprefix = "ArtList";
var panellocation = "";
var schillingbase = "http://www.antique-acc.com";
var showarticle = ""
var schilling_check_packing_quantity = 0;

//var logouturl = schRedir + "?user_event=USER_LOGOUT&url="+escape("/");
//var loginurl = schShowArticle + "?ident=loginCombo&user_returnarticle=loginCombo";
//var changeuserurl = schShowArticle + "?ident=oaseChangeUser"
var forgottenpwdident = "oaseSendPassword";
var schillingbasketident = "oaseShowBasket";
var schillingurlbeforebasket;
var schillingshopinfourl = "http://www.antique-acc.com/";
var schillingtiparticle = "TipFriend";

function setwfw() {
document.basketForm.wfw.value=(new Date()).getTime();
document.basketForm.kurv_antal.focus();

}

function addComment() {
	if (myform.firma == null)
		document.body.insertAdjacentHTML('beforeEnd', '<br><br>Er fakturaadressen ikke korrekt, bedes du kontakte ACC per telefon eller mail.');
}

function SchSetTipFields()
{
	var Varetextnode = document.getElementById('Varetext');
	var Varebesknode = document.getElementById('Varebeskrivelse');
	var headline = document.getElementById('Varetext').childNodes[0].childNodes[0].nodeValue;
	//document.forms['mailform'].headline.value = headline;
	document.forms['mailform'].subject.value = headline;
	var mailtext =  document.getElementById('Varebeskrivelse').childNodes[0].childNodes[0].nodeValue;
	document.forms['mailform'].mailtext.value = mailtext;
	var varenrnode =  document.getElementById('Varenr').childNodes[0].childNodes[0].childNodes[0].childNodes[0];
	document.forms['mailform'].sendError.value = location.href;
	document.forms['mailform'].link.value = schShowArticle + "?ident=Art&art_event=GET_ART&art_vnr="+varenrnode.childNodes[0].nodeValue;
	var inputnode = document.forms['mailform'].mailbody;
	if (inputnode) {
		var textareanode = document.createElement("textarea");
		textareanode.cols = 28;
		textareanode.rows = 8;
		textareanode.name = "mailbody";
		textareanode.value = mailtext + "\n\n" + "Se mere: " + document.forms['mailform'].link.value;
		
		inputnode.parentNode.replaceChild(textareanode, inputnode);
	}
	varenrnode.style.display = "none";
	Varebesknode.style.display = "none";
	Varetextnode.style.display = "none";
	document.forms['mailform'].mailRecipient.focus();
}

function SchIsEmail(elm) {
    if (elm.value.indexOf("@") + "" != "-1" &&
        elm.value.indexOf(".") + "" != "-1" &&
        elm.value != "")
    return true;
    else return false;
}

function SchIsFilled(elm) {
    if (elm.value == "" ||
        elm.value == null)
    return false;
    else return true;
}

function SchValidateTipForm() {
	if (SchIsEmail(document.mailform.mailRecipient) == false) {
		alert("Modtagerens emailadresse er ikke gyldig");
		document.mailform.mailRecipient.focus();
		return false;
	}
	if (SchIsFilled(document.mailform.sendername) == false) {
		alert("Skriv venligst dit navn.");
		document.mailform.sendername.focus();
		return false;
	}
	if (SchIsEmail(document.mailform.sender) == false) {
		alert("Afsenderens emailadresse er ikke gyldig");
		document.mailform.sender.focus();
		return false;
	}
return true;
}

function AccShowFutureTitles()
{
	if (document.URL.indexOf("/accinc/")>0)
		changeProsaHref(schShowArticle+"?ident=ArticleListFuture&&art_event=GET_LIST&art_listtype=ahead&wfw="+(new Date()).getTime());
	else
		changeProsaHref(schShowArticle+"?ident=ArtListFuture&&art_event=GET_LIST&art_listtype=ahead&wfw="+(new Date()).getTime());
}

function AccShowNewTitles()
{
	if (document.URL.indexOf("/accinc/")>0)
		changeProsaHref(schShowArticle+"?ident=ArticleListNews&art_event=GET_LIST&art_listtype=news&wfw="+(new Date()).getTime());
	else
		changeProsaHref(schShowArticle+"?ident=ArtListNews&art_event=GET_LIST&art_listtype=news&wfw="+(new Date()).getTime());
}

function fieldsFilledOut() {
 	var nodeList = document.ccform.getElementsByTagName("INPUT");
    	for (var i = 0; i < nodeList.length; i++) {
			if (nodeList[i].name != "ccform_issuenumber" && nodeList[i].name != "ccform_validfrommonth" && nodeList[i].name != "ccform_validfromyear") {
        		if (nodeList[i].value.length == 0) {
            		nodeList[i].focus();
            		alert("All fields must be filled out!");
            		return false;
				}
			}
		}
	nodeList = document.ccform.getElementsByTagName("SELECT");
	for (var i = 0; i < nodeList.length; i++) {
		if (nodeList[i].value == "BLANK") {
			alert("Please select expiration date!");
			return false;
		}
	}
	return true;
}

function cardval(s) {
// remove non-numerics
var v = "0123456789";
var w = "";
for (i=0; i < s.length; i++) {
	x = s.charAt(i);
	if (v.indexOf(x,0) != -1)
	w += x;
}
// validate number
j = w.length / 2;
if (document.ccform.ccform_cardtype.value == "American Express" && j != 7.5) {
	alert("Wrong number of digits! American Express numbers must contain 15 digits.");
	return false;
} else if (document.ccform.ccform_cardtype.value != "American Express" && j == 7.5) {
	alert("Wrong number of digits! Please check that the credit card number entered is valid!");
	return false;
}
if (j < 6.5 || j > 8 || j == 7) {
	alert("Wrong number of digits! Please check that the credit card number entered is valid!");
	return false;
}
k = Math.floor(j);
m = Math.ceil(j) - k;
c = 0;
for (i=0; i<k; i++) {
	a = w.charAt(i*2+m) * 2;
	c += a > 9 ? Math.floor(a/10 + a%10) : a;
}
for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	if (c%10 != 0)
    	alert("Please check that the credit card number entered is valid!");
	return (c%10 == 0);
}

function validateCreditCard() {

fields_ok = fieldsFilledOut();
if (fields_ok) {
	var s = document.ccform.ccform_number.value;
	return cardval(s);
} else {
    return false;
}
}

function SchBasketFinish() {
	prosalocation.replace(schillingbase+"/"+schSiteName);
}
