var currentUrl=location.href;
var siteUrl = "http://" + document.domain;

/*************TEST IF AJAX WORKS************/
function getXhttp ( ){
    var ajax_request;
    if(window.ActiveXObject){
        var mSoftVersions = [
        'MSXML2.DOMDocument.5.0',
        'MSXML2.DOMDocument.4.0',
        'MSXML2.DOMDocument.3.0',
        'MSXML2.DOMDocument.2.0',
        'MSXML2.DOMDocument',
        'Microsoft.XmlDom',
        'Msxml2.XMLHTTP',
        'Microsoft.XMLHTTP'];
        for(i=0;i<mSoftVersions.length;i++){
            try {
                ajax_request = new ActiveXObject (mSoftVersions[i]);
            }
            catch (e){
            }
        }
    }
    else if(!ajax_request && typeof XMLHttpRequest!='undefined'){
        try {
            ajax_request = new XMLHttpRequest();
        }
        catch (e){
        }
    }
    else if(!ajax_request && window.createRequest){
        try {
            ajax_request = window.createRequest;
        }
        catch (e){
        }
    }
    else{
        ajax_request = false;
    }
    return ajax_request;
}
/*
Cross browser Marquee II- � Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS, visit http://www.dynamicdrive.com
Modified by jscheuer1 for continuous content. Credit MUST stay intact for use
 */

//Specify the marquee's width (in pixels)
var marqueewidth="100%"
//Specify the marquee's height
var marqueeheight="118px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=1
//Specify initial pause before scrolling in milliseconds
var initPause=2000
//Specify start with Full(1)or Empty(0) Marquee
var full=1
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1
//Specify Break characters for IE as the two iterations
//of the marquee, if text, will be too close together in IE
var iebreak='<p></p>'

//Specify the marquee's content
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):




////NO NEED TO EDIT BELOW THIS LINE////////////
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
var actualheight=''
var cross_marquee, cross_marquee2, ns_marquee

function populate(){
    if (iedom){
        var lb=document.getElementById&&!document.all? '' : iebreak
        cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
        cross_marquee2=document.getElementById? document.getElementById("iemarquee2") : document.all.iemarquee2
        cross_marquee.style.top=(full==1)? '8px' : parseInt(marqueeheight)+8+"px"
        cross_marquee2.innerHTML=cross_marquee.innerHTML=marqueecontent+lb
        actualheight=cross_marquee.offsetHeight
        cross_marquee2.style.top=(parseInt(cross_marquee.style.top)+actualheight+8)+"px" //indicates following #1
    }
    else if (document.layers){
        ns_marquee=document.ns_marquee.document.ns_marquee2
        ns_marquee.top=parseInt(marqueeheight)+8
        ns_marquee.document.write(marqueecontent)
        ns_marquee.document.close()
        actualheight=ns_marquee.document.height
    }
    setTimeout('lefttime=setInterval("scrollmarquee()",20)',initPause)
}


function scrollmarquee(){

    if (iedom){
        if (parseInt(cross_marquee.style.top)<(actualheight*(-1)+8))
            cross_marquee.style.top=(parseInt(cross_marquee2.style.top)+actualheight+8)+"px"
        if (parseInt(cross_marquee2.style.top)<(actualheight*(-1)+8))
            cross_marquee2.style.top=(parseInt(cross_marquee.style.top)+actualheight+8)+"px"
        cross_marquee2.style.top=parseInt(cross_marquee2.style.top)-copyspeed+"px"
        cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
    }

    else if (document.layers){
        if (ns_marquee.top>(actualheight*(-1)+8))
            ns_marquee.top-=copyspeed
        else
            ns_marquee.top=parseInt(marqueeheight)+8
    }
}

function js_refreshContent(obj){
    if(obj){
        objName = obj.getAttribute("name");
        parentForm = findParentForm(obj);
        formName =  parentForm.getAttribute("name");
        origAction = parentForm.getAttribute("action");
        if(origAction.search(/\?/)==-1){
            if(document.URL.search(/\?/)==-1){
                origAction = document.URL + "?";
            }
            else{
                origAction = document.URL;
            }
        }

        if(objName=="educationfield"){
            value = obj.options[obj.selectedIndex].value;
            finalValue = (value.split('_'))[0];
            try{
                if(document.URL.search(/collegeid/)!=-1 || parentForm.review2college.value!=""){
                    if(confirm("Changing the Education Field will reset the college you have selected. Are you sure you want to continue?")){
                        origAction = origAction.replace(/&collegeid=[^&]*/,"");
                        parentForm.review2college.value="";
                    }
                    else
                        return false;
                }
            }
            catch (e){
                origAction = origAction;
            }
            if(origAction.search("form=")==-1){
                origAction =origAction + "form="+formName;
            }
            else{
                origAction =origAction.replace(/form=([^&]+)/,"form="+formName)
            }
            if(origAction.search("&educationfield=")==-1){
                origAction =origAction + "&educationfield="+finalValue;
            }
            else{
                origAction =origAction.replace(/&educationfield=([^&]+)/,"&educationfield="+finalValue);
            }
            parentForm.action = origAction;
            parentForm.submit();
        }
        else if(objName=="changeCollege"){
            try{
                if(document.URL.search(/collegeid/)!=-1){
                    origAction = origAction.replace(/&collegeid=[^&]*/,"");
                    parentForm.review2college.value="";
                }
            }
            catch (e){
                origAction = origAction;
            }
            parentForm.action = origAction;
            
            parentForm.submit();
        }
    }
}
function findParentForm(obj){
    while(obj.parentNode){
        obj = obj.parentNode;
        if(obj.nodeName.match("FORM")){
            return obj;
        }
    }
    return false;
}
var MAX_DUMP_DEPTH = 10;



function dumpObj(obj, name, indent, depth) {
    if (depth > MAX_DUMP_DEPTH) {
        return indent + name + ": <Maximum Depth Reached>---";
    }
    if (typeof obj == "object") {
        var child = null;
        var output = indent + name + "---";
        indent += "\t";
        for (var item in obj)
        {
            try {
                child = obj[item];
            } catch (e) {
                child = "<Unable to Evaluate>";
            }
            if (typeof child == "object") {
                output += dumpObj(child, item, indent, depth + 1);
            } else {
                output += indent + item + ": " + child + "---";
            }
        }
        return output;
    } else {
        return obj;
    }
}
function dumptr(){
    trs = document.getElementsByTagName("TR");
    //doutput = dumpObj(obj.style, "TR", "\t", 0);
    //alert(doutput);
    //alert(obj.style.border);
    str ="border: ";
    for(i=0;i++;i<trs.length){
        objtr = trs[i];
        str = str + objtr.style.border;
        alert(i);
    }
    alert(str);
    
}
var ajaxReq;
var ajaxResponse;
loadingContent = "<div class=\"loading message\">Loading...</div>"
iframeContent = "<iframe src=\"%target_loc%\" class=\"iframe\" id=\"dynamic_iframe\" frameborder=\"0\"></iframe>";
function loadIframe(id,obj){
    container = document.getElementById(id);
    container.innerHTML="";
    container.innerHTML=loadingContent;
    targetLocation = obj.getAttribute("href");
    if(document.URL.search(/\?/)==-1){
        targetLocation = targetLocation + "&ajax=true";
    }
    else{
        targetLocation = targetLocation + "?ajax=true";
    }
    container.innerHTML = iframeContent.replace("%target_loc%",targetLocation);
    return false;
//location.href = targetLocation;
}
function writeContent(id,content){
    document.getElementById(id).innerHTML = content;
}
function ajaxOpenUrl(url,id){
    ajaxReq = getXhttp( );
    ajaxResponse ="";
    if ( !ajaxReq ){
        alert("error");
    } //Usually you alert something but I don't :d
    //show('submitformloading');
    ajaxReq.onreadystatechange=function(){
        if(ajaxReq.readyState==4){
            ajaxResponse=ajaxReq.responseText;
            alert(ajaxResponse);
            if(ajaxResponse!=""){
                writeContent(id,ajaxResponse);
            }

        }
    };
    ajaxReq.open('POST',url);
    ajaxReq.send(null);
//ANYTHING EXTRA IS ADDED HERE.
}
function clearForm(){
    thisform=document.getElementById("submitform");
    with(thisform)	{
        name.value="";
        email.value="";
        url.value="http://";
        category.selectedIndex=0;
        }
}

/**************ajax submit Form***************/
var focusid=false;
function displayError(field){
    var errorStringFormat=errorhandles.error;
    if(field.getAttribute("id")=="domain"){
        errorString=errorStringFormat.replace("%desc%","Duplicate Domain!");
    }
    else{
        errorString=errorStringFormat.replace("%desc%",errorhandles[field.getAttribute("id")]);
    }
    document.getElementById(''+ field.getAttribute("id")+'check').innerHTML=errorString;
    //var oldcontent=document.getElementById('jnotice').innerHTML;
    document.getElementById('jnotice').innerHTML+="<p>"+errorhandles[field.getAttribute("id")]+"</p>";
    if(focus===false){
        field.focus();
        focusid=field.getAttribute("id");
    }
}
function hide(id){
    if(document.getElementById(id)){
        document.getElementById(id).style.display="none";
    }
    else{
        id.style.display="none";
    }
    return true;
}
function show(id){
    if(document.getElementById(id)){
        document.getElementById(id).style.display="block";
    }
    else{
        id.style.display="block";
    }
    return true;
}
var xml;
var xmlAbort=false;
function closeAjaxSubmit(){
    xmlAbort=true;
    xml.abort();
    hide('submitformloading');
}
/*
function ajaxSubmit2(obj){
    var ajax =false;
    if(ajax==true){
        alert("Hello");
    }else{
        obj.submit();
    }
    return false;
}

function ajaxSubmit(thisform){
    var status=true;
    myfocus=false;
    with(thisform){
        document.getElementById("jnotice").innerHTML=errorhandles.jnotice;
        if(validate_required(name)==false){
            status=false;
        }
        //if(validate_required(email,"Email must be filled out!")==false){status=false;}
        if(echeck(email.value)==false){
            status=false;
        }
        if(validate_url(url)==false){
            status=false;
        }
        if(validate_required(category)==false){
            status=false;
        }
        if(status==false){
            document.getElementById("jnotice").innerHTML+="<center><input type='button' onclick='hide(\"jnotice\");document.getElementById(\""+focusid+"\").focus();' value='Try Again!' class='mybutton' /></center>";
            show("jnotice");
            return false;
        }
        }
    xml = getXhttp( );
    if ( !xml ){
        alert("error");
    } //Usually you alert something but I don't :d
    show('submitformloading');
    xml.onreadystatechange=function(){
        if(xml.readyState==4){
            if(xmlAbort===false){
                var response=xml.responseText;
                if(response=="success"){
                    hide('submitformloading');
                    hide('submitform');
                    clearForm();
                    show('submitsuccess');
                }
                else{
                    //alert(response);
                    var errors=response.split("&");
                    focusid=false;
                    document.getElementById("jnotice").innerHTML=errorhandles.jnotice;
                    for(i=0;i<errors.length;i++){
                        if(errors[i]!="infowrong"){
                            if(document.getElementById(errors[i]+"check")){
                                displayError(document.getElementById(errors[i]));
                            }
                            else{
                                document.getElementById('jnotice').innerHTML+=errorhandles[errors[i]];
                            }
                        }

                    }
                    document.getElementById("jnotice").innerHTML+="<center><input type='button' onclick='hide(\"jnotice\");document.getElementById(\""+focusid+"\").focus();' value='Try Again!' class='mybutton' /></center>";
                    hide('submitformloading');
                    show('jnotice');
                }
            }
        }
        else{
            xmlAbort=false;
        }
    };
    var name = document.getElementById('name').value;
    var email = document.getElementById('email').value;
    var url = document.getElementById('url').value;
    var category = document.getElementById('category').value;
    xml.open('POST',siteUrl+'submit.php');
    xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xml.send('name=' + name + '&email=' + email + '&url=' + url+ '&category=' + category + '&media=ajax' + '&action=submit');
//ANYTHING EXTRA IS ADDED HERE.
}
function validate_required(field)
{
    with (field)
    {
        if (value==null||value==""||value==" ")
        {
            displayError(field);return false;
        }
        else {
            removeError(field);return true
        }
        }
}

function removeError(field){
    document.getElementById(''+ field.getAttribute("id")+'check').innerHTML="";
}
function validate_url(field)
{
    with (field)
    {
        if (value==null||value==""||value=="http://"|| value.search(/\./)==-1)
        {
            displayError(field);return false;
        }
        else {
            removeError(field);return true
        }
        }
}

*/
function adjustIFrameSize(iframeWindow) {
    try{
        if (iframeWindow.document.height) {
        
            var iframeElement = document.getElementById ("dynamic_iframe");
            iframeElement.style.height = iframeWindow.document.height + 10 + 'px';
            iframeElement.style.width = iframeWindow.document.width + 'px';
        } else if (document.all) {
            iframeElement = document.all["dynamic_iframe"];
            iframeElement.style.height = "0px";//hack for ie..resetting iframe height;
            if (iframeWindow.document.compatMode &&
                iframeWindow.document.compatMode != 'BackCompat') {
                iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
                iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
            } else {
                iframeElement.style.height = iframeWindow.document.body.scrollHeight + 5 + 'px';
                iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
            }
        }
    }
    catch (e){
        error = e;
    }
}
