﻿var ie = (navigator.userAgent.indexOf("MSIE") > -1);
var d = document;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var path = '/';

//var sitePath = '/csmain/';
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function confirmNewPassword() {
    var np = document.getElementById('txtNewPassword');
    var ncp = document.getElementById('txtConfirmNewPassword');
    if (np.value == "" || ncp.value == "") { 
        alert('Both fields are required');
        if (np.value == "") {
            np.focus();        
        } else {
            ncp.focus();
        }
        return false;
    } else if (np.value != ncp.value) { 
        alert('Password fields do not match');
        return false;
    } else if (np.value.length < 6) {
        alert('Password must be 6 characters in length');
        return false;
    } else {
        document.getElementById('err').innerHTML = "Updating Password...";
        return true;
    }
}
function validateEmail(email) {
    return (filter.test(email));
}
function jumpNav(url) {
    document.location.href = sitePath + url;
}
function jumpNav2(url, local) {
    if (local==1) {
        window.open(url);
    } else {
        document.location.href = url;
    }
}
function jumpDomain(obj, autoId) {
    var domainStr = obj.options[obj.selectedIndex].value;
    if (domainStr.indexOf(".") > -1)
        window.parent.location = "http://"+domainStr+"?autoID="+autoId;
    else
        window.parent.location = "http://"+domainStr+".conceptshare.com?autoID="+autoId;
}
function simDoPostBack(eventTarget, eventArgument)  {
    var theForm = document.forms['form1'];
    if (!theForm) { theForm = document.form1; }
    theForm.__EVENTTARGET.value = eventTarget;
	theForm.__EVENTARGUMENT.value = eventArgument;
	theForm.submit();
}
function setInnerText(obj, text) {
    if (document.all)
        obj.innerText = text;
    else
        obj.textContent = text;
}
function SwapCSS(obj, newClass) {
    if (obj) {
        obj.oldCss = obj.className;
        obj.className = newClass;
    }
}
function RestoreCSS(obj) {
    if (obj && obj.oldCss)
        obj.className = obj.oldCss;
}
function emailUs(email) {
    var domain = 'conceptshare.com';
	window.location.href = "mailto:"+email+"@"+domain;
}
function addEmail(email, num) {
    var domain = 'conceptshare.com';
    d.getElementById('email'+num).innerHTML = email+"@"+domain;
}
function apiCall1(funcName, var1) {
    var api = document.getElementById('api');
    if (api) api.src = sitePath + "API/api.aspx?f=" + funcName + "&p1=" + escape(var1);
}
function apiCall2(funcName, var1, var2) {
    var api = document.getElementById('api');
    if (api) api.src = sitePath + "API/api.aspx?f=" + funcName + "&p1=" + escape(var1) + "&p2=" + escape(var2); 
}
function apiCall3(funcName, var1, var2, var3) {
    var api = document.getElementById('api');
    if (api) api.src = sitePath + "API/api.aspx?f=" + funcName + "&p1=" + escape(var1) + "&p2=" + escape(var2) + "&p3=" + escape(var3);
}
function submitOnEnter(e, eventTarget, eventArgument) {
    var key = (ie)? event.keyCode : e.which;
    if (key==13)
        simDoPostBack(eventTarget,eventArgument);
}
/* LOGIN & LIGHTBOX */
function userLogin() {
    popupLB("https://www.conceptshare.com/login/", 350, 200);
}
function popupLB(url,_w,_h) {
    if (d.getElementById('flashmovie')) {
        d.getElementById('flashmovie').style.display = "none";
    }
    bdy = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
    bdy.id = "layerControl";
    frameControl = d.createElement("iframe");
    frameControl.src = path+"blank.htm";
    frameControl.id = "iframeLayer";
    frameControl.frameBorder = 0;
    frameControl.setAttribute("frameborder", "0");
    frameControl.style.height = d.documentElement.scrollHeight + "px";
    bdy.appendChild(frameControl);
    bdy = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
    bdy.id="jsEventContainer";
    iframe = d.createElement("iframe");
    iframe.src = url;
    iframe.id = "iframeLayer2";
    iframe.frameBorder = 0;
    iframe.setAttribute("frameborder", "0");
    iframe.setAttribute("scrolling", "no");
    iframe.style.top = (d.documentElement.scrollTop+120) + "px";
    iframe.style.width = _w + "px";
    iframe.style.height = _h +"px";
    iframe.style.left = (d.documentElement.scrollWidth - _w)/2 + "px";
    bdy.appendChild(iframe);
}
function cancelLogin() {
    if (d.getElementById('flashmovie')) {
        d.getElementById('flashmovie').style.display = "block";
    }
	d = window.top.document;
	if (d.getElementById("jsEventContainer"))
	    d.getElementsByTagName("body")[0].removeChild(d.getElementById("jsEventContainer"));
	if (d.getElementById("layerControl"))
	    d.getElementsByTagName("body")[0].removeChild(d.getElementById("layerControl"));
	if (d.getElementById("field")) {
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("field"));
	}
}
function processForm()  {
	var e = document.getElementById("txtEmail");
	var pass = document.getElementById('txtPassword');
	if (!validateEmail(e.value)) {
		alert('Invalid Email Address.');
		e.focus();
		return false;
	} else if (pass.value == "") {
	    alert('You must supply a password.');
	    pass.focus();
	    return false;
	}
	return true;
}
function submitLoginForm(e, Obj) {
	var e1 = d.getElementById("txtEmail");
	var e2 = d.getElementById("txtPassword");
    var key = (ie)? event.keyCode : e.which;
    if (e2.value!="" && key==13 && validateEmail(e1.value)) {
        simDoPostBack(Obj,'');
    }
}
function forgotPassword() {
    var e = document.getElementById("txtEmail");
    if (!validateEmail(e.value)) {
		alert('Invalid Email Address.');
		e.focus();
		return false;
	}
	return true;
}
function attachInputEvents() {
    var inputs = d.getElementsByTagName('input');
    for (i=0;i<inputs.length;i++) {
        if (inputs[i].type=="text" || inputs[i].type=="password") {
            inputs[i].onfocus = function () { this.style.border = '1px solid #3D7BAD'};
            inputs[i].onblur = function () { this.style.border = '1px solid #ABADB3'};
        }
    }    
    var textarea = d.getElementsByTagName('textarea');
    for (i=0;i<textarea.length;i++) {
           textarea[i].onfocus = function () { this.style.border = '1px solid #3D7BAD'};
           textarea[i].onblur = function () { this.style.border = '1px solid #ABADB3'};
    }
}