﻿ var timerID, global, globalS;
global=0;
globalS=0;
checkboxs = 0;
mainCheckboxs = 2;
  
function HideTable(tr_id){ document.getElementById(tr_id).style.display = "none";}
function ShowTable(tr_id){document.getElementById(tr_id).style.display = "";}
function jsfDo()
{
//        var sPath = window.location.pathname;
//        //var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
//        var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
//        if(sPage == 'Default.aspx')
//            alert(sPage)
//        else
//            alert(sPage)
            //document.getElementById('register_body').style.display = "none";
            
    var obj = document.getElementById('td_main');
    if (obj != null)
        obj.style.display = "none";
     
    obj = document.getElementById('home_content_bottom');
    if (obj != null)
        obj.style.display = "none";

   obj = document.getElementById('td_temp');
   if (obj != null)
   {
        obj.style.height= "500px";
        obj.innerHTML = "<table><tr><td colspan=\"2\" style=\"height:50px\">&nbsp;</td></tr><tr><td align='center' id='td_load'></td></tr><tr><td align=\"center\" id='td_timer' style=\"color:#484848\"></td></tr><tr><td style='padding:100px 100px 100px 100px'>&nbsp;</td></tr></table>";
   }

    obj = document.getElementById('td_load');
    if (obj != null)
        obj.innerHTML = document.getElementById('td_loading').innerHTML;
}

function ShowAnimated(id)
{

    var elem = document.getElementById(id);
   
    if(elem)
    {
        if(elem.style.display == 'none')
            elem.style.display = 'block';
        else if(elem.style.display=='')
            elem.style.display='block';
       else  elem.style.display='none';
        
    }
}


function Inc(c_id)
{
    switch(c_id)
    {
        case "cb_msn_com":
            if(document.getElementById(c_id).checked == true) mainCheckboxs ++;
            else mainCheckboxs --;
        break;
        
        case "cb_ask_com":
            if(document.getElementById(c_id).checked == true) mainCheckboxs ++;
            else mainCheckboxs --;
        break;
        
        case "cb_google_com":
            if(document.getElementById(c_id).checked == true) mainCheckboxs++;
            else mainCheckboxs --;
        break;
        
        case "cb_yahoo_com":
            if(document.getElementById(c_id).checked == true) mainCheckboxs ++;
            else mainCheckboxs --;
        break;
    }
    
}
var _ID_o_txt_site = "";
var _ID_o_txt_site_compare = "";
var _ID_o_txt_word1 = "";
var _ID_o_txt_word2 = "";
var _ID_o_txt_word3 = "";
var _ID_o_btn_search = "";
function chkCheck()
{
    if(mainCheckboxs > 0 && document.getElementById(_ID_o_txt_site).value != "")
    {
        if(document.getElementById(_ID_o_txt_word1).value != "" || 
            document.getElementById(_ID_o_txt_word2).value != "" ||
             document.getElementById(_ID_o_txt_word3).value != "")
        {
           //var res = url_check();
           var url = document.getElementById(_ID_o_txt_site).value;
           var res = valid_url(url);
            if(res != 1)
           {
               alert("Invalid url specified!");
                return;
           }
           if(document.getElementById(_ID_o_txt_site_compare).value != "")
           {
            var urlcomp = document.getElementById(_ID_o_txt_site_compare).value;
            var rescomp = valid_url(urlcomp);
                if(rescomp != 1)
                {
                    alert("Invalid Compatitor url specified!");
                    return;
                }
           }
            jsfDo();
                
           __doPostBack(_ID_o_btn_search,'');
            CallTimer();
        }
        else window.alert("Please fill all fields!");
    }
    else window.alert("Please fill all fields!");
}

function chkCheck2()
{
      jsfDo();
       __doPostBack('ctl00_ContentPlaceHolder1_obtn_search2','');
        CallTimer();
}

function chkCheck3()
{
      jsfDo();

       __doPostBack('ctl00_ContentPlaceHolder1_btnSubmit','');

        CallTimer(); 
}

function valid_url(str)
{
		var RegExp = /^(https?:\/\/)?([a-z0-9]+[\-\.]{1})+[a-z]{2,5}/im; 
    if(RegExp.test(str)){ 
        return true; 
    }else{ 
        return false; 
    } 

}

function url_check()
{

            var url = document.getElementById('ctl00_ContentPlaceHolder1_o_txt_site').value;
            
            var iRes = url.indexOf(".", 0);
            if (iRes == -1)
            {
                return 0;
            }
            if(document.getElementById('ctl00_ContentPlaceHolder1_o_txt_site_compare').value != "")
            {
            var url2 = document.getElementById('ctl00_ContentPlaceHolder1_o_txt_site_compare').value;
                  
                var iRes = url2.indexOf(".", 0);
                if (iRes == -1)
                {
                    return 0;
                }
            }
            return 1;
}

function CallTimer()
{
       timerID = window.setTimeout("CallTimer()",1000);
        globalS++;
        if(globalS==60)
            {
                global++;
                globalS=0;
            }

         if(globalS < 10)
            txt = global + " m : 0" + globalS+" s";
         else
            txt = global + " m : " + globalS+" s";
             
         var obj = document.getElementById('td_timer')
         if (obj != null)
            obj.innerHTML =  txt;            
}
function CallTimerSecond()
{
       timerID = window.setTimeout("CallTimerSecond()",1000);
        globalS++;
        if(globalS==60)
            {
                global++;
                globalS=0;
            }
          if(globalS < 10)
          {
                txt = global + " m : 0" + globalS+" s";
            }
        else
        {
             txt = global + " m : " + globalS+" s";
        }
        
         document.getElementById('td_timer').innerHTML = txt; 
         
            
}    
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
  
function ShowHide(id)
{
    if(document.getElementById(id).style.display == "") document.getElementById(id).style.display = "none";
    else  document.getElementById(id).style.display = ""; 
}
function SendCb(x)
{
    main.SwitchCb(x,temp);
}
function temp(s)
{
    document.getElementById('td_cb_first').innerHTML = s;
} 

function jsfGo(idTD)
{
    document.getElementById('td_up').style.display = "none";
  //  document.getElementById('td_cb_first').innerHTML = "";
  //  document.getElementById('td_cb_sec').innerHTML = "";
    ShowHide('tbl_hidden_chk');
    
    if(null==(gr=document.getElementsByName('chGroup'))) return;
    
    var sResult = "<table width='100%' cellspacing=\"0\" cellpadding=\"0\" border=\"0\">" ;
    var count = 0;
    var max = 0;
    
    for(i = 0 ; i < gr.length ; i++)
    {
        if(max != 4)
        {
            if(gr[i].checked==true)
            {
                max++;
                if(count == 0) sResult += "<tr>";
                a = gr[i].value.split('$');

                sResult += "<td>";
                sResult += "<input onclick=\"jsfCheckUncheck()\" id=\"id" + a[1] + "\" type=\"checkbox\" value=\"" + a[0] + "\" name=\"chNewGroup\" /><label for=\"id" + a[1] + "\">" + a[0] + "</label>" ;
                sResult += "</td>";
                if(count == 1) 
                    {
                        sResult += "</tr>";
                        count = 0;
                    }
                    else
                    {
                    
                        count++;
                    }
            }
        }

        
    }
    
    sResult += "</table>";
    
    if(null==(o=document.getElementById(idTD))) return;
    o.innerHTML = sResult;
}

function jsfCheckUncheck()
{
    if(null==(o=document.getElementById('oTxtIDs'))) return;
    o.value = "" ;

    if(null==(gr=document.getElementsByName('chNewGroup'))) return;

    for(i = 0 ; i < gr.length; i++)
    {
        if(gr[i].checked==true)
        {
            if(o.value.length >0) o.value += '$';
            o.value += gr[i].value;
        }
    }
}
function CheckCheckBox(id)
{

    checkboxs++;
    if(checkboxs >= 5)
    {   
        alert("You have selected maximum!");
        document.getElementById(id).checked = false;
        return;
    }
}
function ProceedSecondReport()
{
    document.getElementById('td_space1').style.display = "";
    document.getElementById('td_space2').style.display = "";
    document.getElementById('td_main').style.display = "none";
    document.getElementById('td_prog').innerHTML = document.getElementById('progress').innerHTML;
    document.getElementById('td_prog').style.display = "";
}
function HideProgress()
{
    var oDiv = document.getElementById('upp1');
    oDiv.innerHTML = "";
}


function submitForm(btnId)
{
    if (event.keyCode == 13)
    {
        
        event.cancelBubble = true;
        event.returnValue = false;
        var elem = document.getElementById(btnId).click(); // getting object
     
    }
}
function submitFormTmp(e)
{
    if (e.keyCode == 13)
    {
        e.cancelBubble = true;
        e.returnValue = false;
        
       chkCheck();
    }
}

function getOnResults(googleBackLinks,yahooBackLinks, msnBackLinks, googleIndexed, yahooIndexed, msnIndexed)
{
//    this.googleB = document.getElementById(googleBackLinks);
//    this.yahooB = document.getElementById(yahooBackLinks);
//    this.msnB = document.getElementById(msnBackLinks);
    this.googleI = document.getElementById(googleIndexed);
    this.yahooI = document.getElementById(yahooIndexed);
    this.msnI = document.getElementById(msnIndexed);
    
//    setTimeout(function(){ main.GetBackLinksIndexed("1",sGooglebacklinks);},0001);
//    setTimeout(function(){ main.GetBackLinksIndexed("2",sYahoobacklinks);},0001);
//   
//    setTimeout(function(){ main.GetBackLinksIndexed("3",sMsnbacklinks);},0001);

      setTimeout(function(){ main.GetBackLinksIndexed("4",sGoogleI);},0001);
      setTimeout(function(){main.GetBackLinksIndexed("5",sYahooI);},0001);
    
 
//    setTimeout(function(){main.GetBackLinksIndexed("6",sMsnI);},0001);
    
    
//    function sGooglebacklinks(result){ this.googleB.innerHTML = result; }
//    function sYahoobacklinks(result){ this.yahooB.innerHTML = result; }
//    function sMsnbacklinks(result){ this.msnB.innerHTML = result; }
    function sGoogleI(result){ this.googleI.innerHTML = result; }
    function sYahooI(result){ this.yahooI.innerHTML = result; }
//    function sMsnI(result){ this.msnI.innerHTML = result; }
}

function beginSearch(elemId)
{
    if(elemId != "-1")
    {
        var elem = document.getElementById(elemId);
        this.elem = elem;
        this.loading = document.getElementById('loading');
        var word1 = document.getElementById('word1');
        var word2 = document.getElementById('word2');
        var word3 = document.getElementById('word3');
        if(word1.value != '' || word2.value != '' || word3.value != '')
            {
                showLoading();
                var arr = new Array(3);
                arr[0] = word1.value; arr[1] = word2.value; arr[2] = word3.value;
                proceedResults(arr,false);
                
            }
        else alert('Enter all required fields!');
      }
    else {
     var arr = new Array(3);
     arr[0] = ""; arr[1] = ""; arr[2] = "";
     proceedResults(arr,true);
    }
    function showLoading()
    {
        this.elem.style.display = 'none';
        this.loading.innerHTML = '<img style=\"margin-top:60px\" src=\"img/progress.gif\">';
    }
    
    function proceedResults(words, depth)
    {
        main.AddToResults(words, depth, succ);
        function succ(result){document.location = 'show.aspx?renew=true';}
    }
    
}



/* POPUP FUNC */
//obj - element na stranize
//cssClass - nu tut i egu ponatno
//width,height - visota i wirina
//smeshLeft,smeshRight - smesshenie v lefo i vpravo(primer: -300,897)
//title - verhnaia text (SPAN)
//desc - nignyi tekst (P)
var oDiv = null; var oSpan = null; var oDesc = null;
function RemovePopup()
{ 
    var div = document.getElementById('popupDiv');
    if (div != null)
    {

        document.body.removeChild(div);
    }
}

function Popup(obj,cssClass,width,height,smeshLeft,smeshRight,title,desc)
{
    this.className = cssClass; this.title = title; this.desc = desc;
    this.width = width; this.height = height; this.smeshLeft = smeshLeft; this.smeshRight = smeshRight;
    var arr = findPos(obj); // getting position
    
    CreateElement(arr[0],arr[1]);


    function CreateElement(left,top){
        left += this.smeshLeft; 
        top += this.smeshRight;
        
        oDiv = document.createElement("div");
        oDiv.className = this.className;
        oDiv.id = 'popupDiv';
        oDiv.style.left = left + "px"; 
        oDiv.style.top = top + "px";
        oDiv.style.width = this.width;
        oDiv.style.height = this.height;
        oDiv.onblur = function() {RemovePopup();}
         
        oSpan = document.createElement("span");
       // oSpan.removeChild(0);
        oSpan.appendChild(document.createTextNode(title));
         
        oDesc = document.createElement("p");
        //oDesc.removeChild(0);
        oDesc.appendChild(document.createTextNode(this.desc));
        
        if(oDiv.childNodes.length == 0)
        {
            oDiv.appendChild(oSpan);
            oDiv.appendChild(oDesc);
            document.body.appendChild(oDiv); 
            oDiv.focus();
        }
   }
   


    function findPos(obj) {
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
		    curleft = obj.offsetLeft;
		    curtop = obj.offsetTop;
		    while (obj = obj.offsetParent) {
			    curleft += obj.offsetLeft;
			    curtop += obj.offsetTop;
		    }
	    }
	    return [curleft,curtop];
    }
    
    function specifyRow(){
        
        var x=document.getElementById('ctl00_ContentPlaceHolder1_oDivchklstKeyWordsKeywordWiz')
        /*alert(x);*/
        x.height="100"
    }
}

function copyToClipboard(field)
{
    var content = document.getElementById(field)
    content.focus()
    content.select()
    range = content.createTextRange()
    range.execCommand("Copy")    
    setTimeout("window.status=''",1800)
}