function trim(str){
    return str.replace(/^\s+|\s+$/g,"");
}

$(document).ready(function() {    
    //hide the goTop button if the content height is less then 400px;
    if($("#containerInternContent").height()<450) {
        $("#goTop").hide('slow');   
    }
    
    
    var textToSearch=$("input#query").val();
    if($.trim(textToSearch)!="")
        $("input#TextToSearch").val(textToSearch);
    
});

function collbackRedirCurrent(v,m,f){
    //when user close the AlertBox::WithCollback_1btn (no matter how), is redirected to the initial state of the page
    window.location = 'index.php';
}


/*
 *Javascript equivalent function of php AlertBox::Error() function
 **/
function JsAlertBox_Error(htmlMessage, site_folder){
    htmlMessage='<div style="text-align:center; color:red;">'+htmlMessage+'</div>';
    htmlMessage+='<img src="'+site_folder+'/_Images/impromptu/icon_error.png" alt="Error" class="helpImg"/>';
    $.prompt(htmlMessage,{ opacity: 0.7 });
}
/*
 *Javascript equivalent function of php AlertBox::Warning() function
 **/
function JsAlertBox_Warning(htmlMessage, site_folder){
    htmlMessage='<div style="text-align:center;">'+htmlMessage+'</div>';
    htmlMessage+='<img src="'+site_folder+'/_Images/impromptu/icon_warning.png" alt="Warning" class="helpImg"/>';
    $.prompt(htmlMessage,{ opacity: 0.7 });
}
/*
 *Javascript equivalent function of php AlertBox::Inform() function
 **/
function JsAlertBox_Inform(htmlMessage, site_folder){
    htmlMessage='<div style="color:green;">'+htmlMessage+'</div>';
    htmlMessage+='<img src="'+site_folder+'/_Images/impromptu/icon_inform.png" alt="Inform" class="helpImg"/>';
    $.prompt(htmlMessage,{ opacity: 0.7 });
}
/*
 *Javascript equivalent function of php AlertBox::WithCollback_1btn() function
 *Example: JsAlertBox_WithAction('<?=$htmlInformMessage?>', mycallbackfunction, '<?=$CFG->site_folder?>'); return true;
 **/
function JsAlertBox_WithCollback_1btn(htmlMessage, collbackfunction, site_folder){
    htmlMessage='<div style="text-align:center; color:blue;">'+htmlMessage+'</div>';
    htmlMessage+='<img src="'+site_folder+'/_Images/impromptu/icon_confirm.png" alt="Confirm" class="helpImg"/>';
    $.prompt(htmlMessage,{ callback: collbackfunction });
}
/*
 *Javascript equivalent function of php AlertBox::WithCollback_2btn() function
 *Example: JsAlertBox_WithAction('<?=$htmlInformMessage?>', mycallbackfunction, '<?=$CFG->site_folder?>'); return true;
 **/
function JsAlertBox_WithCollback_2btn(htmlMessage, collbackfunction, site_folder){
    htmlMessage='<div style="text-align:center; color:blue;">'+htmlMessage+'</div>';
    htmlMessage+='<img src="'+site_folder+'/_Images/impromptu/icon_confirm.png" alt="Confirm" class="helpImg"/>';
    $.prompt(htmlMessage,{ callback: collbackfunction, buttons:{Yes: 'Yes', No: 'No'}, focus:1 });
}



//necessary for the search functionality
function FirstFocus() {    
    //apply trim function
    text_de_cautat = document.getElementById('TextToSearch').value.replace(/^\s+|\s+$/g, "");
    if (text_de_cautat == "Search |") {
        document.getElementById('TextToSearch').value = "";
    }
}
function OnBlure() {
    //apply trim function
    text_de_cautat = document.getElementById('TextToSearch').value.replace(/^\s+|\s+$/g, "");
    if (text_de_cautat == "") {
        document.getElementById('TextToSearch').value = "Search |";
    }
}



function SearchKeyPress(event) { 
    //if ENTER was press in search input or CLICK button for search then do the action
    if (event.keyCode == 13 || event.type=='click') {
        //daca am apasat enter atunci aplic cautarea   
        text_de_cautat_trim = document.getElementById('TextToSearch').value.replace(/^\s+|\s+$/g, "");
        text_de_cautat = text_de_cautat_trim.replace(/ /gi, "+");  //inlocuiesc spatiile cu +

        if(text_de_cautat!="" && text_de_cautat!="Search+|"){
            event.returnValue = false;
            event.cancel = true;
            window.open('/newversion/search/search.php?query=' + text_de_cautat+'&search=1','_blank');
            //window.location.href = "/PaatronatSfera/Search.aspx?ksearch=" + text_de_cautat;
        }
        return false;
    }
}



function divizii_over(old_src_img, new_img) {
    var new_src = old_src_img.src.substring(0, old_src_img.src.lastIndexOf("/"));
    new_src += "/" + new_img;
    old_src_img.src = new_src;
}


























/*
 *
function trimitePeEmail()
{
    var url=location.href;    
    //testwindow= window.open ("/PatronatSfera/TrimitePeMail.aspx?loc="+url, "TrimitePeMail","'left=20, top=20, width=730, height=510, resizable=0, menubar=0");    
    
    var form = document.createElement("form"); 
    form.setAttribute("method", "post"); 
    form.setAttribute("action", "/PatronatSfera/TrimitePeMail.aspx");
    
    var hiddenField = document.createElement("input"); 
    hiddenField.setAttribute("type", "hidden"); 
    hiddenField.setAttribute("name", "fromUrl"); 
    hiddenField.setAttribute("value", url); 
    
    form.appendChild(hiddenField); 
 
    document.body.appendChild(form);
    form.submit(); 
}    

function printVersion()
{    
    var url=location.href;    
    //continutul ce se gaseste in diviziunea 'continutAndPrint' se va afisa efectiv pentru printare
    var continutPrint=document.getElementById('continutAndPrint').innerHTML;
    
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", "/PatronatSfera/PrintVersion.aspx");
    
    var hiddenField = document.createElement("input"); 
    hiddenField.setAttribute("type", "hidden"); 
    hiddenField.setAttribute("name", "fromUrl"); 
    hiddenField.setAttribute("value", url);
    form.appendChild(hiddenField); 
    
    var hiddenField = document.createElement("input"); 
    hiddenField.setAttribute("type", "hidden"); 
    hiddenField.setAttribute("name", "printContent"); 
    hiddenField.setAttribute("value", continutPrint);   
    form.appendChild(hiddenField); 
 
    document.body.appendChild(form);
    form.submit();
}

*/

