function fnSetDateRange(DateType, NoDays, DateLow, DateHigh, dates) {

    //Calculate Date Values
    switch (DateType) { // YYYY-MM-DD HH:MM:SS.SSS 01/01/2009
        case "1": //Date Range
            dates[0] = DateLow.substr(6, 4) + "-" + DateLow.substr(3, 2) + "-" + DateLow.substr(0, 2) + " 00:00:00";
            dates[1] = DateHigh.substr(6, 4) + "-" + DateHigh.substr(3, 2) + "-" + DateHigh.substr(0, 2) + " 23:59:59";
            break;

        case "2": //Today
            dates[0] = 0;
            dates[1] = 0;
            break;

        case "3": //Last x Days
            dates[0] = "-" + NoDays;
            dates[1] = 0;
            break;

        case "4": //Next x Days
            dates[0] = 0;
            dates[1] = "+" + NoDays;
            break;

        case "5": //More than x Days Ago
            dates[0] = 0;
            dates[1] = "-" + NoDays;
            break;

        case "6": //After x Days Time
            dates[0] = "+" + NoDays;
            dates[1] = 0;
            break;
    }
}

function fnCreditAlert(credit, itemtype) {
    var s = credit + " more ";
    var s1;
    var s2;
    switch (itemtype) {
        case "contact": s1 = "Contact."; s2 = "Contacts."; break;
        case "email": s1 = "Email."; s2 = "Emails."; break;
        case "file": s1 = "Document."; s2 = "Documents."; break;
        case "job": s1 = "Job."; s2 = "Jobs."; break;
        case "property": s1 = "Property."; s2 = "Properties."; break;
        case "sms": s1 = "Text Message."; s2 = "Text Messages."; break;
    }
    if (credit == 1)
        s += s1;
    else
        s += s2;

    if (confirm('Warning, You can only add ' + s + '\n\nClick \'OK\' to Buy Top-Up Token.') == true)
        location = 'viewpoint.aspx?action=agent_summary&credit_alert=property&credit_value=' + credit;
}


function DateAdd(timeU, byMany, dateObj) {
    var millisecond = 1;
    var second = millisecond * 1000;
    var minute = second * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var year = day * 365;

    var newDate;
    var dVal = dateObj.valueOf();
    switch (timeU) {
        case "ms": newDate = new Date(dVal + millisecond * byMany); break;
        case "s": newDate = new Date(dVal + second * byMany); break;
        case "mi": newDate = new Date(dVal + minute * byMany); break;
        case "h": newDate = new Date(dVal + hour * byMany); break;
        case "d": newDate = new Date(dVal + day * byMany); break;
        case "y": newDate = new Date(dVal + year * byMany); break;
    }
    return newDate;
}

function fnShowHelp(e) {

    if(e.innerText == 'Show Help') {
        e.innerText = 'Hide Help';
        display = 'block';
    }
    else {
        e.innerText = 'Show Help';
        display = 'none';
    }

    for (x = 0; x < document.all.divHelp.length; x++) {
        document.all.divHelp[x].style.display = display;
    }
}

function fnSetActionData(url,name,data){
	document.all.fraAction.src=url+'&'+name+'='+data;
}
function fnSetAction(url){
	document.all.fraAction.src=url;
}

function fnAction(action){
	var xhttp = new ActiveXObject("Msxml2.XMLHTTP");
	xhttp.open("GET", action, false);
	//xhttp.setRequestHeader("Content-Type", "text/html")
	xhttp.send();
}

function fnActionPost(action,name,body){ //debugger;
	var xhttp = new ActiveXObject("Msxml2.XMLHTTP");
	xhttp.open("POST", action, false);
	xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
	xhttp.send(name+'='+escape(body));
}

function checkEmail(email) {

	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email))
		return false;
	else
		return true;
}

function fnExpand(img, tbl) {
	if (img.title == 'Expand') {
		tbl.style.display = 'block';
		img.title = 'Close';
		img.src = 'common/icoMinus.gif';
	}
	else {
		tbl.style.display = 'none';
		img.title = 'Expand';
		img.src = 'common/icoPlus.gif';
	}
}
function fnShowFilter(){
	if (tdFilter.style.display == 'none') {
		tdFilter.style.display = 'block';
		form1.ShowFilter.value = 1;
	}
	else {
		tdFilter.style.display = 'none';
		form1.ShowFilter.value = 0;
	}
}
function fnMenuOver(obj1,obj2,img){
	obj1.className='MouseOverBox1';
	obj2.className='MouseOverBox2';
	img.style.display='block';
}
function fnMenuOut(obj1,obj2,img){
	obj1.className='MouseOutBox1';
	obj2.className='MouseOutBox2';
	img.style.display='none';
}

function fnMenuOver_Template(obj1,obj2,img){
	obj1.className='MouseOverBox1_Template';
	obj2.className='MouseOverBox2_Template';
	img.style.display='block';
}
function fnMenuOut_Template(obj1,obj2,img){
	obj1.className='MouseOutBox1_Template';
	obj2.className='MouseOutBox2_Template';
	img.style.display='none';
}

