function action(url, winheight, winwidth, var1name, var1val, var2name, var2val, var3name, var3val, var4name, var4val, var5name, var5val) {
	window.name = 'main';
	iMyWidth = (window.screen.width/2) - (parseInt(winwidth) / 2 ); 
	iMyHeight = (window.screen.height/2) - (parseInt(winheight) / 2 );
	//alert(var1name);
	if (!var1name) {
	var url = url;
	}	
	else if(!var2val) {
		var url = url + "?" + var1name + "=" + var1val;
	} 
	else if (!var3name) {
		var url = url + "?" + var1name + "=" + var1val + "&" + var2name + "=" + var2val;
	}
	else if (!var4name) {
		var url = url + "?" + var1name + "=" + var1val + "&" + var2name + "=" + var2val + "&" + var3name + "=" + var3val;
	}
	else if (!var5name) {
		var url = url + "?" + var1name + "=" + var1val + "&" + var2name + "=" + var2val + "&" + var3name + "=" + var3val + "&" + var4name + "=" + var4val;
	}
	else {
		var url = url + "?" + var1name + "=" + var1val + "&" + var2name + "=" + var2val + "&" + var3name + "=" + var3val + "&" + var4name + "=" + var4val + "&" + var5name + "=" + var5val;
	}
	
	childwin = window.open(url, "childwin", "height="+winheight+",width="+winwidth+",screenX="+iMyWidth+",left="+iMyWidth+",screenY="+iMyHeight+",top="+iMyHeight+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=1,status=1,toolbar=0");
	childwin.focus();
	//alert(url);
}

function CloseWin(url) {
  if (window.opener && !window.opener.closed)
    window.opener.document.location.href = url;
  window.close();
}

function validEmail(form,field) {
    url = prompt("Enter your email address ONLY.","");
    if (url != null && url != "") {
        a = url.lastIndexOf("@");
        b = url.lastIndexOf(".");
        c = url.indexOf(":");
        d = url.indexOf("/");
        e = url.substring(0,a);
        f = e.indexOf("@");
        g = url.substring(a+1,url.length);
        h = g.indexOf("[");
        i = g.indexOf("]");
        j = g.indexOf("<");
        k = g.indexOf(">");
        l = url.substring(a+1,b);
        m = url.substring(b+1,url.length);
        n = url.substring(0,a);
        o = 0;
        if (a > b) {o++};
        if (c != -1) {o++};
        if (d != -1) {o++};
        if (f != -1) {o++};
        if (h != -1) {o++};
        if (i != -1) {o++};
        if (j != -1) {o++};
        if (k != -1) {o++};
        if (l.length < 3) {o++};
        if (m.length < 2) {o++};
        if (n.length < 1) {o++};
        if (o == 0) {
            document[form][field].value=url;
        }
        else {
            alert("You have entered an invalid email address!");
        }
    }
    else {
        alert("You may subscribe some other time.");
        url="";
    }
}

function check()
	{
		window.name = 'main';
		var com_name = document.details.com_name.value;
		var welcome = document.details.welcome.value;
		var about = document.details.about.value;
		var services = document.details.services.value;
		var address_1 = document.details.address_1.value;
		var address_2 = document.details.address_2.value;
		var address_3 = document.details.address_3.value;
		var address_4 = document.details.address_4.value;
		var post_code = document.details.post_code.value;
		var phone = document.details.phone.value;
		var fax = document.details.fax.value;
		var email = document.details.email.value;

		var longstr = welcome+about+services+address_1+address_2+address_3+address_4+post_code+phone+fax+email;
		
		var islt = longstr.indexOf("<");
		var isgt = longstr.indexOf(">");
		
		if(com_name == '' || islt != -1 || isgt != -1)
			{
				alert('Skillsite cannot submit your MicroSite\n\nEither you have not entered a site name or you have used the characters \'<\' or \'>\'');
			}
		else
			{
				iMyWidth = (window.screen.width/2) - 175; //was 10 half the screen width minus half the new window width (plus 5 pixel borders).
				iMyHeight = (window.screen.height/2) - 165; //was 50 half the screen height minus half the new window height (plus title and status bars).
				savewin = window.open("about:blank", "savewin", "height=330,width=350,screenX="+iMyWidth+",left="+iMyWidth+",screenY="+iMyHeight+",top="+iMyHeight+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
				document.details.target = 'savewin';
				document.details.submit();
				//alert("to db");
			}
	}

function process(todo, name, value) {
	action('../microsite/smallmsworking.php', 330, 350,'process',todo,name,value);
}

function loadpage(startrec, endrec) {

	var res = document.resultlist;
	var lower = parseInt(res.lower.value);
	var fromrec = parseInt(res.fromrec.value);
	var torec = parseInt(res.torec.value);
	var upper = parseInt(res.upper.value);

	res.lower.value = startrec;
	res.fromrec.value = startrec;
	res.torec.value = endrec;

	res.submit();

}

function direction(direc) {
	var com = document.resultlist;
	var lower = parseInt(com.lower.value);
	var fromrec = parseInt(com.fromrec.value);
	var torec = parseInt(com.torec.value);
	var upper = parseInt(com.upper.value);
	if(direc == 'next') {
		com.lower.value = lower + upper;
		com.fromrec.value = fromrec + upper;
		com.torec.value = torec + upper;
	}
	else {
		com.lower.value = lower - upper;
		com.fromrec.value = fromrec - upper;
		com.torec.value = torec - upper;
	}
	//com.action = '../cand/canresults.php';
    com.target = '_self';
	com.submit();
}

function SetChecked(val,cbname,formname,byvalue) {
	var dml = formname;
	len = dml.elements.length;
	clen = dml.elements[cbname].length;
	var i=0; var c=0;
	for(i=0;i<clen;i++) {
		//if(dml.elements[i].type == 'checkbox') {
			if(byvalue) {
				if(dml.elements[cbname][i].value == cbname) dml.elements[cbname][i].checked = val;
			}
			else {
				if(dml.elements[cbname][i].name == cbname) dml.elements[cbname][i].checked = val;
			}
			if(val) window.status = 'Checking boxes, ' + parseInt(((i+1)/clen)*100) + '% done...';
			else    window.status = 'Unchecking boxes, ' + parseInt(((i+1)/clen)*100) + '% done...';
			c++;
		//}
	}
}
function checkselection(cbname,formname,alertstring) {
	noSelection=true;
	dml=formname;
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if(dml.elements[i].name==cbname) {
			if(dml.elements[i].checked) {
				noSelection=false; break;
			}
		}
	}
	if (noSelection) {
		window.alert(alertstring);
		return false;
	}
	else return true;
}
function inputtoday(objectname) {
	todaysdate = new Date();

	v_month = todaysdate.getMonth();
	/*if (v_month < 10) {v_fullmonth = "0" + v_month;} else {v_fullmonth = v_month;}*/
	
	var	allthemonths = Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
	v_fullmonthname = allthemonths[parseInt(v_month)];
	//alert(todaysdate.getDate() + "-" + v_fullmonth  + "-" + todaysdate.getFullYear());

	v_day = todaysdate.getDate();
	if (v_day < 10) {v_fullday = "0" + v_day;} else {v_fullday = v_day}
	objectname.value = v_fullday + "-" + v_fullmonthname  + "-" + todaysdate.getFullYear(); 
}
function inputtime(obj) { // 24hr clock only
	var now = new Date();

	var hours = now.getHours();
	hours = hours.toString();
	if(hours.length == 1) hours = "0" + hours;
	var minutes = now.getMinutes();
	minutes = minutes.toString();
	if(minutes.length == 1) minutes = "0" + minutes;
	
	obj.value = hours + ":" + minutes; 
}

function listform(url,a,b,hwidth,vheight) {
	if(!hwidth) hwidth=255;
	if(!vheight) vheight=500;
	action(url, hwidth, vheight, a, b);
}
var agentind = 0;
function setMe(me, obj) {
	if(!obj) obj = document.form1.agent;
	var a = obj;
	var opts = obj.options;
	for(var i=0;i<=opts.length-1;i++) {
		if(opts[i].value==me) {
			//if(!agentind==0) lastagentoption = i;
			if(!opts[i].selected){
				agentind = a.selectedIndex;
				opts[i].selected=true;
			}
			else {
				opts[agentind].selected=true;
			}
			break;
		}
	}
}
