﻿// JScript File


function controlClickSTF(obj)
{
    method = "controlClickSTF";
    if((obj.id=="txtCustName" && obj.value==yourNameSF) || (obj.id=="txtCustEmail" && obj.value==yourEmailSF)
    || (obj.id=="txtFrComment" && obj.value==writeMessageSF) || (obj.id=="txtFriendEmail" && obj.value==yourFriendsEmailSF))
    {
        obj.value="";
    }
    method = null;
}
function controlBlurSTF(obj)
{
    method = "controlBlurSTF";
    if(obj.id=="txtCustName" && obj.value==""){
        obj.value=yourNameSF;}
    else if(obj.id=="txtCustEmail" && obj.value=="")
        obj.value=yourEmailSF;
    else if(obj.id=="txtFriendEmail" && obj.value=="")
        obj.value=yourFriendsEmailSF;
    else if(obj.id=="txtFrComment" && obj.value=="")
        obj.value=writeMessageSF;
    method = null;
}

function controlFocusSTF(obj)
{
    method = "controlFocusSTF";
    obj.select();
    method = null;
}

function checkValidSTF(value,control,criteria)
{
    method = "checkValid";
    var retVal="ok";
    var val=new String();
    val=value;
    var DefaultValue='';
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(criteria==criNameSF)
    {
        DefaultValue=yourNameSF;
    }
    else if(criteria==yourFriendsEmailSF)
    {
        DefaultValue=yourFriendsEmailSF;
        if(val.indexOf("@")==-1 || filter.test(val) == false)val=yourFriendsEmailSF;
    }
    else if(criteria==criEmailSF)
    {
        DefaultValue=yourEmailSF;
        if(val.indexOf("@")==-1 || filter.test(val) == false)val=yourEmailSF;
    }
    else if(criteria==criCommentSF)
    {
        DefaultValue=writeMessageSF;
    }
    if(val==null || val=="" || (val.indexOf(DefaultValue)!=-1))
    {
        retVal=pleaseFillInSF + " " + criteria ;
        alert(retVal);
        control.focus();
    }
    method = null;
    return retVal;
}




function SendEmailToFriend()
{


    method = "SendEmailToFriend";
	
   var name= document.getElementById("txtCustName").value;

   var email=document.getElementById("txtCustEmail").value;

   var message=document.getElementById("txtComment").value;

   var fmail=document.getElementById("txtFriendEmail").value;

   var PageUrl;
   var CarRegNr;
  

	if(document.getElementById('ifrmDetailView') != null)
        CarRegNr = document.getElementById('ifrmDetailView').contentWindow['CarRegNr'];


    if(typeof(CarRegNr) != "undefined")
        PageUrl ="http://www.holmgrensbil.se/web/searchall.aspx?regnr=" + CarRegNr ;
    else    
        PageUrl = window.location.href;
    
   if(checkValidSTF(name,document.getElementById("txtCustName"),criNameSF)!="ok") return;
   if(checkValidSTF(email,document.getElementById("txtCustEmail"),criEmailSF)!="ok") return;
   if(checkValidSTF(fmail,document.getElementById("txtFriendEmail"),yourFriendsEmailSF)!="ok") return;
   if(checkValidSTF(message,document.getElementById("txtComment"),criCommentSF)!="ok") return;
   
  ClientClickHandlerSendToFriend.SendMailToFriend(name,email,fmail,PageUrl, message,sendMesageToFriendCallBack);
  
     var checkBox = document.getElementById("chkComment");
     if(checkBox!= null && typeof(checkBox) != "undefined")
     {
        if(checkBox.checked)
        {
            ClickHandlerPublic.NewsLetterInsert(email);
        }
     }
   window.status=plsWaitSF;

method = null; 
}


function sendMesageToFriendCallBack(response)
{
    method = "sendMesageToFriendCallBack";
    var retVal=response.value;    
    if(retVal=="ok")
    {
         window.status=thankYouMessageSF;
        alert(thankYouMessageSF);
        
        
        
    }
    else
    {
        window.status=errorMessageSF;
        alert(errorMessageSF);       
    }
    document.getElementById("form1").reset();
    closeWindow();
    method = null;
}

function showSendToFriend()
{
    var obj = document.getElementById("sendtoFriend");
    obj.style.width="280px";
    obj.style.height="220px";
    obj.style.top = "25px";
    obj.style.right = "0px";
    obj.style.display="block";
    obj.style.background="#fff";
    
}


function closeWindow()
{
     var obj = document.getElementById("sendtoFriend");
     obj.style.display="none";
}



// Source for share linl:  http://www.purpleindigo.co.cc/2009/05/07/simply-share-to-twitter-with-just-a-bookmarklet/
 function fbs_click() 
{
method='fbs_click';
    u=location.href;
    if(location.href.toLowerCase().indexOf("searchall.aspx")>-1)
    {
        var CarRegNr;
        if(document.getElementById('ifrmDetailView') != null)
            CarRegNr = document.getElementById('ifrmDetailView').contentWindow['CarRegNr'];


        if(typeof(CarRegNr) != "undefined")
            u ="http://www.holmgrensbil.se/web/searchall.aspx?regnr=" + CarRegNr ;     
   }
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}
    
function blogger_click()
{
    method='blogger_click';
    u=location.href;
    if(location.href.toLowerCase().indexOf("searchall.aspx")>-1)
    {
        var CarRegNr;
        if(document.getElementById('ifrmDetailView') != null)
            CarRegNr = document.getElementById('ifrmDetailView').contentWindow['CarRegNr'];


        if(typeof(CarRegNr) != "undefined")
            u ="http://www.holmgrensbil.se/web/searchall.aspx?regnr=" + CarRegNr ;     
   }
    t=document.title;
    h = "<a href='" +u + "' target='_blank'>"+t+"</a>";
        window.open('http://www.addthis.com/bookmark.php?v=250&winname=addthis&pub=xa-4a2d675d11a52fb0&source=max-250&lng=en-US&s=blogger&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t)+'&html=' +encodeURIComponent(h), 'sharer','toolbar=no,width=1000,height=400,scrollbars=1,resizable=1');

   // window.open('https://ws.addthis.com/share/v2/facade?dest=blogger&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t)+'&html=' +encodeURIComponent(h), 'sharer','toolbar=no,width=1000,height=400,scrollbars=1,resizable=1');
    return false;
}


function bookmark()
{

    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    if (is_chrome == true) {
        alert('Tryck Ctrl+d för att lägga till denna sida som bokmärke.');
        return;
    }

    u=location.href;
    t=document.title;
    if(location.href.toLowerCase().indexOf("searchall.aspx")>-1)
    {
        var CarRegNr;
        if(document.getElementById('ifrmDetailView') != null)
            CarRegNr = document.getElementById('ifrmDetailView').contentWindow['CarRegNr'];


        if(typeof(CarRegNr) != "undefined")
            u ="http://www.holmgrensbil.se/web/searchall.aspx?regnr=" + CarRegNr ;     
   }
    if (document.all)
        window.external.AddFavorite(u,t)
    else if (window.sidebar) // firefox
        window.sidebar.addPanel(t, u, "");
}


function twitter_click()
{
    method='twitter_click';
    u=location.href;
    if(location.href.toLowerCase().indexOf("searchall.aspx")>-1)
    {
        var CarRegNr;
        if(document.getElementById('ifrmDetailView') != null)
            CarRegNr = document.getElementById('ifrmDetailView').contentWindow['CarRegNr'];


        if(typeof(CarRegNr) != "undefined")
            u ="http://www.holmgrensbil.se/web/searchall.aspx?regnr=" + CarRegNr ;     
   }
    window.open('http://twitter.com/home?status='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=830,height=430');
    return false;
}

