//**********************************************************
//  $Id: myyk.js,v 1.1 2005/06/10 07:45:09 tanel Exp $
//**********************************************************

	var expiryDate = new Date();
	expiryDate.setTime(expiryDate.getTime() + (30 * 24 * 60 * 60 * 1000));

	function getCookieVal (offset) {
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}

	function GetCookie (currentURL) {
		var arg = currentURL + "=";
		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 (currentURL, 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 = currentURL + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}

	function DeleteCookie (currentURL) {
		var exp = new Date();
		exp.setTime (exp.getTime() - 1);
		var cval = GetCookie (currentURL);
		document.cookie = currentURL + "=" + cval + "; expires=" + exp.toGMTString();
	}


	

	function initialize() {

		var currentURL = "";

		if (GetCookie("currentURL") == "null") {
		} else if (GetCookie("currentURL") == null) {
		} else {
			currentURL = GetCookie("currentURL");
			self.location = currentURL;
			currentURL = "null";
			SetCookie("currentURL",currentURL,expiryDate);
		}
	}


	var index_page = "http://www.hotmail.com";

	if (top.location == index_page) {

		version = parseInt(navigator.appVersion);

		if (version > 3) {
			initialize();
		}
	}

	if (top.location != index_page) {
//	parent.location = index_page;
	}


	//kontrollib kas v22rtus on integer + koristab komakohad kui on
	function check_val(){
		
	}
	
	// buyItem - adds an item to the shooping basket
	function buyItem(newItem, newPrice, newQuantity,newId) {
		check_val(newQuantity);
		if (newQuantity <= 0) {
			rc = alert('The quantity entered is incorrect');
			return false;
		}
		if (confirm('Lisa '+newQuantity+' x '+newItem+' ostukorvi')) {
			index = document.cookie.indexOf("Korv");
			countbegin = (document.cookie.indexOf("=", index) + 1);
			countend = document.cookie.indexOf(";", index);
			if (countend == -1) {
				countend = document.cookie.length;
			}
			document.cookie="Korv="+document.cookie.substring(countbegin,countend)+"::"+newId+","+newQuantity;
		}
		return true;
	}

	// resetShoppingBasket - resets to shopping basket to empty
	function resetShoppingBasket() {
		index = document.cookie.indexOf("Korv");
		document.cookie="Korv=.";
	}
	
	function kasNumber(foo){     // kas väljakutsuvas lahtris on ainult numbrid?
		var sobib = 'jah';
		var nr = foo.value;
		with(Math){
			if (nr == '') sobib = 'ei';    // tühi ei sobi
			if(nr != abs(nr)) sobib = 'ei';	//olema pos
			if(nr != round(nr)) sobib = 'ei';	// peab t2isarv
			if (nr / nr != 1) {   // kui jagub iseendaga, on ilmselt number, stringid ei jagu :-P
				sobib = 'ei';
			}
			if(sobib == 'ei'){
				alert('Siia tohib sisestada ainult positiivseid täisarve, kogus muudetud');
				foo.value = 1;
			} else {
				return true;
			}
		}
	}
	
	function addcart(vendor,prod,qtybox) {
		box = document.getElementById(qtybox);
		kasNumber(box);
		//window.open('inc/cartadd.php?vendorid='+vendor+'&productid='+prod+'&quantity='+box.value,'','width=1, height=1, location=no, menubar=no')
		window.open('addcart.php?vendorid='+vendor+'&productid='+prod+'&quantity='+box.value,'','width=1, height=1, location=no, menubar=no')
	}
