function go(url,target){
	if (target == null) {
		window.open(url,'_self');
	} else {
	window.open(url,target);
	}
}
function display(what){
	document.getElementById(what).style.display=''
}
function hide(what){
	document.getElementById(what).style.display='none'
}
function displayHide(what){
	document.getElementById(what).style.display = document.getElementById(what).style.display == 'none' ? '' : 'none';
}
function makeSort(source,target){
	document.getElementById(target).innerHTML=document.getElementById(source.id).innerHTML;
	for (i=1;i<=4;i++){
		document.getElementById('sortList'+i).className='sortIt0';
	}
	document.getElementById(source.id).className='sortIt1';
}
function setLocation(){
	if(document.advSearch.selLoc.selectedIndex==1 || document.advSearch.selLoc.selectedIndex==2){
				document.getElementById('selWayT').style.color='#a8b38c';
		document.advSearch.sellWay.disabled=true;		
		document.getElementById('selAucT').style.color='#a8b38c';
		document.advSearch.selAuc.disabled=true;
	} else {
		document.getElementById('selAucT').style.color='#4b6208';
		document.advSearch.selAuc.disabled=false;
				document.getElementById('selWayT').style.color='#4b6208';
		document.advSearch.sellWay.disabled=false;
	}
}
function setModel(){
	if(document.advSearch.brandsListSel.selectedIndex==0){
		document.getElementById('modelsListSelT').style.color='#a8b38c';
		document.advSearch.modelsListSel.disabled=true;
	} else {
		document.getElementById('modelsListSelT').style.color='#4b6208';
		document.advSearch.modelsListSel.disabled=false;	
	}
}
function setFlashHeight(alto){
	document.getElementById("flashcontent").style.height = alto + 'px';
}

function setClass(sourceId,targetClass){
	document.getElementById(sourceId).className=targetClass;
}

//----------------------------------------------------------------- real mof functions
function sField(field, val) {
	if (document.getElementById(field.id).value==val) {
	    document.getElementById(field.id).value = "";
	    document.getElementById(field.id).className = 'Search';
	} else if (document.getElementById(field.id).value.replace(/ /g, '').length == 0) {
	document.getElementById(field.id).value = val;
	document.getElementById(field.id).className = 'Search';
	}
}


//KEYBOARD FUNC
eng = new Array(97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 87, 82, 84, 83, 67, 74, 90);
geo = new Array(4304, 4305, 4330, 4307, 4308, 4324, 4306, 4336, 4312, 4335, 4313, 4314, 4315, 4316, 4317, 4318, 4325, 4320, 4321, 4322, 4323, 4309, 4332, 4334, 4327, 4310, 4333, 4326, 4311, 4328, 4329, 4319, 4331, 91, 93, 59, 39, 44, 46, 96);


function keyfilter_num(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}

function keyfilter_dig(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}

function ValidEmail(EmailAddr) {
    var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
    var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

    var SpecChar = "!#$%^&*()'+{}[]\|:;?/><,~`" + "\"";
    var frmValue = new String(EmailAddr);
    var len = frmValue.length;

    if (len < 1) { return false; }
    for (var i = 0; i < len; i++) {
        temp = frmValue.substring(i, i + 1)
        if (SpecChar.indexOf(temp) != -1) {
            return false;
        }
    }

    if (!reg1.test(frmValue) && reg2.test(frmValue)) {
        return true;
    }

    return false;
}

function keyfilter_alnum(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (!((charCode >= 48 && charCode <= 57) || (charCode >= 97 && charCode <= 122) || (charCode >= 65 && charCode <= 90) || charCode == 95)) {
        status = "This field accepts 'a'-'z','A'-'Z','0'-'9' and '_' only."
        return false
    }
    status = ""
    return true
}

function makeGeo(ob, e) {
    code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;

    if (code == 96) {
        document.getElementById('geoKeys').checked = !document.getElementById('geoKeys').checked;
        return false;
    }

    if (e.which == 0) return true;

    if (!document.getElementById('geoKeys').checked) return true;



    //alert(' e.keyCode='+e.keyCode+'\n'+'e.which='+e.which+'\n'+'e.charCode='+e.charCode);

    var found = false;
    for (i = 0; i <= geo.length; i++) {
        if (eng[i] == code) {
            c = geo[i];
            found = true;
        }
    }

    if (found) {
        if (document.selection) {
            sel = document.selection.createRange();
            sel.text = String.fromCharCode(c);
        } else {
            if (ob.selectionStart || ob.selectionStart == '0') {
                var startPos = ob.selectionStart;
                var endPos = ob.selectionEnd;
                ob.value = ob.value.substring(0, startPos) + String.fromCharCode(c) + ob.value.substring(endPos, ob.value.length);
                ob.selectionStart = startPos + 1;
                ob.selectionEnd = endPos + 1;
            } else {
                //ob.value = ob.value + String.fromCharCode(c);
                return true;
            }
        }
        return false;
    } else {
        return true;
    }

}

//Helix Functions


//second
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18227995-1']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


// Third
var MainError = 'Some mandatory field is empty or inncorect';
var MandatoryField = 'Field is mandatory';
var TaxpayerID = 'Incorect ID';
var TermRange = 'Between 0-120 month';

//infratab func

var initialtab = [1, "sc0"]

////////Stop editting////////////////

function cascadedstyle(el, cssproperty, csspropertyNS) {
    if (el.currentStyle)
        return el.currentStyle[cssproperty]
    else if (window.getComputedStyle) {
        var elstyle = window.getComputedStyle(el, "")
        return elstyle.getPropertyValue(csspropertyNS)
    }
}

var previoustab = ""

function expandcontent(cid, aobject) {
    if (document.getElementById) {
        highlighttab(aobject)
        detectSourceindex(aobject)
        if (previoustab != "")
            document.getElementById(previoustab).style.display = "none"
        document.getElementById(cid).style.display = "block"
        previoustab = cid
        if (aobject.blur)
            aobject.blur()
        return false
    }
    else
        return true
}

function highlighttab(aobject) {
    if (typeof tabobjlinks == "undefined")
        collecttablinks()
    for (i = 0; i < tabobjlinks.length; i++)
        tabobjlinks[i].style.backgroundColor = initTabcolor
    var themecolor = aobject.getAttribute("theme") ? aobject.getAttribute("theme") : initTabpostcolor
    aobject.style.backgroundColor = document.getElementById("tabcontentcontainer").style.backgroundColor = themecolor
}

function collecttablinks() {
	if (document.getElementById("tablist")) {
		var tabobj = document.getElementById("tablist");
		tabobjlinks = tabobj.getElementsByTagName("A");
	}
}

function detectSourceindex(aobject) {
    for (i = 0; i < tabobjlinks.length; i++) {
        if (aobject == tabobjlinks[i]) {
            tabsourceindex = i //source index of tab bar relative to other tabs
            break
        }
    }
}

function do_onload() {
    var cookiename = (typeof persisttype != "undefined" && persisttype == "sitewide") ? "tabcontent" : window.location.pathname
    var cookiecheck = window.get_cookie && get_cookie(cookiename).indexOf("|") != -1
    collecttablinks()
    if (typeof tabobjlinks !== 'undefined') {
    	initTabcolor = cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
    	initTabpostcolor = cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
    }
    if (typeof enablepersistence != "undefined" && enablepersistence && cookiecheck) {
    	var cookieparse = get_cookie(cookiename).split("|")
    	var whichtab = cookieparse[0]
    	var tabcontentid = cookieparse[1]
    	expandcontent(tabcontentid, tabobjlinks[whichtab])
    }
    else {
    	if (typeof tabobjlinks !== 'undefined') {
    		expandcontent(initialtab[1], tabobjlinks[initialtab[0] - 1])
    	}
    }
}

if (window.addEventListener)
    window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
    window.attachEvent("onload", do_onload)
else if (document.getElementById)
    window.onload = do_onload



    /*omg*/


var initialtab1 = [1, "sc1"]


////////Stop editting////////////////

function cascadedstyle1(el, cssproperty, csspropertyNS) {
    if (el.currentStyle)
        return el.currentStyle[cssproperty]
    else if (window.getComputedStyle) {
        var elstyle = window.getComputedStyle(el, "")
        return elstyle.getPropertyValue(csspropertyNS)
    }
}

var previoustab = ""

function expandcontent1(cid, aobject) {
    if (document.getElementById) {
        highlighttab1(aobject)
        detectSourceindex1(aobject)
        if (previoustab != "")
            document.getElementById(previoustab).style.display = "none"
        document.getElementById(cid).style.display = "block"


        previoustab = cid
        if (aobject.blur)
            aobject.blur()
        return false
    }
    else
        return true
}

function highlighttab1(aobject) {
    if (typeof tabobjlinks == "undefined")
        collecttablinks1()
    for (i = 0; i < tabobjlinks.length; i++)
        tabobjlinks[i].style.backgroundColor = initTabcolor
    var themecolor = aobject.getAttribute("theme") ? aobject.getAttribute("theme") : initTabpostcolor
    aobject.style.backgroundColor = document.getElementById("tabcontentcontainer1").style.backgroundColor = themecolor
}

function collecttablinks1() {
	if (document.getElementById("tablist1")) {
		var tabobj = document.getElementById("tablist1");
		tabobjlinks = tabobj.getElementsByTagName("A");
	}
}

function detectSourceindex1(aobject) {
	if (tabobjlinks) {
		for (i = 0; i < tabobjlinks.length; i++) {
			if (aobject == tabobjlinks[i]) {
				tabsourceindex = i //source index of tab bar relative to other tabs
				break
			}
		}
	}
}

function do_onload1() {
    var cookiename = (typeof persisttype != "undefined" && persisttype == "sitewide") ? "tabcontent" : window.location.pathname
    var cookiecheck = window.get_cookie && get_cookie(cookiename).indexOf("|") != -1
    collecttablinks1()
    if (typeof tabobjlinks !== 'undefined') {
    	initTabcolor = cascadedstyle1(tabobjlinks[1], "backgroundColor", "background-color");
    	initTabpostcolor = cascadedstyle1(tabobjlinks[0], "backgroundColor", "background-color")
	}
	if (typeof enablepersistence != "undefined" && enablepersistence && cookiecheck) {
		var cookieparse = get_cookie(cookiename).split("|")
		var whichtab = cookieparse[0]
		var tabcontentid = cookieparse[1]
		expandcontent1(tabcontentid, tabobjlinks[whichtab])
	}
	else {
		if (typeof tabobjlinks !== 'undefined') {
			expandcontent1(initialtab1[1], tabobjlinks[initialtab1[0] - 1])
		}
	}
}

if (window.addEventListener)
    window.addEventListener("load", do_onload1, false)
else if (window.attachEvent)
    window.attachEvent("onload", do_onload1)
else if (document.getElementById)
    window.onload = do_onload


//LIGHTBOX BEGINS

var fadeOpacity = new Array();
var fadeTimer = new Array();
var fadeInterval = 15;  // milliseconds

function fade(o, d) {
    // o - Object to fade in or out.
    // d - Display, true =  fade in, false = fade out

    var obj = document.getElementById(o);

    if ((fadeTimer[o]) || (d && obj.style.display != 'block') || (!d && obj.style.display == 'block')) {
        if (fadeTimer[o])
            clearInterval(fadeTimer[o]);
        else
            if (d) fadeOpacity[o] = 0;
            else fadeOpacity[o] = 9;

        obj.style.opacity = "." + fadeOpacity[o].toString();
        obj.style.filter = "alpha(opacity=" + fadeOpacity[o].toString() + "0)";

        if (d) {
            obj.style.display = 'block';
            fadeTimer[o] = setInterval('fadeAnimation("' + o + '",1);', fadeInterval);
        } else
            fadeTimer[o] = setInterval('fadeAnimation("' + o + '",-1);', fadeInterval);
    }
}

function fadeAnimation(o, i) {
    // o - o - Object to fade in or out.
    // i - increment, 1 = Fade In

    var obj = document.getElementById(o);
    fadeOpacity[o] += i;
    obj.style.opacity = "." + fadeOpacity[o].toString();
    obj.style.filter = "alpha(opacity=" + fadeOpacity[o].toString() + "0)";

    if ((fadeOpacity[o] == '9') | (fadeOpacity[o] == '0')) {
        if (fadeOpacity[o] == '0')
            obj.style.display = 'none';
        else {
            obj.style.opacity = "1";
            obj.style.filter = "alpha(opacity=100)";
        }

        clearInterval(fadeTimer[o]);
        delete (fadeTimer[o]);
        delete (fadeTimer[o]);
        delete (fadeOpacity[o]);
    }
}
