﻿// Used in ProductDetail to switch image
function replaceImg (imgFilename, imgPath) {
    document.getElementById("imgCurrentImage").src = imgPath + 'resized_'+imgFilename;
    //document.getElementById("imgCurrentImage").setAttribute("onclick", "window.open('"+imgPath+"big_"+imgFilename+"', 'hehj');"); 
}


// Select all checkboxes in a gridview - used in many of the ListXXX.aspx pages.
function SelectAllCheckboxes(spanChk){
    // Added as ASPX uses SPAN for checkbox
    var oItem = spanChk.children;
    var theBox= (spanChk.type=="checkbox") ? spanChk : spanChk.children.item[0];
    xState=theBox.checked;
    elm=theBox.form.elements;

    for(i=0;i<elm.length;i++)
    {
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
        {
            //elm[i].click();
            if(elm[i].checked!=xState)
                elm[i].click();
                //elm[i].checked=xState;
        }
    }
}

function OpenCompetition()
{
        var popup = window.open("http://test.verticportals.com/tapeconnection/auction/Default.aspx", "Competition", "directories=no, height=520, width=1000, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");
		popup.focus();
}

// Dynamically add html elements an name them - used eg. on CreateArticle.aspx for adding Wordexplanations.
function addElement() {
    document.getElementById('exHeader').style.visibility = "visible";
    var ni = document.getElementById('explanations');
    var numi = document.getElementById('theValue');
    var num = (document.getElementById('theValue').value -1)+ 2;
    numi.value = num;
    var newdiv = document.createElement('div');
    var divIdName = 'exDiv_'+num;
    newdiv.setAttribute('id',divIdName);
    var exWordInput = "<input title=\"Ord\" class=\"exWordInput left\" type=\"text\" name=\"exWord_"+num+"\" id=\"exWord_"+num+"\" /> ";
    var exInput =  " <textarea rows=\"2\" cols=\"10\" class=\"exInput left\" name=\"ex_"+num+"\" id=\"ex_"+num+"\"></textarea>";
    var removeLink = " <a href=\"javascript:;\" class=\"left\" onclick=\"removeElement('"+divIdName+"', 'explanations')\">slet</a>";
    newdiv.innerHTML = exWordInput + exInput + removeLink;
    ni.appendChild(newdiv);
} 

function addImgElement(imgId, imgFileName) {
    var ni = document.getElementById('images');
    var numi = document.getElementById('imgCount');
    var num = (document.getElementById('imgCount').value -1)+ 2;
    numi.value = num;
    
    var newdiv = document.createElement('div');
    var divIdName = 'imgDiv_'+num;
    newdiv.setAttribute('className', 'image_thumb');
    newdiv.setAttribute('id',divIdName);
    var img = "<img src=\"../Media/Image/PictureArchive/thumb_"+imgFileName+"\" alt='' />";
    var imgInputId = "<input type=\"hidden\" value=\""+imgId+"\" name=\"img_"+num+"\" /> ";
    var removeLink = "<a href=\"javascript:;\" onclick=\"removeElement('"+divIdName+"', 'images')\">slet</a>";
    newdiv.innerHTML = imgInputId + img + removeLink;
    ni.appendChild(newdiv);
} 

function removeElement(divNum, divContainer) {
    var d = document.getElementById(divContainer);
    var olddiv = document.getElementById(divNum);
    d.removeChild(olddiv);
}