// JavaScript Document
// document.cookie="testcookiename=testcookievalue;expires=Wednesday, 21-May-03 23:12:40 GMT"
// window.open("index.htm","secondWindow","resizable=no,scrollbars=no,toolbar=no,menubar=no,width=200, height=200")
var CntExpDays = 5; // number of days the cookie should last

var page = "http://www.youngltd.com/moreinfo.asp";
var windowprops = "width=280,height=215,screenY=470,screenX=570,top=470,left=570,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
function GetCookie (name) {  // run 2nd name="count"
	var arg = name + "=";  // arg="count="
	var alen = arg.length;  // alen=6
	var clen = document.cookie.length;  // length of cookie
	var i = 0;  
	while (i < clen) {    // while i < length of cookie
		var j = i + alen;    // j=0+6 =6
		if (document.cookie.substring(i, j) == arg)      // 0,6
		return getCookieVal (j);    // j=6
		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 CntExp = new Date();  
	CntExp.setTime (CntExp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + CntExp.toGMTString();
}

var CntExp = new Date(); 
CntExp.setTime(CntExp.getTime() + (CntExpDays*60*1000)); // current time in milliseconds + time to expire in milliseconds; *24*60*60*1000

function amt(){
	var count = GetCookie('count')
	if(count == null) {
		SetCookie('count','1')
		return 1
	}
	else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,CntExp)
		return count
	}
}

function getCookieVal(offset) {		// run 3rd		offset=6
	var endstr = document.cookie.indexOf (";", offset);	// endstr=-1
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() { // run 1st
	var submitted = GetCookie('submitted');
	if (submitted == null) {
		submitted=0;
		SetCookie('submitted',submitted);
		count=1;
		SetCookie('count',count);
	} else if (submitted == 0) {
		count = GetCookie('count');
		count++;
		SetCookie('count',count);
		if (count==5)
			window.open(page, "", windowprops);
	}
}

function frmSub() { // run when more info is requested
	self.resizeTo(260,140); // absolute positioning
	CntExpDays = 365; // number of years the cookie should last
	CntExp = new Date(); 
	CntExp.setTime(CntExp.getTime() + (CntExpDays*24*60*60*1000)); // current time in milliseconds + time to expire in milliseconds; *24*60*60*1000
	submitted=1;
	SetCookie('submitted',submitted,CntExp);
}
