i = 0
var speed = 3


function getElem(id){
    if( document.getElementById ){ // this is the way the standards work
        elem = document.getElementById( id );
    }
    else if( document.all ){ // this is the way old msie versions work
        elem = document.all[id];
    }
    else if( document.layers ){ // this is the way nn4 works
        elem = document.layers[id];
    }
    return elem;
}


function validateSearch(){
    elem= getElem("q");  
    if(elem.value.length==0){
        alert("Sorry you first have to add criteria to search on");
        elem.focus();
        return false;
    }
    return true;
}
function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}
function setCurrentNum(curr, total, maxrows){ 
//    tot = getElem("total").innerText;
    if(curr==0){ curr=1;  }
    num=parseInt(curr)+parseInt(maxrows);
    if(num>total){
        num=total-maxrows;
    }
    elem = getElem("CurrentNum");
    if(num!=0){
        if(document.all){
            elem.innerText = (num-1);
        } else{
            elem.textContent = (num-1);
        }
    }
}
function setTotalNum(num){
    elem= getElem("total");
    if(document.all){
        elem.innerText = num;
    } else{
        elem.textContent = num;
    }

    elem.innerText=num;
}
function changeImage(name){
    src=getElem(name).src;
    src_array=src.split('/');
   
    switch(src_array[src_array.length-1]){
        case "buynow_up.png": getElem(name).src="images/buynow_Down.png"; break;
        case "buynow_Down.png": getElem(name).src="images/buynow_up.png"; break;
        case "download_up.png": getElem(name).src="images/download_Down.png"; break;
        case "download_Down.png": getElem(name).src="images/download_up.png"; break;
    }
}
function setTotalLinks(val){
    // getElem("total").innerText=val;
}
function scroll() {
    i = i + speed;
    var div1 = getElem("top10Screen");
    var div2 = getElem("RecentlyAddedScreen");
    div1.scrollTop = i;
    div2.scrollTop = i;
    if ((i > div1.scrollHeight - 140)||(i > div2.scrollHeight - 140)) {i = 0;}
    t1=setTimeout("scroll()",100);
}
function ValiComment(frm){
    var len =frm.comment.value.length;
    if(len==0){
        alert("Sorry you have not added a comment");
        frm.comment.focus();
        return false;
    }
    if(frm.email.value!=""){
        if(!validateEmail(frm.email.value)){
            alert("Sorry Email format error please re check and submit again.")
            frm.email.focus();
            return false;
        }
    }
    return true;
}

